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_install_ui.h" | 5 #include "chrome/browser/extensions/extension_install_ui.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 #include "chrome/browser/ui/browser_dialogs.h" | 26 #include "chrome/browser/ui/browser_dialogs.h" |
| 27 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
| 28 #include "chrome/browser/ui/browser_navigator.h" | 28 #include "chrome/browser/ui/browser_navigator.h" |
| 29 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
| 30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 30 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 31 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 31 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 32 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
| 33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 34 #include "chrome/common/extensions/extension.h" | 34 #include "chrome/common/extensions/extension.h" |
| 35 #include "chrome/common/extensions/extension_icon_set.h" | 35 #include "chrome/common/extensions/extension_icon_set.h" |
| 36 #include "chrome/common/extensions/extension_manifest_constants.h" | |
| 36 #include "chrome/common/extensions/extension_resource.h" | 37 #include "chrome/common/extensions/extension_resource.h" |
| 37 #include "chrome/common/extensions/url_pattern.h" | 38 #include "chrome/common/extensions/url_pattern.h" |
| 38 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 39 #include "content/public/browser/notification_service.h" | 40 #include "content/public/browser/notification_service.h" |
| 40 #include "grit/chromium_strings.h" | 41 #include "grit/chromium_strings.h" |
| 41 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
| 42 #include "grit/theme_resources.h" | 43 #include "grit/theme_resources.h" |
| 43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
| 44 #include "ui/base/resource/resource_bundle.h" | 45 #include "ui/base/resource/resource_bundle.h" |
| 45 #include "ui/gfx/image/image.h" | 46 #include "ui/gfx/image/image.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 204 size_t ExtensionInstallUI::Prompt::GetPermissionCount() const { | 205 size_t ExtensionInstallUI::Prompt::GetPermissionCount() const { |
| 205 return permissions_.size(); | 206 return permissions_.size(); |
| 206 } | 207 } |
| 207 | 208 |
| 208 string16 ExtensionInstallUI::Prompt::GetPermission(size_t index) const { | 209 string16 ExtensionInstallUI::Prompt::GetPermission(size_t index) const { |
| 209 CHECK_LT(index, permissions_.size()); | 210 CHECK_LT(index, permissions_.size()); |
| 210 return l10n_util::GetStringFUTF16( | 211 return l10n_util::GetStringFUTF16( |
| 211 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]); | 212 IDS_EXTENSION_PERMISSION_LINE, permissions_[index]); |
| 212 } | 213 } |
| 213 | 214 |
| 215 // static | |
| 216 scoped_refptr<Extension> ExtensionInstallUI::GetLocalizedExtensionForDisplay( | |
| 217 const DictionaryValue* manifest, | |
| 218 const std::string& id, | |
| 219 const std::string& localized_name, | |
| 220 const std::string& localized_description, | |
| 221 std::string* error) { | |
| 222 scoped_ptr<DictionaryValue> localized_manifest; | |
| 223 if (!localized_name.empty() || !localized_description.empty()) { | |
| 224 localized_manifest.reset(manifest->DeepCopy()); | |
| 225 if (!localized_name.empty()) { | |
| 226 localized_manifest->SetString(extension_manifest_keys::kName, | |
| 227 localized_name); | |
| 228 } | |
| 229 if (!localized_description.empty()) { | |
| 230 localized_manifest->SetString(extension_manifest_keys::kDescription, | |
| 231 localized_description); | |
| 232 } | |
| 233 } | |
| 234 | |
| 235 return Extension::Create( | |
| 236 FilePath(), | |
| 237 Extension::INTERNAL, | |
| 238 localized_manifest.get() ? *localized_manifest.get() : *manifest, | |
| 239 Extension::NO_FLAGS, | |
| 240 id, | |
| 241 error); | |
| 242 } | |
| 243 | |
| 214 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) | 244 ExtensionInstallUI::ExtensionInstallUI(Profile* profile) |
| 215 : profile_(profile), | 245 : profile_(profile), |
| 216 ui_loop_(MessageLoop::current()), | 246 ui_loop_(MessageLoop::current()), |
| 217 previous_using_native_theme_(false), | 247 previous_using_native_theme_(false), |
| 218 extension_(NULL), | 248 extension_(NULL), |
| 219 delegate_(NULL), | 249 delegate_(NULL), |
| 250 prompt_(UNSET_PROMPT_TYPE), | |
| 220 prompt_type_(NUM_PROMPT_TYPES), | 251 prompt_type_(NUM_PROMPT_TYPES), |
|
Yoyo Zhou
2012/04/20 17:19:12
nit: Presumably this could be UNSET_PROMPT_TYPE to
jstritar
2012/04/20 18:03:29
Done.
| |
| 221 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), | 252 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
| 222 use_app_installed_bubble_(false), | 253 use_app_installed_bubble_(false), |
| 223 skip_post_install_ui_(false) { | 254 skip_post_install_ui_(false) { |
| 224 // Remember the current theme in case the user presses undo. | 255 // Remember the current theme in case the user presses undo. |
| 225 if (profile_) { | 256 if (profile_) { |
| 226 const Extension* previous_theme = | 257 const Extension* previous_theme = |
| 227 ThemeServiceFactory::GetThemeForProfile(profile_); | 258 ThemeServiceFactory::GetThemeForProfile(profile_); |
| 228 if (previous_theme) | 259 if (previous_theme) |
| 229 previous_theme_id_ = previous_theme->id(); | 260 previous_theme_id_ = previous_theme->id(); |
| 230 previous_using_native_theme_ = | 261 previous_using_native_theme_ = |
| 231 ThemeServiceFactory::GetForProfile(profile_)->UsingNativeTheme(); | 262 ThemeServiceFactory::GetForProfile(profile_)->UsingNativeTheme(); |
| 232 } | 263 } |
| 233 } | 264 } |
| 234 | 265 |
| 235 ExtensionInstallUI::~ExtensionInstallUI() { | 266 ExtensionInstallUI::~ExtensionInstallUI() { |
| 236 } | 267 } |
| 237 | 268 |
| 269 void ExtensionInstallUI::ConfirmBundleInstall( | |
| 270 extensions::BundleInstaller* bundle, | |
| 271 const ExtensionPermissionSet* permissions) { | |
| 272 DCHECK(ui_loop_ == MessageLoop::current()); | |
| 273 bundle_ = bundle; | |
| 274 permissions_ = permissions; | |
| 275 delegate_ = bundle; | |
| 276 | |
| 277 ShowConfirmation(BUNDLE_INSTALL_PROMPT); | |
| 278 } | |
| 279 | |
| 280 void ExtensionInstallUI::ConfirmInlineInstall( | |
| 281 Delegate* delegate, | |
| 282 const Extension* extension, | |
| 283 SkBitmap* icon, | |
| 284 ExtensionInstallUI::Prompt prompt) { | |
| 285 DCHECK(ui_loop_ == MessageLoop::current()); | |
| 286 extension_ = extension; | |
| 287 permissions_ = extension->GetActivePermissions(); | |
| 288 delegate_ = delegate; | |
| 289 prompt_ = prompt; | |
| 290 | |
| 291 SetIcon(icon); | |
| 292 ShowConfirmation(INLINE_INSTALL_PROMPT); | |
| 293 } | |
| 294 | |
| 295 void ExtensionInstallUI::ConfirmWebstoreInstall(Delegate* delegate, | |
| 296 const Extension* extension, | |
| 297 const SkBitmap* icon) { | |
| 298 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the | |
| 299 // remaining fields. | |
| 300 extension_ = extension; | |
| 301 SetIcon(icon); | |
| 302 ConfirmInstall(delegate, extension); | |
| 303 } | |
| 304 | |
| 238 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, | 305 void ExtensionInstallUI::ConfirmInstall(Delegate* delegate, |
| 239 const Extension* extension) { | 306 const Extension* extension) { |
| 240 DCHECK(ui_loop_ == MessageLoop::current()); | 307 DCHECK(ui_loop_ == MessageLoop::current()); |
| 241 extension_ = extension; | 308 extension_ = extension; |
| 242 permissions_ = extension->GetActivePermissions(); | 309 permissions_ = extension->GetActivePermissions(); |
| 243 delegate_ = delegate; | 310 delegate_ = delegate; |
| 244 | 311 |
| 245 // We special-case themes to not show any confirm UI. Instead they are | 312 // We special-case themes to not show any confirm UI. Instead they are |
| 246 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 313 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 247 // to allow the user to revert if they don't like it. | 314 // to allow the user to revert if they don't like it. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 337 else | 404 else |
| 338 icon_ = SkBitmap(); | 405 icon_ = SkBitmap(); |
| 339 if (icon_.empty()) | 406 if (icon_.empty()) |
| 340 icon_ = Extension::GetDefaultIcon(extension_->is_app()); | 407 icon_ = Extension::GetDefaultIcon(extension_->is_app()); |
| 341 } | 408 } |
| 342 | 409 |
| 343 void ExtensionInstallUI::OnImageLoaded(const gfx::Image& image, | 410 void ExtensionInstallUI::OnImageLoaded(const gfx::Image& image, |
| 344 const std::string& extension_id, | 411 const std::string& extension_id, |
| 345 int index) { | 412 int index) { |
| 346 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); | 413 SetIcon(image.IsEmpty() ? NULL : image.ToSkBitmap()); |
| 347 | 414 ShowDialog(); |
| 348 switch (prompt_type_) { | |
| 349 case PERMISSIONS_PROMPT: | |
| 350 case RE_ENABLE_PROMPT: | |
| 351 case INSTALL_PROMPT: { | |
| 352 content::NotificationService* service = | |
| 353 content::NotificationService::current(); | |
| 354 service->Notify(chrome::NOTIFICATION_EXTENSION_WILL_SHOW_CONFIRM_DIALOG, | |
| 355 content::Source<ExtensionInstallUI>(this), | |
| 356 content::NotificationService::NoDetails()); | |
| 357 | |
| 358 Prompt prompt(prompt_type_); | |
| 359 prompt.SetPermissions(permissions_->GetWarningMessages()); | |
| 360 prompt.set_extension(extension_); | |
| 361 prompt.set_icon(gfx::Image(new SkBitmap(icon_))); | |
| 362 ShowExtensionInstallDialog(profile_, delegate_, prompt); | |
| 363 break; | |
| 364 } | |
| 365 default: | |
| 366 NOTREACHED() << "Unknown message"; | |
| 367 break; | |
| 368 } | |
| 369 } | 415 } |
| 370 | 416 |
| 371 // static | 417 // static |
| 372 void ExtensionInstallUI::OpenAppInstalledUI(Browser* browser, | 418 void ExtensionInstallUI::OpenAppInstalledUI(Browser* browser, |
| 373 const std::string& app_id) { | 419 const std::string& app_id) { |
| 374 | 420 |
| 375 if (NewTabUI::ShouldShowApps()) { | 421 if (NewTabUI::ShouldShowApps()) { |
| 376 browser::NavigateParams params = browser->GetSingletonTabNavigateParams( | 422 browser::NavigateParams params = browser->GetSingletonTabNavigateParams( |
| 377 GURL(chrome::kChromeUINewTabURL)); | 423 GURL(chrome::kChromeUINewTabURL)); |
| 378 browser::Navigate(¶ms); | 424 browser::Navigate(¶ms); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 437 // Then either replace that old one or add a new one. | 483 // Then either replace that old one or add a new one. |
| 438 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( | 484 InfoBarDelegate* new_delegate = GetNewThemeInstalledInfoBarDelegate( |
| 439 tab_contents, new_theme, previous_theme_id, previous_using_native_theme); | 485 tab_contents, new_theme, previous_theme_id, previous_using_native_theme); |
| 440 | 486 |
| 441 if (old_delegate) | 487 if (old_delegate) |
| 442 infobar_helper->ReplaceInfoBar(old_delegate, new_delegate); | 488 infobar_helper->ReplaceInfoBar(old_delegate, new_delegate); |
| 443 else | 489 else |
| 444 infobar_helper->AddInfoBar(new_delegate); | 490 infobar_helper->AddInfoBar(new_delegate); |
| 445 } | 491 } |
| 446 | 492 |
| 447 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { | 493 void ExtensionInstallUI::ShowConfirmation(PromptType prompt_type) { |
|
Yoyo Zhou
2012/04/20 17:19:12
prompt_type doesn't need to be passed in here -- y
jstritar
2012/04/20 18:03:29
Done.
| |
| 494 prompt_type_ = prompt_type; | |
| 495 | |
| 496 // Bundle install prompts do not have an icon. | |
| 497 if (!icon_.empty() || prompt_type == BUNDLE_INSTALL_PROMPT) { | |
| 498 ShowDialog(); | |
| 499 return; | |
| 500 } | |
| 501 | |
| 448 // Load the image asynchronously. For the response, check OnImageLoaded. | 502 // Load the image asynchronously. For the response, check OnImageLoaded. |
| 449 prompt_type_ = prompt_type; | |
| 450 ExtensionResource image = | 503 ExtensionResource image = |
| 451 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, | 504 extension_->GetIconResource(ExtensionIconSet::EXTENSION_ICON_LARGE, |
| 452 ExtensionIconSet::MATCH_BIGGER); | 505 ExtensionIconSet::MATCH_BIGGER); |
| 453 tracker_.LoadImage(extension_, image, | 506 tracker_.LoadImage(extension_, image, |
| 454 gfx::Size(kIconSize, kIconSize), | 507 gfx::Size(kIconSize, kIconSize), |
| 455 ImageLoadingTracker::DONT_CACHE); | 508 ImageLoadingTracker::DONT_CACHE); |
| 456 } | 509 } |
| 457 | 510 |
| 511 void ExtensionInstallUI::ShowDialog() { | |
| 512 prompt_.set_type(prompt_type_); | |
| 513 prompt_.SetPermissions(permissions_->GetWarningMessages()); | |
| 514 | |
| 515 switch (prompt_type_) { | |
| 516 case PERMISSIONS_PROMPT: | |
| 517 case RE_ENABLE_PROMPT: | |
| 518 case INLINE_INSTALL_PROMPT: | |
| 519 case INSTALL_PROMPT: { | |
| 520 prompt_.set_extension(extension_); | |
| 521 prompt_.set_icon(gfx::Image(new SkBitmap(icon_))); | |
| 522 ShowExtensionInstallDialog(profile_, delegate_, prompt_); | |
| 523 break; | |
| 524 } | |
| 525 case BUNDLE_INSTALL_PROMPT: { | |
| 526 prompt_.set_bundle(bundle_); | |
| 527 ShowExtensionInstallDialog(profile_, delegate_, prompt_); | |
| 528 break; | |
| 529 } | |
| 530 default: | |
| 531 NOTREACHED() << "Unknown message"; | |
| 532 break; | |
| 533 } | |
| 534 } | |
| 535 | |
| 458 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( | 536 InfoBarDelegate* ExtensionInstallUI::GetNewThemeInstalledInfoBarDelegate( |
| 459 TabContentsWrapper* tab_contents, | 537 TabContentsWrapper* tab_contents, |
| 460 const Extension* new_theme, | 538 const Extension* new_theme, |
| 461 const std::string& previous_theme_id, | 539 const std::string& previous_theme_id, |
| 462 bool previous_using_native_theme) { | 540 bool previous_using_native_theme) { |
| 463 Profile* profile = tab_contents->profile(); | 541 Profile* profile = tab_contents->profile(); |
| 464 return new ThemeInstalledInfoBarDelegate( | 542 return new ThemeInstalledInfoBarDelegate( |
| 465 tab_contents->infobar_tab_helper(), | 543 tab_contents->infobar_tab_helper(), |
| 466 profile->GetExtensionService(), | 544 profile->GetExtensionService(), |
| 467 ThemeServiceFactory::GetForProfile(profile), | 545 ThemeServiceFactory::GetForProfile(profile), |
| 468 new_theme, | 546 new_theme, |
| 469 previous_theme_id, | 547 previous_theme_id, |
| 470 previous_using_native_theme); | 548 previous_using_native_theme); |
| 471 } | 549 } |
| OLD | NEW |