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 ExtensionInstallPromptShowParams
;
24 namespace extensions
{
25 class ExperienceSamplingEvent
;
39 // A custom scrollable view implementation for the dialog.
40 class CustomScrollableView
: public views::View
{
42 CustomScrollableView();
43 ~CustomScrollableView() override
;
46 void Layout() override
;
48 DISALLOW_COPY_AND_ASSIGN(CustomScrollableView
);
51 // Implements the extension installation dialog for TOOLKIT_VIEWS.
52 class ExtensionInstallDialogView
: public views::DialogDelegateView
,
53 public views::LinkListener
{
55 ExtensionInstallDialogView(
57 content::PageNavigator
* navigator
,
58 ExtensionInstallPrompt::Delegate
* delegate
,
59 scoped_refptr
<ExtensionInstallPrompt::Prompt
> prompt
);
60 ~ExtensionInstallDialogView() override
;
62 // Returns the interior ScrollView of the dialog. This allows us to inspect
63 // the contents of the DialogView.
64 const views::ScrollView
* scroll_view() const { return scroll_view_
; }
66 // Called when one of the child elements has expanded/collapsed.
67 void ContentsChanged();
70 // views::DialogDelegateView:
71 int GetDialogButtons() const override
;
72 base::string16
GetDialogButtonLabel(ui::DialogButton button
) const override
;
73 int GetDefaultDialogButton() const override
;
74 bool Cancel() override
;
75 bool Accept() override
;
76 ui::ModalType
GetModalType() const override
;
77 base::string16
GetWindowTitle() const override
;
78 void Layout() override
;
79 gfx::Size
GetPreferredSize() const override
;
81 // views::LinkListener:
82 void LinkClicked(views::Link
* source
, int event_flags
) override
;
84 // Initializes the dialog view, adding in permissions if they exist.
87 // Adds permissions of |perm_type| to the dialog view if they exist.
88 bool AddPermissions(views::GridLayout
* layout
,
89 ui::ResourceBundle
& rb
,
91 int left_column_width
,
92 ExtensionInstallPrompt::PermissionsType perm_type
);
94 // Creates a layout consisting of dialog header, extension name and icon.
95 views::GridLayout
* CreateLayout(
97 int left_column_width
,
99 bool single_detail_row
) const;
101 bool is_inline_install() const {
102 return prompt_
->type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT
;
105 bool is_bundle_install() const {
106 return prompt_
->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT
;
109 bool is_external_install() const {
110 return prompt_
->type() == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT
;
113 // Updates the histogram that holds installation accepted/aborted data.
114 void UpdateInstallResultHistogram(bool accepted
) const;
117 content::PageNavigator
* navigator_
;
118 ExtensionInstallPrompt::Delegate
* delegate_
;
119 scoped_refptr
<ExtensionInstallPrompt::Prompt
> prompt_
;
121 // The scroll view containing all the details for the dialog (including all
122 // collapsible/expandable sections).
123 views::ScrollView
* scroll_view_
;
125 // The container view for the scroll view.
126 CustomScrollableView
* scrollable_
;
128 // The preferred size of the dialog.
129 gfx::Size dialog_size_
;
131 // ExperienceSampling: Track this UI event.
132 scoped_ptr
<extensions::ExperienceSamplingEvent
> sampling_event_
;
134 // Set to true once the user's selection has been received and the
135 // |delegate_| has been notified.
136 bool handled_result_
;
138 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView
);
141 // A simple view that prepends a view with a bullet with the help of a grid
143 class BulletedView
: public views::View
{
145 explicit BulletedView(views::View
* view
);
147 DISALLOW_COPY_AND_ASSIGN(BulletedView
);
150 // A view to display text with an expandable details section.
151 class ExpandableContainerView
: public views::View
,
152 public views::ButtonListener
,
153 public views::LinkListener
,
154 public gfx::AnimationDelegate
{
156 ExpandableContainerView(ExtensionInstallDialogView
* owner
,
157 const base::string16
& description
,
158 const PermissionDetails
& details
,
159 int horizontal_space
,
160 bool parent_bulleted
);
161 ~ExpandableContainerView() override
;
164 void ChildPreferredSizeChanged(views::View
* child
) override
;
166 // views::ButtonListener:
167 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
;
169 // views::LinkListener:
170 void LinkClicked(views::Link
* source
, int event_flags
) override
;
172 // gfx::AnimationDelegate:
173 void AnimationProgressed(const gfx::Animation
* animation
) override
;
174 void AnimationEnded(const gfx::Animation
* animation
) override
;
177 // A view which displays all the details of an IssueAdviceInfoEntry.
178 class DetailsView
: public views::View
{
180 DetailsView(int horizontal_space
, bool parent_bulleted
);
181 ~DetailsView() override
{}
184 gfx::Size
GetPreferredSize() const override
;
186 void AddDetail(const base::string16
& detail
);
188 // Animates this to be a height proportional to |state|.
189 void AnimateToState(double state
);
192 views::GridLayout
* layout_
;
195 DISALLOW_COPY_AND_ASSIGN(DetailsView
);
198 // Expand/Collapse the detail section for this ExpandableContainerView.
199 void ToggleDetailLevel();
201 // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
202 ExtensionInstallDialogView
* owner_
;
204 // A view for showing |issue_advice.details|.
205 DetailsView
* details_view_
;
207 gfx::SlideAnimation slide_animation_
;
209 // The 'more details' link shown under the heading (changes to 'hide details'
210 // when the details section is expanded).
211 views::Link
* more_details_
;
213 // The up/down arrow next to the 'more detail' link (points up/down depending
214 // on whether the details section is expanded).
215 views::ImageButton
* arrow_toggle_
;
217 // Whether the details section is expanded.
220 DISALLOW_COPY_AND_ASSIGN(ExpandableContainerView
);
223 void ShowExtensionInstallDialogImpl(
224 ExtensionInstallPromptShowParams
* show_params
,
225 ExtensionInstallPrompt::Delegate
* delegate
,
226 scoped_refptr
<ExtensionInstallPrompt::Prompt
> prompt
);
228 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_