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

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: Redirect to the continue URL when Sync is disabled 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..263f2d9a679b503d41df15a0d381df6f9860bf22 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,96 @@ 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()) {
+ // TODO(isherman): Is it better to pass the error message to the callback,
+ // or to set it as the last |error_|?
guohui 2014/03/24 20:55:58 how do you expose the last |error_| to webstore?
Ilya Sherman 2014/03/26 08:21:39 Apparently, chrome.runtime.lastError is available
+ 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()) {
+ error_ = "user_is_already_signed_in";
+ SendResponse(false);
guohui 2014/03/24 20:55:58 i think it should return true in this case, since
Ilya Sherman 2014/03/26 08:21:39 Hmm, I'm not sure that it's appropriate to return
+ 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) {
+ SendResponse(true);
+ } else {
+ error_ = "merge_session_failed";
+ SendResponse(false);
+ }
+
+ SigninManagerFactory::GetInstance()->RemoveObserver(this);
+ Release(); // Balanced in RunImpl().
+}
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698