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

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

Issue 11786003: Move Icons out of Extension class (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Latest master + Yoyo's requests Created 7 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/extensions/image_loader.h"
19 #include "chrome/browser/prefs/pref_service.h" 19 #include "chrome/browser/prefs/pref_service.h"
20 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/signin/token_service.h" 21 #include "chrome/browser/signin/token_service.h"
22 #include "chrome/browser/signin/token_service_factory.h" 22 #include "chrome/browser/signin/token_service_factory.h"
23 #include "chrome/browser/ui/browser.h" 23 #include "chrome/browser/ui/browser.h"
24 #include "chrome/browser/ui/browser_window.h" 24 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/common/extensions/api/icons/icons_handler.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"
28 #include "chrome/common/extensions/extension_icon_set.h" 29 #include "chrome/common/extensions/extension_icon_set.h"
29 #include "chrome/common/extensions/extension_manifest_constants.h" 30 #include "chrome/common/extensions/extension_manifest_constants.h"
30 #include "chrome/common/extensions/extension_resource.h" 31 #include "chrome/common/extensions/extension_resource.h"
31 #include "chrome/common/extensions/feature_switch.h" 32 #include "chrome/common/extensions/feature_switch.h"
32 #include "chrome/common/extensions/permissions/permission_set.h" 33 #include "chrome/common/extensions/permissions/permission_set.h"
33 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
34 #include "content/public/browser/web_contents.h" 35 #include "content/public/browser/web_contents.h"
35 #include "content/public/browser/web_contents_view.h" 36 #include "content/public/browser/web_contents_view.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 // independent size is |size_in_dip| 107 // independent size is |size_in_dip|
107 int GetSizeForMaxScaleFactor(int size_in_dip) { 108 int GetSizeForMaxScaleFactor(int size_in_dip) {
108 float max_scale_factor_scale = 109 float max_scale_factor_scale =
109 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); 110 ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
110 return static_cast<int>(size_in_dip * max_scale_factor_scale); 111 return static_cast<int>(size_in_dip * max_scale_factor_scale);
111 } 112 }
112 113
113 // Returns bitmap for the default icon with size equal to the default icon's 114 // Returns bitmap for the default icon with size equal to the default icon's
114 // pixel size under maximal supported scale factor. 115 // pixel size under maximal supported scale factor.
115 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { 116 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
116 return Extension::GetDefaultIcon(is_app). 117 const gfx::ImageSkia& image = is_app ?
117 GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap(); 118 extensions::IconsInfo::GetDefaultAppIcon() :
119 extensions::IconsInfo::GetDefaultExtensionIcon();
120 return image.GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap();
118 } 121 }
119 122
120 // If auto confirm is enabled then posts a task to proceed with or cancel the 123 // If auto confirm is enabled then posts a task to proceed with or cancel the
121 // install and returns true. Otherwise returns false. 124 // install and returns true. Otherwise returns false.
122 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { 125 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) {
123 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); 126 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
124 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) 127 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests))
125 return false; 128 return false;
126 std::string value = cmdline->GetSwitchValueASCII( 129 std::string value = cmdline->GetSwitchValueASCII(
127 switches::kAppsGalleryInstallAutoConfirmForTests); 130 switches::kAppsGalleryInstallAutoConfirmForTests);
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 565
563 void ExtensionInstallPrompt::LoadImageIfNeeded() { 566 void ExtensionInstallPrompt::LoadImageIfNeeded() {
564 // Bundle install prompts do not have an icon. 567 // Bundle install prompts do not have an icon.
565 // Also |install_ui_.profile()| can be NULL in unit tests. 568 // Also |install_ui_.profile()| can be NULL in unit tests.
566 if (!icon_.empty() || !install_ui_->profile()) { 569 if (!icon_.empty() || !install_ui_->profile()) {
567 FetchOAuthIssueAdviceIfNeeded(); 570 FetchOAuthIssueAdviceIfNeeded();
568 return; 571 return;
569 } 572 }
570 573
571 // Load the image asynchronously. For the response, check OnImageLoaded. 574 // Load the image asynchronously. For the response, check OnImageLoaded.
572 ExtensionResource image = 575 ExtensionResource image = extensions::IconsInfo::GetIconResource(
573 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, 576 extension_,
574 ExtensionIconSet::MATCH_BIGGER); 577 extension_misc::EXTENSION_ICON_LARGE,
578 ExtensionIconSet::MATCH_BIGGER);
575 // Load the icon whose pixel size is large enough to be displayed under 579 // Load the icon whose pixel size is large enough to be displayed under
576 // maximal supported scale factor. UI code will scale the icon down if needed. 580 // maximal supported scale factor. UI code will scale the icon down if needed.
577 // TODO(tbarzic): We should use IconImage here and load the required bitmap 581 // TODO(tbarzic): We should use IconImage here and load the required bitmap
578 // lazily. 582 // lazily.
579 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); 583 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
580 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync( 584 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync(
581 extension_, image, gfx::Size(pixel_size, pixel_size), 585 extension_, image, gfx::Size(pixel_size, pixel_size),
582 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); 586 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr()));
583 } 587 }
584 588
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 } 659 }
656 660
657 if (AutoConfirmPrompt(delegate_)) 661 if (AutoConfirmPrompt(delegate_))
658 return; 662 return;
659 663
660 if (show_dialog_callback_.is_null()) 664 if (show_dialog_callback_.is_null())
661 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 665 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
662 else 666 else
663 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 667 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
664 } 668 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698