| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/extension_install_dialog.h" | 9 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 parent->AddChildView(image_view); | 61 parent->AddChildView(image_view); |
| 62 } | 62 } |
| 63 | 63 |
| 64 } // namespace | 64 } // namespace |
| 65 | 65 |
| 66 // Implements the extension installation dialog for TOOLKIT_VIEWS. | 66 // Implements the extension installation dialog for TOOLKIT_VIEWS. |
| 67 class ExtensionInstallDialogView : public views::DialogDelegateView, | 67 class ExtensionInstallDialogView : public views::DialogDelegateView, |
| 68 public views::LinkListener { | 68 public views::LinkListener { |
| 69 public: | 69 public: |
| 70 ExtensionInstallDialogView(ExtensionInstallUI::Delegate* delegate, | 70 ExtensionInstallDialogView(ExtensionInstallUI::Delegate* delegate, |
| 71 const Extension* extension, | |
| 72 SkBitmap* skia_icon, | |
| 73 const ExtensionInstallUI::Prompt& prompt); | 71 const ExtensionInstallUI::Prompt& prompt); |
| 74 virtual ~ExtensionInstallDialogView(); | 72 virtual ~ExtensionInstallDialogView(); |
| 75 | 73 |
| 76 private: | 74 private: |
| 77 // views::DialogDelegateView: | 75 // views::DialogDelegateView: |
| 78 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; | 76 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; |
| 79 virtual int GetDefaultDialogButton() const OVERRIDE; | 77 virtual int GetDefaultDialogButton() const OVERRIDE; |
| 80 virtual bool Cancel() OVERRIDE; | 78 virtual bool Cancel() OVERRIDE; |
| 81 virtual bool Accept() OVERRIDE; | 79 virtual bool Accept() OVERRIDE; |
| 82 | 80 |
| 83 // views::WidgetDelegate: | 81 // views::WidgetDelegate: |
| 84 virtual ui::ModalType GetModalType() const OVERRIDE; | 82 virtual ui::ModalType GetModalType() const OVERRIDE; |
| 85 virtual string16 GetWindowTitle() const OVERRIDE; | 83 virtual string16 GetWindowTitle() const OVERRIDE; |
| 86 virtual views::View* GetContentsView() OVERRIDE; | 84 virtual views::View* GetContentsView() OVERRIDE; |
| 87 | 85 |
| 88 // views::LinkListener: | 86 // views::LinkListener: |
| 89 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; | 87 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE; |
| 90 | 88 |
| 91 bool is_inline_install() { | 89 bool is_inline_install() { |
| 92 return prompt_.type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT; | 90 return prompt_.type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT; |
| 93 } | 91 } |
| 94 | 92 |
| 95 ExtensionInstallUI::Delegate* delegate_; | 93 ExtensionInstallUI::Delegate* delegate_; |
| 96 const Extension* extension_; | |
| 97 ExtensionInstallUI::Prompt prompt_; | 94 ExtensionInstallUI::Prompt prompt_; |
| 98 | 95 |
| 99 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView); | 96 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallDialogView); |
| 100 }; | 97 }; |
| 101 | 98 |
| 102 ExtensionInstallDialogView::ExtensionInstallDialogView( | 99 ExtensionInstallDialogView::ExtensionInstallDialogView( |
| 103 ExtensionInstallUI::Delegate* delegate, | 100 ExtensionInstallUI::Delegate* delegate, |
| 104 const Extension* extension, | |
| 105 SkBitmap* skia_icon, | |
| 106 const ExtensionInstallUI::Prompt& prompt) | 101 const ExtensionInstallUI::Prompt& prompt) |
| 107 : delegate_(delegate), | 102 : delegate_(delegate), |
| 108 extension_(extension), | |
| 109 prompt_(prompt) { | 103 prompt_(prompt) { |
| 110 // Possible grid layouts: | 104 // Possible grid layouts: |
| 111 // Inline install | 105 // Inline install |
| 112 // w/ permissions no permissions | 106 // w/ permissions no permissions |
| 113 // +--------------------+------+ +--------------+------+ | 107 // +--------------------+------+ +--------------+------+ |
| 114 // | heading | icon | | heading | icon | | 108 // | heading | icon | | heading | icon | |
| 115 // +--------------------| | +--------------| | | 109 // +--------------------| | +--------------| | |
| 116 // | rating | | | rating | | | 110 // | rating | | | rating | | |
| 117 // +--------------------| | +--------------+ | | 111 // +--------------------| | +--------------+ | |
| 118 // | user_count | | | user_count | | | 112 // | user_count | | | user_count | | |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); | 151 column_set->AddPaddingColumn(0, views::kPanelHorizMargin); |
| 158 column_set->AddColumn(views::GridLayout::LEADING, | 152 column_set->AddColumn(views::GridLayout::LEADING, |
| 159 views::GridLayout::LEADING, | 153 views::GridLayout::LEADING, |
| 160 0, // no resizing | 154 0, // no resizing |
| 161 views::GridLayout::USE_PREF, | 155 views::GridLayout::USE_PREF, |
| 162 0, // no fixed width | 156 0, // no fixed width |
| 163 kIconSize); | 157 kIconSize); |
| 164 | 158 |
| 165 layout->StartRow(0, column_set_id); | 159 layout->StartRow(0, column_set_id); |
| 166 | 160 |
| 167 views::Label* heading = new views::Label( | 161 views::Label* heading = new views::Label(prompt.GetHeading()); |
| 168 prompt.GetHeading(extension->name())); | |
| 169 heading->SetFont(heading->font().DeriveFont(kHeadingFontSizeDelta, | 162 heading->SetFont(heading->font().DeriveFont(kHeadingFontSizeDelta, |
| 170 gfx::Font::BOLD)); | 163 gfx::Font::BOLD)); |
| 171 heading->SetMultiLine(true); | 164 heading->SetMultiLine(true); |
| 172 heading->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 165 heading->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 173 heading->SizeToFit(left_column_width); | 166 heading->SizeToFit(left_column_width); |
| 174 layout->AddView(heading); | 167 layout->AddView(heading); |
| 175 | 168 |
| 176 // Scale down to icon size, but allow smaller icons (don't scale up). | 169 // Scale down to icon size, but allow smaller icons (don't scale up). |
| 177 gfx::Size size(skia_icon->width(), skia_icon->height()); | 170 SkBitmap bitmap = prompt.icon(); |
| 171 gfx::Size size(bitmap.width(), bitmap.height()); |
| 178 if (size.width() > kIconSize || size.height() > kIconSize) | 172 if (size.width() > kIconSize || size.height() > kIconSize) |
| 179 size = gfx::Size(kIconSize, kIconSize); | 173 size = gfx::Size(kIconSize, kIconSize); |
| 180 views::ImageView* icon = new views::ImageView(); | 174 views::ImageView* icon = new views::ImageView(); |
| 181 icon->SetImageSize(size); | 175 icon->SetImageSize(size); |
| 182 icon->SetImage(*skia_icon); | 176 icon->SetImage(bitmap); |
| 183 icon->SetHorizontalAlignment(views::ImageView::CENTER); | 177 icon->SetHorizontalAlignment(views::ImageView::CENTER); |
| 184 icon->SetVerticalAlignment(views::ImageView::CENTER); | 178 icon->SetVerticalAlignment(views::ImageView::CENTER); |
| 185 int icon_row_span = 1; | 179 int icon_row_span = 1; |
| 186 if (is_inline_install()) { | 180 if (is_inline_install()) { |
| 187 // Also span the rating, user_count and store_link rows. | 181 // Also span the rating, user_count and store_link rows. |
| 188 icon_row_span = 4; | 182 icon_row_span = 4; |
| 189 } else if (prompt.GetPermissionCount()) { | 183 } else if (prompt.GetPermissionCount()) { |
| 190 // Also span the permission header and each of the permission rows (all have | 184 // Also span the permission header and each of the permission rows (all have |
| 191 // a padding row above it). | 185 // a padding row above it). |
| 192 icon_row_span = 3 + prompt.GetPermissionCount() * 2; | 186 icon_row_span = 3 + prompt.GetPermissionCount() * 2; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 | 222 |
| 229 if (is_inline_install()) { | 223 if (is_inline_install()) { |
| 230 layout->StartRow(0, column_set_id); | 224 layout->StartRow(0, column_set_id); |
| 231 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL, | 225 layout->AddView(new views::Separator(), 3, 1, views::GridLayout::FILL, |
| 232 views::GridLayout::FILL); | 226 views::GridLayout::FILL); |
| 233 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 227 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 234 } | 228 } |
| 235 | 229 |
| 236 layout->StartRow(0, column_set_id); | 230 layout->StartRow(0, column_set_id); |
| 237 views::Label* permissions_header = new views::Label( | 231 views::Label* permissions_header = new views::Label( |
| 238 prompt.GetPermissionsHeader()); | 232 prompt.GetPermissionsHeading()); |
| 239 permissions_header->SetMultiLine(true); | 233 permissions_header->SetMultiLine(true); |
| 240 permissions_header->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 234 permissions_header->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 241 permissions_header->SizeToFit(left_column_width); | 235 permissions_header->SizeToFit(left_column_width); |
| 242 layout->AddView(permissions_header); | 236 layout->AddView(permissions_header); |
| 243 | 237 |
| 244 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { | 238 for (size_t i = 0; i < prompt.GetPermissionCount(); ++i) { |
| 245 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 239 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 246 layout->StartRow(0, column_set_id); | 240 layout->StartRow(0, column_set_id); |
| 247 views::Label* permission_label = new views::Label( | 241 views::Label* permission_label = new views::Label( |
| 248 prompt.GetPermission(i)); | 242 prompt.GetPermission(i)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 bool ExtensionInstallDialogView::Accept() { | 278 bool ExtensionInstallDialogView::Accept() { |
| 285 delegate_->InstallUIProceed(); | 279 delegate_->InstallUIProceed(); |
| 286 return true; | 280 return true; |
| 287 } | 281 } |
| 288 | 282 |
| 289 ui::ModalType ExtensionInstallDialogView::GetModalType() const { | 283 ui::ModalType ExtensionInstallDialogView::GetModalType() const { |
| 290 return ui::MODAL_TYPE_WINDOW; | 284 return ui::MODAL_TYPE_WINDOW; |
| 291 } | 285 } |
| 292 | 286 |
| 293 string16 ExtensionInstallDialogView::GetWindowTitle() const { | 287 string16 ExtensionInstallDialogView::GetWindowTitle() const { |
| 294 return prompt_.GetDialogTitle(extension_); | 288 return prompt_.GetDialogTitle(); |
| 295 } | 289 } |
| 296 | 290 |
| 297 views::View* ExtensionInstallDialogView::GetContentsView() { | 291 views::View* ExtensionInstallDialogView::GetContentsView() { |
| 298 return this; | 292 return this; |
| 299 } | 293 } |
| 300 | 294 |
| 301 void ExtensionInstallDialogView::LinkClicked(views::Link* source, | 295 void ExtensionInstallDialogView::LinkClicked(views::Link* source, |
| 302 int event_flags) { | 296 int event_flags) { |
| 303 GURL store_url( | 297 GURL store_url(extension_urls::GetWebstoreItemDetailURLPrefix() + |
| 304 extension_urls::GetWebstoreItemDetailURLPrefix() + extension_->id()); | 298 prompt_.extension()->id()); |
| 305 OpenURLParams params( | 299 OpenURLParams params( |
| 306 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, | 300 store_url, Referrer(), NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_LINK, |
| 307 false); | 301 false); |
| 308 BrowserList::GetLastActive()->OpenURL(params); | 302 BrowserList::GetLastActive()->OpenURL(params); |
| 309 GetWidget()->Close(); | 303 GetWidget()->Close(); |
| 310 } | 304 } |
| 311 | 305 |
| 312 void ShowExtensionInstallDialogImpl( | 306 void ShowExtensionInstallDialogImpl( |
| 313 Profile* profile, | 307 Profile* profile, |
| 314 ExtensionInstallUI::Delegate* delegate, | 308 ExtensionInstallUI::Delegate* delegate, |
| 315 const Extension* extension, | |
| 316 SkBitmap* icon, | |
| 317 const ExtensionInstallUI::Prompt& prompt) { | 309 const ExtensionInstallUI::Prompt& prompt) { |
| 318 #if defined(OS_CHROMEOS) | 310 #if defined(OS_CHROMEOS) |
| 319 // Use a tabbed browser window as parent on ChromeOS. | 311 // Use a tabbed browser window as parent on ChromeOS. |
| 320 Browser* browser = BrowserList::FindTabbedBrowser(profile, true); | 312 Browser* browser = BrowserList::FindTabbedBrowser(profile, true); |
| 321 #else | 313 #else |
| 322 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); | 314 Browser* browser = BrowserList::GetLastActiveWithProfile(profile); |
| 323 #endif | 315 #endif |
| 324 if (!browser) { | 316 if (!browser) { |
| 325 delegate->InstallUIAbort(false); | 317 delegate->InstallUIAbort(false); |
| 326 return; | 318 return; |
| 327 } | 319 } |
| 328 | 320 |
| 329 BrowserWindow* browser_window = browser->window(); | 321 BrowserWindow* browser_window = browser->window(); |
| 330 if (!browser_window) { | 322 if (!browser_window) { |
| 331 delegate->InstallUIAbort(false); | 323 delegate->InstallUIAbort(false); |
| 332 return; | 324 return; |
| 333 } | 325 } |
| 334 | 326 |
| 335 ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView( | 327 ExtensionInstallDialogView* dialog = new ExtensionInstallDialogView( |
| 336 delegate, extension, icon, prompt); | 328 delegate, prompt); |
| 337 | 329 |
| 338 views::Widget* window = browser::CreateViewsWindow( | 330 views::Widget* window = browser::CreateViewsWindow( |
| 339 browser_window->GetNativeHandle(), dialog, STYLE_GENERIC); | 331 browser_window->GetNativeHandle(), dialog, STYLE_GENERIC); |
| 340 | 332 |
| 341 window->Show(); | 333 window->Show(); |
| 342 } | 334 } |
| OLD | NEW |