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_ui.h" | 17 #include "chrome/browser/extensions/extension_install_ui.h" |
18 #include "chrome/browser/extensions/extension_system.h" | |
19 #include "chrome/browser/extensions/image_loader.h" | |
18 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
19 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
20 #include "chrome/browser/signin/token_service.h" | 22 #include "chrome/browser/signin/token_service.h" |
21 #include "chrome/browser/signin/token_service_factory.h" | 23 #include "chrome/browser/signin/token_service_factory.h" |
22 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/browser_window.h" | 25 #include "chrome/browser/ui/browser_window.h" |
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 26 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
25 #include "chrome/common/chrome_switches.h" | 27 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/extensions/extension.h" | 28 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_constants.h" | 29 #include "chrome/common/extensions/extension_constants.h" |
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
369 } | 371 } |
370 | 372 |
371 ExtensionInstallPrompt::ExtensionInstallPrompt( | 373 ExtensionInstallPrompt::ExtensionInstallPrompt( |
372 content::WebContents* contents) | 374 content::WebContents* contents) |
373 : record_oauth2_grant_(false), | 375 : record_oauth2_grant_(false), |
374 parent_web_contents_(contents), | 376 parent_web_contents_(contents), |
375 ui_loop_(MessageLoop::current()), | 377 ui_loop_(MessageLoop::current()), |
376 extension_(NULL), | 378 extension_(NULL), |
377 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), | 379 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), |
378 delegate_(NULL), | 380 delegate_(NULL), |
379 prompt_(ProfileForWebContents(contents), UNSET_PROMPT_TYPE), | 381 profile_(ProfileForWebContents(contents)), |
380 prompt_type_(UNSET_PROMPT_TYPE), | 382 prompt_(profile_, UNSET_PROMPT_TYPE), |
381 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { | 383 prompt_type_(UNSET_PROMPT_TYPE) { |
382 } | 384 } |
383 | 385 |
384 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 386 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
385 } | 387 } |
386 | 388 |
387 void ExtensionInstallPrompt::ConfirmBundleInstall( | 389 void ExtensionInstallPrompt::ConfirmBundleInstall( |
388 extensions::BundleInstaller* bundle, | 390 extensions::BundleInstaller* bundle, |
389 const PermissionSet* permissions) { | 391 const PermissionSet* permissions) { |
390 DCHECK(ui_loop_ == MessageLoop::current()); | 392 DCHECK(ui_loop_ == MessageLoop::current()); |
391 bundle_ = bundle; | 393 bundle_ = bundle; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 else | 524 else |
523 icon_ = SkBitmap(); | 525 icon_ = SkBitmap(); |
524 if (icon_.empty()) { | 526 if (icon_.empty()) { |
525 // Let's set default icon bitmap whose size is equal to the default icon's | 527 // Let's set default icon bitmap whose size is equal to the default icon's |
526 // pixel size under maximal supported scale factor. If the bitmap is larger | 528 // pixel size under maximal supported scale factor. If the bitmap is larger |
527 // than the one we need, it will be scaled down by the ui code. | 529 // than the one we need, it will be scaled down by the ui code. |
528 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); | 530 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); |
529 } | 531 } |
530 } | 532 } |
531 | 533 |
532 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, | 534 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) { |
533 const std::string& extension_id, | |
534 int index) { | |
535 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); | 535 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
536 FetchOAuthIssueAdviceIfNeeded(); | 536 FetchOAuthIssueAdviceIfNeeded(); |
537 } | 537 } |
538 | 538 |
539 void ExtensionInstallPrompt::LoadImageIfNeeded() { | 539 void ExtensionInstallPrompt::LoadImageIfNeeded() { |
540 // Bundle install prompts do not have an icon. | 540 // Bundle install prompts do not have an icon. |
541 if (!icon_.empty()) { | 541 if (!icon_.empty()) { |
542 FetchOAuthIssueAdviceIfNeeded(); | 542 FetchOAuthIssueAdviceIfNeeded(); |
543 return; | 543 return; |
544 } | 544 } |
545 | 545 |
546 // Load the image asynchronously. For the response, check OnImageLoaded. | 546 // Load the image asynchronously. For the response, check OnImageLoaded. |
547 ExtensionResource image = | 547 ExtensionResource image = |
548 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, | 548 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, |
549 ExtensionIconSet::MATCH_BIGGER); | 549 ExtensionIconSet::MATCH_BIGGER); |
550 // Load the icon whose pixel size is large enough to be displayed under | 550 // Load the icon whose pixel size is large enough to be displayed under |
551 // maximal supported scale factor. UI code will scale the icon down if needed. | 551 // maximal supported scale factor. UI code will scale the icon down if needed. |
552 // TODO(tbarzic): We should use IconImage here and load the required bitmap | 552 // TODO(tbarzic): We should use IconImage here and load the required bitmap |
553 // lazily. | 553 // lazily. |
554 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); | 554 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); |
555 tracker_.LoadImage(extension_, image, | 555 extensions::ExtensionSystem::Get(profile_)->image_loader()->LoadImageAsync( |
Aaron Boodman
2012/10/31 07:38:22
I think ImageLoader should be its own PKS, not own
Marijn Kruisselbrink
2012/10/31 21:22:59
Done.
| |
556 gfx::Size(pixel_size, pixel_size), | 556 extension_, image, gfx::Size(pixel_size, pixel_size), |
557 ImageLoadingTracker::DONT_CACHE); | 557 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); |
558 } | 558 } |
559 | 559 |
560 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { | 560 void ExtensionInstallPrompt::FetchOAuthIssueAdviceIfNeeded() { |
561 // |extension_| may be NULL, e.g. in the bundle install case. | 561 // |extension_| may be NULL, e.g. in the bundle install case. |
562 if (!extension_ || | 562 if (!extension_ || |
563 prompt_type_ == BUNDLE_INSTALL_PROMPT || | 563 prompt_type_ == BUNDLE_INSTALL_PROMPT || |
564 prompt_type_ == INLINE_INSTALL_PROMPT || | 564 prompt_type_ == INLINE_INSTALL_PROMPT || |
565 prompt_type_ == EXTERNAL_INSTALL_PROMPT || | 565 prompt_type_ == EXTERNAL_INSTALL_PROMPT || |
566 prompt_.GetOAuthIssueCount() != 0U) { | 566 prompt_.GetOAuthIssueCount() != 0U) { |
567 ShowConfirmation(); | 567 ShowConfirmation(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 if (AutoConfirmPrompt(delegate_)) | 633 if (AutoConfirmPrompt(delegate_)) |
634 return; | 634 return; |
635 | 635 |
636 if (show_dialog_callback_.is_null()) { | 636 if (show_dialog_callback_.is_null()) { |
637 GetDefaultShowDialogCallback().Run( | 637 GetDefaultShowDialogCallback().Run( |
638 parent_web_contents_, delegate_, prompt_); | 638 parent_web_contents_, delegate_, prompt_); |
639 } else { | 639 } else { |
640 show_dialog_callback_.Run(parent_web_contents_, delegate_, prompt_); | 640 show_dialog_callback_.Run(parent_web_contents_, delegate_, prompt_); |
641 } | 641 } |
642 } | 642 } |
OLD | NEW |