Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / views / extensions / extension_install_dialog_view.h
blob0e81c852e7185b213e7d19a2865cec72b69740b8
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 Profile;
19 namespace content {
20 class PageNavigator;
23 namespace extensions {
24 class ExperienceSamplingEvent;
27 namespace ui {
28 class ResourceBundle;
31 namespace views {
32 class GridLayout;
33 class ImageButton;
34 class Link;
37 // Implements the extension installation dialog for TOOLKIT_VIEWS.
38 class ExtensionInstallDialogView : public views::DialogDelegateView,
39 public views::LinkListener {
40 public:
41 ExtensionInstallDialogView(
42 Profile* profile,
43 content::PageNavigator* navigator,
44 ExtensionInstallPrompt::Delegate* delegate,
45 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
46 ~ExtensionInstallDialogView() override;
48 // Returns the interior ScrollView of the dialog. This allows us to inspect
49 // the contents of the DialogView.
50 const views::ScrollView* scroll_view() const { return scroll_view_; }
52 private:
53 // views::DialogDelegateView:
54 int GetDialogButtons() const override;
55 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override;
56 int GetDefaultDialogButton() const override;
57 bool Cancel() override;
58 bool Accept() override;
59 ui::ModalType GetModalType() const override;
60 void Layout() override;
61 gfx::Size GetPreferredSize() const override;
63 // views::LinkListener:
64 void LinkClicked(views::Link* source, int event_flags) override;
66 // Initializes the dialog view, adding in permissions if they exist.
67 void InitView();
69 // Adds permissions of |perm_type| to the dialog view if they exist.
70 bool AddPermissions(views::GridLayout* layout,
71 ui::ResourceBundle& rb,
72 int column_set_id,
73 int left_column_width,
74 ExtensionInstallPrompt::PermissionsType perm_type);
76 // Creates a layout consisting of dialog header, extension name and icon.
77 views::GridLayout* CreateLayout(int left_column_width, int column_set_id);
79 bool is_bundle_install() const {
80 return prompt_->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT ||
81 prompt_->type() ==
82 ExtensionInstallPrompt::DELEGATED_BUNDLE_PERMISSIONS_PROMPT;
85 bool is_external_install() const {
86 return prompt_->type() == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT;
89 // Updates the histogram that holds installation accepted/aborted data.
90 void UpdateInstallResultHistogram(bool accepted) const;
92 Profile* profile_;
93 content::PageNavigator* navigator_;
94 ExtensionInstallPrompt::Delegate* delegate_;
95 scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_;
97 // The container view that contains all children (heading, icon, webstore
98 // data, and the scroll view with permissions etc.), excluding the buttons,
99 // which are added automatically by the dialog system.
100 View* container_;
102 // The scroll view containing all the details for the dialog (including all
103 // collapsible/expandable sections).
104 views::ScrollView* scroll_view_;
106 // The preferred size of the dialog.
107 gfx::Size dialog_size_;
109 // ExperienceSampling: Track this UI event.
110 scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
112 // Set to true once the user's selection has been received and the
113 // |delegate_| has been notified.
114 bool handled_result_;
116 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView);
119 // A simple view that prepends a view with a bullet with the help of a grid
120 // layout.
121 class BulletedView : public views::View {
122 public:
123 explicit BulletedView(views::View* view);
124 private:
125 DISALLOW_COPY_AND_ASSIGN(BulletedView);
128 // A simple view that prepends a view with an icon with the help of a grid
129 // layout.
130 class IconedView : public views::View {
131 public:
132 IconedView(views::View* view, const gfx::ImageSkia& image);
133 private:
134 DISALLOW_COPY_AND_ASSIGN(IconedView);
137 // A view to display text with an expandable details section.
138 class ExpandableContainerView : public views::View,
139 public views::ButtonListener,
140 public views::LinkListener,
141 public gfx::AnimationDelegate {
142 public:
143 ExpandableContainerView(ExtensionInstallDialogView* owner,
144 const base::string16& description,
145 const PermissionDetails& details,
146 int horizontal_space,
147 bool parent_bulleted);
148 ~ExpandableContainerView() override;
150 // views::View:
151 void ChildPreferredSizeChanged(views::View* child) override;
153 // views::ButtonListener:
154 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
156 // views::LinkListener:
157 void LinkClicked(views::Link* source, int event_flags) override;
159 // gfx::AnimationDelegate:
160 void AnimationProgressed(const gfx::Animation* animation) override;
161 void AnimationEnded(const gfx::Animation* animation) override;
163 private:
164 // A view which displays all the details of an IssueAdviceInfoEntry.
165 class DetailsView : public views::View {
166 public:
167 DetailsView(int horizontal_space, bool parent_bulleted);
168 ~DetailsView() override {}
170 // views::View:
171 gfx::Size GetPreferredSize() const override;
173 void AddDetail(const base::string16& detail);
175 // Animates this to be a height proportional to |state|.
176 void AnimateToState(double state);
178 private:
179 views::GridLayout* layout_;
180 double state_;
182 DISALLOW_COPY_AND_ASSIGN(DetailsView);
185 // Expand/Collapse the detail section for this ExpandableContainerView.
186 void ToggleDetailLevel();
188 // Updates |arrow_toggle_| according to the given state.
189 void UpdateArrowToggle(bool expanded);
191 // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
192 ExtensionInstallDialogView* owner_;
194 // A view for showing |issue_advice.details|.
195 DetailsView* details_view_;
197 gfx::SlideAnimation slide_animation_;
199 // The 'more details' link shown under the heading (changes to 'hide details'
200 // when the details section is expanded).
201 views::Link* more_details_;
203 // The up/down arrow next to the 'more detail' link (points up/down depending
204 // on whether the details section is expanded).
205 views::ImageButton* arrow_toggle_;
207 // Whether the details section is expanded.
208 bool expanded_;
210 DISALLOW_COPY_AND_ASSIGN(ExpandableContainerView);
213 #endif // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_