Upstream version 10.38.220.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / extensions / extension_install_dialog_view.h
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.
4
5 #ifndef CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_
6 #define CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_
7
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"
15
16 typedef std::vector<base::string16> PermissionDetails;
17 class ExpandableContainerView;
18
19 namespace content {
20 class PageNavigator;
21 }
22
23 namespace extensions {
24 class ExperienceSamplingEvent;
25 }
26
27 namespace views {
28 class GridLayout;
29 class ImageButton;
30 class Label;
31 class Link;
32 }
33
34 // A custom scrollable view implementation for the dialog.
35 class CustomScrollableView : public views::View {
36  public:
37   CustomScrollableView();
38   virtual ~CustomScrollableView();
39
40  private:
41   virtual void Layout() OVERRIDE;
42
43   DISALLOW_COPY_AND_ASSIGN(CustomScrollableView);
44 };
45
46 // Implements the extension installation dialog for TOOLKIT_VIEWS.
47 class ExtensionInstallDialogView : public views::DialogDelegateView,
48                                    public views::LinkListener,
49                                    public views::ButtonListener {
50  public:
51   ExtensionInstallDialogView(
52       content::PageNavigator* navigator,
53       ExtensionInstallPrompt::Delegate* delegate,
54       scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
55   virtual ~ExtensionInstallDialogView();
56
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_; }
60
61   // Called when one of the child elements has expanded/collapsed.
62   void ContentsChanged();
63
64  private:
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;
78
79   // views::LinkListener:
80   virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
81
82   // views::ButtonListener:
83   virtual void ButtonPressed(views::Button* sender,
84                              const ui::Event& event) OVERRIDE;
85
86   // Experimental: Toggles inline permission explanations with an animation.
87   void ToggleInlineExplanations();
88
89   // Creates a layout consisting of dialog header, extension name and icon.
90   views::GridLayout* CreateLayout(
91       views::View* parent,
92       int left_column_width,
93       int column_set_id,
94       bool single_detail_row) const;
95
96   bool is_inline_install() const {
97     return prompt_->type() == ExtensionInstallPrompt::INLINE_INSTALL_PROMPT;
98   }
99
100   bool is_bundle_install() const {
101     return prompt_->type() == ExtensionInstallPrompt::BUNDLE_INSTALL_PROMPT;
102   }
103
104   bool is_external_install() const {
105     return prompt_->type() == ExtensionInstallPrompt::EXTERNAL_INSTALL_PROMPT;
106   }
107
108   // Updates the histogram that holds installation accepted/aborted data.
109   void UpdateInstallResultHistogram(bool accepted) const;
110
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;
114
115   content::PageNavigator* navigator_;
116   ExtensionInstallPrompt::Delegate* delegate_;
117   scoped_refptr<ExtensionInstallPrompt::Prompt> prompt_;
118
119   // The scroll view containing all the details for the dialog (including all
120   // collapsible/expandable sections).
121   views::ScrollView* scroll_view_;
122
123   // The container view for the scroll view.
124   CustomScrollableView* scrollable_;
125
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_;
130
131   // The preferred size of the dialog.
132   gfx::Size dialog_size_;
133
134   // Experimental: "Show details" link to expand inline explanations and reveal
135   // permision dialog.
136   views::Link* show_details_link_;
137
138   // Experimental: Label for showing information about the checkboxes.
139   views::Label* checkbox_info_label_;
140
141   // Experimental: Contains pointers to inline explanation views.
142   typedef std::vector<ExpandableContainerView*> InlineExplanations;
143   InlineExplanations inline_explanations_;
144
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_;
148
149   // ExperienceSampling: Track this UI event.
150   scoped_ptr<extensions::ExperienceSamplingEvent> sampling_event_;
151
152   // Set to true once the user's selection has been received and the
153   // |delegate_| has been notified.
154   bool handled_result_;
155
156   DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView);
157 };
158
159 // A simple view that prepends a view with a bullet with the help of a grid
160 // layout.
161 class BulletedView : public views::View {
162  public:
163   explicit BulletedView(views::View* view);
164  private:
165   DISALLOW_COPY_AND_ASSIGN(BulletedView);
166 };
167
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 {
172  public:
173   CheckboxedView(views::View* view, views::ButtonListener* listener);
174  private:
175   DISALLOW_COPY_AND_ASSIGN(CheckboxedView);
176 };
177
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 {
183  public:
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();
192
193   // views::View:
194   virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE;
195
196   // views::ButtonListener:
197   virtual void ButtonPressed(views::Button* sender,
198                              const ui::Event& event) OVERRIDE;
199
200   // views::LinkListener:
201   virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
202
203   // gfx::AnimationDelegate:
204   virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE;
205   virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE;
206
207   // Expand/Collapse the detail section for this ExpandableContainerView.
208   void ToggleDetailLevel();
209
210   // Expand the detail section without any animation.
211   // TODO(meacer): Remove once the experiment is completed.
212   void ExpandWithoutAnimation();
213
214  private:
215   // A view which displays all the details of an IssueAdviceInfoEntry.
216   class DetailsView : public views::View {
217    public:
218     explicit DetailsView(int horizontal_space, bool parent_bulleted,
219                          bool lighter_color);
220     virtual ~DetailsView() {}
221
222     // views::View:
223     virtual gfx::Size GetPreferredSize() const OVERRIDE;
224
225     void AddDetail(const base::string16& detail);
226
227     // Animates this to be a height proportional to |state|.
228     void AnimateToState(double state);
229
230    private:
231     views::GridLayout* layout_;
232     double state_;
233
234     // Whether the detail text should be shown with a lighter color.
235     bool lighter_color_;
236
237     DISALLOW_COPY_AND_ASSIGN(DetailsView);
238   };
239
240   // The dialog that owns |this|. It's also an ancestor in the View hierarchy.
241   ExtensionInstallDialogView* owner_;
242
243   // A view for showing |issue_advice.details|.
244   DetailsView* details_view_;
245
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_;
249
250   gfx::SlideAnimation slide_animation_;
251
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_;
255
256   // Whether the details section is expanded.
257   bool expanded_;
258
259   DISALLOW_COPY_AND_ASSIGN(ExpandableContainerView);
260 };
261
262 void ShowExtensionInstallDialogImpl(
263     const ExtensionInstallPrompt::ShowParams& show_params,
264     ExtensionInstallPrompt::Delegate* delegate,
265     scoped_refptr<ExtensionInstallPrompt::Prompt> prompt);
266
267 #endif  // CHROME_BROWSER_UI_VIEWS_EXTENSIONS_EXTENSION_INSTALL_DIALOG_VIEW_H_