OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_generic_dialog.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/message_loop.h" |
| 9 #include "chrome/browser/extensions/extension_install_dialog.h" |
| 10 #include "chrome/browser/profiles/profile.h" |
| 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/extensions/extension_icon_set.h" |
| 13 #include "chrome/common/extensions/extension_resource.h" |
| 14 #include "grit/theme_resources.h" |
| 15 #include "ui/base/resource/resource_bundle.h" |
| 16 |
| 17 // Size of extension icon in top left of dialog. |
| 18 static const int kIconSize = 69; |
| 19 |
| 20 ExtensionGenericDialog::ExtensionGenericDialog(Profile* profile) |
| 21 : profile_(profile), |
| 22 ui_loop_(MessageLoop::current()), |
| 23 delegate_(NULL), |
| 24 extension_(NULL), |
| 25 dialog_type_(DIALOG_NUM_TYPES), |
| 26 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)) { |
| 27 } |
| 28 |
| 29 ExtensionGenericDialog::~ExtensionGenericDialog() { |
| 30 } |
| 31 |
| 32 void ExtensionGenericDialog::ConfirmUninstall(Delegate* delegate, |
| 33 const Extension* extension) { |
| 34 DCHECK(ui_loop_ == MessageLoop::current()); |
| 35 delegate_ = delegate; |
| 36 extension_ = extension; |
| 37 |
| 38 ShowConfirmation(DIALOG_UNINSTALL); |
| 39 } |
| 40 |
| 41 void ExtensionGenericDialog::ConfirmReenable(Delegate* delegate, |
| 42 const Extension* extension) { |
| 43 DCHECK(ui_loop_ == MessageLoop::current()); |
| 44 delegate_ = delegate; |
| 45 extension_ = extension; |
| 46 |
| 47 ShowConfirmation(DIALOG_RE_ENABLE); |
| 48 } |
| 49 |
| 50 void ExtensionGenericDialog::ShowConfirmation(DialogType dialog_type) { |
| 51 dialog_type_ = dialog_type; |
| 52 ExtensionResource image = |
| 53 extension_->GetIconResource(Extension::EXTENSION_ICON_LARGE, |
| 54 ExtensionIconSet::MATCH_EXACTLY); |
| 55 // Load the image asynchronously. The response will be sent to OnImageLoaded. |
| 56 tracker_.LoadImage(extension_, image, |
| 57 gfx::Size(kIconSize, kIconSize), |
| 58 ImageLoadingTracker::DONT_CACHE); |
| 59 } |
| 60 |
| 61 void ExtensionGenericDialog::SetIcon(SkBitmap* image) { |
| 62 if (image) |
| 63 icon_ = *image; |
| 64 else |
| 65 icon_ = SkBitmap(); |
| 66 if (icon_.empty()) { |
| 67 if (extension_->is_app()) { |
| 68 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 69 IDR_APP_DEFAULT_ICON); |
| 70 } else { |
| 71 icon_ = *ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 72 IDR_EXTENSION_DEFAULT_ICON); |
| 73 } |
| 74 } |
| 75 } |
| 76 |
| 77 void ExtensionGenericDialog::OnImageLoaded(SkBitmap* image, |
| 78 const ExtensionResource& resource, |
| 79 int index) { |
| 80 SetIcon(image); |
| 81 |
| 82 switch (dialog_type_) { |
| 83 case DIALOG_UNINSTALL: { |
| 84 // ShowGenericExtensionDialog( |
| 85 // profile_, delegate_, extension_, &icon_, DIALOG_UNINSTALL); |
| 86 break; |
| 87 } |
| 88 default: |
| 89 NOTREACHED() << "Unknown message"; |
| 90 break; |
| 91 } |
| 92 } |
OLD | NEW |