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_disabled_ui.h" | 5 #include "chrome/browser/extensions/extension_disabled_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 } | 135 } |
| 136 | 136 |
| 137 // ExtensionDisabledGlobalError ----------------------------------------------- | 137 // ExtensionDisabledGlobalError ----------------------------------------------- |
| 138 | 138 |
| 139 class ExtensionDisabledGlobalError : public GlobalErrorWithStandardBubble, | 139 class ExtensionDisabledGlobalError : public GlobalErrorWithStandardBubble, |
| 140 public content::NotificationObserver, | 140 public content::NotificationObserver, |
| 141 public ExtensionUninstallDialog::Delegate { | 141 public ExtensionUninstallDialog::Delegate { |
| 142 public: | 142 public: |
| 143 ExtensionDisabledGlobalError(ExtensionService* service, | 143 ExtensionDisabledGlobalError(ExtensionService* service, |
| 144 const Extension* extension, | 144 const Extension* extension, |
| 145 bool is_remote_install, | |
| 145 const gfx::Image& icon); | 146 const gfx::Image& icon); |
| 146 virtual ~ExtensionDisabledGlobalError(); | 147 virtual ~ExtensionDisabledGlobalError(); |
| 147 | 148 |
| 148 // GlobalError implementation. | 149 // GlobalError implementation. |
| 149 virtual Severity GetSeverity() OVERRIDE; | 150 virtual Severity GetSeverity() OVERRIDE; |
| 150 virtual bool HasMenuItem() OVERRIDE; | 151 virtual bool HasMenuItem() OVERRIDE; |
| 151 virtual int MenuItemCommandID() OVERRIDE; | 152 virtual int MenuItemCommandID() OVERRIDE; |
| 152 virtual base::string16 MenuItemLabel() OVERRIDE; | 153 virtual base::string16 MenuItemLabel() OVERRIDE; |
| 153 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; | 154 virtual void ExecuteMenuItem(Browser* browser) OVERRIDE; |
| 154 virtual gfx::Image GetBubbleViewIcon() OVERRIDE; | 155 virtual gfx::Image GetBubbleViewIcon() OVERRIDE; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 165 virtual void ExtensionUninstallCanceled() OVERRIDE; | 166 virtual void ExtensionUninstallCanceled() OVERRIDE; |
| 166 | 167 |
| 167 // content::NotificationObserver implementation. | 168 // content::NotificationObserver implementation. |
| 168 virtual void Observe(int type, | 169 virtual void Observe(int type, |
| 169 const content::NotificationSource& source, | 170 const content::NotificationSource& source, |
| 170 const content::NotificationDetails& details) OVERRIDE; | 171 const content::NotificationDetails& details) OVERRIDE; |
| 171 | 172 |
| 172 private: | 173 private: |
| 173 ExtensionService* service_; | 174 ExtensionService* service_; |
| 174 const Extension* extension_; | 175 const Extension* extension_; |
| 176 bool is_remote_install_; | |
| 175 gfx::Image icon_; | 177 gfx::Image icon_; |
| 176 | 178 |
| 177 // How the user responded to the error; used for metrics. | 179 // How the user responded to the error; used for metrics. |
| 178 enum UserResponse { | 180 enum UserResponse { |
| 179 IGNORED, | 181 IGNORED, |
| 180 REENABLE, | 182 REENABLE, |
| 181 UNINSTALL, | 183 UNINSTALL, |
| 182 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY | 184 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY |
| 183 }; | 185 }; |
| 184 UserResponse user_response_; | 186 UserResponse user_response_; |
| 185 | 187 |
| 186 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_; | 188 scoped_ptr<ExtensionUninstallDialog> uninstall_dialog_; |
| 187 | 189 |
| 188 // Menu command ID assigned for this extension's error. | 190 // Menu command ID assigned for this extension's error. |
| 189 int menu_command_id_; | 191 int menu_command_id_; |
| 190 | 192 |
| 191 content::NotificationRegistrar registrar_; | 193 content::NotificationRegistrar registrar_; |
| 192 }; | 194 }; |
| 193 | 195 |
| 194 // TODO(yoz): create error at startup for disabled extensions. | 196 // TODO(yoz): create error at startup for disabled extensions. |
| 195 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( | 197 ExtensionDisabledGlobalError::ExtensionDisabledGlobalError( |
| 196 ExtensionService* service, | 198 ExtensionService* service, |
| 197 const Extension* extension, | 199 const Extension* extension, |
| 200 bool is_remote_install, | |
| 198 const gfx::Image& icon) | 201 const gfx::Image& icon) |
| 199 : service_(service), | 202 : service_(service), |
| 200 extension_(extension), | 203 extension_(extension), |
| 204 is_remote_install_(is_remote_install), | |
| 201 icon_(icon), | 205 icon_(icon), |
| 202 user_response_(IGNORED), | 206 user_response_(IGNORED), |
| 203 menu_command_id_(GetMenuCommandID()) { | 207 menu_command_id_(GetMenuCommandID()) { |
| 204 if (icon_.IsEmpty()) { | 208 if (icon_.IsEmpty()) { |
| 205 icon_ = gfx::Image( | 209 icon_ = gfx::Image( |
| 206 gfx::ImageSkiaOperations::CreateResizedImage( | 210 gfx::ImageSkiaOperations::CreateResizedImage( |
| 207 extension_->is_app() ? | 211 extension_->is_app() ? |
| 208 extensions::util::GetDefaultAppIcon() : | 212 extensions::util::GetDefaultAppIcon() : |
| 209 extensions::util::GetDefaultExtensionIcon(), | 213 extensions::util::GetDefaultExtensionIcon(), |
| 210 skia::ImageOperations::RESIZE_BEST, | 214 skia::ImageOperations::RESIZE_BEST, |
| 211 gfx::Size(kIconSize, kIconSize))); | 215 gfx::Size(kIconSize, kIconSize))); |
| 212 } | 216 } |
| 213 registrar_.Add(this, | 217 registrar_.Add(this, |
| 214 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | 218 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, |
| 215 content::Source<Profile>(service->profile())); | 219 content::Source<Profile>(service->profile())); |
| 216 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_REMOVED, | 220 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_REMOVED, |
| 217 content::Source<Profile>(service->profile())); | 221 content::Source<Profile>(service->profile())); |
| 218 } | 222 } |
| 219 | 223 |
| 220 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { | 224 ExtensionDisabledGlobalError::~ExtensionDisabledGlobalError() { |
| 221 ReleaseMenuCommandID(menu_command_id_); | 225 ReleaseMenuCommandID(menu_command_id_); |
| 222 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse", | 226 if (is_remote_install_) { |
| 223 user_response_, | 227 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponseRemoteInstall", |
| 224 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); | 228 user_response_, |
| 229 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); | |
| 230 } else { | |
| 231 UMA_HISTOGRAM_ENUMERATION("Extensions.DisabledUIUserResponse", | |
| 232 user_response_, | |
| 233 EXTENSION_DISABLED_UI_BUCKET_BOUNDARY); | |
| 234 } | |
| 225 } | 235 } |
| 226 | 236 |
| 227 GlobalError::Severity ExtensionDisabledGlobalError::GetSeverity() { | 237 GlobalError::Severity ExtensionDisabledGlobalError::GetSeverity() { |
| 228 return SEVERITY_LOW; | 238 return SEVERITY_LOW; |
| 229 } | 239 } |
| 230 | 240 |
| 231 bool ExtensionDisabledGlobalError::HasMenuItem() { | 241 bool ExtensionDisabledGlobalError::HasMenuItem() { |
| 232 return true; | 242 return true; |
| 233 } | 243 } |
| 234 | 244 |
| 235 int ExtensionDisabledGlobalError::MenuItemCommandID() { | 245 int ExtensionDisabledGlobalError::MenuItemCommandID() { |
| 236 return menu_command_id_; | 246 return menu_command_id_; |
| 237 } | 247 } |
| 238 | 248 |
| 239 base::string16 ExtensionDisabledGlobalError::MenuItemLabel() { | 249 base::string16 ExtensionDisabledGlobalError::MenuItemLabel() { |
| 240 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, | 250 if (is_remote_install_) { |
| 241 base::UTF8ToUTF16(extension_->name())); | 251 return l10n_util::GetStringFUTF16( |
| 252 IDS_EXTENSION_DISABLED_REMOTE_INSTALL_ERROR_TITLE, | |
| 253 base::UTF8ToUTF16(extension_->name())); | |
| 254 } else { | |
| 255 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, | |
| 256 base::UTF8ToUTF16(extension_->name())); | |
| 257 } | |
| 242 } | 258 } |
| 243 | 259 |
| 244 void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) { | 260 void ExtensionDisabledGlobalError::ExecuteMenuItem(Browser* browser) { |
| 245 ShowBubbleView(browser); | 261 ShowBubbleView(browser); |
| 246 } | 262 } |
| 247 | 263 |
| 248 gfx::Image ExtensionDisabledGlobalError::GetBubbleViewIcon() { | 264 gfx::Image ExtensionDisabledGlobalError::GetBubbleViewIcon() { |
| 249 return icon_; | 265 return icon_; |
| 250 } | 266 } |
| 251 | 267 |
| 252 base::string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() { | 268 base::string16 ExtensionDisabledGlobalError::GetBubbleViewTitle() { |
| 253 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, | 269 if (is_remote_install_) { |
| 254 base::UTF8ToUTF16(extension_->name())); | 270 return l10n_util::GetStringFUTF16( |
| 271 IDS_EXTENSION_DISABLED_REMOTE_INSTALL_ERROR_TITLE, | |
| 272 base::UTF8ToUTF16(extension_->name())); | |
| 273 } else { | |
| 274 return l10n_util::GetStringFUTF16(IDS_EXTENSION_DISABLED_ERROR_TITLE, | |
| 275 base::UTF8ToUTF16(extension_->name())); | |
| 276 } | |
| 255 } | 277 } |
| 256 | 278 |
| 257 std::vector<base::string16> | 279 std::vector<base::string16> |
| 258 ExtensionDisabledGlobalError::GetBubbleViewMessages() { | 280 ExtensionDisabledGlobalError::GetBubbleViewMessages() { |
| 259 std::vector<base::string16> messages; | 281 std::vector<base::string16> messages; |
| 260 messages.push_back(l10n_util::GetStringFUTF16( | |
| 261 extension_->is_app() ? | |
| 262 IDS_APP_DISABLED_ERROR_LABEL : IDS_EXTENSION_DISABLED_ERROR_LABEL, | |
| 263 base::UTF8ToUTF16(extension_->name()))); | |
| 264 messages.push_back(l10n_util::GetStringUTF16( | |
| 265 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO)); | |
| 266 std::vector<base::string16> permission_warnings = | 282 std::vector<base::string16> permission_warnings = |
| 267 extensions::PermissionMessageProvider::Get()->GetWarningMessages( | 283 extensions::PermissionMessageProvider::Get()->GetWarningMessages( |
| 268 extension_->GetActivePermissions(), extension_->GetType()); | 284 extension_->GetActivePermissions(), extension_->GetType()); |
| 285 if (is_remote_install_) { | |
| 286 messages.push_back(l10n_util::GetStringFUTF16( | |
| 287 extension_->is_app() | |
| 288 ? IDS_APP_DISABLED_REMOTE_INSTALL_ERROR_LABEL | |
| 289 : IDS_EXTENSION_DISABLED_REMOTE_INSTALL_ERROR_LABEL, | |
| 290 base::UTF8ToUTF16(extension_->name()))); | |
| 291 if (!permission_warnings.empty()) | |
| 292 messages.push_back( | |
| 293 l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_WILL_HAVE_ACCESS_TO)); | |
| 294 } else { | |
| 295 messages.push_back(l10n_util::GetStringFUTF16( | |
| 296 extension_->is_app() ? IDS_APP_DISABLED_ERROR_LABEL | |
| 297 : IDS_EXTENSION_DISABLED_ERROR_LABEL, | |
| 298 base::UTF8ToUTF16(extension_->name()))); | |
| 299 messages.push_back(l10n_util::GetStringUTF16( | |
| 300 IDS_EXTENSION_PROMPT_WILL_NOW_HAVE_ACCESS_TO)); | |
| 301 } | |
| 269 for (size_t i = 0; i < permission_warnings.size(); ++i) { | 302 for (size_t i = 0; i < permission_warnings.size(); ++i) { |
| 270 messages.push_back(l10n_util::GetStringFUTF16( | 303 messages.push_back(l10n_util::GetStringFUTF16( |
| 271 IDS_EXTENSION_PERMISSION_LINE, permission_warnings[i])); | 304 IDS_EXTENSION_PERMISSION_LINE, permission_warnings[i])); |
| 272 } | 305 } |
| 273 return messages; | 306 return messages; |
| 274 } | 307 } |
| 275 | 308 |
| 276 base::string16 ExtensionDisabledGlobalError::GetBubbleViewAcceptButtonLabel() { | 309 base::string16 ExtensionDisabledGlobalError::GetBubbleViewAcceptButtonLabel() { |
| 277 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON); | 310 if (is_remote_install_) { |
| 311 return l10n_util::GetStringUTF16( | |
| 312 IDS_EXTENSION_PROMPT_REMOTE_INSTALL_BUTTON); | |
| 313 } else { | |
| 314 return l10n_util::GetStringUTF16(IDS_EXTENSION_PROMPT_RE_ENABLE_BUTTON); | |
|
meacer
2014/05/15 00:01:10
nit: might want to use
return is_remote_install_
| |
| 315 } | |
| 278 } | 316 } |
| 279 | 317 |
| 280 base::string16 ExtensionDisabledGlobalError::GetBubbleViewCancelButtonLabel() { | 318 base::string16 ExtensionDisabledGlobalError::GetBubbleViewCancelButtonLabel() { |
| 281 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL); | 319 return l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL); |
| 282 } | 320 } |
| 283 | 321 |
| 284 void ExtensionDisabledGlobalError::OnBubbleViewDidClose(Browser* browser) { | 322 void ExtensionDisabledGlobalError::OnBubbleViewDidClose(Browser* browser) { |
| 285 } | 323 } |
| 286 | 324 |
| 287 void ExtensionDisabledGlobalError::BubbleViewAcceptButtonPressed( | 325 void ExtensionDisabledGlobalError::BubbleViewAcceptButtonPressed( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 user_response_ = UNINSTALL; | 370 user_response_ = UNINSTALL; |
| 333 delete this; | 371 delete this; |
| 334 } | 372 } |
| 335 | 373 |
| 336 // Globals -------------------------------------------------------------------- | 374 // Globals -------------------------------------------------------------------- |
| 337 | 375 |
| 338 namespace extensions { | 376 namespace extensions { |
| 339 | 377 |
| 340 void AddExtensionDisabledErrorWithIcon(base::WeakPtr<ExtensionService> service, | 378 void AddExtensionDisabledErrorWithIcon(base::WeakPtr<ExtensionService> service, |
| 341 const std::string& extension_id, | 379 const std::string& extension_id, |
| 380 bool is_remote_install, | |
| 342 const gfx::Image& icon) { | 381 const gfx::Image& icon) { |
| 343 if (!service.get()) | 382 if (!service.get()) |
| 344 return; | 383 return; |
| 345 const Extension* extension = service->GetInstalledExtension(extension_id); | 384 const Extension* extension = service->GetInstalledExtension(extension_id); |
| 346 if (extension) { | 385 if (extension) { |
| 347 GlobalErrorServiceFactory::GetForProfile(service->profile()) | 386 GlobalErrorServiceFactory::GetForProfile(service->profile()) |
| 348 ->AddGlobalError( | 387 ->AddGlobalError(new ExtensionDisabledGlobalError( |
| 349 new ExtensionDisabledGlobalError(service.get(), extension, icon)); | 388 service.get(), extension, is_remote_install, icon)); |
| 350 } | 389 } |
| 351 } | 390 } |
| 352 | 391 |
| 353 void AddExtensionDisabledError(ExtensionService* service, | 392 void AddExtensionDisabledError(ExtensionService* service, |
| 354 const Extension* extension) { | 393 const Extension* extension, |
| 394 bool is_remote_install) { | |
| 355 // Do not display notifications for ephemeral apps that have been disabled. | 395 // Do not display notifications for ephemeral apps that have been disabled. |
| 356 // Instead, a prompt will be shown the next time the app is launched. | 396 // Instead, a prompt will be shown the next time the app is launched. |
| 357 if (extension->is_ephemeral()) | 397 if (extension->is_ephemeral()) |
| 358 return; | 398 return; |
| 359 | 399 |
| 360 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( | 400 extensions::ExtensionResource image = extensions::IconsInfo::GetIconResource( |
| 361 extension, kIconSize, ExtensionIconSet::MATCH_BIGGER); | 401 extension, kIconSize, ExtensionIconSet::MATCH_BIGGER); |
| 362 gfx::Size size(kIconSize, kIconSize); | 402 gfx::Size size(kIconSize, kIconSize); |
| 363 ImageLoader::Get(service->profile())->LoadImageAsync( | 403 ImageLoader::Get(service->profile()) |
| 364 extension, image, size, | 404 ->LoadImageAsync(extension, |
| 365 base::Bind(&AddExtensionDisabledErrorWithIcon, | 405 image, |
| 366 service->AsWeakPtr(), extension->id())); | 406 size, |
| 407 base::Bind(&AddExtensionDisabledErrorWithIcon, | |
| 408 service->AsWeakPtr(), | |
| 409 extension->id(), | |
| 410 is_remote_install)); | |
| 367 } | 411 } |
| 368 | 412 |
| 369 void ShowExtensionDisabledDialog(ExtensionService* service, | 413 void ShowExtensionDisabledDialog(ExtensionService* service, |
| 370 content::WebContents* web_contents, | 414 content::WebContents* web_contents, |
| 371 const Extension* extension) { | 415 const Extension* extension) { |
| 372 scoped_ptr<ExtensionInstallPrompt> install_ui( | 416 scoped_ptr<ExtensionInstallPrompt> install_ui( |
| 373 new ExtensionInstallPrompt(web_contents)); | 417 new ExtensionInstallPrompt(web_contents)); |
| 374 // This object manages its own lifetime. | 418 // This object manages its own lifetime. |
| 375 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension); | 419 new ExtensionDisabledDialogDelegate(service, install_ui.Pass(), extension); |
| 376 } | 420 } |
| 377 | 421 |
| 378 } // namespace extensions | 422 } // namespace extensions |
| OLD | NEW |