Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: chrome/browser/views/extensions/extension_install_prompt.cc

Issue 173463: Update of the extension install UI: (Closed)
Patch Set: mpcompelte comments Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "app/l10n_util.h" 5 #include "app/l10n_util.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/rand_util.h" 7 #include "base/rand_util.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/browser_list.h" 9 #include "chrome/browser/browser_list.h"
10 #include "chrome/browser/browser_window.h" 10 #include "chrome/browser/browser_window.h"
11 #include "chrome/browser/extensions/extension_install_ui.h" 11 #include "chrome/browser/extensions/extension_install_ui.h"
12 #include "chrome/common/extensions/extension.h" 12 #include "chrome/common/extensions/extension.h"
13 #include "grit/generated_resources.h" 13 #include "grit/generated_resources.h"
14 #include "views/controls/image_view.h" 14 #include "views/controls/image_view.h"
15 #include "views/controls/label.h" 15 #include "views/controls/label.h"
16 #include "views/controls/link.h" 16 #include "views/controls/link.h"
17 #include "views/standard_layout.h" 17 #include "views/standard_layout.h"
18 #include "views/view.h" 18 #include "views/view.h"
19 #include "views/window/dialog_delegate.h" 19 #include "views/window/dialog_delegate.h"
20 #include "views/window/window.h" 20 #include "views/window/window.h"
21 21
22 class Profile; 22 class Profile;
23 23
24 namespace { 24 namespace {
25 25
26 const int kRightColumnWidth = 290; 26 const int kRightColumnWidth = 270;
27 const int kIconSize = 85;
27 28
28 // Implements the extension installation prompt for Windows. 29 // Implements the extension installation prompt for Windows.
29 // TODO(aa): It would be cool to add an "extensions threat level" when we have
30 // granular permissions implemented:
31 // - red: npapi
32 // - orange: access to any domains
33 // - yellow: access to browser data
34 // - green: nothing
35 // We could have a collection of funny descriptions for each color.
36 class InstallDialogContent : public views::View, public views::DialogDelegate { 30 class InstallDialogContent : public views::View, public views::DialogDelegate {
37 public: 31 public:
38 InstallDialogContent(ExtensionInstallUI::Delegate* delegate, 32 InstallDialogContent(ExtensionInstallUI::Delegate* delegate,
39 Extension* extension, 33 Extension* extension, SkBitmap* icon, const std::wstring& warning_text)
40 SkBitmap* icon) 34 : delegate_(delegate), icon_(NULL) {
41 : delegate_(delegate), icon_(NULL) {
42 if (icon) { 35 if (icon) {
43 icon_ = new views::ImageView(); 36 icon_ = new views::ImageView();
37 icon_->SetImageSize(gfx::Size(kIconSize, kIconSize));
44 icon_->SetImage(*icon); 38 icon_->SetImage(*icon);
45 AddChildView(icon_); 39 AddChildView(icon_);
46 } 40 }
47 41
48 heading_ = new views::Label( 42 heading_ = new views::Label(
49 l10n_util::GetStringF(IDS_EXTENSION_PROMPT_HEADING, 43 l10n_util::GetStringF(IDS_EXTENSION_PROMPT_HEADING,
50 UTF8ToWide(extension->name()))); 44 UTF8ToWide(extension->name())));
51 heading_->SetFont(heading_->GetFont().DeriveFont(1, gfx::Font::BOLD)); 45 heading_->SetFont(heading_->GetFont().DeriveFont(1, gfx::Font::BOLD));
52 heading_->SetMultiLine(true); 46 heading_->SetMultiLine(true);
53 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 47 heading_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
54 AddChildView(heading_); 48 AddChildView(heading_);
55 49
56 // Pick a random warning. 50 warning_ = new views::Label(warning_text);
57 std::wstring warnings[] = {
58 l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_1),
59 l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_2),
60 l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_3)
61 };
62 warning_ = new views::Label(
63 warnings[base::RandInt(0, arraysize(warnings) - 1)]);
64 warning_->SetMultiLine(true); 51 warning_->SetMultiLine(true);
65 warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); 52 warning_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
66 AddChildView(warning_); 53 AddChildView(warning_);
67
68 severe_ = new views::Label(
69 l10n_util::GetString(IDS_EXTENSION_PROMPT_WARNING_SEVERE));
70 severe_->SetMultiLine(true);
71 severe_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
72 severe_->SetFont(heading_->GetFont().DeriveFont(0, gfx::Font::BOLD));
73 severe_->SetColor(SK_ColorRED);
74 AddChildView(severe_);
75 } 54 }
76 55
77 private: 56 private:
78 // DialogDelegate 57 // DialogDelegate
79 virtual std::wstring GetDialogButtonLabel( 58 virtual std::wstring GetDialogButtonLabel(
80 MessageBoxFlags::DialogButton button) const { 59 MessageBoxFlags::DialogButton button) const {
81 switch (button) { 60 switch (button) {
82 case MessageBoxFlags::DIALOGBUTTON_OK: 61 case MessageBoxFlags::DIALOGBUTTON_OK:
83 return l10n_util::GetString(IDS_EXTENSION_PROMPT_INSTALL_BUTTON); 62 return l10n_util::GetString(IDS_EXTENSION_PROMPT_INSTALL_BUTTON);
84 case MessageBoxFlags::DIALOGBUTTON_CANCEL: 63 case MessageBoxFlags::DIALOGBUTTON_CANCEL:
(...skipping 24 matching lines...) Expand all
109 virtual std::wstring GetWindowTitle() const { 88 virtual std::wstring GetWindowTitle() const {
110 return l10n_util::GetString(IDS_EXTENSION_PROMPT_TITLE); 89 return l10n_util::GetString(IDS_EXTENSION_PROMPT_TITLE);
111 } 90 }
112 virtual views::View* GetContentsView() { return this; } 91 virtual views::View* GetContentsView() { return this; }
113 92
114 // View 93 // View
115 virtual gfx::Size GetPreferredSize() { 94 virtual gfx::Size GetPreferredSize() {
116 int width = kRightColumnWidth + kPanelHorizMargin + kPanelHorizMargin; 95 int width = kRightColumnWidth + kPanelHorizMargin + kPanelHorizMargin;
117 96
118 if (icon_) { 97 if (icon_) {
119 width += Extension::EXTENSION_ICON_LARGE; 98 width += kIconSize;
120 width += kPanelHorizMargin; 99 width += kPanelHorizMargin;
121 } 100 }
122 101
123 int height = kPanelVertMargin * 2; 102 int height = kPanelVertMargin * 2;
124 height += heading_->GetHeightForWidth(kRightColumnWidth); 103 height += heading_->GetHeightForWidth(kRightColumnWidth);
125 height += kPanelVertMargin; 104 height += kPanelVertMargin;
126 height += warning_->GetHeightForWidth(kRightColumnWidth); 105 height += warning_->GetHeightForWidth(kRightColumnWidth);
127 height += kPanelVertMargin; 106 height += kPanelVertMargin;
128 height += severe_->GetHeightForWidth(kRightColumnWidth);
129 height += kPanelVertMargin;
130 107
131 return gfx::Size(width, std::max(height, 108 return gfx::Size(width, std::max(height, kIconSize));
132 static_cast<int>(Extension::EXTENSION_ICON_LARGE)));
133 } 109 }
134 110
135 virtual void Layout() { 111 virtual void Layout() {
136 int x = kPanelHorizMargin; 112 int x = kPanelHorizMargin;
137 int y = kPanelVertMargin; 113 int y = kPanelVertMargin;
138 114
139 if (icon_) { 115 if (icon_) {
140 icon_->SetBounds(x, y, Extension::EXTENSION_ICON_LARGE, 116 icon_->SetBounds(x, y, kIconSize, kIconSize);
141 Extension::EXTENSION_ICON_LARGE); 117 x += kIconSize;
142 x += Extension::EXTENSION_ICON_LARGE;
143 x += kPanelHorizMargin; 118 x += kPanelHorizMargin;
144 } 119 }
145 120
146 heading_->SizeToFit(kRightColumnWidth); 121 heading_->SizeToFit(kRightColumnWidth);
147 heading_->SetX(x); 122 heading_->SetX(x);
148 heading_->SetY(y); 123 heading_->SetY(y);
149 y += heading_->height(); 124 y += heading_->height();
150 125
151 y += kPanelVertMargin; 126 y += kPanelVertMargin;
152 127
153 warning_->SizeToFit(kRightColumnWidth); 128 warning_->SizeToFit(kRightColumnWidth);
154 warning_->SetX(x); 129 warning_->SetX(x);
155 warning_->SetY(y); 130 warning_->SetY(y);
156 y += warning_->height(); 131 y += warning_->height();
157 132
158 y += kPanelVertMargin; 133 y += kPanelVertMargin;
159
160 severe_->SizeToFit(kRightColumnWidth);
161 severe_->SetX(x);
162 severe_->SetY(y);
163 y += severe_->height();
164 } 134 }
165 135
166 ExtensionInstallUI::Delegate* delegate_; 136 ExtensionInstallUI::Delegate* delegate_;
167 views::ImageView* icon_; 137 views::ImageView* icon_;
168 views::Label* heading_; 138 views::Label* heading_;
169 views::Label* warning_; 139 views::Label* warning_;
170 views::Label* severe_;
171 140
172 DISALLOW_COPY_AND_ASSIGN(InstallDialogContent); 141 DISALLOW_COPY_AND_ASSIGN(InstallDialogContent);
173 }; 142 };
174 143
175 } // namespace 144 } // namespace
176 145
177 void ExtensionInstallUI::ShowExtensionInstallPrompt(Profile* profile, 146 void ExtensionInstallUI::ShowExtensionInstallPrompt(
178 Delegate* delegate, 147 Profile* profile, Delegate* delegate, Extension* extension, SkBitmap* icon,
179 Extension* extension, 148 const std::wstring& warning_text) {
180 SkBitmap* icon) {
181 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); 149 Browser* browser = BrowserList::GetLastActiveWithProfile(profile);
182 if (!browser) { 150 if (!browser) {
183 delegate->ContinueInstall(); 151 delegate->ContinueInstall();
184 return; 152 return;
185 } 153 }
186 154
187 BrowserWindow* window = browser->window(); 155 BrowserWindow* window = browser->window();
188 if (!window) { 156 if (!window) {
189 delegate->AbortInstall(); 157 delegate->AbortInstall();
190 return; 158 return;
191 } 159 }
192 160
193 views::Window::CreateChromeWindow(window->GetNativeHandle(), gfx::Rect(), 161 views::Window::CreateChromeWindow(window->GetNativeHandle(), gfx::Rect(),
194 new InstallDialogContent(delegate, extension, icon))->Show(); 162 new InstallDialogContent(delegate, extension, icon,
163 warning_text))->Show();
195 } 164 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698