| OLD | NEW |
| 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_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 Browser* browser, | 50 Browser* browser, |
| 48 ExtensionUninstallDialog::Delegate* delegate) | 51 ExtensionUninstallDialog::Delegate* delegate) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 } | 62 } |
| 60 | 63 |
| 61 ExtensionUninstallDialog::~ExtensionUninstallDialog() { | 64 ExtensionUninstallDialog::~ExtensionUninstallDialog() { |
| 62 } | 65 } |
| 63 | 66 |
| 64 void ExtensionUninstallDialog::ConfirmUninstall( | 67 void ExtensionUninstallDialog::ConfirmUninstall( |
| 65 const extensions::Extension* extension) { | 68 const extensions::Extension* extension) { |
| 66 DCHECK(ui_loop_ == MessageLoop::current()); | 69 DCHECK(ui_loop_ == MessageLoop::current()); |
| 67 extension_ = extension; | 70 extension_ = extension; |
| 68 | 71 |
| 69 ExtensionResource image = | 72 ExtensionResource image = extensions::IconsInfo::GetIconResource( |
| 70 extension_->GetIconResource(extension_misc::EXTENSION_ICON_LARGE, | 73 extension_, |
| 71 ExtensionIconSet::MATCH_BIGGER); | 74 extension_misc::EXTENSION_ICON_LARGE, |
| 72 | 75 ExtensionIconSet::MATCH_BIGGER); |
| 73 // Load the icon whose pixel size is large enough to be displayed under | 76 // Load the icon whose pixel size is large enough to be displayed under |
| 74 // maximal supported scale factor. UI code will scale the icon down if needed. | 77 // maximal supported scale factor. UI code will scale the icon down if needed. |
| 75 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); | 78 int pixel_size = GetSizeForMaxScaleFactor(kIconSize); |
| 76 | 79 |
| 77 // Load the image asynchronously. The response will be sent to OnImageLoaded. | 80 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
| 78 state_ = kImageIsLoading; | 81 state_ = kImageIsLoading; |
| 79 extensions::ImageLoader* loader = | 82 extensions::ImageLoader* loader = |
| 80 extensions::ImageLoader::Get(browser_->profile()); | 83 extensions::ImageLoader::Get(browser_->profile()); |
| 81 loader->LoadImageAsync(extension_, image, | 84 loader->LoadImageAsync(extension_, image, |
| 82 gfx::Size(pixel_size, pixel_size), | 85 gfx::Size(pixel_size, pixel_size), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // If the browser is closed while waiting for the image, we need to send a | 123 // If the browser is closed while waiting for the image, we need to send a |
| 121 // "cancel" event here, because there will not be another opportunity to | 124 // "cancel" event here, because there will not be another opportunity to |
| 122 // notify the delegate of the cancellation as we won't open the dialog. | 125 // notify the delegate of the cancellation as we won't open the dialog. |
| 123 if (state_ == kImageIsLoading) { | 126 if (state_ == kImageIsLoading) { |
| 124 state_ = kBrowserIsClosing; | 127 state_ = kBrowserIsClosing; |
| 125 DCHECK(browser_ != NULL); | 128 DCHECK(browser_ != NULL); |
| 126 browser_ = NULL; | 129 browser_ = NULL; |
| 127 delegate_->ExtensionUninstallCanceled(); | 130 delegate_->ExtensionUninstallCanceled(); |
| 128 } | 131 } |
| 129 } | 132 } |
| OLD | NEW |