1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_
8 #include "chrome/browser/extensions/extension_install_prompt.h"
9 #include "ui/gfx/animation/animation_delegate.h"
10 #include "ui/gfx/animation/slide_animation.h"
11 #include "ui/views/controls/button/button.h"
12 #include "ui/views/controls/link_listener.h"
13 #include "ui/views/view.h"
14 #include "ui/views/window/dialog_delegate.h"
16 typedef std::vector<base::string16> PermissionDetails;
17 class ExpandableContainerView;
23 namespace extensions {
24 class ExperienceSamplingEvent;
38 // A custom scrollable view implementation for the dialog.
39 class CustomScrollableView : public views::View {
41 CustomScrollableView();
42 virtual ~CustomScrollableView();
45 virtual void Layout() OVERRIDE;
47 DISALLOW_COPY_AND_ASSIGN(CustomScrollableView);
50 // Implements the extension installation dialog for TOOLKIT_VIEWS.
51 class ExtensionInstallDialogView : public views::DialogDelegateView,
52 public views::LinkListener,
53 public views::ButtonListener {
55 ExtensionInstallDialogView(
56 content::PageNavigator* navigator,
57 ExtensionInstallPrompt::Delegate* delegate,
58 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
59 virtual ~ExtensionInstallDialogView();
61 // Returns the interior ScrollView of the dialog. This allows us to inspect
62 // the contents of the DialogView.
63 const views::ScrollView* scroll_view() const { return scroll_view_; }
65 // Called when one of the child elements has expanded/collapsed.
66 void ContentsChanged();
69 // views::DialogDelegateView:
70 virtual int GetDialogButtons() const OVERRIDE;
71 virtual base::string16 GetDialogButtonLabel(
72 ui::DialogButton button) const OVERRIDE;
73 virtual int GetDefaultDialogButton() const OVERRIDE;
74 virtual bool Cancel() OVERRIDE;
75 virtual bool Accept() OVERRIDE;
76 virtual ui::ModalType GetModalType() const OVERRIDE;
77 virtual base::string16 GetWindowTitle() const OVERRIDE;
78 virtual void Layout() OVERRIDE;
79 virtual gfx::Size GetPreferredSize() const OVERRIDE;
80 virtual void ViewHierarchyChanged(
81 const ViewHierarchyChangedDetails& details) OVERRIDE;
83 // views::LinkListener:
84 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
86 // views::ButtonListener:
87 virtual void ButtonPressed(views::Button* sender,
88 const ui::Event& event) OVERRIDE;
90 // Experimental: Toggles inline permission explanations with an animation.
91 void ToggleInlineExplanations();
93 // Initializes the dialog view, adding in permissions if they exist.
96 // Adds permissions of |perm_type| to the dialog view if they exist.
97 bool AddPermissions(views::GridLayout* layout,
98 ui::ResourceBundle& rb,
100 int left_column_width,
101 ExtensionInstallPrompt::PermissionsType perm_type);
103 // Creates a layout consisting of dialog header, extension name and icon.
104 views::GridLayout* CreateLayout(
106 int left_column_width,
108 bool single_detail_row) const;
110 bool is_inline_install() const {
111 return prompt_->type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT;
114 bool is_bundle_install() const {
115 return prompt_->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT;
118 bool is_external_install() const {
119 return prompt_->type() == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT;
122 // Updates the histogram that holds installation accepted/aborted data.
123 void UpdateInstallResultHistogram(bool accepted) const;
125 // Updates the histogram that holds data about whether "Show details" or
126 // "Show permissions" links were shown and/or clicked.
127 void UpdateLinkActionHistogram(int action_type) const;
129 content::PageNavigator* navigator_;
130 ExtensionInstallPrompt::Delegate* delegate_;
131 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_;
133 // The scroll view containing all the details for the dialog (including all
134 // collapsible/expandable sections).
135 views::ScrollView* scroll_view_;
137 // The container view for the scroll view.
138 CustomScrollableView* scrollable_;
140 // The container for the simpler view with only the dialog header and the
141 // extension icon. Used for the experiment where the permissions are
142 // initially hidden when the dialog shows.
143 CustomScrollableView* scrollable_header_only_;
145 // The preferred size of the dialog.
146 gfx::Size dialog_size_;
148 // Experimental: "Show details" link to expand inline explanations and reveal
150 views::Link* show_details_link_;
152 // Experimental: Label for showing information about the checkboxes.
153 views::Label* checkbox_info_label_;
155 // Experimental: Contains pointers to inline explanation views.
156 typedef std::vector<ExpandableContainerView*> InlineExplanations;
157 InlineExplanations inline_explanations_;
159 // Experimental: Number of unchecked checkboxes in the permission list.
160 // If this becomes zero, the accept button is enabled, otherwise disabled.
161 int unchecked_boxes_;
163 // ExperienceSampling: Track this UI event.
164 scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
166 // Set to true once the user's selection has been received and the
167 // |delegate_| has been notified.
168 bool handled_result_;
170 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView);
173 // A simple view that prepends a view with a bullet with the help of a grid
175 class BulletedView : public views::View {
177 explicit BulletedView(views::View* view);
179 DISALLOW_COPY_AND_ASSIGN(BulletedView);
182 // A simple view that prepends a view with a checkbox with the help of a grid
183 // layout. Used for the permission experiment.
184 // TODO(meacer): Remove once the experiment is completed.
185 class CheckboxedView : public views::View {
187 CheckboxedView(views::View* view, views::ButtonListener* listener);
189 DISALLOW_COPY_AND_ASSIGN(CheckboxedView);
192 // A view to display text with an expandable details section.
193 class ExpandableContainerView : public views::View,
194 public views::ButtonListener,
195 public views::LinkListener,
196 public gfx::AnimationDelegate {
198 ExpandableContainerView(ExtensionInstallDialogView* owner,
199 const base::string16& description,
200 const PermissionDetails& details,
201 int horizontal_space,
202 bool parent_bulleted,
203 bool show_expand_link,
204 bool lighter_color_details);
205 virtual ~ExpandableContainerView();
208 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
210 // views::ButtonListener:
211 virtual void ButtonPressed(views::Button* sender,
212 const ui::Event& event) OVERRIDE;
214 // views::LinkListener:
215 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
217 // gfx::AnimationDelegate:
218 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
219 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
221 // Expand/Collapse the detail section for this ExpandableContainerView.
222 void ToggleDetailLevel();
224 // Expand the detail section without any animation.
225 // TODO(meacer): Remove once the experiment is completed.
226 void ExpandWithoutAnimation();
229 // A view which displays all the details of an IssueAdviceInfoEntry.
230 class DetailsView : public views::View {
232 explicit DetailsView(int horizontal_space, bool parent_bulleted,
234 virtual ~DetailsView() {}
237 virtual gfx::Size GetPreferredSize() const OVERRIDE;
239 void AddDetail(const base::string16& detail);
241 // Animates this to be a height proportional to |state|.
242 void AnimateToState(double state);
245 views::GridLayout* layout_;
248 // Whether the detail text should be shown with a lighter color.
251 DISALLOW_COPY_AND_ASSIGN(DetailsView);
254 // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
255 ExtensionInstallDialogView* owner_;
257 // A view for showing |issue_advice.details|.
258 DetailsView* details_view_;
260 // The 'more details' link shown under the heading (changes to 'hide details'
261 // when the details section is expanded).
262 views::Link* more_details_;
264 gfx::SlideAnimation slide_animation_;
266 // The up/down arrow next to the 'more detail' link (points up/down depending
267 // on whether the details section is expanded).
268 views::ImageButton* arrow_toggle_;
270 // Whether the details section is expanded.
273 DISALLOW_COPY_AND_ASSIGN(ExpandableContainerView);
276 void ShowExtensionInstallDialogImpl(
277 const ExtensionInstallPrompt::ShowParams& show_params,
278 ExtensionInstallPrompt::Delegate* delegate,
279 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
281 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_