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

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: Created 7 years, 9 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) 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/prefs/pref_service.h" 12 #include "base/prefs/pref_service.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/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "chrome/browser/extensions/bundle_installer.h" 17 #include "chrome/browser/extensions/bundle_installer.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_loader.h" 19 #include "chrome/browser/extensions/image_loader.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/api/identity/oauth2_manifest_handler.h" 27 #include "chrome/common/extensions/api/identity/oauth2_manifest_handler.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"
29 #include "chrome/common/extensions/extension_icon_set.h" 30 #include "chrome/common/extensions/extension_icon_set.h"
30 #include "chrome/common/extensions/extension_manifest_constants.h" 31 #include "chrome/common/extensions/extension_manifest_constants.h"
31 #include "chrome/common/extensions/extension_resource.h" 32 #include "chrome/common/extensions/extension_resource.h"
32 #include "chrome/common/extensions/feature_switch.h" 33 #include "chrome/common/extensions/feature_switch.h"
33 #include "chrome/common/extensions/manifest.h" 34 #include "chrome/common/extensions/manifest.h"
34 #include "chrome/common/extensions/permissions/permission_set.h" 35 #include "chrome/common/extensions/permissions/permission_set.h"
35 #include "chrome/common/pref_names.h" 36 #include "chrome/common/pref_names.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // independent size is |size_in_dip| 125 // independent size is |size_in_dip|
125 int GetSizeForMaxScaleFactor(int size_in_dip) { 126 int GetSizeForMaxScaleFactor(int size_in_dip) {
126 float max_scale_factor_scale = 127 float max_scale_factor_scale =
127 ui::GetScaleFactorScale(ui::GetMaxScaleFactor()); 128 ui::GetScaleFactorScale(ui::GetMaxScaleFactor());
128 return static_cast<int>(size_in_dip * max_scale_factor_scale); 129 return static_cast<int>(size_in_dip * max_scale_factor_scale);
129 } 130 }
130 131
131 // Returns bitmap for the default icon with size equal to the default icon's 132 // Returns bitmap for the default icon with size equal to the default icon's
132 // pixel size under maximal supported scale factor. 133 // pixel size under maximal supported scale factor.
133 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { 134 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
134 return Extension::GetDefaultIcon(is_app). 135 const gfx::ImageSkia& image = is_app ?
135 GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap(); 136 extensions::IconsInfo::GetDefaultAppIcon() :
137 extensions::IconsInfo::GetDefaultExtensionIcon();
138 return image.GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap();
136 } 139 }
137 140
138 // If auto confirm is enabled then posts a task to proceed with or cancel the 141 // If auto confirm is enabled then posts a task to proceed with or cancel the
139 // install and returns true. Otherwise returns false. 142 // install and returns true. Otherwise returns false.
140 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { 143 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) {
141 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); 144 const CommandLine* cmdline = CommandLine::ForCurrentProcess();
142 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) 145 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests))
143 return false; 146 return false;
144 std::string value = cmdline->GetSwitchValueASCII( 147 std::string value = cmdline->GetSwitchValueASCII(
145 switches::kAppsGalleryInstallAutoConfirmForTests); 148 switches::kAppsGalleryInstallAutoConfirmForTests);
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 602
600 void ExtensionInstallPrompt::LoadImageIfNeeded() { 603 void ExtensionInstallPrompt::LoadImageIfNeeded() {
601 // Bundle install prompts do not have an icon. 604 // Bundle install prompts do not have an icon.
602 // Also |install_ui_.profile()| can be NULL in unit tests. 605 // Also |install_ui_.profile()| can be NULL in unit tests.
603 if (!icon_.empty() || !install_ui_->profile()) { 606 if (!icon_.empty() || !install_ui_->profile()) {
604 FetchOAuthIssueAdviceIfNeeded(); 607 FetchOAuthIssueAdviceIfNeeded();
605 return; 608 return;
606 } 609 }
607 610
608 // Load the image asynchronously. For the response, check OnImageLoaded. 611 // Load the image asynchronously. For the response, check OnImageLoaded.
609 ExtensionResource image = 612 ExtensionResource image = extensions::IconsInfo::GetIconResource(
610 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, 613 extension_,
611 ExtensionIconSet::MATCH_BIGGER); 614 extension_misc::EXTENSION_ICON_LARGE,
615 ExtensionIconSet::MATCH_BIGGER);
612 // Load the icon whose pixel size is large enough to be displayed under 616 // Load the icon whose pixel size is large enough to be displayed under
613 // maximal supported scale factor. UI code will scale the icon down if needed. 617 // maximal supported scale factor. UI code will scale the icon down if needed.
614 // TODO(tbarzic): We should use IconImage here and load the required bitmap 618 // TODO(tbarzic): We should use IconImage here and load the required bitmap
615 // lazily. 619 // lazily.
616 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); 620 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
617 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync( 621 extensions::ImageLoader::Get(install_ui_->profile())->LoadImageAsync(
618 extension_, image, gfx::Size(pixel_size, pixel_size), 622 extension_, image, gfx::Size(pixel_size, pixel_size),
619 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr())); 623 base::Bind(&ExtensionInstallPrompt::OnImageLoaded, AsWeakPtr()));
620 } 624 }
621 625
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 } 698 }
695 699
696 if (AutoConfirmPrompt(delegate_)) 700 if (AutoConfirmPrompt(delegate_))
697 return; 701 return;
698 702
699 if (show_dialog_callback_.is_null()) 703 if (show_dialog_callback_.is_null())
700 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 704 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
701 else 705 else
702 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 706 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
703 } 707 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698