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

Side by Side Diff: chrome/browser/extensions/extension_uninstall_dialog.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_uninstall_dialog.h" 5 #include "chrome/browser/extensions/extension_uninstall_dialog.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "chrome/browser/extensions/image_loader.h" 9 #include "chrome/browser/extensions/image_loader.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/common/chrome_notification_types.h" 11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/extensions/api/icons/icons_handler.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/extension_constants.h" 14 #include "chrome/common/extensions/extension_constants.h"
14 #include "chrome/common/extensions/extension_icon_set.h" 15 #include "chrome/common/extensions/extension_icon_set.h"
15 #include "chrome/common/extensions/extension_resource.h" 16 #include "chrome/common/extensions/extension_resource.h"
16 #include "content/public/browser/notification_service.h" 17 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/notification_source.h" 18 #include "content/public/browser/notification_source.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
20 #include "ui/base/resource/resource_bundle.h" 21 #include "ui/base/resource/resource_bundle.h"
21 #include "ui/gfx/image/image.h" 22 #include "ui/gfx/image/image.h"
22 23
23 namespace { 24 namespace {
24 25
25 // Returns pixel size under maximal scale factor for the icon whose device 26 // Returns pixel size under maximal scale factor for the icon whose device
26 // independent size is |size_in_dip| 27 // independent size is |size_in_dip|
27 int GetSizeForMaxScaleFactor(int size_in_dip) { 28 int GetSizeForMaxScaleFactor(int size_in_dip) {
28 ui::ScaleFactor max_scale_factor = ui::GetMaxScaleFactor(); 29 ui::ScaleFactor max_scale_factor = ui::GetMaxScaleFactor();
29 float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor); 30 float max_scale_factor_scale = ui::GetScaleFactorScale(max_scale_factor);
30 31
31 return static_cast<int>(size_in_dip * max_scale_factor_scale); 32 return static_cast<int>(size_in_dip * max_scale_factor_scale);
32 } 33 }
33 34
34 // Returns bitmap for the default icon with size equal to the default icon's 35 // Returns bitmap for the default icon with size equal to the default icon's
35 // pixel size under maximal supported scale factor. 36 // pixel size under maximal supported scale factor.
36 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { 37 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) {
37 return extensions::Extension::GetDefaultIcon(is_app). 38 const gfx::ImageSkia& image = is_app ?
38 GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap(); 39 extensions::IconsInfo::GetDefaultAppIcon() :
40 extensions::IconsInfo::GetDefaultExtensionIcon();
41 return image.GetRepresentation(ui::GetMaxScaleFactor()).sk_bitmap();
39 } 42 }
40 43
41 } // namespace 44 } // namespace
42 45
43 // Size of extension icon in top left of dialog. 46 // Size of extension icon in top left of dialog.
44 static const int kIconSize = 69; 47 static const int kIconSize = 69;
45 48
46 ExtensionUninstallDialog::ExtensionUninstallDialog( 49 ExtensionUninstallDialog::ExtensionUninstallDialog(
47 Profile* profile, 50 Profile* profile,
48 Browser* browser, 51 Browser* browser,
(...skipping 12 matching lines...) Expand all
61 } 64 }
62 65
63 ExtensionUninstallDialog::~ExtensionUninstallDialog() { 66 ExtensionUninstallDialog::~ExtensionUninstallDialog() {
64 } 67 }
65 68
66 void ExtensionUninstallDialog::ConfirmUninstall( 69 void ExtensionUninstallDialog::ConfirmUninstall(
67 const extensions::Extension* extension) { 70 const extensions::Extension* extension) {
68 DCHECK(ui_loop_ == MessageLoop::current()); 71 DCHECK(ui_loop_ == MessageLoop::current());
69 extension_ = extension; 72 extension_ = extension;
70 73
71 ExtensionResource image = 74 ExtensionResource image = extensions::IconsInfo::GetIconResource(
72 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, 75 extension_,
73 ExtensionIconSet::MATCH_BIGGER); 76 extension_misc::EXTENSION_ICON_LARGE,
74 77 ExtensionIconSet::MATCH_BIGGER);
75 // Load the icon whose pixel size is large enough to be displayed under 78 // Load the icon whose pixel size is large enough to be displayed under
76 // maximal supported scale factor. UI code will scale the icon down if needed. 79 // maximal supported scale factor. UI code will scale the icon down if needed.
77 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); 80 int pixel_size = GetSizeForMaxScaleFactor(kIconSize);
78 81
79 // Load the image asynchronously. The response will be sent to OnImageLoaded. 82 // Load the image asynchronously. The response will be sent to OnImageLoaded.
80 state_ = kImageIsLoading; 83 state_ = kImageIsLoading;
81 extensions::ImageLoader* loader = 84 extensions::ImageLoader* loader =
82 extensions::ImageLoader::Get(profile_); 85 extensions::ImageLoader::Get(profile_);
83 loader->LoadImageAsync(extension_, image, 86 loader->LoadImageAsync(extension_, image,
84 gfx::Size(pixel_size, pixel_size), 87 gfx::Size(pixel_size, pixel_size),
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 123
121 browser_ = NULL; 124 browser_ = NULL;
122 // If the browser is closed while waiting for the image, we need to send a 125 // If the browser is closed while waiting for the image, we need to send a
123 // "cancel" event here, because there will not be another opportunity to 126 // "cancel" event here, because there will not be another opportunity to
124 // notify the delegate of the cancellation as we won't open the dialog. 127 // notify the delegate of the cancellation as we won't open the dialog.
125 if (state_ == kImageIsLoading) { 128 if (state_ == kImageIsLoading) {
126 state_ = kBrowserIsClosing; 129 state_ = kBrowserIsClosing;
127 delegate_->ExtensionUninstallCanceled(); 130 delegate_->ExtensionUninstallCanceled();
128 } 131 }
129 } 132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698