Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/extension_util.h" | 12 #include "chrome/browser/extensions/extension_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | |
| 15 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_source.h" | 17 #include "content/public/browser/notification_source.h" |
| 17 #include "extensions/browser/extension_registry.h" | 18 #include "extensions/browser/extension_registry.h" |
| 18 #include "extensions/browser/image_loader.h" | 19 #include "extensions/browser/image_loader.h" |
| 19 #include "extensions/common/constants.h" | 20 #include "extensions/common/constants.h" |
| 20 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/extension_icon_set.h" | 22 #include "extensions/common/extension_icon_set.h" |
| 22 #include "extensions/common/extension_resource.h" | 23 #include "extensions/common/extension_resource.h" |
| 23 #include "extensions/common/manifest_handlers/icons_handler.h" | 24 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
| 28 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
| 29 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
| 30 | 31 |
| 31 namespace extensions { | 32 namespace extensions { |
| 32 | 33 |
| 33 namespace { | 34 namespace { |
| 34 | 35 |
| 35 // Returns bitmap for the default icon with size equal to the default icon's | 36 // Returns bitmap for the default icon with size equal to the default icon's |
| 36 // pixel size under maximal supported scale factor. | 37 // pixel size under maximal supported scale factor. |
| 37 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { | 38 SkBitmap GetDefaultIconBitmapForMaxScaleFactor(bool is_app) { |
| 38 const gfx::ImageSkia& image = | 39 const gfx::ImageSkia& image = |
| 39 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); | 40 is_app ? util::GetDefaultAppIcon() : util::GetDefaultExtensionIcon(); |
| 40 return image.GetRepresentation( | 41 return image.GetRepresentation( |
| 41 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); | 42 gfx::ImageSkia::GetMaxSupportedScale()).sk_bitmap(); |
| 42 } | 43 } |
| 43 | 44 |
| 45 // Returns parent window for extension uninstall dialog. | |
| 46 gfx::NativeWindow GetParent(Browser* browser) { | |
| 47 if (browser && browser->window()) | |
| 48 return browser->window()->GetNativeWindow(); | |
| 49 return NULL; | |
| 50 } | |
| 51 | |
| 44 } // namespace | 52 } // namespace |
| 45 | 53 |
| 46 ExtensionUninstallDialog::ExtensionUninstallDialog( | 54 ExtensionUninstallDialog::ExtensionUninstallDialog( |
| 47 Profile* profile, | 55 Profile* profile, |
| 48 Browser* browser, | 56 Browser* browser, |
| 57 gfx::NativeWindow parent, | |
| 49 ExtensionUninstallDialog::Delegate* delegate) | 58 ExtensionUninstallDialog::Delegate* delegate) |
| 50 : profile_(profile), | 59 : profile_(profile), |
| 51 browser_(browser), | 60 browser_(browser), |
| 61 parent_(parent), | |
| 52 delegate_(delegate), | 62 delegate_(delegate), |
| 53 extension_(NULL), | 63 extension_(NULL), |
| 54 triggering_extension_(NULL), | 64 triggering_extension_(NULL), |
| 55 state_(kImageIsLoading), | 65 state_(kImageIsLoading), |
| 56 ui_loop_(base::MessageLoop::current()) { | 66 ui_loop_(base::MessageLoop::current()) { |
| 57 if (browser) { | 67 if (browser) { |
| 68 // Close the dialog if the browser is closed while the dialog is open. | |
| 58 registrar_.Add(this, | 69 registrar_.Add(this, |
| 59 chrome::NOTIFICATION_BROWSER_CLOSED, | 70 chrome::NOTIFICATION_BROWSER_CLOSED, |
| 60 content::Source<Browser>(browser)); | 71 content::Source<Browser>(browser)); |
| 72 | |
| 73 // If there are no open browser windows, close the dialog immediately. | |
|
not at google - send to devlin
2014/07/23 01:49:21
is this logic that you actually need?
...
I ask
| |
| 74 parent_ = GetParent(browser); | |
| 75 if (!parent_) | |
| 76 delegate_->ExtensionUninstallCanceled(); | |
| 61 } | 77 } |
| 62 } | 78 } |
| 63 | 79 |
| 64 ExtensionUninstallDialog::~ExtensionUninstallDialog() { | 80 ExtensionUninstallDialog::~ExtensionUninstallDialog() { |
| 65 } | 81 } |
| 66 | 82 |
| 67 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( | 83 void ExtensionUninstallDialog::ConfirmProgrammaticUninstall( |
| 68 const Extension* extension, | 84 const Extension* extension, |
| 69 const Extension* triggering_extension) { | 85 const Extension* triggering_extension) { |
| 70 triggering_extension_ = triggering_extension; | 86 triggering_extension_ = triggering_extension; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 Show(); | 148 Show(); |
| 133 } | 149 } |
| 134 } | 150 } |
| 135 | 151 |
| 136 void ExtensionUninstallDialog::Observe( | 152 void ExtensionUninstallDialog::Observe( |
| 137 int type, | 153 int type, |
| 138 const content::NotificationSource& source, | 154 const content::NotificationSource& source, |
| 139 const content::NotificationDetails& details) { | 155 const content::NotificationDetails& details) { |
| 140 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED); | 156 DCHECK(type == chrome::NOTIFICATION_BROWSER_CLOSED); |
| 141 | 157 |
| 142 browser_ = NULL; | |
| 143 // If the browser is closed while waiting for the image, we need to send a | 158 // If the browser is closed while waiting for the image, we need to send a |
| 144 // "cancel" event here, because there will not be another opportunity to | 159 // "cancel" event here, because there will not be another opportunity to |
| 145 // notify the delegate of the cancellation as we won't open the dialog. | 160 // notify the delegate of the cancellation as we won't open the dialog. |
| 146 if (state_ == kImageIsLoading) { | 161 if (state_ == kImageIsLoading) { |
| 147 state_ = kBrowserIsClosing; | 162 state_ = kBrowserIsClosing; |
| 148 delegate_->ExtensionUninstallCanceled(); | 163 delegate_->ExtensionUninstallCanceled(); |
| 149 } | 164 } |
| 150 } | 165 } |
| 151 | 166 |
| 152 std::string ExtensionUninstallDialog::GetHeadingText() { | 167 std::string ExtensionUninstallDialog::GetHeadingText() { |
| 153 if (triggering_extension_) { | 168 if (triggering_extension_) { |
| 154 return l10n_util::GetStringFUTF8( | 169 return l10n_util::GetStringFUTF8( |
| 155 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, | 170 IDS_EXTENSION_PROGRAMMATIC_UNINSTALL_PROMPT_HEADING, |
| 156 base::UTF8ToUTF16(triggering_extension_->name()), | 171 base::UTF8ToUTF16(triggering_extension_->name()), |
| 157 base::UTF8ToUTF16(extension_->name())); | 172 base::UTF8ToUTF16(extension_->name())); |
| 158 } | 173 } |
| 159 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, | 174 return l10n_util::GetStringFUTF8(IDS_EXTENSION_UNINSTALL_PROMPT_HEADING, |
| 160 base::UTF8ToUTF16(extension_->name())); | 175 base::UTF8ToUTF16(extension_->name())); |
| 161 } | 176 } |
| 162 | 177 |
| 163 } // namespace extensions | 178 } // namespace extensions |
| OLD | NEW |