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

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

Issue 11027044: Add a class to replace ImageLoadingTracker with a nicer API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix include order Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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/image_loader.h"
18 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/signin/token_service.h" 21 #include "chrome/browser/signin/token_service.h"
21 #include "chrome/browser/signin/token_service_factory.h" 22 #include "chrome/browser/signin/token_service_factory.h"
22 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
23 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/tab_contents/tab_contents.h" 25 #include "chrome/browser/ui/tab_contents/tab_contents.h"
25 #include "chrome/common/chrome_switches.h" 26 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/extensions/extension.h" 27 #include "chrome/common/extensions/extension.h"
27 #include "chrome/common/extensions/extension_constants.h" 28 #include "chrome/common/extensions/extension_constants.h"
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 } 370 }
370 371
371 ExtensionInstallPrompt::ExtensionInstallPrompt( 372 ExtensionInstallPrompt::ExtensionInstallPrompt(
372 content::WebContents* contents) 373 content::WebContents* contents)
373 : record_oauth2_grant_(false), 374 : record_oauth2_grant_(false),
374 parent_web_contents_(contents), 375 parent_web_contents_(contents),
375 ui_loop_(MessageLoop::current()), 376 ui_loop_(MessageLoop::current()),
376 extension_(NULL), 377 extension_(NULL),
377 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), 378 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))),
378 delegate_(NULL), 379 delegate_(NULL),
379 prompt_(ProfileForWebContents(contents), UNSET_PROMPT_TYPE), 380 profile_(ProfileForWebContents(contents)),
380 prompt_type_(UNSET_PROMPT_TYPE), 381 prompt_(profile_, UNSET_PROMPT_TYPE),
381 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { 382 prompt_type_(UNSET_PROMPT_TYPE) {
382 } 383 }
383 384
384 ExtensionInstallPrompt::~ExtensionInstallPrompt() { 385 ExtensionInstallPrompt::~ExtensionInstallPrompt() {
385 } 386 }
386 387
387 void ExtensionInstallPrompt::ConfirmBundleInstall( 388 void ExtensionInstallPrompt::ConfirmBundleInstall(
388 extensions::BundleInstaller* bundle, 389 extensions::BundleInstaller* bundle,
389 const PermissionSet* permissions) { 390 const PermissionSet* permissions) {
390 DCHECK(ui_loop_ == MessageLoop::current()); 391 DCHECK(ui_loop_ == MessageLoop::current());
391 bundle_ = bundle; 392 bundle_ = bundle;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 else 523 else
523 icon_ = SkBitmap(); 524 icon_ = SkBitmap();
524 if (icon_.empty()) { 525 if (icon_.empty()) {
525 // Let's set default icon bitmap whose size is equal to the default icon's 526 // 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 527 // 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. 528 // than the one we need, it will be scaled down by the ui code.
528 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app()); 529 icon_ = GetDefaultIconBitmapForMaxScaleFactor(extension_->is_app());
529 } 530 }
530 } 531 }
531 532
532 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image, 533 void ExtensionInstallPrompt::OnImageLoaded(const gfx::Image& image) {
533 const std::string& extension_id,
534 int index) {
535 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); 534 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap());
536 FetchOAuthIssueAdviceIfNeeded(); 535 FetchOAuthIssueAdviceIfNeeded();
537 } 536 }
538 537
539 void ExtensionInstallPrompt::LoadImageIfNeeded() { 538 void ExtensionInstallPrompt::LoadImageIfNeeded() {
540 // Bundle install prompts do not have an icon. 539 // Bundle install prompts do not have an icon.
541 if (!icon_.empty()) { 540 // Also |profile_| can be NULL in unit tests.
541 if (!icon_.empty() || !profile_) {
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::ImageLoader::Get(profile_)->LoadImageAsync(
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 if (AutoConfirmPrompt(delegate_)) 634 if (AutoConfirmPrompt(delegate_))
635 return; 635 return;
636 636
637 if (show_dialog_callback_.is_null()) { 637 if (show_dialog_callback_.is_null()) {
638 GetDefaultShowDialogCallback().Run( 638 GetDefaultShowDialogCallback().Run(
639 parent_web_contents_, delegate_, prompt_); 639 parent_web_contents_, delegate_, prompt_);
640 } else { 640 } else {
641 show_dialog_callback_.Run(parent_web_contents_, delegate_, prompt_); 641 show_dialog_callback_.Run(parent_web_contents_, delegate_, prompt_);
642 } 642 }
643 } 643 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698