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;
34 // A custom scrollable view implementation for the dialog.
35 class CustomScrollableView : public views::View {
37 CustomScrollableView();
38 virtual ~CustomScrollableView();
41 virtual void Layout() OVERRIDE;
43 DISALLOW_COPY_AND_ASSIGN(CustomScrollableView);
46 // Implements the extension installation dialog for TOOLKIT_VIEWS.
47 class ExtensionInstallDialogView : public views::DialogDelegateView,
48 public views::LinkListener,
49 public views::ButtonListener {
51 ExtensionInstallDialogView(
52 content::PageNavigator* navigator,
53 ExtensionInstallPrompt::Delegate* delegate,
54 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
55 virtual ~ExtensionInstallDialogView();
57 // Returns the interior ScrollView of the dialog. This allows us to inspect
58 // the contents of the DialogView.
59 const views::ScrollView* scroll_view() const { return scroll_view_; }
61 // Called when one of the child elements has expanded/collapsed.
62 void ContentsChanged();
65 // views::DialogDelegateView:
66 virtual int GetDialogButtons() const OVERRIDE;
67 virtual base::string16 GetDialogButtonLabel(
68 ui::DialogButton button) const OVERRIDE;
69 virtual int GetDefaultDialogButton() const OVERRIDE;
70 virtual bool Cancel() OVERRIDE;
71 virtual bool Accept() OVERRIDE;
72 virtual ui::ModalType GetModalType() const OVERRIDE;
73 virtual base::string16 GetWindowTitle() const OVERRIDE;
74 virtual void Layout() OVERRIDE;
75 virtual gfx::Size GetPreferredSize() const OVERRIDE;
76 virtual void ViewHierarchyChanged(
77 const ViewHierarchyChangedDetails& details) OVERRIDE;
79 // views::LinkListener:
80 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
82 // views::ButtonListener:
83 virtual void ButtonPressed(views::Button* sender,
84 const ui::Event& event) OVERRIDE;
86 // Experimental: Toggles inline permission explanations with an animation.
87 void ToggleInlineExplanations();
89 // Creates a layout consisting of dialog header, extension name and icon.
90 views::GridLayout* CreateLayout(
92 int left_column_width,
94 bool single_detail_row) const;
96 bool is_inline_install() const {
97 return prompt_->type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT;
100 bool is_bundle_install() const {
101 return prompt_->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT;
104 bool is_external_install() const {
105 return prompt_->type() == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT;
108 // Updates the histogram that holds installation accepted/aborted data.
109 void UpdateInstallResultHistogram(bool accepted) const;
111 // Updates the histogram that holds data about whether "Show details" or
112 // "Show permissions" links were shown and/or clicked.
113 void UpdateLinkActionHistogram(int action_type) const;
115 content::PageNavigator* navigator_;
116 ExtensionInstallPrompt::Delegate* delegate_;
117 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_;
119 // The scroll view containing all the details for the dialog (including all
120 // collapsible/expandable sections).
121 views::ScrollView* scroll_view_;
123 // The container view for the scroll view.
124 CustomScrollableView* scrollable_;
126 // The container for the simpler view with only the dialog header and the
127 // extension icon. Used for the experiment where the permissions are
128 // initially hidden when the dialog shows.
129 CustomScrollableView* scrollable_header_only_;
131 // The preferred size of the dialog.
132 gfx::Size dialog_size_;
134 // Experimental: "Show details" link to expand inline explanations and reveal
136 views::Link* show_details_link_;
138 // Experimental: Label for showing information about the checkboxes.
139 views::Label* checkbox_info_label_;
141 // Experimental: Contains pointers to inline explanation views.
142 typedef std::vector<ExpandableContainerView*> InlineExplanations;
143 InlineExplanations inline_explanations_;
145 // Experimental: Number of unchecked checkboxes in the permission list.
146 // If this becomes zero, the accept button is enabled, otherwise disabled.
147 int unchecked_boxes_;
149 // ExperienceSampling: Track this UI event.
150 scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
152 // Set to true once the user's selection has been received and the
153 // |delegate_| has been notified.
154 bool handled_result_;
156 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView);
159 // A simple view that prepends a view with a bullet with the help of a grid
161 class BulletedView : public views::View {
163 explicit BulletedView(views::View* view);
165 DISALLOW_COPY_AND_ASSIGN(BulletedView);
168 // A simple view that prepends a view with a checkbox with the help of a grid
169 // layout. Used for the permission experiment.
170 // TODO(meacer): Remove once the experiment is completed.
171 class CheckboxedView : public views::View {
173 CheckboxedView(views::View* view, views::ButtonListener* listener);
175 DISALLOW_COPY_AND_ASSIGN(CheckboxedView);
178 // A view to display text with an expandable details section.
179 class ExpandableContainerView : public views::View,
180 public views::ButtonListener,
181 public views::LinkListener,
182 public gfx::AnimationDelegate {
184 ExpandableContainerView(ExtensionInstallDialogView* owner,
185 const base::string16& description,
186 const PermissionDetails& details,
187 int horizontal_space,
188 bool parent_bulleted,
189 bool show_expand_link,
190 bool lighter_color_details);
191 virtual ~ExpandableContainerView();
194 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
196 // views::ButtonListener:
197 virtual void ButtonPressed(views::Button* sender,
198 const ui::Event& event) OVERRIDE;
200 // views::LinkListener:
201 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
203 // gfx::AnimationDelegate:
204 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
205 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
207 // Expand/Collapse the detail section for this ExpandableContainerView.
208 void ToggleDetailLevel();
210 // Expand the detail section without any animation.
211 // TODO(meacer): Remove once the experiment is completed.
212 void ExpandWithoutAnimation();
215 // A view which displays all the details of an IssueAdviceInfoEntry.
216 class DetailsView : public views::View {
218 explicit DetailsView(int horizontal_space, bool parent_bulleted,
220 virtual ~DetailsView() {}
223 virtual gfx::Size GetPreferredSize() const OVERRIDE;
225 void AddDetail(const base::string16& detail);
227 // Animates this to be a height proportional to |state|.
228 void AnimateToState(double state);
231 views::GridLayout* layout_;
234 // Whether the detail text should be shown with a lighter color.
237 DISALLOW_COPY_AND_ASSIGN(DetailsView);
240 // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
241 ExtensionInstallDialogView* owner_;
243 // A view for showing |issue_advice.details|.
244 DetailsView* details_view_;
246 // The 'more details' link shown under the heading (changes to 'hide details'
247 // when the details section is expanded).
248 views::Link* more_details_;
250 gfx::SlideAnimation slide_animation_;
252 // The up/down arrow next to the 'more detail' link (points up/down depending
253 // on whether the details section is expanded).
254 views::ImageButton* arrow_toggle_;
256 // Whether the details section is expanded.
259 DISALLOW_COPY_AND_ASSIGN(ExpandableContainerView);
262 void ShowExtensionInstallDialogImpl(
263 const ExtensionInstallPrompt::ShowParams& show_params,
264 ExtensionInstallPrompt::Delegate* delegate,
265 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
267 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_