| 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_disabled_ui.h" | 5 #include "chrome/browser/extensions/extension_disabled_ui.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "extensions/common/extension.h" | 45 #include "extensions/common/extension.h" |
| 46 #include "extensions/common/extension_icon_set.h" | 46 #include "extensions/common/extension_icon_set.h" |
| 47 #include "extensions/common/manifest_handlers/icons_handler.h" | 47 #include "extensions/common/manifest_handlers/icons_handler.h" |
| 48 #include "extensions/common/permissions/permission_message.h" | 48 #include "extensions/common/permissions/permission_message.h" |
| 49 #include "extensions/common/permissions/permissions_data.h" | 49 #include "extensions/common/permissions/permissions_data.h" |
| 50 #include "ui/base/l10n/l10n_util.h" | 50 #include "ui/base/l10n/l10n_util.h" |
| 51 #include "ui/gfx/geometry/size.h" | 51 #include "ui/gfx/geometry/size.h" |
| 52 #include "ui/gfx/image/image.h" | 52 #include "ui/gfx/image/image.h" |
| 53 #include "ui/gfx/image/image_skia_operations.h" | 53 #include "ui/gfx/image/image_skia_operations.h" |
| 54 | 54 |
| 55 using extensions::Extension; | |
| 56 using extensions::PermissionMessage; | |
| 57 using extensions::PermissionMessages; | |
| 58 | |
| 59 namespace { | 55 namespace { |
| 60 | 56 |
| 61 static const int kIconSize = extension_misc::EXTENSION_ICON_SMALL; | 57 static const int kIconSize = extension_misc::EXTENSION_ICON_SMALL; |
| 62 | 58 |
| 63 } // namespace | 59 } // namespace |
| 64 | 60 |
| 65 // ExtensionDisabledGlobalError ----------------------------------------------- | 61 // ExtensionDisabledGlobalError ----------------------------------------------- |
| 66 | 62 |
| 67 class ExtensionDisabledGlobalError | 63 namespace extensions { |
| 68 : public GlobalErrorWithStandardBubble, | 64 |
| 69 public content::NotificationObserver, | 65 class ExtensionDisabledGlobalError : public GlobalErrorWithStandardBubble, |
| 70 public extensions::ExtensionUninstallDialog::Delegate, | 66 public content::NotificationObserver, |
| 71 public extensions::ExtensionRegistryObserver { | 67 public ExtensionUninstallDialog::Delegate, |
| 68 public ExtensionRegistryObserver { |
| 72 public: | 69 public: |
| 73 ExtensionDisabledGlobalError(ExtensionService* service, | 70 ExtensionDisabledGlobalError(ExtensionService* service, |
| 74 const Extension* extension, | 71 const Extension* extension, |
| 75 bool is_remote_install, | 72 bool is_remote_install, |
| 76 const gfx::Image& icon); | 73 const gfx::Image& icon); |
| 77 ~ExtensionDisabledGlobalError() override; | 74 ~ExtensionDisabledGlobalError() override; |
| 78 | 75 |
| 79 // GlobalError: | 76 // GlobalError: |
| 80 Severity GetSeverity() override; | 77 Severity GetSeverity() override; |
| 81 bool HasMenuItem() override; | 78 bool HasMenuItem() override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 99 | 96 |
| 100 private: | 97 private: |
| 101 // content::NotificationObserver: | 98 // content::NotificationObserver: |
| 102 void Observe(int type, | 99 void Observe(int type, |
| 103 const content::NotificationSource& source, | 100 const content::NotificationSource& source, |
| 104 const content::NotificationDetails& details) override; | 101 const content::NotificationDetails& details) override; |
| 105 | 102 |
| 106 // ExtensionRegistryObserver: | 103 // ExtensionRegistryObserver: |
| 107 void OnExtensionLoaded(content::BrowserContext* browser_context, | 104 void OnExtensionLoaded(content::BrowserContext* browser_context, |
| 108 const Extension* extension) override; | 105 const Extension* extension) override; |
| 109 void OnShutdown(extensions::ExtensionRegistry* registry) override; | 106 void OnShutdown(ExtensionRegistry* registry) override; |
| 110 | 107 |
| 111 void RemoveGlobalError(); | 108 void RemoveGlobalError(); |
| 112 | 109 |
| 113 ExtensionService* service_; | 110 ExtensionService* service_; |
| 114 const Extension* extension_; | 111 const Extension* extension_; |
| 115 bool is_remote_install_; | 112 bool is_remote_install_; |
| 116 gfx::Image icon_; | 113 gfx::Image icon_; |
| 117 | 114 |
| 118 // How the user responded to the error; used for metrics. | 115 // How the user responded to the error; used for metrics. |
| 119 enum UserResponse { | 116 enum UserResponse { |
| 120 IGNORED, | 117 IGNORED, |
| 121 REENABLE, | 118 REENABLE, |
| 122 UNINSTALL, | 119 UNINSTALL, |
| 123 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY | 120 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY |
| 124 }; | 121 }; |
| 125 UserResponse user_response_; | 122 UserResponse user_response_; |
| 126 | 123 |
| 127 std::unique_ptr<extensions::ExtensionUninstallDialog> uninstall_dialog_; | 124 std::unique_ptr<ExtensionUninstallDialog> uninstall_dialog_; |
| 128 | 125 |
| 129 // Helper to get menu command ID assigned for this extension's error. | 126 // Helper to get menu command ID assigned for this extension's error. |
| 130 extensions::ExtensionInstallErrorMenuItemIdProvider id_provider_; | 127 ExtensionInstallErrorMenuItemIdProvider id_provider_; |
| 131 | 128 |
| 132 content::NotificationRegistrar registrar_; | 129 content::NotificationRegistrar registrar_; |
| 133 | 130 |
| 134 ScopedObserver<extensions::ExtensionRegistry, | 131 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
| 135 extensions::ExtensionRegistryObserver> registry_observer_; | 132 registry_observer_; |
| 136 }; | 133 }; |
| 137 | 134 |
| 138 // TODO(yoz): create error at startup for disabled extensions. | 135 // TODO(yoz): create error at startup for disabled extensions. |
| 139 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( | 136 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( |
| 140 ExtensionService* service, | 137 ExtensionService* service, |
| 141 const Extension* extension, | 138 const Extension* extension, |
| 142 bool is_remote_install, | 139 bool is_remote_install, |
| 143 const gfx::Image& icon) | 140 const gfx::Image& icon) |
| 144 : service_(service), | 141 : service_(service), |
| 145 extension_(extension), | 142 extension_(extension), |
| 146 is_remote_install_(is_remote_install), | 143 is_remote_install_(is_remote_install), |
| 147 icon_(icon), | 144 icon_(icon), |
| 148 user_response_(IGNORED), | 145 user_response_(IGNORED), |
| 149 registry_observer_(this) { | 146 registry_observer_(this) { |
| 150 if (icon_.IsEmpty()) { | 147 if (icon_.IsEmpty()) { |
| 151 icon_ = gfx::Image( | 148 icon_ = gfx::Image(gfx::ImageSkiaOperations::CreateResizedImage( |
| 152 gfx::ImageSkiaOperations::CreateResizedImage( | 149 extension_->is_app() ? util::GetDefaultAppIcon() |
| 153 extension_->is_app() ? | 150 : util::GetDefaultExtensionIcon(), |
| 154 extensions::util::GetDefaultAppIcon() : | 151 skia::ImageOperations::RESIZE_BEST, gfx::Size(kIconSize, kIconSize))); |
| 155 extensions::util::GetDefaultExtensionIcon(), | |
| 156 skia::ImageOperations::RESIZE_BEST, | |
| 157 gfx::Size(kIconSize, kIconSize))); | |
| 158 } | 152 } |
| 159 registry_observer_.Add( | 153 registry_observer_.Add(ExtensionRegistry::Get(service->profile())); |
| 160 extensions::ExtensionRegistry::Get(service->profile())); | 154 registrar_.Add(this, NOTIFICATION_EXTENSION_REMOVED, |
| 161 registrar_.Add(this, | |
| 162 extensions::NOTIFICATION_EXTENSION_REMOVED, | |
| 163 content::Source<Profile>(service->profile())); | 155 content::Source<Profile>(service->profile())); |
| 164 } | 156 } |
| 165 | 157 |
| 166 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() {} | 158 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() {} |
| 167 | 159 |
| 168 GlobalError::Severity ExtensionDisabledGlobalError::GetSeverity() { | 160 GlobalError::Severity ExtensionDisabledGlobalError::GetSeverity() { |
| 169 return SEVERITY_LOW; | 161 return SEVERITY_LOW; |
| 170 } | 162 } |
| 171 | 163 |
| 172 bool ExtensionDisabledGlobalError::HasMenuItem() { | 164 bool ExtensionDisabledGlobalError::HasMenuItem() { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 base::UTF8ToUTF16(extension_->name())); | 200 base::UTF8ToUTF16(extension_->name())); |
| 209 } else { | 201 } else { |
| 210 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, | 202 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, |
| 211 base::UTF8ToUTF16(extension_->name())); | 203 base::UTF8ToUTF16(extension_->name())); |
| 212 } | 204 } |
| 213 } | 205 } |
| 214 | 206 |
| 215 std::vector<base::string16> | 207 std::vector<base::string16> |
| 216 ExtensionDisabledGlobalError::GetBubbleViewMessages() { | 208 ExtensionDisabledGlobalError::GetBubbleViewMessages() { |
| 217 std::vector<base::string16> messages; | 209 std::vector<base::string16> messages; |
| 210 |
| 211 std::unique_ptr<const PermissionSet> granted_permissions = |
| 212 ExtensionPrefs::Get(service_->GetBrowserContext()) |
| 213 ->GetGrantedPermissions(extension_->id()); |
| 214 |
| 218 PermissionMessages permission_warnings = | 215 PermissionMessages permission_warnings = |
| 219 extension_->permissions_data()->GetPermissionMessages(); | 216 extension_->permissions_data()->GetNewPermissionMessages( |
| 217 *granted_permissions); |
| 218 |
| 220 if (is_remote_install_) { | 219 if (is_remote_install_) { |
| 221 if (!permission_warnings.empty()) | 220 if (!permission_warnings.empty()) |
| 222 messages.push_back( | 221 messages.push_back( |
| 223 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO)); | 222 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO)); |
| 224 } else { | 223 } else { |
| 225 // TODO(treib): If NeedCustodianApprovalForPermissionIncrease, add an extra | 224 // TODO(treib): If NeedCustodianApprovalForPermissionIncrease, add an extra |
| 226 // message for supervised users. crbug.com/461261 | 225 // message for supervised users. crbug.com/461261 |
| 227 messages.push_back(l10n_util::GetStringFUTF16( | 226 messages.push_back( |
| 228 extension_->is_app() ? IDS_APP_DISABLED_ERROR_LABEL | 227 l10n_util::GetStringUTF16(IDS_EXTENSION_DISABLED_ERROR_LABEL)); |
| 229 : IDS_EXTENSION_DISABLED_ERROR_LABEL, | |
| 230 base::UTF8ToUTF16(extension_->name()))); | |
| 231 messages.push_back(l10n_util::GetStringUTF16( | |
| 232 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO)); | |
| 233 } | 228 } |
| 234 for (const PermissionMessage& msg : permission_warnings) { | 229 for (const PermissionMessage& msg : permission_warnings) { |
| 235 messages.push_back(l10n_util::GetStringFUTF16(IDS_EXTENSION_PERMISSION_LINE, | 230 messages.push_back(l10n_util::GetStringFUTF16(IDS_EXTENSION_PERMISSION_LINE, |
| 236 msg.message())); | 231 msg.message())); |
| 237 } | 232 } |
| 238 return messages; | 233 return messages; |
| 239 } | 234 } |
| 240 | 235 |
| 241 base::string16 ExtensionDisabledGlobalError::GetBubbleViewAcceptButtonLabel() { | 236 base::string16 ExtensionDisabledGlobalError::GetBubbleViewAcceptButtonLabel() { |
| 242 if (extensions::util::IsExtensionSupervised(extension_, | 237 if (util::IsExtensionSupervised(extension_, service_->profile())) { |
| 243 service_->profile())) { | |
| 244 // TODO(treib): Probably use a new string here once we get UX design. | 238 // TODO(treib): Probably use a new string here once we get UX design. |
| 245 // For now, just use "OK". crbug.com/461261 | 239 // For now, just use "OK". crbug.com/461261 |
| 246 return l10n_util::GetStringUTF16(IDS_OK); | 240 return l10n_util::GetStringUTF16(IDS_OK); |
| 247 } | 241 } |
| 248 if (is_remote_install_) { | 242 if (is_remote_install_) { |
| 249 return l10n_util::GetStringUTF16( | 243 return l10n_util::GetStringUTF16( |
| 250 extension_->is_app() | 244 extension_->is_app() |
| 251 ? IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON_APP | 245 ? IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON_APP |
| 252 : IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON_EXTENSION); | 246 : IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON_EXTENSION); |
| 253 } | 247 } |
| 254 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON); | 248 return l10n_util::GetStringUTF16( |
| 249 IDS_EXTENSION_PROMPT_PERMISSIONS_ACCEPT_BUTTON); |
| 255 } | 250 } |
| 256 | 251 |
| 257 base::string16 ExtensionDisabledGlobalError::GetBubbleViewCancelButtonLabel() { | 252 base::string16 ExtensionDisabledGlobalError::GetBubbleViewCancelButtonLabel() { |
| 258 if (extensions::util::IsExtensionSupervised(extension_, | 253 if (util::IsExtensionSupervised(extension_, service_->profile())) { |
| 259 service_->profile())) { | |
| 260 // The supervised user can't approve the update, and hence there is no | 254 // The supervised user can't approve the update, and hence there is no |
| 261 // "cancel" button. Return an empty string such that the "cancel" button | 255 // "cancel" button. Return an empty string such that the "cancel" button |
| 262 // is not shown in the dialog. | 256 // is not shown in the dialog. |
| 263 return base::string16(); | 257 return base::string16(); |
| 264 } | 258 } |
| 265 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL); | 259 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_UNINSTALL_BUTTON); |
| 266 } | 260 } |
| 267 | 261 |
| 268 void ExtensionDisabledGlobalError::OnBubbleViewDidClose(Browser* browser) { | 262 void ExtensionDisabledGlobalError::OnBubbleViewDidClose(Browser* browser) { |
| 269 // If the user takes an action, |user_response_| is set in | 263 // If the user takes an action, |user_response_| is set in |
| 270 // BubbleView[Cancel|Accept]Pressed(). Otherwise, the IGNORE value set in the | 264 // BubbleView[Cancel|Accept]Pressed(). Otherwise, the IGNORE value set in the |
| 271 // constructor is correct. | 265 // constructor is correct. |
| 272 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponseRemoteInstall2", | 266 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponseRemoteInstall2", |
| 273 user_response_, | 267 user_response_, |
| 274 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); | 268 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); |
| 275 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse2", | 269 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse2", |
| 276 user_response_, | 270 user_response_, |
| 277 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); | 271 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); |
| 278 // Reset in case the user does not follow through on subsequent dialogs to | 272 // Reset in case the user does not follow through on subsequent dialogs to |
| 279 // confirm removal decision, in which case the bubble can be shown again | 273 // confirm removal decision, in which case the bubble can be shown again |
| 280 // when the user clicks on the global error in the menu. | 274 // when the user clicks on the global error in the menu. |
| 281 user_response_ = IGNORED; | 275 user_response_ = IGNORED; |
| 282 } | 276 } |
| 283 | 277 |
| 284 void ExtensionDisabledGlobalError::BubbleViewAcceptButtonPressed( | 278 void ExtensionDisabledGlobalError::BubbleViewAcceptButtonPressed( |
| 285 Browser* browser) { | 279 Browser* browser) { |
| 286 if (extensions::util::IsExtensionSupervised(extension_, | 280 if (util::IsExtensionSupervised(extension_, service_->profile())) { |
| 287 service_->profile())) { | |
| 288 return; | 281 return; |
| 289 } | 282 } |
| 290 user_response_ = REENABLE; | 283 user_response_ = REENABLE; |
| 291 // Delay extension reenabling so this bubble closes properly. | 284 // Delay extension reenabling so this bubble closes properly. |
| 292 base::ThreadTaskRunnerHandle::Get()->PostTask( | 285 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 293 FROM_HERE, | 286 FROM_HERE, |
| 294 base::BindOnce(&ExtensionService::GrantPermissionsAndEnableExtension, | 287 base::BindOnce(&ExtensionService::GrantPermissionsAndEnableExtension, |
| 295 service_->AsWeakPtr(), extension_)); | 288 service_->AsWeakPtr(), extension_)); |
| 296 } | 289 } |
| 297 | 290 |
| 298 void ExtensionDisabledGlobalError::BubbleViewCancelButtonPressed( | 291 void ExtensionDisabledGlobalError::BubbleViewCancelButtonPressed( |
| 299 Browser* browser) { | 292 Browser* browser) { |
| 300 // For custodian-installed extensions, this button should not exist because | 293 // For custodian-installed extensions, this button should not exist because |
| 301 // there is only an "OK" button. | 294 // there is only an "OK" button. |
| 302 // Supervised users may never remove custodian-installed extensions. | 295 // Supervised users may never remove custodian-installed extensions. |
| 303 DCHECK(!extensions::util::IsExtensionSupervised(extension_, | 296 DCHECK(!util::IsExtensionSupervised(extension_, service_->profile())); |
| 304 service_->profile())); | 297 uninstall_dialog_.reset(ExtensionUninstallDialog::Create( |
| 305 uninstall_dialog_.reset(extensions::ExtensionUninstallDialog::Create( | |
| 306 service_->profile(), browser->window()->GetNativeWindow(), this)); | 298 service_->profile(), browser->window()->GetNativeWindow(), this)); |
| 307 user_response_ = UNINSTALL; | 299 user_response_ = UNINSTALL; |
| 308 // Delay showing the uninstall dialog, so that this function returns | 300 // Delay showing the uninstall dialog, so that this function returns |
| 309 // immediately, to close the bubble properly. See crbug.com/121544. | 301 // immediately, to close the bubble properly. See crbug.com/121544. |
| 310 base::ThreadTaskRunnerHandle::Get()->PostTask( | 302 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 311 FROM_HERE, | 303 FROM_HERE, base::Bind(&ExtensionUninstallDialog::ConfirmUninstall, |
| 312 base::BindOnce(&extensions::ExtensionUninstallDialog::ConfirmUninstall, | 304 uninstall_dialog_->AsWeakPtr(), extension_, |
| 313 uninstall_dialog_->AsWeakPtr(), extension_, | 305 UNINSTALL_REASON_EXTENSION_DISABLED, |
| 314 extensions::UNINSTALL_REASON_EXTENSION_DISABLED, | 306 UNINSTALL_SOURCE_PERMISSIONS_INCREASE)); |
| 315 extensions::UNINSTALL_SOURCE_PERMISSIONS_INCREASE)); | |
| 316 } | 307 } |
| 317 | 308 |
| 318 bool ExtensionDisabledGlobalError::ShouldCloseOnDeactivate() const { | 309 bool ExtensionDisabledGlobalError::ShouldCloseOnDeactivate() const { |
| 319 // Since this indicates that an extension was disabled, we should definitely | 310 // Since this indicates that an extension was disabled, we should definitely |
| 320 // have the user acknowledge it, rather than having the bubble disappear when | 311 // have the user acknowledge it, rather than having the bubble disappear when |
| 321 // a new window pops up. | 312 // a new window pops up. |
| 322 return false; | 313 return false; |
| 323 } | 314 } |
| 324 | 315 |
| 325 bool ExtensionDisabledGlobalError::ShouldShowCloseButton() const { | 316 bool ExtensionDisabledGlobalError::ShouldShowCloseButton() const { |
| 326 // As we don't close the bubble on deactivation (see ShouldCloseOnDeactivate), | 317 // As we don't close the bubble on deactivation (see ShouldCloseOnDeactivate), |
| 327 // we add a close button so the user doesn't *need* to act right away. | 318 // we add a close button so the user doesn't *need* to act right away. |
| 328 // If the bubble is closed, the error remains in the wrench menu and the user | 319 // If the bubble is closed, the error remains in the wrench menu and the user |
| 329 // can address it later. | 320 // can address it later. |
| 330 return true; | 321 return true; |
| 331 } | 322 } |
| 332 | 323 |
| 333 void ExtensionDisabledGlobalError::OnExtensionUninstallDialogClosed( | 324 void ExtensionDisabledGlobalError::OnExtensionUninstallDialogClosed( |
| 334 bool did_start_uninstall, | 325 bool did_start_uninstall, |
| 335 const base::string16& error) { | 326 const base::string16& error) { |
| 336 // No need to do anything. | 327 // No need to do anything. |
| 337 } | 328 } |
| 338 | 329 |
| 339 void ExtensionDisabledGlobalError::Observe( | 330 void ExtensionDisabledGlobalError::Observe( |
| 340 int type, | 331 int type, |
| 341 const content::NotificationSource& source, | 332 const content::NotificationSource& source, |
| 342 const content::NotificationDetails& details) { | 333 const content::NotificationDetails& details) { |
| 343 // The error is invalidated if the extension has been loaded or removed. | 334 // The error is invalidated if the extension has been loaded or removed. |
| 344 DCHECK_EQ(extensions::NOTIFICATION_EXTENSION_REMOVED, type); | 335 DCHECK_EQ(NOTIFICATION_EXTENSION_REMOVED, type); |
| 345 const Extension* extension = content::Details<const Extension>(details).ptr(); | 336 const Extension* extension = content::Details<const Extension>(details).ptr(); |
| 346 if (extension != extension_) | 337 if (extension != extension_) |
| 347 return; | 338 return; |
| 348 RemoveGlobalError(); | 339 RemoveGlobalError(); |
| 349 } | 340 } |
| 350 | 341 |
| 351 void ExtensionDisabledGlobalError::OnExtensionLoaded( | 342 void ExtensionDisabledGlobalError::OnExtensionLoaded( |
| 352 content::BrowserContext* browser_context, | 343 content::BrowserContext* browser_context, |
| 353 const Extension* extension) { | 344 const Extension* extension) { |
| 354 if (extension != extension_) | 345 if (extension != extension_) |
| 355 return; | 346 return; |
| 356 RemoveGlobalError(); | 347 RemoveGlobalError(); |
| 357 } | 348 } |
| 358 | 349 |
| 359 void ExtensionDisabledGlobalError::OnShutdown( | 350 void ExtensionDisabledGlobalError::OnShutdown(ExtensionRegistry* registry) { |
| 360 extensions::ExtensionRegistry* registry) { | 351 DCHECK_EQ(ExtensionRegistry::Get(service_->profile()), registry); |
| 361 DCHECK_EQ(extensions::ExtensionRegistry::Get(service_->profile()), registry); | |
| 362 registry_observer_.RemoveAll(); | 352 registry_observer_.RemoveAll(); |
| 363 } | 353 } |
| 364 | 354 |
| 365 void ExtensionDisabledGlobalError::RemoveGlobalError() { | 355 void ExtensionDisabledGlobalError::RemoveGlobalError() { |
| 366 std::unique_ptr<GlobalError> ptr = | 356 std::unique_ptr<GlobalError> ptr = |
| 367 GlobalErrorServiceFactory::GetForProfile(service_->profile()) | 357 GlobalErrorServiceFactory::GetForProfile(service_->profile()) |
| 368 ->RemoveGlobalError(this); | 358 ->RemoveGlobalError(this); |
| 369 registrar_.RemoveAll(); | 359 registrar_.RemoveAll(); |
| 370 registry_observer_.RemoveAll(); | 360 registry_observer_.RemoveAll(); |
| 371 // Delete this object after any running tasks, so that the extension dialog | 361 // Delete this object after any running tasks, so that the extension dialog |
| 372 // still has it as a delegate to finish the current tasks. | 362 // still has it as a delegate to finish the current tasks. |
| 373 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, ptr.release()); | 363 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, ptr.release()); |
| 374 } | 364 } |
| 375 | 365 |
| 376 // Globals -------------------------------------------------------------------- | 366 // Globals -------------------------------------------------------------------- |
| 377 | 367 |
| 378 namespace extensions { | |
| 379 | |
| 380 void AddExtensionDisabledErrorWithIcon(base::WeakPtr<ExtensionService> service, | 368 void AddExtensionDisabledErrorWithIcon(base::WeakPtr<ExtensionService> service, |
| 381 const std::string& extension_id, | 369 const std::string& extension_id, |
| 382 bool is_remote_install, | 370 bool is_remote_install, |
| 383 const gfx::Image& icon) { | 371 const gfx::Image& icon) { |
| 384 if (!service.get()) | 372 if (!service.get()) |
| 385 return; | 373 return; |
| 386 const Extension* extension = service->GetInstalledExtension(extension_id); | 374 const Extension* extension = service->GetInstalledExtension(extension_id); |
| 387 if (extension) { | 375 if (extension) { |
| 388 GlobalErrorServiceFactory::GetForProfile(service->profile()) | 376 GlobalErrorServiceFactory::GetForProfile(service->profile()) |
| 389 ->AddGlobalError(base::MakeUnique<ExtensionDisabledGlobalError>( | 377 ->AddGlobalError(base::MakeUnique<ExtensionDisabledGlobalError>( |
| 390 service.get(), extension, is_remote_install, icon)); | 378 service.get(), extension, is_remote_install, icon)); |
| 391 } | 379 } |
| 392 } | 380 } |
| 393 | 381 |
| 394 void AddExtensionDisabledError(ExtensionService* service, | 382 void AddExtensionDisabledError(ExtensionService* service, |
| 395 const Extension* extension, | 383 const Extension* extension, |
| 396 bool is_remote_install) { | 384 bool is_remote_install) { |
| 397 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 385 ExtensionResource image = IconsInfo::GetIconResource( |
| 398 extension, kIconSize, ExtensionIconSet::MATCH_BIGGER); | 386 extension, kIconSize, ExtensionIconSet::MATCH_BIGGER); |
| 399 gfx::Size size(kIconSize, kIconSize); | 387 gfx::Size size(kIconSize, kIconSize); |
| 400 ImageLoader::Get(service->profile()) | 388 ImageLoader::Get(service->profile()) |
| 401 ->LoadImageAsync(extension, | 389 ->LoadImageAsync(extension, |
| 402 image, | 390 image, |
| 403 size, | 391 size, |
| 404 base::Bind(&AddExtensionDisabledErrorWithIcon, | 392 base::Bind(&AddExtensionDisabledErrorWithIcon, |
| 405 service->AsWeakPtr(), | 393 service->AsWeakPtr(), |
| 406 extension->id(), | 394 extension->id(), |
| 407 is_remote_install)); | 395 is_remote_install)); |
| 408 } | 396 } |
| 409 | 397 |
| 410 } // namespace extensions | 398 } // namespace extensions |
| OLD | NEW |