| 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/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 144 const CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 145 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) | 145 if (!cmdline->HasSwitch(switches::kAppsGalleryInstallAutoConfirmForTests)) |
| 146 return false; | 146 return false; |
| 147 std::string value = cmdline->GetSwitchValueASCII( | 147 std::string value = cmdline->GetSwitchValueASCII( |
| 148 switches::kAppsGalleryInstallAutoConfirmForTests); | 148 switches::kAppsGalleryInstallAutoConfirmForTests); |
| 149 | 149 |
| 150 // We use PostTask instead of calling the delegate directly here, because in | 150 // We use PostTask instead of calling the delegate directly here, because in |
| 151 // the real implementations it's highly likely the message loop will be | 151 // the real implementations it's highly likely the message loop will be |
| 152 // pumping a few times before the user clicks accept or cancel. | 152 // pumping a few times before the user clicks accept or cancel. |
| 153 if (value == "accept") { | 153 if (value == "accept") { |
| 154 MessageLoop::current()->PostTask( | 154 base::MessageLoop::current()->PostTask( |
| 155 FROM_HERE, | 155 FROM_HERE, |
| 156 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, | 156 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIProceed, |
| 157 base::Unretained(delegate))); | 157 base::Unretained(delegate))); |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| 160 | 160 |
| 161 if (value == "cancel") { | 161 if (value == "cancel") { |
| 162 MessageLoop::current()->PostTask( | 162 base::MessageLoop::current()->PostTask( |
| 163 FROM_HERE, | 163 FROM_HERE, |
| 164 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, | 164 base::Bind(&ExtensionInstallPrompt::Delegate::InstallUIAbort, |
| 165 base::Unretained(delegate), | 165 base::Unretained(delegate), |
| 166 true)); | 166 true)); |
| 167 return true; | 167 return true; |
| 168 } | 168 } |
| 169 | 169 |
| 170 NOTREACHED(); | 170 NOTREACHED(); |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 Manifest::INTERNAL, | 407 Manifest::INTERNAL, |
| 408 localized_manifest.get() ? *localized_manifest.get() : *manifest, | 408 localized_manifest.get() ? *localized_manifest.get() : *manifest, |
| 409 flags, | 409 flags, |
| 410 id, | 410 id, |
| 411 error); | 411 error); |
| 412 } | 412 } |
| 413 | 413 |
| 414 ExtensionInstallPrompt::ExtensionInstallPrompt( | 414 ExtensionInstallPrompt::ExtensionInstallPrompt( |
| 415 content::WebContents* contents) | 415 content::WebContents* contents) |
| 416 : record_oauth2_grant_(false), | 416 : record_oauth2_grant_(false), |
| 417 ui_loop_(MessageLoop::current()), | 417 ui_loop_(base::MessageLoop::current()), |
| 418 extension_(NULL), | 418 extension_(NULL), |
| 419 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), | 419 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), |
| 420 show_params_(contents), | 420 show_params_(contents), |
| 421 delegate_(NULL), | 421 delegate_(NULL), |
| 422 prompt_(UNSET_PROMPT_TYPE) { | 422 prompt_(UNSET_PROMPT_TYPE) { |
| 423 prompt_.SetUserNameFromProfile(install_ui_->profile()); | 423 prompt_.SetUserNameFromProfile(install_ui_->profile()); |
| 424 } | 424 } |
| 425 | 425 |
| 426 ExtensionInstallPrompt::ExtensionInstallPrompt( | 426 ExtensionInstallPrompt::ExtensionInstallPrompt( |
| 427 Profile* profile, | 427 Profile* profile, |
| 428 gfx::NativeWindow native_window, | 428 gfx::NativeWindow native_window, |
| 429 content::PageNavigator* navigator) | 429 content::PageNavigator* navigator) |
| 430 : record_oauth2_grant_(false), | 430 : record_oauth2_grant_(false), |
| 431 ui_loop_(MessageLoop::current()), | 431 ui_loop_(base::MessageLoop::current()), |
| 432 extension_(NULL), | 432 extension_(NULL), |
| 433 install_ui_(ExtensionInstallUI::Create(profile)), | 433 install_ui_(ExtensionInstallUI::Create(profile)), |
| 434 show_params_(native_window, navigator), | 434 show_params_(native_window, navigator), |
| 435 delegate_(NULL), | 435 delegate_(NULL), |
| 436 prompt_(UNSET_PROMPT_TYPE) { | 436 prompt_(UNSET_PROMPT_TYPE) { |
| 437 prompt_.SetUserNameFromProfile(install_ui_->profile()); | 437 prompt_.SetUserNameFromProfile(install_ui_->profile()); |
| 438 } | 438 } |
| 439 | 439 |
| 440 ExtensionInstallPrompt::~ExtensionInstallPrompt() { | 440 ExtensionInstallPrompt::~ExtensionInstallPrompt() { |
| 441 } | 441 } |
| 442 | 442 |
| 443 void ExtensionInstallPrompt::ConfirmBundleInstall( | 443 void ExtensionInstallPrompt::ConfirmBundleInstall( |
| 444 extensions::BundleInstaller* bundle, | 444 extensions::BundleInstaller* bundle, |
| 445 const PermissionSet* permissions) { | 445 const PermissionSet* permissions) { |
| 446 DCHECK(ui_loop_ == MessageLoop::current()); | 446 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 447 bundle_ = bundle; | 447 bundle_ = bundle; |
| 448 permissions_ = permissions; | 448 permissions_ = permissions; |
| 449 delegate_ = bundle; | 449 delegate_ = bundle; |
| 450 prompt_.set_type(BUNDLE_INSTALL_PROMPT); | 450 prompt_.set_type(BUNDLE_INSTALL_PROMPT); |
| 451 | 451 |
| 452 FetchOAuthIssueAdviceIfNeeded(); | 452 FetchOAuthIssueAdviceIfNeeded(); |
| 453 } | 453 } |
| 454 | 454 |
| 455 void ExtensionInstallPrompt::ConfirmStandaloneInstall( | 455 void ExtensionInstallPrompt::ConfirmStandaloneInstall( |
| 456 Delegate* delegate, | 456 Delegate* delegate, |
| 457 const Extension* extension, | 457 const Extension* extension, |
| 458 SkBitmap* icon, | 458 SkBitmap* icon, |
| 459 const ExtensionInstallPrompt::Prompt& prompt) { | 459 const ExtensionInstallPrompt::Prompt& prompt) { |
| 460 DCHECK(ui_loop_ == MessageLoop::current()); | 460 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 461 extension_ = extension; | 461 extension_ = extension; |
| 462 permissions_ = extension->GetActivePermissions(); | 462 permissions_ = extension->GetActivePermissions(); |
| 463 delegate_ = delegate; | 463 delegate_ = delegate; |
| 464 prompt_ = prompt; | 464 prompt_ = prompt; |
| 465 | 465 |
| 466 SetIcon(icon); | 466 SetIcon(icon); |
| 467 FetchOAuthIssueAdviceIfNeeded(); | 467 FetchOAuthIssueAdviceIfNeeded(); |
| 468 } | 468 } |
| 469 | 469 |
| 470 void ExtensionInstallPrompt::ConfirmWebstoreInstall( | 470 void ExtensionInstallPrompt::ConfirmWebstoreInstall( |
| 471 Delegate* delegate, | 471 Delegate* delegate, |
| 472 const Extension* extension, | 472 const Extension* extension, |
| 473 const SkBitmap* icon, | 473 const SkBitmap* icon, |
| 474 const ShowDialogCallback& show_dialog_callback) { | 474 const ShowDialogCallback& show_dialog_callback) { |
| 475 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the | 475 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the |
| 476 // remaining fields. | 476 // remaining fields. |
| 477 extension_ = extension; | 477 extension_ = extension; |
| 478 SetIcon(icon); | 478 SetIcon(icon); |
| 479 ConfirmInstall(delegate, extension, show_dialog_callback); | 479 ConfirmInstall(delegate, extension, show_dialog_callback); |
| 480 } | 480 } |
| 481 | 481 |
| 482 void ExtensionInstallPrompt::ConfirmInstall( | 482 void ExtensionInstallPrompt::ConfirmInstall( |
| 483 Delegate* delegate, | 483 Delegate* delegate, |
| 484 const Extension* extension, | 484 const Extension* extension, |
| 485 const ShowDialogCallback& show_dialog_callback) { | 485 const ShowDialogCallback& show_dialog_callback) { |
| 486 DCHECK(ui_loop_ == MessageLoop::current()); | 486 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 487 extension_ = extension; | 487 extension_ = extension; |
| 488 permissions_ = extension->GetActivePermissions(); | 488 permissions_ = extension->GetActivePermissions(); |
| 489 delegate_ = delegate; | 489 delegate_ = delegate; |
| 490 prompt_.set_type(INSTALL_PROMPT); | 490 prompt_.set_type(INSTALL_PROMPT); |
| 491 show_dialog_callback_ = show_dialog_callback; | 491 show_dialog_callback_ = show_dialog_callback; |
| 492 | 492 |
| 493 // We special-case themes to not show any confirm UI. Instead they are | 493 // We special-case themes to not show any confirm UI. Instead they are |
| 494 // immediately installed, and then we show an infobar (see OnInstallSuccess) | 494 // immediately installed, and then we show an infobar (see OnInstallSuccess) |
| 495 // to allow the user to revert if they don't like it. | 495 // to allow the user to revert if they don't like it. |
| 496 // | 496 // |
| 497 // We don't do this in the case where off-store extension installs are | 497 // We don't do this in the case where off-store extension installs are |
| 498 // disabled because in that case, we don't show the dangerous download UI, so | 498 // disabled because in that case, we don't show the dangerous download UI, so |
| 499 // we need the UI confirmation. | 499 // we need the UI confirmation. |
| 500 if (extension->is_theme()) { | 500 if (extension->is_theme()) { |
| 501 if (extension->from_webstore() || | 501 if (extension->from_webstore() || |
| 502 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { | 502 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { |
| 503 delegate->InstallUIProceed(); | 503 delegate->InstallUIProceed(); |
| 504 return; | 504 return; |
| 505 } | 505 } |
| 506 } | 506 } |
| 507 | 507 |
| 508 LoadImageIfNeeded(); | 508 LoadImageIfNeeded(); |
| 509 } | 509 } |
| 510 | 510 |
| 511 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, | 511 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, |
| 512 const Extension* extension) { | 512 const Extension* extension) { |
| 513 DCHECK(ui_loop_ == MessageLoop::current()); | 513 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 514 extension_ = extension; | 514 extension_ = extension; |
| 515 permissions_ = extension->GetActivePermissions(); | 515 permissions_ = extension->GetActivePermissions(); |
| 516 delegate_ = delegate; | 516 delegate_ = delegate; |
| 517 prompt_.set_type(RE_ENABLE_PROMPT); | 517 prompt_.set_type(RE_ENABLE_PROMPT); |
| 518 | 518 |
| 519 LoadImageIfNeeded(); | 519 LoadImageIfNeeded(); |
| 520 } | 520 } |
| 521 | 521 |
| 522 void ExtensionInstallPrompt::ConfirmExternalInstall( | 522 void ExtensionInstallPrompt::ConfirmExternalInstall( |
| 523 Delegate* delegate, | 523 Delegate* delegate, |
| 524 const Extension* extension, | 524 const Extension* extension, |
| 525 const ShowDialogCallback& show_dialog_callback) { | 525 const ShowDialogCallback& show_dialog_callback) { |
| 526 DCHECK(ui_loop_ == MessageLoop::current()); | 526 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 527 extension_ = extension; | 527 extension_ = extension; |
| 528 permissions_ = extension->GetActivePermissions(); | 528 permissions_ = extension->GetActivePermissions(); |
| 529 delegate_ = delegate; | 529 delegate_ = delegate; |
| 530 prompt_.set_type(EXTERNAL_INSTALL_PROMPT); | 530 prompt_.set_type(EXTERNAL_INSTALL_PROMPT); |
| 531 show_dialog_callback_ = show_dialog_callback; | 531 show_dialog_callback_ = show_dialog_callback; |
| 532 | 532 |
| 533 LoadImageIfNeeded(); | 533 LoadImageIfNeeded(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 void ExtensionInstallPrompt::ConfirmPermissions( | 536 void ExtensionInstallPrompt::ConfirmPermissions( |
| 537 Delegate* delegate, | 537 Delegate* delegate, |
| 538 const Extension* extension, | 538 const Extension* extension, |
| 539 const PermissionSet* permissions) { | 539 const PermissionSet* permissions) { |
| 540 DCHECK(ui_loop_ == MessageLoop::current()); | 540 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 541 extension_ = extension; | 541 extension_ = extension; |
| 542 permissions_ = permissions; | 542 permissions_ = permissions; |
| 543 delegate_ = delegate; | 543 delegate_ = delegate; |
| 544 prompt_.set_type(PERMISSIONS_PROMPT); | 544 prompt_.set_type(PERMISSIONS_PROMPT); |
| 545 | 545 |
| 546 LoadImageIfNeeded(); | 546 LoadImageIfNeeded(); |
| 547 } | 547 } |
| 548 | 548 |
| 549 void ExtensionInstallPrompt::ConfirmIssueAdvice( | 549 void ExtensionInstallPrompt::ConfirmIssueAdvice( |
| 550 Delegate* delegate, | 550 Delegate* delegate, |
| 551 const Extension* extension, | 551 const Extension* extension, |
| 552 const IssueAdviceInfo& issue_advice) { | 552 const IssueAdviceInfo& issue_advice) { |
| 553 DCHECK(ui_loop_ == MessageLoop::current()); | 553 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 554 extension_ = extension; | 554 extension_ = extension; |
| 555 delegate_ = delegate; | 555 delegate_ = delegate; |
| 556 prompt_.set_type(PERMISSIONS_PROMPT); | 556 prompt_.set_type(PERMISSIONS_PROMPT); |
| 557 | 557 |
| 558 record_oauth2_grant_ = true; | 558 record_oauth2_grant_ = true; |
| 559 prompt_.SetOAuthIssueAdvice(issue_advice); | 559 prompt_.SetOAuthIssueAdvice(issue_advice); |
| 560 | 560 |
| 561 LoadImageIfNeeded(); | 561 LoadImageIfNeeded(); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void ExtensionInstallPrompt::ReviewPermissions(Delegate* delegate, | 564 void ExtensionInstallPrompt::ReviewPermissions(Delegate* delegate, |
| 565 const Extension* extension) { | 565 const Extension* extension) { |
| 566 DCHECK(ui_loop_ == MessageLoop::current()); | 566 DCHECK(ui_loop_ == base::MessageLoop::current()); |
| 567 extension_ = extension; | 567 extension_ = extension; |
| 568 permissions_ = extension->GetActivePermissions(); | 568 permissions_ = extension->GetActivePermissions(); |
| 569 delegate_ = delegate; | 569 delegate_ = delegate; |
| 570 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); | 570 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); |
| 571 | 571 |
| 572 LoadImageIfNeeded(); | 572 LoadImageIfNeeded(); |
| 573 } | 573 } |
| 574 | 574 |
| 575 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, | 575 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, |
| 576 SkBitmap* icon) { | 576 SkBitmap* icon) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 } | 708 } |
| 709 | 709 |
| 710 if (AutoConfirmPrompt(delegate_)) | 710 if (AutoConfirmPrompt(delegate_)) |
| 711 return; | 711 return; |
| 712 | 712 |
| 713 if (show_dialog_callback_.is_null()) | 713 if (show_dialog_callback_.is_null()) |
| 714 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); | 714 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); |
| 715 else | 715 else |
| 716 show_dialog_callback_.Run(show_params_, delegate_, prompt_); | 716 show_dialog_callback_.Run(show_params_, delegate_, prompt_); |
| 717 } | 717 } |
| OLD | NEW |