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 "chrome/browser/extensions/extension_install_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "chrome/browser/extensions/bundle_installer.h" | 16 #include "chrome/browser/extensions/bundle_installer.h" |
17 #include "chrome/browser/extensions/extension_install_dialog.h" | 17 #include "chrome/browser/extensions/extension_install_dialog.h" |
18 #include "chrome/browser/extensions/extension_install_ui.h" | 18 #include "chrome/browser/extensions/extension_install_ui.h" |
| 19 #include "chrome/browser/extensions/image_utils.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/signin/token_service.h" | 22 #include "chrome/browser/signin/token_service.h" |
22 #include "chrome/browser/signin/token_service_factory.h" | 23 #include "chrome/browser/signin/token_service_factory.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
25 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
26 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
27 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
28 #include "chrome/common/extensions/extension_constants.h" | 29 #include "chrome/common/extensions/extension_constants.h" |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 content::PageNavigator* navigator, | 307 content::PageNavigator* navigator, |
307 Profile* profile) | 308 Profile* profile) |
308 : record_oauth2_grant_(false), | 309 : record_oauth2_grant_(false), |
309 parent_(parent), | 310 parent_(parent), |
310 navigator_(navigator), | 311 navigator_(navigator), |
311 ui_loop_(MessageLoop::current()), | 312 ui_loop_(MessageLoop::current()), |
312 extension_(NULL), | 313 extension_(NULL), |
313 install_ui_(ExtensionInstallUI::Create(profile)), | 314 install_ui_(ExtensionInstallUI::Create(profile)), |
314 delegate_(NULL), | 315 delegate_(NULL), |
315 prompt_(profile, UNSET_PROMPT_TYPE), | 316 prompt_(profile, UNSET_PROMPT_TYPE), |
316 prompt_type_(UNSET_PROMPT_TYPE), | 317 prompt_type_(UNSET_PROMPT_TYPE) { |
317 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | |
318 } | 318 } |
319 | 319 |
320 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 320 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
321 } | 321 } |
322 | 322 |
323 void ExtensionInstallPrompt::ConfirmBundleInstall( | 323 void ExtensionInstallPrompt::ConfirmBundleInstall( |
324 extensions::BundleInstaller* bundle, | 324 extensions::BundleInstaller* bundle, |
325 const PermissionSet* permissions) { | 325 const PermissionSet* permissions) { |
326 DCHECK(ui_loop_ == MessageLoop::current()); | 326 DCHECK(ui_loop_ == MessageLoop::current()); |
327 bundle_ = bundle; | 327 bundle_ = bundle; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 else | 442 else |
443 icon_ = SkBitmap(); | 443 icon_ = SkBitmap(); |
444 if (icon_.empty()) { | 444 if (icon_.empty()) { |
445 // Let's set default icon bitmap whose size is equal to the default icon's | 445 // Let's set default icon bitmap whose size is equal to the default icon's |
446 // pixel size under maximal supported scale factor. If the bitmap is larger | 446 // pixel size under maximal supported scale factor. If the bitmap is larger |
447 // than the one we need, it will be scaled down by the ui code. | 447 // than the one we need, it will be scaled down by the ui code. |
448 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); | 448 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); |
449 } | 449 } |
450 } | 450 } |
451 | 451 |
452 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, | 452 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { |
453 const std::string& extension_id, | |
454 int index) { | |
455 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); | 453 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
456 FetchOAuthIssueAdviceIfNeeded(); | 454 FetchOAuthIssueAdviceIfNeeded(); |
457 } | 455 } |
458 | 456 |
459 void ExtensionInstallPrompt::LoadImageIfNeeded() { | 457 void ExtensionInstallPrompt::LoadImageIfNeeded() { |
460 // Bundle install prompts do not have an icon. | 458 // Bundle install prompts do not have an icon. |
461 if (!icon_.empty()) { | 459 if (!icon_.empty()) { |
462 FetchOAuthIssueAdviceIfNeeded(); | 460 FetchOAuthIssueAdviceIfNeeded(); |
463 return; | 461 return; |
464 } | 462 } |
465 | 463 |
466 // Load the image asynchronously. For the response, check OnImageLoaded. | 464 // Load the image asynchronously. For the response, check OnImageLoaded. |
467 ExtensionResource image = | 465 ExtensionResource image = |
468 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, | 466 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, |
469 ExtensionIconSet::MATCH_BIGGER); | 467 ExtensionIconSet::MATCH_BIGGER); |
470 // Load the icon whose pixel size is large enough to be displayed under | 468 // Load the icon whose pixel size is large enough to be displayed under |
471 // maximal supported scale factor. UI code will scale the icon down if needed. | 469 // maximal supported scale factor. UI code will scale the icon down if needed. |
472 // TODO(tbarzic): We should use IconImage here and load the required bitmap | 470 // TODO(tbarzic): We should use IconImage here and load the required bitmap |
473 // lazily. | 471 // lazily. |
474 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); | 472 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); |
475 tracker_.LoadImage(extension_, image, | 473 extension_image_utils::LoadImageAsync( |
476 gfx::Size(pixel_size, pixel_size), | 474 extension_, image, gfx::Size(pixel_size, pixel_size), |
477 ImageLoadingTracker::DONT_CACHE); | 475 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
478 } | 476 } |
479 | 477 |
480 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { | 478 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { |
481 // |extension_| may be NULL, e.g. in the bundle install case. | 479 // |extension_| may be NULL, e.g. in the bundle install case. |
482 if (!extension_ || | 480 if (!extension_ || |
483 prompt_type_ == BUNDLE_INSTALL_PROMPT || | 481 prompt_type_ == BUNDLE_INSTALL_PROMPT || |
484 prompt_type_ == INLINE_INSTALL_PROMPT || | 482 prompt_type_ == INLINE_INSTALL_PROMPT || |
485 prompt_.GetOAuthIssueCount() != 0U) { | 483 prompt_.GetOAuthIssueCount() != 0U) { |
486 ShowConfirmation(); | 484 ShowConfirmation(); |
487 return; | 485 return; |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 Browser* browser) { | 555 Browser* browser) { |
558 // |browser| can be NULL in unit tests. | 556 // |browser| can be NULL in unit tests. |
559 if (!browser) | 557 if (!browser) |
560 return new ExtensionInstallPrompt(NULL, NULL, NULL); | 558 return new ExtensionInstallPrompt(NULL, NULL, NULL); |
561 gfx::NativeWindow parent = | 559 gfx::NativeWindow parent = |
562 browser->window() ? browser->window()->GetNativeWindow() : NULL; | 560 browser->window() ? browser->window()->GetNativeWindow() : NULL; |
563 return new ExtensionInstallPrompt(parent, browser, browser->profile()); | 561 return new ExtensionInstallPrompt(parent, browser, browser->profile()); |
564 } | 562 } |
565 | 563 |
566 } // namespace chrome | 564 } // namespace chrome |
OLD | NEW |