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

Unified Diff: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc

Issue 196783002: Export a private webstore API to call into the new inline sign-in flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add API tests Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
diff --git a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
index 9551970003d89b66a7c005b982815e3a88f92302..bc3f2fb49bb7add5d754b9f12e387ae0e1b866e6 100644
--- a/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
+++ b/chrome/browser/extensions/api/webstore_private/webstore_private_api.cc
@@ -23,7 +23,7 @@
#include "chrome/browser/gpu/gpu_feature_checker.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/signin/signin_manager.h"
-#include "chrome/browser/signin/signin_manager_factory.h"
+#include "chrome/browser/signin/signin_promo.h"
#include "chrome/browser/sync/profile_sync_service.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "chrome/browser/ui/app_list/app_list_service.h"
@@ -32,18 +32,23 @@
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_l10n_util.h"
#include "chrome/common/pref_names.h"
+#include "chrome/common/profile_management_switches.h"
#include "content/public/browser/gpu_data_manager.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/page_transition_types.h"
+#include "content/public/common/referrer.h"
#include "extensions/browser/extension_function_dispatcher.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/error_utils.h"
#include "extensions/common/extension.h"
+#include "google_apis/gaia/google_service_auth_error.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
+#include "url/gurl.h"
using content::GpuDataManager;
@@ -58,6 +63,7 @@ namespace GetStoreLogin = api::webstore_private::GetStoreLogin;
namespace GetWebGLStatus = api::webstore_private::GetWebGLStatus;
namespace InstallBundle = api::webstore_private::InstallBundle;
namespace IsInIncognitoMode = api::webstore_private::IsInIncognitoMode;
+namespace SignIn = api::webstore_private::SignIn;
namespace SetStoreLogin = api::webstore_private::SetStoreLogin;
namespace {
@@ -686,4 +692,98 @@ bool WebstorePrivateIsInIncognitoModeFunction::RunImpl() {
return true;
}
+WebstorePrivateSignInFunction::WebstorePrivateSignInFunction()
+ : signin_manager_(NULL) {}
+WebstorePrivateSignInFunction::~WebstorePrivateSignInFunction() {}
+
+bool WebstorePrivateSignInFunction::RunImpl() {
+ scoped_ptr<SignIn::Params> params = SignIn::Params::Create(*args_);
+ EXTENSION_FUNCTION_VALIDATE(params);
+
+ // The |continue_url| is required, and must be hosted on the same origin as
+ // the calling page.
+ GURL continue_url(params->continue_url);
+ content::WebContents* web_contents = GetAssociatedWebContents();
+ if (!continue_url.is_valid() ||
+ continue_url.GetOrigin() !=
+ web_contents->GetLastCommittedURL().GetOrigin()) {
+ error_ = "invalid_continue_url";
+ SendResponse(false);
+ return false;
+ }
+
+ // If sign-in is disallowed, give up.
+ signin_manager_ = SigninManagerFactory::GetForProfile(GetProfile());
+ if (!signin_manager_ || !signin_manager_->IsSigninAllowed() ||
+ switches::IsEnableWebBasedSignin()) {
+ error_ = "signin_is_disallowed";
+ SendResponse(false);
+ return false;
+ }
+
+ // If the user is already signed in, there's nothing else to do.
+ if (!signin_manager_->GetAuthenticatedUsername().empty()) {
+ // TODO(isherman): Hui suggests returning |true| below, because the user is
+ // successfully signed in after this call. Is it ever appropriate to set an
+ // |error_| and also return |true|? In general, what's the guideline for
+ // when to return |true| vs. |false|? How is the return value used? Note
+ // that this comment also applies to the MergeSessionComplete() case below.
+ error_ = "user_is_already_signed_in";
+ SendResponse(false);
+ return false;
+ }
+
+ // If an authentication is currently in progress, wait for it to complete.
+ if (signin_manager_->AuthInProgress()) {
+ SigninManagerFactory::GetInstance()->AddObserver(this);
+ signin_tracker_.reset(new SigninTracker(GetProfile(), this));
+ AddRef(); // Balanced in the sign-in observer methods below.
+ return true;
+ }
+
+ GURL signin_url =
+ signin::GetPromoURLWithContinueURL(signin::SOURCE_WEBSTORE_INSTALL,
+ false /* auto_close */,
+ false /* is_constrained */,
+ continue_url);
+ web_contents->GetController().LoadURL(signin_url,
+ content::Referrer(),
+ content::PAGE_TRANSITION_AUTO_TOPLEVEL,
+ std::string());
+
+ SendResponse(true);
+ return true;
+}
+
+void WebstorePrivateSignInFunction::SigninManagerShutdown(
+ SigninManagerBase* manager) {
+ if (manager == signin_manager_)
+ SigninFailed(GoogleServiceAuthError::AuthErrorNone());
+}
+
+void WebstorePrivateSignInFunction::SigninFailed(
+ const GoogleServiceAuthError& error) {
+ error_ = "signin_failed";
+ SendResponse(false);
+
+ SigninManagerFactory::GetInstance()->RemoveObserver(this);
+ Release(); // Balanced in RunImpl().
+}
+
+void WebstorePrivateSignInFunction::SigninSuccess() {
+ // Nothing to do yet. Keep waiting until MergeSessionComplete() is called.
+}
+
+void WebstorePrivateSignInFunction::MergeSessionComplete(
+ const GoogleServiceAuthError& error) {
+ if (error.state() == GoogleServiceAuthError::NONE)
+ error_ = "user_is_already_signed_in";
+ else
+ error_ = "merge_session_failed";
+
+ SigninManagerFactory::GetInstance()->RemoveObserver(this);
+ SendResponse(false);
+ Release(); // Balanced in RunImpl().
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698