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

Side by Side Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 482293003: Remove webstore code for signin that is no longer used. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 3 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/api/webstore_private/webstore_private_api.h" 5 #include "chrome/browser/extensions/api/webstore_private/webstore_private_api.h"
6 6
7 #include "base/bind_helpers.h" 7 #include "base/bind_helpers.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/memory/scoped_vector.h" 10 #include "base/memory/scoped_vector.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/prefs/pref_service.h" 12 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "base/version.h" 17 #include "base/version.h"
18 #include "chrome/browser/about_flags.h" 18 #include "chrome/browser/about_flags.h"
19 #include "chrome/browser/apps/ephemeral_app_launcher.h" 19 #include "chrome/browser/apps/ephemeral_app_launcher.h"
20 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/chrome_notification_types.h" 21 #include "chrome/browser/chrome_notification_types.h"
22 #include "chrome/browser/extensions/crx_installer.h" 22 #include "chrome/browser/extensions/crx_installer.h"
23 #include "chrome/browser/extensions/extension_install_ui_util.h" 23 #include "chrome/browser/extensions/extension_install_ui_util.h"
24 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
25 #include "chrome/browser/extensions/install_tracker.h" 25 #include "chrome/browser/extensions/install_tracker.h"
26 #include "chrome/browser/extensions/webstore_installer.h" 26 #include "chrome/browser/extensions/webstore_installer.h"
27 #include "chrome/browser/gpu/gpu_feature_checker.h" 27 #include "chrome/browser/gpu/gpu_feature_checker.h"
28 #include "chrome/browser/profiles/profile_manager.h" 28 #include "chrome/browser/profiles/profile_manager.h"
29 #include "chrome/browser/signin/signin_manager_factory.h"
30 #include "chrome/browser/signin/signin_promo.h"
31 #include "chrome/browser/signin/signin_tracker_factory.h"
32 #include "chrome/browser/sync/profile_sync_service.h" 29 #include "chrome/browser/sync/profile_sync_service.h"
33 #include "chrome/browser/sync/profile_sync_service_factory.h" 30 #include "chrome/browser/sync/profile_sync_service_factory.h"
34 #include "chrome/browser/ui/app_list/app_list_service.h" 31 #include "chrome/browser/ui/app_list/app_list_service.h"
35 #include "chrome/browser/ui/app_list/app_list_util.h" 32 #include "chrome/browser/ui/app_list/app_list_util.h"
36 #include "chrome/browser/ui/browser.h" 33 #include "chrome/browser/ui/browser.h"
37 #include "chrome/common/extensions/extension_constants.h" 34 #include "chrome/common/extensions/extension_constants.h"
38 #include "chrome/common/pref_names.h" 35 #include "chrome/common/pref_names.h"
39 #include "components/crx_file/id_util.h" 36 #include "components/crx_file/id_util.h"
40 #include "components/signin/core/browser/signin_manager.h"
41 #include "components/signin/core/common/profile_management_switches.h"
42 #include "content/public/browser/gpu_data_manager.h" 37 #include "content/public/browser/gpu_data_manager.h"
43 #include "content/public/browser/notification_details.h" 38 #include "content/public/browser/notification_details.h"
44 #include "content/public/browser/notification_source.h" 39 #include "content/public/browser/notification_source.h"
45 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
46 #include "content/public/common/page_transition_types.h" 41 #include "content/public/common/page_transition_types.h"
47 #include "content/public/common/referrer.h" 42 #include "content/public/common/referrer.h"
48 #include "extensions/browser/extension_function_dispatcher.h" 43 #include "extensions/browser/extension_function_dispatcher.h"
49 #include "extensions/browser/extension_prefs.h" 44 #include "extensions/browser/extension_prefs.h"
50 #include "extensions/browser/extension_registry.h" 45 #include "extensions/browser/extension_registry.h"
51 #include "extensions/browser/extension_system.h" 46 #include "extensions/browser/extension_system.h"
(...skipping 14 matching lines...) Expand all
66 api::webstore_private::GetEphemeralAppsEnabled; 61 api::webstore_private::GetEphemeralAppsEnabled;
67 namespace CompleteInstall = api::webstore_private::CompleteInstall; 62 namespace CompleteInstall = api::webstore_private::CompleteInstall;
68 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin; 63 namespace GetBrowserLogin = api::webstore_private::GetBrowserLogin;
69 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled; 64 namespace GetIsLauncherEnabled = api::webstore_private::GetIsLauncherEnabled;
70 namespace GetStoreLogin = api::webstore_private::GetStoreLogin; 65 namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
71 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus; 66 namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
72 namespace InstallBundle = api::webstore_private::InstallBundle; 67 namespace InstallBundle = api::webstore_private::InstallBundle;
73 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode; 68 namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
74 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp; 69 namespace LaunchEphemeralApp = api::webstore_private::LaunchEphemeralApp;
75 namespace LaunchEphemeralAppResult = LaunchEphemeralApp::Results; 70 namespace LaunchEphemeralAppResult = LaunchEphemeralApp::Results;
76 namespace SignIn = api::webstore_private::SignIn;
77 namespace SetStoreLogin = api::webstore_private::SetStoreLogin; 71 namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
78 72
79 namespace { 73 namespace {
80 74
81 // Holds the Approvals between the time we prompt and start the installs. 75 // Holds the Approvals between the time we prompt and start the installs.
82 class PendingApprovals { 76 class PendingApprovals {
83 public: 77 public:
84 PendingApprovals(); 78 PendingApprovals();
85 ~PendingApprovals(); 79 ~PendingApprovals();
86 80
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 case MANIFEST_ERROR: 306 case MANIFEST_ERROR:
313 return "manifest_error"; 307 return "manifest_error";
314 case ICON_ERROR: 308 case ICON_ERROR:
315 return "icon_error"; 309 return "icon_error";
316 case INVALID_ID: 310 case INVALID_ID:
317 return "invalid_id"; 311 return "invalid_id";
318 case PERMISSION_DENIED: 312 case PERMISSION_DENIED:
319 return "permission_denied"; 313 return "permission_denied";
320 case INVALID_ICON_URL: 314 case INVALID_ICON_URL:
321 return "invalid_icon_url"; 315 return "invalid_icon_url";
322 case SIGNIN_FAILED:
323 return "signin_failed";
324 case ALREADY_INSTALLED: 316 case ALREADY_INSTALLED:
325 return "already_installed"; 317 return "already_installed";
326 } 318 }
327 NOTREACHED(); 319 NOTREACHED();
328 return ""; 320 return "";
329 } 321 }
330 322
331 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode( 323 void WebstorePrivateBeginInstallWithManifest3Function::SetResultCode(
332 ResultCode code) { 324 ResultCode code) {
333 results_ = BeginInstallWithManifest3::Results::Create( 325 results_ = BeginInstallWithManifest3::Results::Create(
(...skipping 21 matching lines...) Expand all
355 std::string(), 347 std::string(),
356 &error); 348 &error);
357 349
358 if (!dummy_extension_.get()) { 350 if (!dummy_extension_.get()) {
359 OnWebstoreParseFailure(params_->details.id, 351 OnWebstoreParseFailure(params_->details.id,
360 WebstoreInstallHelper::Delegate::MANIFEST_ERROR, 352 WebstoreInstallHelper::Delegate::MANIFEST_ERROR,
361 kInvalidManifestError); 353 kInvalidManifestError);
362 return; 354 return;
363 } 355 }
364 356
365 SigninManagerBase* signin_manager = 357 content::WebContents* web_contents = GetAssociatedWebContents();
366 SigninManagerFactory::GetForProfile(GetProfile()); 358 if (!web_contents) // The browser window has gone away.
367 if (dummy_extension_->is_platform_app() &&
368 signin_manager &&
369 signin_manager->GetAuthenticatedUsername().empty() &&
370 signin_manager->AuthInProgress()) {
371 signin_tracker_ =
372 SigninTrackerFactory::CreateForProfile(GetProfile(), this);
373 return; 359 return;
374 } 360 install_prompt_.reset(new ExtensionInstallPrompt(web_contents));
375 361 install_prompt_->ConfirmWebstoreInstall(
376 SigninCompletedOrNotNeeded(); 362 this,
363 dummy_extension_.get(),
364 &icon_,
365 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
366 // Control flow finishes up in InstallUIProceed or InstallUIAbort.
377 } 367 }
378 368
379 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure( 369 void WebstorePrivateBeginInstallWithManifest3Function::OnWebstoreParseFailure(
380 const std::string& id, 370 const std::string& id,
381 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code, 371 WebstoreInstallHelper::Delegate::InstallHelperResultCode result_code,
382 const std::string& error_message) { 372 const std::string& error_message) {
383 CHECK_EQ(params_->details.id, id); 373 CHECK_EQ(params_->details.id, id);
384 374
385 // Map from WebstoreInstallHelper's result codes to ours. 375 // Map from WebstoreInstallHelper's result codes to ours.
386 switch (result_code) { 376 switch (result_code) {
387 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR: 377 case WebstoreInstallHelper::Delegate::UNKNOWN_ERROR:
388 SetResultCode(UNKNOWN_ERROR); 378 SetResultCode(UNKNOWN_ERROR);
389 break; 379 break;
390 case WebstoreInstallHelper::Delegate::ICON_ERROR: 380 case WebstoreInstallHelper::Delegate::ICON_ERROR:
391 SetResultCode(ICON_ERROR); 381 SetResultCode(ICON_ERROR);
392 break; 382 break;
393 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR: 383 case WebstoreInstallHelper::Delegate::MANIFEST_ERROR:
394 SetResultCode(MANIFEST_ERROR); 384 SetResultCode(MANIFEST_ERROR);
395 break; 385 break;
396 default: 386 default:
397 CHECK(false); 387 CHECK(false);
398 } 388 }
399 error_ = error_message; 389 error_ = error_message;
400 SendResponse(false); 390 SendResponse(false);
401 391
402 // Matches the AddRef in RunAsync(). 392 // Matches the AddRef in RunAsync().
403 Release(); 393 Release();
404 } 394 }
405 395
406 void WebstorePrivateBeginInstallWithManifest3Function::SigninFailed(
407 const GoogleServiceAuthError& error) {
408 signin_tracker_.reset();
409
410 SetResultCode(SIGNIN_FAILED);
411 error_ = error.ToString();
412 SendResponse(false);
413
414 // Matches the AddRef in RunAsync().
415 Release();
416 }
417
418 void WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess() {
419 signin_tracker_.reset();
420
421 SigninCompletedOrNotNeeded();
422 }
423
424 void WebstorePrivateBeginInstallWithManifest3Function::MergeSessionComplete(
425 const GoogleServiceAuthError& error) {
426 // TODO(rogerta): once the embeded inline flow is enabled, the code in
427 // WebstorePrivateBeginInstallWithManifest3Function::SigninSuccess()
428 // should move to here.
429 }
430
431 void WebstorePrivateBeginInstallWithManifest3Function::
432 SigninCompletedOrNotNeeded() {
433 content::WebContents* web_contents = GetAssociatedWebContents();
434 if (!web_contents) // The browser window has gone away.
435 return;
436 install_prompt_.reset(new ExtensionInstallPrompt(web_contents));
437 install_prompt_->ConfirmWebstoreInstall(
438 this,
439 dummy_extension_.get(),
440 &icon_,
441 ExtensionInstallPrompt::GetDefaultShowDialogCallback());
442 // Control flow finishes up in InstallUIProceed or InstallUIAbort.
443 }
444
445 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() { 396 void WebstorePrivateBeginInstallWithManifest3Function::InstallUIProceed() {
446 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in 397 // This gets cleared in CrxInstaller::ConfirmInstall(). TODO(asargent) - in
447 // the future we may also want to add time-based expiration, where a whitelist 398 // the future we may also want to add time-based expiration, where a whitelist
448 // entry is only valid for some number of minutes. 399 // entry is only valid for some number of minutes.
449 scoped_ptr<WebstoreInstaller::Approval> approval( 400 scoped_ptr<WebstoreInstaller::Approval> approval(
450 WebstoreInstaller::Approval::CreateWithNoInstallPrompt( 401 WebstoreInstaller::Approval::CreateWithNoInstallPrompt(
451 GetProfile(), params_->details.id, parsed_manifest_.Pass(), false)); 402 GetProfile(), params_->details.id, parsed_manifest_.Pass(), false));
452 approval->use_app_installed_bubble = params_->details.app_install_bubble; 403 approval->use_app_installed_bubble = params_->details.app_install_bubble;
453 approval->enable_launcher = params_->details.enable_launcher; 404 approval->enable_launcher = params_->details.enable_launcher;
454 // If we are enabling the launcher, we should not show the app list in order 405 // If we are enabling the launcher, we should not show the app list in order
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled()); 630 results_ = GetIsLauncherEnabled::Results::Create(IsAppLauncherEnabled());
680 return true; 631 return true;
681 } 632 }
682 633
683 bool WebstorePrivateIsInIncognitoModeFunction::RunSync() { 634 bool WebstorePrivateIsInIncognitoModeFunction::RunSync() {
684 results_ = IsInIncognitoMode::Results::Create( 635 results_ = IsInIncognitoMode::Results::Create(
685 GetProfile() != GetProfile()->GetOriginalProfile()); 636 GetProfile() != GetProfile()->GetOriginalProfile());
686 return true; 637 return true;
687 } 638 }
688 639
689 WebstorePrivateSignInFunction::WebstorePrivateSignInFunction()
690 : signin_manager_(NULL) {}
691 WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {}
692
693 bool WebstorePrivateSignInFunction::RunAsync() {
694 scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_);
695 EXTENSION_FUNCTION_VALIDATE(params);
696
697 // This API must be called only in response to a user gesture.
698 if (!user_gesture()) {
699 error_ = "user_gesture_required";
700 SendResponse(false);
701 return false;
702 }
703
704 // The |continue_url| is required, and must be hosted on the same origin as
705 // the calling page.
706 GURL continue_url(params->continue_url);
707 content::WebContents* web_contents = GetAssociatedWebContents();
708 if (!continue_url.is_valid() ||
709 continue_url.GetOrigin() !=
710 web_contents->GetLastCommittedURL().GetOrigin()) {
711 error_ = "invalid_continue_url";
712 SendResponse(false);
713 return false;
714 }
715
716 // If sign-in is disallowed, give up.
717 signin_manager_ = SigninManagerFactory::GetForProfile(GetProfile());
718 if (!signin_manager_ || !signin_manager_->IsSigninAllowed() ||
719 switches::IsEnableWebBasedSignin()) {
720 error_ = "signin_is_disallowed";
721 SendResponse(false);
722 return false;
723 }
724
725 // If the user is already signed in, there's nothing else to do.
726 if (!signin_manager_->GetAuthenticatedUsername().empty()) {
727 SendResponse(true);
728 return true;
729 }
730
731 // If an authentication is currently in progress, wait for it to complete.
732 if (signin_manager_->AuthInProgress()) {
733 SigninManagerFactory::GetInstance()->AddObserver(this);
734 signin_tracker_ =
735 SigninTrackerFactory::CreateForProfile(GetProfile(), this).Pass();
736 AddRef(); // Balanced in the sign-in observer methods below.
737 return true;
738 }
739
740 GURL signin_url =
741 signin::GetPromoURLWithContinueURL(signin::SOURCE_WEBSTORE_INSTALL,
742 false /* auto_close */,
743 false /* is_constrained */,
744 continue_url);
745 web_contents->GetController().LoadURL(signin_url,
746 content::Referrer(),
747 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
748 std::string());
749
750 SendResponse(true);
751 return true;
752 }
753
754 void WebstorePrivateSignInFunction::SigninManagerShutdown(
755 SigninManagerBase* manager) {
756 if (manager == signin_manager_)
757 SigninFailed(GoogleServiceAuthError::AuthErrorNone());
758 }
759
760 void WebstorePrivateSignInFunction::SigninFailed(
761 const GoogleServiceAuthError& error) {
762 error_ = "signin_failed";
763 SendResponse(false);
764
765 SigninManagerFactory::GetInstance()->RemoveObserver(this);
766 Release(); // Balanced in RunAsync().
767 }
768
769 void WebstorePrivateSignInFunction::SigninSuccess() {
770 // Nothing to do yet. Keep waiting until MergeSessionComplete() is called.
771 }
772
773 void WebstorePrivateSignInFunction::MergeSessionComplete(
774 const GoogleServiceAuthError& error) {
775 if (error.state() == GoogleServiceAuthError::NONE) {
776 SendResponse(true);
777 } else {
778 error_ = "merge_session_failed";
779 SendResponse(false);
780 }
781
782 SigninManagerFactory::GetInstance()->RemoveObserver(this);
783 Release(); // Balanced in RunAsync().
784 }
785
786 WebstorePrivateLaunchEphemeralAppFunction:: 640 WebstorePrivateLaunchEphemeralAppFunction::
787 WebstorePrivateLaunchEphemeralAppFunction() {} 641 WebstorePrivateLaunchEphemeralAppFunction() {}
788 642
789 WebstorePrivateLaunchEphemeralAppFunction:: 643 WebstorePrivateLaunchEphemeralAppFunction::
790 ~WebstorePrivateLaunchEphemeralAppFunction() {} 644 ~WebstorePrivateLaunchEphemeralAppFunction() {}
791 645
792 bool WebstorePrivateLaunchEphemeralAppFunction::RunAsync() { 646 bool WebstorePrivateLaunchEphemeralAppFunction::RunAsync() {
793 // Check whether the browser window still exists. 647 // Check whether the browser window still exists.
794 content::WebContents* web_contents = GetAssociatedWebContents(); 648 content::WebContents* web_contents = GetAssociatedWebContents();
795 if (!web_contents) { 649 if (!web_contents) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 WebstorePrivateGetEphemeralAppsEnabledFunction:: 756 WebstorePrivateGetEphemeralAppsEnabledFunction::
903 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {} 757 ~WebstorePrivateGetEphemeralAppsEnabledFunction() {}
904 758
905 bool WebstorePrivateGetEphemeralAppsEnabledFunction::RunSync() { 759 bool WebstorePrivateGetEphemeralAppsEnabledFunction::RunSync() {
906 results_ = GetEphemeralAppsEnabled::Results::Create( 760 results_ = GetEphemeralAppsEnabled::Results::Create(
907 EphemeralAppLauncher::IsFeatureEnabled()); 761 EphemeralAppLauncher::IsFeatureEnabled());
908 return true; 762 return true;
909 } 763 }
910 764
911 } // namespace extensions 765 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698