Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: chrome/browser/extensions/extension_install_prompt.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 404
405 return Extension::Create( 405 return Extension::Create(
406 base::FilePath(), 406 base::FilePath(),
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(content::WebContents* contents)
415 content::WebContents* contents)
416 : record_oauth2_grant_(false), 415 : record_oauth2_grant_(false),
417 ui_loop_(MessageLoop::current()), 416 ui_loop_(base::MessageLoop::current()),
418 extension_(NULL), 417 extension_(NULL),
419 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))), 418 install_ui_(ExtensionInstallUI::Create(ProfileForWebContents(contents))),
420 show_params_(contents), 419 show_params_(contents),
421 delegate_(NULL), 420 delegate_(NULL),
422 prompt_(UNSET_PROMPT_TYPE) { 421 prompt_(UNSET_PROMPT_TYPE) {
423 prompt_.SetUserNameFromProfile(install_ui_->profile()); 422 prompt_.SetUserNameFromProfile(install_ui_->profile());
424 } 423 }
425 424
426 ExtensionInstallPrompt::ExtensionInstallPrompt( 425 ExtensionInstallPrompt::ExtensionInstallPrompt(
427 Profile* profile, 426 Profile* profile,
428 gfx::NativeWindow native_window, 427 gfx::NativeWindow native_window,
429 content::PageNavigator* navigator) 428 content::PageNavigator* navigator)
430 : record_oauth2_grant_(false), 429 : record_oauth2_grant_(false),
431 ui_loop_(MessageLoop::current()), 430 ui_loop_(base::MessageLoop::current()),
432 extension_(NULL), 431 extension_(NULL),
433 install_ui_(ExtensionInstallUI::Create(profile)), 432 install_ui_(ExtensionInstallUI::Create(profile)),
434 show_params_(native_window, navigator), 433 show_params_(native_window, navigator),
435 delegate_(NULL), 434 delegate_(NULL),
436 prompt_(UNSET_PROMPT_TYPE) { 435 prompt_(UNSET_PROMPT_TYPE) {
437 prompt_.SetUserNameFromProfile(install_ui_->profile()); 436 prompt_.SetUserNameFromProfile(install_ui_->profile());
438 } 437 }
439 438
440 ExtensionInstallPrompt::~ExtensionInstallPrompt() { 439 ExtensionInstallPrompt::~ExtensionInstallPrompt() {
441 } 440 }
442 441
443 void ExtensionInstallPrompt::ConfirmBundleInstall( 442 void ExtensionInstallPrompt::ConfirmBundleInstall(
444 extensions::BundleInstaller* bundle, 443 extensions::BundleInstaller* bundle,
445 const PermissionSet* permissions) { 444 const PermissionSet* permissions) {
446 DCHECK(ui_loop_ == MessageLoop::current()); 445 DCHECK(ui_loop_ == base::MessageLoop::current());
447 bundle_ = bundle; 446 bundle_ = bundle;
448 permissions_ = permissions; 447 permissions_ = permissions;
449 delegate_ = bundle; 448 delegate_ = bundle;
450 prompt_.set_type(BUNDLE_INSTALL_PROMPT); 449 prompt_.set_type(BUNDLE_INSTALL_PROMPT);
451 450
452 FetchOAuthIssueAdviceIfNeeded(); 451 FetchOAuthIssueAdviceIfNeeded();
453 } 452 }
454 453
455 void ExtensionInstallPrompt::ConfirmStandaloneInstall( 454 void ExtensionInstallPrompt::ConfirmStandaloneInstall(
456 Delegate* delegate, 455 Delegate* delegate,
457 const Extension* extension, 456 const Extension* extension,
458 SkBitmap* icon, 457 SkBitmap* icon,
459 const ExtensionInstallPrompt::Prompt& prompt) { 458 const ExtensionInstallPrompt::Prompt& prompt) {
460 DCHECK(ui_loop_ == MessageLoop::current()); 459 DCHECK(ui_loop_ == base::MessageLoop::current());
461 extension_ = extension; 460 extension_ = extension;
462 permissions_ = extension->GetActivePermissions(); 461 permissions_ = extension->GetActivePermissions();
463 delegate_ = delegate; 462 delegate_ = delegate;
464 prompt_ = prompt; 463 prompt_ = prompt;
465 464
466 SetIcon(icon); 465 SetIcon(icon);
467 FetchOAuthIssueAdviceIfNeeded(); 466 FetchOAuthIssueAdviceIfNeeded();
468 } 467 }
469 468
470 void ExtensionInstallPrompt::ConfirmWebstoreInstall( 469 void ExtensionInstallPrompt::ConfirmWebstoreInstall(
471 Delegate* delegate, 470 Delegate* delegate,
472 const Extension* extension, 471 const Extension* extension,
473 const SkBitmap* icon, 472 const SkBitmap* icon,
474 const ShowDialogCallback& show_dialog_callback) { 473 const ShowDialogCallback& show_dialog_callback) {
475 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the 474 // SetIcon requires |extension_| to be set. ConfirmInstall will setup the
476 // remaining fields. 475 // remaining fields.
477 extension_ = extension; 476 extension_ = extension;
478 SetIcon(icon); 477 SetIcon(icon);
479 ConfirmInstall(delegate, extension, show_dialog_callback); 478 ConfirmInstall(delegate, extension, show_dialog_callback);
480 } 479 }
481 480
482 void ExtensionInstallPrompt::ConfirmInstall( 481 void ExtensionInstallPrompt::ConfirmInstall(
483 Delegate* delegate, 482 Delegate* delegate,
484 const Extension* extension, 483 const Extension* extension,
485 const ShowDialogCallback& show_dialog_callback) { 484 const ShowDialogCallback& show_dialog_callback) {
486 DCHECK(ui_loop_ == MessageLoop::current()); 485 DCHECK(ui_loop_ == base::MessageLoop::current());
487 extension_ = extension; 486 extension_ = extension;
488 permissions_ = extension->GetActivePermissions(); 487 permissions_ = extension->GetActivePermissions();
489 delegate_ = delegate; 488 delegate_ = delegate;
490 prompt_.set_type(INSTALL_PROMPT); 489 prompt_.set_type(INSTALL_PROMPT);
491 show_dialog_callback_ = show_dialog_callback; 490 show_dialog_callback_ = show_dialog_callback;
492 491
493 // We special-case themes to not show any confirm UI. Instead they are 492 // We special-case themes to not show any confirm UI. Instead they are
494 // immediately installed, and then we show an infobar (see OnInstallSuccess) 493 // immediately installed, and then we show an infobar (see OnInstallSuccess)
495 // to allow the user to revert if they don't like it. 494 // to allow the user to revert if they don't like it.
496 // 495 //
497 // We don't do this in the case where off-store extension installs are 496 // 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 497 // disabled because in that case, we don't show the dangerous download UI, so
499 // we need the UI confirmation. 498 // we need the UI confirmation.
500 if (extension->is_theme()) { 499 if (extension->is_theme()) {
501 if (extension->from_webstore() || 500 if (extension->from_webstore() ||
502 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) { 501 extensions::FeatureSwitch::easy_off_store_install()->IsEnabled()) {
503 delegate->InstallUIProceed(); 502 delegate->InstallUIProceed();
504 return; 503 return;
505 } 504 }
506 } 505 }
507 506
508 LoadImageIfNeeded(); 507 LoadImageIfNeeded();
509 } 508 }
510 509
511 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate, 510 void ExtensionInstallPrompt::ConfirmReEnable(Delegate* delegate,
512 const Extension* extension) { 511 const Extension* extension) {
513 DCHECK(ui_loop_ == MessageLoop::current()); 512 DCHECK(ui_loop_ == base::MessageLoop::current());
514 extension_ = extension; 513 extension_ = extension;
515 permissions_ = extension->GetActivePermissions(); 514 permissions_ = extension->GetActivePermissions();
516 delegate_ = delegate; 515 delegate_ = delegate;
517 prompt_.set_type(RE_ENABLE_PROMPT); 516 prompt_.set_type(RE_ENABLE_PROMPT);
518 517
519 LoadImageIfNeeded(); 518 LoadImageIfNeeded();
520 } 519 }
521 520
522 void ExtensionInstallPrompt::ConfirmExternalInstall( 521 void ExtensionInstallPrompt::ConfirmExternalInstall(
523 Delegate* delegate, 522 Delegate* delegate,
524 const Extension* extension, 523 const Extension* extension,
525 const ShowDialogCallback& show_dialog_callback) { 524 const ShowDialogCallback& show_dialog_callback) {
526 DCHECK(ui_loop_ == MessageLoop::current()); 525 DCHECK(ui_loop_ == base::MessageLoop::current());
527 extension_ = extension; 526 extension_ = extension;
528 permissions_ = extension->GetActivePermissions(); 527 permissions_ = extension->GetActivePermissions();
529 delegate_ = delegate; 528 delegate_ = delegate;
530 prompt_.set_type(EXTERNAL_INSTALL_PROMPT); 529 prompt_.set_type(EXTERNAL_INSTALL_PROMPT);
531 show_dialog_callback_ = show_dialog_callback; 530 show_dialog_callback_ = show_dialog_callback;
532 531
533 LoadImageIfNeeded(); 532 LoadImageIfNeeded();
534 } 533 }
535 534
536 void ExtensionInstallPrompt::ConfirmPermissions( 535 void ExtensionInstallPrompt::ConfirmPermissions(
537 Delegate* delegate, 536 Delegate* delegate,
538 const Extension* extension, 537 const Extension* extension,
539 const PermissionSet* permissions) { 538 const PermissionSet* permissions) {
540 DCHECK(ui_loop_ == MessageLoop::current()); 539 DCHECK(ui_loop_ == base::MessageLoop::current());
541 extension_ = extension; 540 extension_ = extension;
542 permissions_ = permissions; 541 permissions_ = permissions;
543 delegate_ = delegate; 542 delegate_ = delegate;
544 prompt_.set_type(PERMISSIONS_PROMPT); 543 prompt_.set_type(PERMISSIONS_PROMPT);
545 544
546 LoadImageIfNeeded(); 545 LoadImageIfNeeded();
547 } 546 }
548 547
549 void ExtensionInstallPrompt::ConfirmIssueAdvice( 548 void ExtensionInstallPrompt::ConfirmIssueAdvice(
550 Delegate* delegate, 549 Delegate* delegate,
551 const Extension* extension, 550 const Extension* extension,
552 const IssueAdviceInfo& issue_advice) { 551 const IssueAdviceInfo& issue_advice) {
553 DCHECK(ui_loop_ == MessageLoop::current()); 552 DCHECK(ui_loop_ == base::MessageLoop::current());
554 extension_ = extension; 553 extension_ = extension;
555 delegate_ = delegate; 554 delegate_ = delegate;
556 prompt_.set_type(PERMISSIONS_PROMPT); 555 prompt_.set_type(PERMISSIONS_PROMPT);
557 556
558 record_oauth2_grant_ = true; 557 record_oauth2_grant_ = true;
559 prompt_.SetOAuthIssueAdvice(issue_advice); 558 prompt_.SetOAuthIssueAdvice(issue_advice);
560 559
561 LoadImageIfNeeded(); 560 LoadImageIfNeeded();
562 } 561 }
563 562
564 void ExtensionInstallPrompt::ReviewPermissions(Delegate* delegate, 563 void ExtensionInstallPrompt::ReviewPermissions(Delegate* delegate,
565 const Extension* extension) { 564 const Extension* extension) {
566 DCHECK(ui_loop_ == MessageLoop::current()); 565 DCHECK(ui_loop_ == base::MessageLoop::current());
567 extension_ = extension; 566 extension_ = extension;
568 permissions_ = extension->GetActivePermissions(); 567 permissions_ = extension->GetActivePermissions();
569 delegate_ = delegate; 568 delegate_ = delegate;
570 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT); 569 prompt_.set_type(POST_INSTALL_PERMISSIONS_PROMPT);
571 570
572 LoadImageIfNeeded(); 571 LoadImageIfNeeded();
573 } 572 }
574 573
575 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension, 574 void ExtensionInstallPrompt::OnInstallSuccess(const Extension* extension,
576 SkBitmap* icon) { 575 SkBitmap* icon) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } 700 }
702 701
703 if (AutoConfirmPrompt(delegate_)) 702 if (AutoConfirmPrompt(delegate_))
704 return; 703 return;
705 704
706 if (show_dialog_callback_.is_null()) 705 if (show_dialog_callback_.is_null())
707 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_); 706 GetDefaultShowDialogCallback().Run(show_params_, delegate_, prompt_);
708 else 707 else
709 show_dialog_callback_.Run(show_params_, delegate_, prompt_); 708 show_dialog_callback_.Run(show_params_, delegate_, prompt_);
710 } 709 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698