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_prompt.h" | 5 #include "chrome/browser/extensions/extension_install_prompt.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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "chrome/browser/extensions/bundle_installer.h" | 16 #include "chrome/browser/extensions/bundle_installer.h" |
| 17 #include "chrome/browser/extensions/extension_install_dialog.h" | |
| 18 #include "chrome/browser/extensions/extension_install_ui.h" | 17 #include "chrome/browser/extensions/extension_install_ui.h" |
| 19 #include "chrome/browser/prefs/pref_service.h" | 18 #include "chrome/browser/prefs/pref_service.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/browser/signin/token_service.h" | 20 #include "chrome/browser/signin/token_service.h" |
| 22 #include "chrome/browser/signin/token_service_factory.h" | 21 #include "chrome/browser/signin/token_service_factory.h" |
| 23 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
| 24 #include "chrome/browser/ui/browser_window.h" | 23 #include "chrome/browser/ui/browser_window.h" |
| 25 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 24 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 26 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 27 #include "chrome/common/extensions/extension.h" | 26 #include "chrome/common/extensions/extension.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 std::vector<ui::ScaleFactor> supported_scale_factors = | 112 std::vector<ui::ScaleFactor> supported_scale_factors = |
| 114 ui::GetSupportedScaleFactors(); | 113 ui::GetSupportedScaleFactors(); |
| 115 // Scale factors are in ascending order, so the last one is the one we need. | 114 // Scale factors are in ascending order, so the last one is the one we need. |
| 116 ui::ScaleFactor max_scale_factor = | 115 ui::ScaleFactor max_scale_factor = |
| 117 supported_scale_factors[supported_scale_factors.size() - 1]; | 116 supported_scale_factors[supported_scale_factors.size() - 1]; |
| 118 | 117 |
| 119 return Extension::GetDefaultIcon(is_app). | 118 return Extension::GetDefaultIcon(is_app). |
| 120 GetRepresentation(max_scale_factor).sk_bitmap(); | 119 GetRepresentation(max_scale_factor).sk_bitmap(); |
| 121 } | 120 } |
| 122 | 121 |
| 122 // If auto confirm is enabled then posts a task to proceed with or cancel the | |
| 123 // install and returns true. Otherwise returns false. | |
| 124 bool AutoConfirmPrompt(ExtensionInstallPrompt::Delegate* delegate) { | |
| 125 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | |
| 126 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) | |
| 127 return false; | |
| 128 std::string value = cmdline->GetSwitchValueASCII( | |
| 129 switches::kAppsGalleryInstallAutoConfirmForTests); | |
| 130 | |
| 131 // We use PostTask instead of calling the delegate directly here, because in | |
| 132 // the real implementations it's highly likely the message loop will be | |
| 133 // pumping a few times before the user clicks accept or cancel. | |
| 134 if (value == "accept") { | |
| 135 MessageLoop::current()->PostTask( | |
| 136 FROM_HERE, | |
| 137 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, | |
| 138 base::Unretained(delegate))); | |
| 139 return true; | |
| 140 } | |
| 141 | |
| 142 if (value == "cancel") { | |
| 143 MessageLoop::current()->PostTask( | |
| 144 FROM_HERE, | |
| 145 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, | |
| 146 base::Unretained(delegate), | |
| 147 true)); | |
| 148 return true; | |
| 149 } | |
| 150 | |
| 151 NOTREACHED(); | |
| 152 return false; | |
| 153 } | |
| 154 | |
| 123 } // namespace | 155 } // namespace |
| 124 | 156 |
| 125 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) | 157 ExtensionInstallPrompt::Prompt::Prompt(Profile* profile, PromptType type) |
| 126 : type_(type), | 158 : type_(type), |
| 127 extension_(NULL), | 159 extension_(NULL), |
| 128 bundle_(NULL), | 160 bundle_(NULL), |
| 129 average_rating_(0.0), | 161 average_rating_(0.0), |
| 130 rating_count_(0), | 162 rating_count_(0), |
| 131 profile_(profile) { | 163 profile_(profile) { |
| 132 } | 164 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 extension_ = extension; | 373 extension_ = extension; |
| 342 permissions_ = extension->GetActivePermissions(); | 374 permissions_ = extension->GetActivePermissions(); |
| 343 delegate_ = delegate; | 375 delegate_ = delegate; |
| 344 prompt_ = prompt; | 376 prompt_ = prompt; |
| 345 prompt_type_ = prompt.type(); | 377 prompt_type_ = prompt.type(); |
| 346 | 378 |
| 347 SetIcon(icon); | 379 SetIcon(icon); |
| 348 FetchOAuthIssueAdviceIfNeeded(); | 380 FetchOAuthIssueAdviceIfNeeded(); |
| 349 } | 381 } |
| 350 | 382 |
| 351 void ExtensionInstallPrompt::ConfirmWebstoreInstall(Delegate* delegate, | 383 void ExtensionInstallPrompt::ConfirmWebstoreInstall( |
| 352 const Extension* extension, | 384 Delegate* delegate, |
| 353 const SkBitmap* icon) { | 385 const Extension* extension, |
| 386 const SkBitmap* icon, | |
| 387 const ShowDialogCallback& show_dialog_callback) { | |
| 354 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the | 388 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the |
| 355 // remaining fields. | 389 // remaining fields. |
| 356 extension_ = extension; | 390 extension_ = extension; |
| 357 SetIcon(icon); | 391 SetIcon(icon); |
| 358 ConfirmInstall(delegate, extension); | 392 ConfirmInstall(delegate, extension, show_dialog_callback); |
| 359 } | 393 } |
| 360 | 394 |
| 361 void ExtensionInstallPrompt::ConfirmInstall(Delegate* delegate, | 395 void ExtensionInstallPrompt::ConfirmInstall( |
| 362 const Extension* extension) { | 396 Delegate* delegate, |
| 397 const Extension* extension, | |
| 398 const ShowDialogCallback& show_dialog_callback) { | |
| 363 DCHECK(ui_loop_ == MessageLoop::current()); | 399 DCHECK(ui_loop_ == MessageLoop::current()); |
| 364 extension_ = extension; | 400 extension_ = extension; |
| 365 permissions_ = extension->GetActivePermissions(); | 401 permissions_ = extension->GetActivePermissions(); |
| 366 delegate_ = delegate; | 402 delegate_ = delegate; |
| 367 prompt_type_ = INSTALL_PROMPT; | 403 prompt_type_ = INSTALL_PROMPT; |
| 404 show_dialog_callback_ = show_dialog_callback; | |
| 405 DCHECK(!show_dialog_callback_.is_null()); | |
|
Matt Perry
2012/10/12 19:28:04
We need to do this for the 3 other ConfirmFoo() me
| |
| 368 | 406 |
| 369 // We special-case themes to not show any confirm UI. Instead they are | 407 // We special-case themes to not show any confirm UI. Instead they are |
| 370 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 408 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 371 // to allow the user to revert if they don't like it. | 409 // to allow the user to revert if they don't like it. |
| 372 // | 410 // |
| 373 // We don't do this in the case where off-store extension installs are | 411 // We don't do this in the case where off-store extension installs are |
| 374 // disabled because in that case, we don't show the dangerous download UI, so | 412 // disabled because in that case, we don't show the dangerous download UI, so |
| 375 // we need the UI confirmation. | 413 // we need the UI confirmation. |
| 376 if (extension->is_theme()) { | 414 if (extension->is_theme()) { |
| 377 if (extension->from_webstore() || | 415 if (extension->from_webstore() || |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 530 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); | 568 prompt_.SetPermissions(permissions_->GetWarningMessages(extension_type)); |
| 531 } | 569 } |
| 532 | 570 |
| 533 switch (prompt_type_) { | 571 switch (prompt_type_) { |
| 534 case PERMISSIONS_PROMPT: | 572 case PERMISSIONS_PROMPT: |
| 535 case RE_ENABLE_PROMPT: | 573 case RE_ENABLE_PROMPT: |
| 536 case INLINE_INSTALL_PROMPT: | 574 case INLINE_INSTALL_PROMPT: |
| 537 case INSTALL_PROMPT: { | 575 case INSTALL_PROMPT: { |
| 538 prompt_.set_extension(extension_); | 576 prompt_.set_extension(extension_); |
| 539 prompt_.set_icon(gfx::Image(icon_)); | 577 prompt_.set_icon(gfx::Image(icon_)); |
| 540 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_); | |
| 541 break; | 578 break; |
| 542 } | 579 } |
| 543 case BUNDLE_INSTALL_PROMPT: { | 580 case BUNDLE_INSTALL_PROMPT: { |
| 544 prompt_.set_bundle(bundle_); | 581 prompt_.set_bundle(bundle_); |
| 545 ShowExtensionInstallDialog(parent_, navigator_, delegate_, prompt_); | |
| 546 break; | 582 break; |
| 547 } | 583 } |
| 548 default: | 584 default: |
| 549 NOTREACHED() << "Unknown message"; | 585 NOTREACHED() << "Unknown message"; |
| 550 break; | 586 return; |
| 551 } | 587 } |
| 588 | |
| 589 if (AutoConfirmPrompt(delegate_)) | |
| 590 return; | |
| 591 | |
| 592 DCHECK(!show_dialog_callback_.is_null()); | |
| 593 show_dialog_callback_.Run(parent_, navigator_, delegate_, prompt_); | |
|
Matt Perry
2012/10/12 19:33:05
We still need the callback here when we actually w
| |
| 552 } | 594 } |
| 553 | 595 |
| 554 namespace chrome { | 596 namespace chrome { |
| 555 | 597 |
| 556 ExtensionInstallPrompt* CreateExtensionInstallPromptWithBrowser( | 598 ExtensionInstallPrompt* CreateExtensionInstallPromptWithBrowser( |
| 557 Browser* browser) { | 599 Browser* browser) { |
| 558 // |browser| can be NULL in unit tests. | 600 // |browser| can be NULL in unit tests. |
| 559 if (!browser) | 601 if (!browser) |
| 560 return new ExtensionInstallPrompt(NULL, NULL, NULL); | 602 return new ExtensionInstallPrompt(NULL, NULL, NULL); |
| 561 gfx::NativeWindow parent = | 603 gfx::NativeWindow parent = |
| 562 browser->window() ? browser->window()->GetNativeWindow() : NULL; | 604 browser->window() ? browser->window()->GetNativeWindow() : NULL; |
| 563 return new ExtensionInstallPrompt(parent, browser, browser->profile()); | 605 return new ExtensionInstallPrompt(parent, browser, browser->profile()); |
| 564 } | 606 } |
| 565 | 607 |
| 566 } // namespace chrome | 608 } // namespace chrome |
| OLD | NEW |