diff options
author | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-01 04:41:23 +0000 |
---|---|---|
committer | asargent@chromium.org <asargent@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-01 04:41:23 +0000 |
commit | 63cda0c1ef4637c345c286e72c5e4af9e4f94fb0 (patch) | |
tree | c45017f8cb08e7bf23a38db6774e97d56d683759 | |
parent | 270979d4c618381a522a556b806cf77401b7b8ea (diff) | |
download | chromium_src-63cda0c1ef4637c345c286e72c5e4af9e4f94fb0.zip chromium_src-63cda0c1ef4637c345c286e72c5e4af9e4f94fb0.tar.gz chromium_src-63cda0c1ef4637c345c286e72c5e4af9e4f94fb0.tar.bz2 |
Private API for web store to get sync login and set store login information.
BUG=53489
TEST=Not sure yet the best way to test this - it will depend on how the store
implements their part of the API.
Review URL: http://codereview.chromium.org/3219006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58126 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_function_dispatcher.cc | 6 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.cc | 17 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.h | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_webstore_private_api.cc | 52 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_webstore_private_api.h | 26 | ||||
-rw-r--r-- | chrome/browser/resources/webstore_app/manifest.json | 1 | ||||
-rw-r--r-- | chrome/chrome_browser.gypi | 2 | ||||
-rw-r--r-- | chrome/common/extensions/api/extension_api.json | 43 | ||||
-rw-r--r-- | chrome/common/extensions/extension.cc | 13 | ||||
-rw-r--r-- | chrome/common/extensions/extension.h | 1 | ||||
-rw-r--r-- | chrome/renderer/resources/renderer_extension_bindings.js | 1 |
11 files changed, 169 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index fd4ba5f..dc03bbb 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -49,6 +49,7 @@ #if defined(OS_CHROMEOS) #include "chrome/browser/extensions/extension_tts_api.h" #endif +#include "chrome/browser/extensions/extension_webstore_private_api.h" #include "chrome/browser/extensions/extensions_quota_service.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/profile.h" @@ -279,6 +280,11 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<SetEnabledFunction>(); RegisterFunction<InstallFunction>(); RegisterFunction<UninstallFunction>(); + + // WebstorePrivate. + RegisterFunction<GetSyncLoginFunction>(); + RegisterFunction<GetStoreLoginFunction>(); + RegisterFunction<SetStoreLoginFunction>(); } void FactoryRegistry::GetAllNames(std::vector<std::string>* names) { diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index c7799c7..058ede3 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -75,6 +75,10 @@ const char kPrefIncognitoEnabled[] = "incognito"; // pages with file URLs. const char kPrefAllowFileAccess[] = "allowFileAccess"; +// A preference set by the web store to indicate login information for +// purchased apps. +const char kWebStoreLogin[] = "extensions.webstore_login"; + } // namespace //////////////////////////////////////////////////////////////////////////////// @@ -793,6 +797,18 @@ std::set<std::string> ExtensionPrefs::GetIdleInstallInfoIds() { return result; } +bool ExtensionPrefs::GetWebStoreLogin(std::string* result) { + if (prefs_->HasPrefPath(kWebStoreLogin)) { + *result = prefs_->GetString(kWebStoreLogin); + return true; + } + return false; +} + +void ExtensionPrefs::SetWebStoreLogin(const std::string& login) { + prefs_->SetString(kWebStoreLogin, login); + prefs_->ScheduleSavePersistentPrefs(); +} // static void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { @@ -802,4 +818,5 @@ void ExtensionPrefs::RegisterUserPrefs(PrefService* prefs) { prefs->RegisterDictionaryPref(kExtensionsBlacklistUpdate); prefs->RegisterListPref(kExtensionInstallAllowList); prefs->RegisterListPref(kExtensionInstallDenyList); + prefs->RegisterStringPref(kWebStoreLogin, std::string() /* default_value */); } diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index 30dde70..d753e08 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -147,6 +147,14 @@ class ExtensionPrefs { // Returns the extension id's that have idle install information. std::set<std::string> GetIdleInstallInfoIds(); + // We allow the web store to set a string containing login information when a + // purchase is made, so that when a user logs into sync with a different + // account we can recognize the situation. The Get function returns true if + // there was previously stored data (placing it in |result|), or false + // otherwise. The Set will overwrite any previous login. + bool GetWebStoreLogin(std::string* result); + void SetWebStoreLogin(const std::string& login); + static void RegisterUserPrefs(PrefService* prefs); // The underlying PrefService. diff --git a/chrome/browser/extensions/extension_webstore_private_api.cc b/chrome/browser/extensions/extension_webstore_private_api.cc new file mode 100644 index 0000000..536008c --- /dev/null +++ b/chrome/browser/extensions/extension_webstore_private_api.cc @@ -0,0 +1,52 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/extensions/extension_webstore_private_api.h" + +#include "base/values.h" +#include "chrome/browser/extensions/extension_prefs.h" +#include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/sync/profile_sync_service.h" + +static bool IsWebStoreURL(const GURL& url) { + GURL store_url(Extension::ChromeStoreURL()); + if (!url.is_valid() || !store_url.is_valid()) { + return false; + } + return store_url.GetOrigin() == url.GetOrigin(); +} + +bool GetSyncLoginFunction::RunImpl() { + if (!IsWebStoreURL(source_url())) + return false; + ProfileSyncService* sync_service = profile_->GetProfileSyncService(); + string16 username = sync_service->GetAuthenticatedUsername(); + result_.reset(Value::CreateStringValue(username)); + return true; +} + +bool GetStoreLoginFunction::RunImpl() { + if (!IsWebStoreURL(source_url())) + return false; + ExtensionsService* service = profile_->GetExtensionsService(); + ExtensionPrefs* prefs = service->extension_prefs(); + std::string login; + if (prefs->GetWebStoreLogin(&login)) { + result_.reset(Value::CreateStringValue(login)); + } else { + result_.reset(Value::CreateStringValue(std::string())); + } + return true; +} + +bool SetStoreLoginFunction::RunImpl() { + if (!IsWebStoreURL(source_url())) + return false; + std::string login; + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &login)); + ExtensionsService* service = profile_->GetExtensionsService(); + ExtensionPrefs* prefs = service->extension_prefs(); + prefs->SetWebStoreLogin(login); + return true; +} diff --git a/chrome/browser/extensions/extension_webstore_private_api.h b/chrome/browser/extensions/extension_webstore_private_api.h new file mode 100644 index 0000000..1f2abff --- /dev/null +++ b/chrome/browser/extensions/extension_webstore_private_api.h @@ -0,0 +1,26 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBSTORE_PRIVATE_API_H__ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBSTORE_PRIVATE_API_H__ +#pragma once + +#include "chrome/browser/extensions/extension_function.h" + +class GetSyncLoginFunction : public SyncExtensionFunction { + virtual bool RunImpl(); + DECLARE_EXTENSION_FUNCTION_NAME("webstorePrivate.getSyncLogin"); +}; + +class GetStoreLoginFunction : public SyncExtensionFunction { + virtual bool RunImpl(); + DECLARE_EXTENSION_FUNCTION_NAME("webstorePrivate.getStoreLogin"); +}; + +class SetStoreLoginFunction : public SyncExtensionFunction { + virtual bool RunImpl(); + DECLARE_EXTENSION_FUNCTION_NAME("webstorePrivate.setStoreLogin"); +}; + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_WEBSTORE_PRIVATE_API_H__ diff --git a/chrome/browser/resources/webstore_app/manifest.json b/chrome/browser/resources/webstore_app/manifest.json index 0b94ace..6282d7c 100644 --- a/chrome/browser/resources/webstore_app/manifest.json +++ b/chrome/browser/resources/webstore_app/manifest.json @@ -16,5 +16,6 @@ ] }, "permissions": [ + "webstorePrivate" ] } diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index c851581..8a79a46 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1453,6 +1453,8 @@ 'browser/extensions/extension_updater.h', 'browser/extensions/extension_web_navigation_api_constants.cc', 'browser/extensions/extension_web_navigation_api_constants.h', + 'browser/extensions/extension_webstore_private_api.cc', + 'browser/extensions/extension_webstore_private_api.h', 'browser/extensions/extensions_quota_service.cc', 'browser/extensions/extensions_quota_service.h', 'browser/extensions/extensions_service.cc', diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index 4699d3a..9a4ae8d 100644 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -4070,5 +4070,48 @@ "parameters": [{"name": "info", "$ref":"ExtensionInfo"}] } ] + }, + + { + "namespace":"webstorePrivate", + "nodoc": "true", + "functions": [ + { + "name": "getSyncLogin", + "description": "Returns the logged-in sync user login if there is one, or the empty string otherwise.", + "parameters": [ + { + "name": "callback", + "type": "function", + "optional": "false", + "parameters": [ + { "name": "login", "type": "string" } + ] + } + ] + }, + { + "name": "getStoreLogin", + "description": "Returns the previous value set by setStoreLogin, or the empty string if there is none.", + "parameters": [ + { + "name": "callback", + "type": "function", + "optional": "false", + "parameters": [ + { "name": "login", "type": "string" } + ] + } + ] + }, + { + "name": "setStoreLogin", + "description": "Set a preference value with the store login.", + "parameters": [ + { "name": "login", "type": "string" }, + { "name": "callback", "type": "function", "optional": "true" } + ] + } + ] } ] diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index 692daf0..c40f93e 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -160,6 +160,7 @@ const char* Extension::kProxyPermission = "proxy"; const char* Extension::kTabPermission = "tabs"; const char* Extension::kUnlimitedStoragePermission = "unlimitedStorage"; const char* Extension::kNativeClientPermission = "nativeClient"; +const char* Extension::kWebstorePrivatePermission = "webstorePrivate"; const char* Extension::kPermissionNames[] = { Extension::kBackgroundPermission, @@ -175,6 +176,7 @@ const char* Extension::kPermissionNames[] = { Extension::kTabPermission, Extension::kUnlimitedStoragePermission, Extension::kNativeClientPermission, + Extension::kWebstorePrivatePermission, }; const size_t Extension::kNumPermissions = arraysize(Extension::kPermissionNames); @@ -184,7 +186,8 @@ const char* Extension::kHostedAppPermissionNames[] = { Extension::kGeolocationPermission, Extension::kNotificationPermission, Extension::kUnlimitedStoragePermission, - Extension::kNativeClientPermission + Extension::kNativeClientPermission, + Extension::kWebstorePrivatePermission, }; const size_t Extension::kNumHostedAppPermissions = arraysize(Extension::kHostedAppPermissionNames); @@ -1470,6 +1473,14 @@ bool Extension::InitFromValue(const DictionaryValue& source, bool require_key, return false; } + // Only COMPONENT extensions can use the webstorePrivate APIs. + // TODO(asargent) - We want a more general purpose mechanism for this, + // and better error messages. (http://crbug.com/54013) + if (permission_str == kWebstorePrivatePermission && + location_ != Extension::COMPONENT) { + continue; + } + // Remap the old unlimited storage permission name. if (permission_str == kOldUnlimitedStoragePermission) permission_str = kUnlimitedStoragePermission; diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index 519c19a..117aa33 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -110,6 +110,7 @@ class Extension { static const char* kTabPermission; static const char* kUnlimitedStoragePermission; static const char* kNativeClientPermission; + static const char* kWebstorePrivatePermission; static const char* kPermissionNames[]; static const size_t kNumPermissions; diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js index 5a2c731..f7955d1 100644 --- a/chrome/renderer/resources/renderer_extension_bindings.js +++ b/chrome/renderer/resources/renderer_extension_bindings.js @@ -275,6 +275,7 @@ var chrome = chrome || {}; "tabs", "test", "toolstrip", + "webstorePrivate", "windows", // Functions/events/properties within the extension namespace. |