diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 04:17:31 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-13 04:17:31 +0000 |
commit | be9d9c8af20532001eff248886578d4ab844707d (patch) | |
tree | 5440af7f7193ccaae9e0dcfb8bdb2676debb045a /chrome | |
parent | eeb3a533308c6a9ebe2206a57137c095bfbb2e01 (diff) | |
download | chromium_src-be9d9c8af20532001eff248886578d4ab844707d.zip chromium_src-be9d9c8af20532001eff248886578d4ab844707d.tar.gz chromium_src-be9d9c8af20532001eff248886578d4ab844707d.tar.bz2 |
Re-land change 7253001.
This change was reverted in r90547 due to unrelated test failures.
BUG=None
TEST=Unit-tests.
Review URL: http://codereview.chromium.org/7348001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
28 files changed, 402 insertions, 27 deletions
diff --git a/chrome/browser/browser_resources.grd b/chrome/browser/browser_resources.grd index 7effd4a..f01fc6f 100644 --- a/chrome/browser/browser_resources.grd +++ b/chrome/browser/browser_resources.grd @@ -96,6 +96,7 @@ <include name="IDR_BUGREPORT_HTML" file="resources\bug_report.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_BUGREPORT_HTML_INVALID" file="resources\bug_report_invalid.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_WEBSTORE_MANIFEST" file="resources\webstore_app\manifest.json" type="BINDATA" /> + <include name="IDR_CLOUDPRINT_MANIFEST" file="resources\cloud_print_app\manifest.json" type="BINDATA" /> <if expr="pp_ifdef('chromeos')"> <include name="IDR_ABOUT_SYS_HTML" file="resources\about_sys.html" flattenhtml="true" type="BINDATA" /> <include name="IDR_CHOOSE_MOBILE_NETWORK_HTML" file="resources\chromeos\choose_mobile_network.html" flattenhtml="true" type="BINDATA" /> diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 3cc99b8..8f780c3 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -292,6 +292,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( switches::kAllowScriptingGallery, switches::kAppsCheckoutURL, switches::kAppsGalleryURL, + switches::kCloudPrintServiceURL, switches::kDebugPrint, #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) && !defined(OS_MACOSX) // Enabled by default in Google Chrome builds, except on CrOS. diff --git a/chrome/browser/extensions/extension_chrome_auth_private_api.cc b/chrome/browser/extensions/extension_chrome_auth_private_api.cc new file mode 100644 index 0000000..79bae39 --- /dev/null +++ b/chrome/browser/extensions/extension_chrome_auth_private_api.cc @@ -0,0 +1,66 @@ +// Copyright (c) 2011 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_chrome_auth_private_api.h" + +#include <string> +#include "base/values.h" +#include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/printing/cloud_print/cloud_print_proxy_service.h" + +namespace { + +bool IsCloudPrintEnableURL(Profile* profile, const GURL& url) { + ExtensionService* service = profile->GetExtensionService(); + const Extension* cloud_print_app = service->GetExtensionById( + extension_misc::kCloudPrintAppId, false); + if (!cloud_print_app) { + NOTREACHED(); + return false; + } + return (service->GetExtensionByWebExtent(url) == cloud_print_app); +} + +bool test_mode = false; + +const char kAccessDeniedError[] = + "Cannot call this API from a non-cloudprint URL."; +} // namespace + +SetCloudPrintCredentialsFunction::SetCloudPrintCredentialsFunction() { +} + +SetCloudPrintCredentialsFunction::~SetCloudPrintCredentialsFunction() { +} + +bool SetCloudPrintCredentialsFunction::RunImpl() { + // This has to be called from the specific cloud print app. + if (!IsCloudPrintEnableURL(profile_, source_url())) { + error_ = kAccessDeniedError; + return false; + } + + std::string user_email; + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &user_email)); + std::string robot_email; + EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &robot_email)); + std::string credentials; + EXTENSION_FUNCTION_VALIDATE(args_->GetString(2, &credentials)); + if (test_mode) { + std::string test_response = user_email; + test_response.append(robot_email); + test_response.append(credentials); + result_.reset(Value::CreateStringValue(test_response)); + } else { + profile_->GetCloudPrintProxyService()->EnableForUserWithRobot( + credentials, robot_email, user_email); + } + SendResponse(true); + return true; +} + +// static +void SetCloudPrintCredentialsFunction::SetTestMode(bool test_mode_enabled) { + test_mode = test_mode_enabled; +} diff --git a/chrome/browser/extensions/extension_chrome_auth_private_api.h b/chrome/browser/extensions/extension_chrome_auth_private_api.h new file mode 100644 index 0000000..d5f6629 --- /dev/null +++ b/chrome/browser/extensions/extension_chrome_auth_private_api.h @@ -0,0 +1,31 @@ +// Copyright (c) 2011 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_CHROME_AUTH_PRIVATE_API_H_ +#define CHROME_BROWSER_EXTENSIONS_EXTENSION_CHROME_AUTH_PRIVATE_API_H_ +#pragma once + +#include <string> +#include "chrome/browser/extensions/extension_function.h" + +class SetCloudPrintCredentialsFunction : public AsyncExtensionFunction { + public: + SetCloudPrintCredentialsFunction(); + + // For use only in tests - sets a flag that can cause this function to not + // actually set the credentials but instead simply reflect the passed in + // arguments appended together as one string back in results_. + static void SetTestMode(bool test_mode_enabled); + + protected: + virtual ~SetCloudPrintCredentialsFunction(); + + virtual bool RunImpl(); + + private: + DECLARE_EXTENSION_FUNCTION_NAME("chromeAuthPrivate.setCloudPrintCredentials"); +}; + + +#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_CHROME_AUTH_PRIVATE_API_H_ diff --git a/chrome/browser/extensions/extension_chrome_auth_private_apitest.cc b/chrome/browser/extensions/extension_chrome_auth_private_apitest.cc new file mode 100644 index 0000000..ac7b11d --- /dev/null +++ b/chrome/browser/extensions/extension_chrome_auth_private_apitest.cc @@ -0,0 +1,74 @@ +// Copyright (c) 2011 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 "base/stringprintf.h" +#include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/extensions/extension_chrome_auth_private_api.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/test/ui_test_utils.h" +#include "net/base/mock_host_resolver.h" + +// A base class for tests below. +class ExtensionChromeAuthPrivateApiTest : public ExtensionApiTest { + public: + void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + ExtensionApiTest::SetUpCommandLine(command_line); + command_line->AppendSwitchASCII(switches::kCloudPrintServiceURL, + "http://www.cloudprintapp.com/files/extensions/api_test/" + "chrome_auth_private"); + } + + void SetUpInProcessBrowserTestFixture() OVERRIDE { + // Start up the test server and get us ready for calling the install + // API functions. + host_resolver()->AddRule("www.cloudprintapp.com", "127.0.0.1"); + ASSERT_TRUE(test_server()->Start()); + } + + protected: + // Returns a test server URL, but with host 'www.cloudprintapp.com' so it + // matches the cloud print app's extent that we set up via command line + // flags. + GURL GetTestServerURL(const std::string& path) { + GURL url = test_server()->GetURL( + "files/extensions/api_test/chrome_auth_private/" + path); + + // Replace the host with 'www.cloudprintapp.com' so it matches the cloud + // print app's extent. + GURL::Replacements replace_host; + std::string host_str("www.cloudprintapp.com"); + replace_host.SetHostStr(host_str); + return url.ReplaceComponents(replace_host); + } +}; + +IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, + SetCloudPrintCredentialsSuccessHosted) { + // Run this as a hosted app. Since we have overridden the cloud print service + // URL in the command line, this URL should match the web extent for our + // cloud print component app and it should work. + SetCloudPrintCredentialsFunction::SetTestMode(true); + GURL page_url = GetTestServerURL( + "enable_chrome_connector/cloud_print_success_tests.html"); + ASSERT_TRUE(RunPageTest(page_url.spec())); + SetCloudPrintCredentialsFunction::SetTestMode(false); +} + +IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, + SetCloudPrintCredentialsFailureInstalled) { + // Run this as an installed app. Since this is not a component app, it + // should fail. + ASSERT_TRUE(RunExtensionTest("chrome_auth_private/installed_app")); +} + +IN_PROC_BROWSER_TEST_F(ExtensionChromeAuthPrivateApiTest, + SetCloudPrintCredentialsFailureInstalledComponent) { + // Run this as an installed component app. This should also fail because of + // the explicit URL check in the API. + ASSERT_TRUE(RunComponentExtensionTest( + "chrome_auth_private/installed_component_app")); +} + diff --git a/chrome/browser/extensions/extension_function_dispatcher.cc b/chrome/browser/extensions/extension_function_dispatcher.cc index 15fa40e..d7fb4e7 100644 --- a/chrome/browser/extensions/extension_function_dispatcher.cc +++ b/chrome/browser/extensions/extension_function_dispatcher.cc @@ -17,6 +17,7 @@ #include "chrome/browser/extensions/extension_bookmark_manager_api.h" #include "chrome/browser/extensions/extension_bookmarks_module.h" #include "chrome/browser/extensions/extension_browser_actions_api.h" +#include "chrome/browser/extensions/extension_chrome_auth_private_api.h" #include "chrome/browser/extensions/extension_content_settings_api.h" #include "chrome/browser/extensions/extension_context_menu_api.h" #include "chrome/browser/extensions/extension_cookies_api.h" @@ -375,6 +376,9 @@ void FactoryRegistry::ResetFunctions() { RegisterFunction<GetContentSettingFunction>(); RegisterFunction<SetContentSettingFunction>(); + // ChromeAuth settings. + RegisterFunction<SetCloudPrintCredentialsFunction>(); + // Experimental App API. RegisterFunction<AppNotifyFunction>(); RegisterFunction<AppClearAllNotificationsFunction>(); diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index b28484f..5820c92 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -527,6 +527,10 @@ void ProfileImpl::RegisterComponentExtensions() { FILE_PATH_LITERAL("web_store"), IDR_WEBSTORE_MANIFEST)); + component_extensions.push_back(std::make_pair( + FILE_PATH_LITERAL("cloud_print"), + IDR_CLOUDPRINT_MANIFEST)); + for (ComponentExtensionList::iterator iter = component_extensions.begin(); iter != component_extensions.end(); ++iter) { FilePath path(iter->first); diff --git a/chrome/browser/resources/cloud_print_app/manifest.json b/chrome/browser/resources/cloud_print_app/manifest.json new file mode 100644 index 0000000..d42bd4b --- /dev/null +++ b/chrome/browser/resources/cloud_print_app/manifest.json @@ -0,0 +1,19 @@ +{ + "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDqOhnwk4+HXVfGyaNsAQdU/js1Na56diW08oF1MhZiwzSnJsEaeuMN9od9q9N4ZdK3o1xXOSARrYdE+syV7Dl31nf6qz3A6K+D5NHe6sSB9yvYlIiN37jdWdrfxxE0pRYEVYZNTe3bzq3NkcYJlOdt1UPcpJB+isXpAGUKUvt7EQIDAQAB", + "name": "Cloud Print", + "version": "0.1", + "description": "Cloud Print", + "icons": { + }, + "app": { + "launch": { + "web_url": "https://www.google.com/cloudprint/enable_chrome_connector" + }, + "urls": [ + "https://www.google.com/cloudprint/enable_chrome_connector" + ] + }, + "permissions": [ + "chromeAuthPrivate" + ] +} diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc index 2f2b1c28..1aacaa0 100644 --- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc @@ -285,11 +285,12 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { const ExtensionList* extensions = extensions_service_->extensions(); ExtensionList::const_iterator it; for (it = extensions->begin(); it != extensions->end(); ++it) { - // Don't include the WebStore. + // Don't include the WebStore and the Cloud Print app. // The WebStore launcher gets special treatment in ntp/apps.js. + // The Cloud Print app should never be displayed in the NTP. const Extension* extension = *it; DictionaryValue* app_info = GetAppInfo(extension); - if (app_info) + if (app_info && ((*it)->id() != extension_misc::kCloudPrintAppId)) list->Append(app_info); } @@ -298,7 +299,8 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { bool ntp3 = !CommandLine::ForCurrentProcess()->HasSwitch(switches::kNewTabPage4); if ((*it)->is_app() && - !(ntp3 && (*it)->id() == extension_misc::kWebStoreAppId)) { + !(ntp3 && (*it)->id() == extension_misc::kWebStoreAppId) && + ((*it)->id() != extension_misc::kCloudPrintAppId)) { DictionaryValue* app_info = new DictionaryValue(); CreateAppInfo(*it, NULL, diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 83d9d6f..e67a6dc 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -888,6 +888,8 @@ 'browser/extensions/extension_browser_actions_api.h', 'browser/extensions/extension_browser_event_router.cc', 'browser/extensions/extension_browser_event_router.h', + 'browser/extensions/extension_chrome_auth_private_api.cc', + 'browser/extensions/extension_chrome_auth_private_api.h', 'browser/extensions/extension_content_settings_api.cc', 'browser/extensions/extension_content_settings_api.h', 'browser/extensions/extension_content_settings_api_constants.cc', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index a7e901c..3a74577 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -2432,6 +2432,7 @@ 'browser/extensions/extension_browsertest.cc', 'browser/extensions/extension_browsertest.h', 'browser/extensions/extension_browsertests_misc.cc', + 'browser/extensions/extension_chrome_auth_private_apitest.cc', 'browser/extensions/extension_clipboard_apitest.cc', 'browser/extensions/extension_content_settings_apitest.cc', 'browser/extensions/extension_context_menu_apitest.cc', diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index 6458211..bac8e0b 100644 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -6414,5 +6414,47 @@ ] } ] + }, + { + "namespace": "chromeAuthPrivate", + "nodoc": "true", + "functions": [ + { + "name": "setCloudPrintCredentials", + "description": "Sets the login credentials for Cloud Print.", + "type": "function", + "parameters": [ + { + "name": "userEmail", + "type": "string", + "description": "The email address of the user." + }, + { + "name": "robotEmail", + "type": "string", + "description": "The email address of the robot account." + }, + { + "name": "credentials", + "type": "string", + "description": "The login credentials(OAuth2 Auth code)." + }, + { + "name": "callback", + "type": "function", + "description": "Called when a failure happens. Called upon success only in tests.", + "optional": "true", + "parameters": [ + { + "name": "result", + "type": "string", + "description": "A string result code. The value is non-empty on success only in tests.", + "optional": "true" + } + ] + } + ] + } + ] } ] diff --git a/chrome/common/extensions/extension.cc b/chrome/common/extensions/extension.cc index f61f789..c0ba929 100644 --- a/chrome/common/extensions/extension.cc +++ b/chrome/common/extensions/extension.cc @@ -300,6 +300,29 @@ std::vector<string16> Extension::GetPermissionMessageStrings() const { return permission_set_->GetWarningMessages(); } +void Extension::OverrideLaunchUrl(const GURL& override_url) { + GURL new_url(override_url); + if (!new_url.is_valid()) { + LOG(WARNING) << "Invalid override url given for " << name(); + } else { + if (new_url.has_port()) { + LOG(WARNING) << "Override URL passed for " << name() + << " should not contain a port. Removing it."; + + GURL::Replacements remove_port; + remove_port.ClearPort(); + new_url = new_url.ReplaceComponents(remove_port); + } + + launch_web_url_ = new_url.spec(); + + URLPattern pattern(kValidWebExtentSchemes); + pattern.Parse(new_url.spec(), URLPattern::ERROR_ON_PORTS); + pattern.SetPath(pattern.path() + '*'); + extent_.AddPattern(pattern); + } +} + FilePath Extension::MaybeNormalizePath(const FilePath& path) { #if defined(OS_WIN) // Normalize any drive letter to upper-case. We do this for consistency with @@ -1041,29 +1064,26 @@ bool Extension::LoadLaunchURL(const DictionaryValue* manifest, // Empty string means option was not used. if (!gallery_url_str.empty()) { GURL gallery_url(gallery_url_str); - if (!gallery_url.is_valid()) { - LOG(WARNING) << "Invalid url given in switch " - << switches::kAppsGalleryURL; - } else { - if (gallery_url.has_port()) { - LOG(WARNING) << "URLs passed to switch " << switches::kAppsGalleryURL - << " should not contain a port. Removing it."; - - GURL::Replacements remove_port; - remove_port.ClearPort(); - gallery_url = gallery_url.ReplaceComponents(remove_port); - } - - launch_web_url_ = gallery_url.spec(); - - URLPattern pattern(kValidWebExtentSchemes); - pattern.Parse(gallery_url.spec(), URLPattern::ERROR_ON_PORTS); - pattern.SetPath(pattern.path() + '*'); - extent_.AddPattern(pattern); - } + OverrideLaunchUrl(gallery_url); + } + } else if (id() == extension_misc::kCloudPrintAppId) { + // In order for the --cloud-print-service switch to work, we must update + // the launch URL and web extent. + // TODO(sanjeevr): Ideally we want to use CloudPrintURL here but that is + // currently under chrome/browser. + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + GURL cloud_print_service_url = GURL(command_line.GetSwitchValueASCII( + switches::kCloudPrintServiceURL)); + if (!cloud_print_service_url.is_empty()) { + std::string path( + cloud_print_service_url.path() + "/enable_chrome_connector"); + GURL::Replacements replacements; + replacements.SetPathStr(path); + GURL cloud_print_enable_connector_url = + cloud_print_service_url.ReplaceComponents(replacements); + OverrideLaunchUrl(cloud_print_enable_connector_url); } } - return true; } diff --git a/chrome/common/extensions/extension.h b/chrome/common/extensions/extension.h index c1543da..517ebdb 100644 --- a/chrome/common/extensions/extension.h +++ b/chrome/common/extensions/extension.h @@ -645,6 +645,10 @@ class Extension : public base::RefCountedThreadSafe<Extension> { // component-private permission. bool IsComponentOnlyPermission(const ExtensionAPIPermission* api) const; + // Updates the launch URL and extents for the extension using the given + // |override_url|. + void OverrideLaunchUrl(const GURL& override_url); + // Cached images for this extension. This should only be touched on the UI // thread. mutable ImageCache image_cache_; diff --git a/chrome/common/extensions/extension_constants.cc b/chrome/common/extensions/extension_constants.cc index 0218761..827c384 100644 --- a/chrome/common/extensions/extension_constants.cc +++ b/chrome/common/extensions/extension_constants.cc @@ -416,6 +416,7 @@ const char* kDecodedMessageCatalogsFilename = "DECODED_MESSAGE_CATALOGS"; namespace extension_misc { const char* kBookmarkManagerId = "eemcgdkfndhakfknompkggombfjjjeno"; const char* kWebStoreAppId = "ahfgeienlihckogmohjhadlkjgocpleb"; +const char* kCloudPrintAppId = "mfehgcgbbipciphmccgaenjidiccnmng"; const char* kAppsPromoHistogram = "Extensions.AppsPromo"; const char* kAppLaunchHistogram = "Extensions.AppLaunch"; #if defined(OS_CHROMEOS) diff --git a/chrome/common/extensions/extension_constants.h b/chrome/common/extensions/extension_constants.h index b9fd273..57742d8 100644 --- a/chrome/common/extensions/extension_constants.h +++ b/chrome/common/extensions/extension_constants.h @@ -294,6 +294,9 @@ namespace extension_misc { // The extension id of the Web Store component application. extern const char* kWebStoreAppId; + // The extension id of the Cloud Print component application. + extern const char* kCloudPrintAppId; + // Note: this structure is an ASN.1 which encodes the algorithm used // with its parameters. This is defined in PKCS #1 v2.1 (RFC 3447). // It is encoding: { OID sha1WithRSAEncryption PARAMETERS NULL } diff --git a/chrome/common/extensions/extension_permission_set.cc b/chrome/common/extensions/extension_permission_set.cc index d87e9e3..c829c10 100644 --- a/chrome/common/extensions/extension_permission_set.cc +++ b/chrome/common/extensions/extension_permission_set.cc @@ -249,6 +249,10 @@ ExtensionPermissionsInfo::ExtensionPermissionsInfo() // Hosted app and private permissions. RegisterPermission( + ExtensionAPIPermission::kChromeAuthPrivate, "chromeAuthPrivate", 0, + ExtensionPermissionMessage::kNone, + true, true, false, false); + RegisterPermission( ExtensionAPIPermission::kWebstorePrivate, "webstorePrivate", 0, ExtensionPermissionMessage::kNone, true, true, false, false); diff --git a/chrome/common/extensions/extension_permission_set.h b/chrome/common/extensions/extension_permission_set.h index 5cd331a..3ed0451 100644 --- a/chrome/common/extensions/extension_permission_set.h +++ b/chrome/common/extensions/extension_permission_set.h @@ -97,6 +97,7 @@ class ExtensionAPIPermission { kContentSettings, kContextMenus, kCookie, + kChromeAuthPrivate, kChromePrivate, kChromeosInfoPrivate, kDebugger, diff --git a/chrome/common/extensions/extension_permission_set_unittest.cc b/chrome/common/extensions/extension_permission_set_unittest.cc index 9cfa698..75e12fa 100644 --- a/chrome/common/extensions/extension_permission_set_unittest.cc +++ b/chrome/common/extensions/extension_permission_set_unittest.cc @@ -162,6 +162,7 @@ TEST(ExtensionAPIPermissionTest, HostedAppPermissions) { hosted_perms.insert(ExtensionAPIPermission::kBackground); hosted_perms.insert(ExtensionAPIPermission::kClipboardRead); hosted_perms.insert(ExtensionAPIPermission::kClipboardWrite); + hosted_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate); hosted_perms.insert(ExtensionAPIPermission::kChromePrivate); hosted_perms.insert(ExtensionAPIPermission::kExperimental); hosted_perms.insert(ExtensionAPIPermission::kGeolocation); @@ -177,13 +178,14 @@ TEST(ExtensionAPIPermissionTest, HostedAppPermissions) { EXPECT_EQ(hosted_perms.count(*i) > 0, info->GetByID(*i)->is_hosted_app()); } - EXPECT_EQ(9u, count); - EXPECT_EQ(9u, info->get_hosted_app_permission_count()); + EXPECT_EQ(10u, count); + EXPECT_EQ(10u, info->get_hosted_app_permission_count()); } TEST(ExtensionAPIPermissionTest, ComponentOnlyPermissions) { ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); ExtensionAPIPermissionSet private_perms; + private_perms.insert(ExtensionAPIPermission::kChromeAuthPrivate); private_perms.insert(ExtensionAPIPermission::kChromeosInfoPrivate); private_perms.insert(ExtensionAPIPermission::kFileBrowserPrivate); private_perms.insert(ExtensionAPIPermission::kMediaPlayerPrivate); @@ -198,7 +200,7 @@ TEST(ExtensionAPIPermissionTest, ComponentOnlyPermissions) { info->GetByID(*i)->is_component_only()); } - EXPECT_EQ(4, count); + EXPECT_EQ(5, count); } TEST(ExtensionPermissionSetTest, EffectiveHostPermissions) { @@ -497,6 +499,7 @@ TEST(ExtensionPermissionSetTest, PermissionMessages) { skip.insert(ExtensionAPIPermission::kWebstorePrivate); skip.insert(ExtensionAPIPermission::kFileBrowserPrivate); skip.insert(ExtensionAPIPermission::kMediaPlayerPrivate); + skip.insert(ExtensionAPIPermission::kChromeAuthPrivate); skip.insert(ExtensionAPIPermission::kChromePrivate); skip.insert(ExtensionAPIPermission::kChromeosInfoPrivate); skip.insert(ExtensionAPIPermission::kWebSocketProxyPrivate); diff --git a/chrome/renderer/resources/renderer_extension_bindings.js b/chrome/renderer/resources/renderer_extension_bindings.js index 777f4fa..1508d8a 100644 --- a/chrome/renderer/resources/renderer_extension_bindings.js +++ b/chrome/renderer/resources/renderer_extension_bindings.js @@ -294,6 +294,7 @@ var chrome = chrome || {}; // Entire namespaces. "bookmarks", "browserAction", + "chromeAuthPrivate", "chromePrivate", "chromeosInfoPrivate", "contextMenus", diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/enable_chrome_connector/cloud_print_success_tests.html b/chrome/test/data/extensions/api_test/chrome_auth_private/enable_chrome_connector/cloud_print_success_tests.html new file mode 100644 index 0000000..bf164c4 --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/enable_chrome_connector/cloud_print_success_tests.html @@ -0,0 +1 @@ +<script src="cloud_print_success_tests.js"></script> diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/enable_chrome_connector/cloud_print_success_tests.js b/chrome/test/data/extensions/api_test/chrome_auth_private/enable_chrome_connector/cloud_print_success_tests.js new file mode 100644 index 0000000..62f9223 --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/enable_chrome_connector/cloud_print_success_tests.js @@ -0,0 +1,22 @@ +// Copyright (c) 2011 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. + + +var tests = [ + function successfulSetCreds() { + var userEmail = 'foo@gmail.com'; + var robotEmail = 'foorobot@googleusercontent.com'; + var credentials = '1/23546efa54'; + chrome.chromeAuthPrivate.setCloudPrintCredentials( + userEmail, robotEmail, credentials, + chrome.test.callbackPass(function(result) { + // In test mode, we expect the API to reflect the arguments back to + // us appended together. + chrome.test.assertNoLastError(); + chrome.test.assertEq(result, userEmail + robotEmail + credentials); + })); + } +]; + +chrome.test.runTests(tests); diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/background.html b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/background.html new file mode 100644 index 0000000..2cfde44 --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/background.html @@ -0,0 +1 @@ +<script src="cloud_print_exception.js"></script> diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/cloud_print_exception.js b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/cloud_print_exception.js new file mode 100644 index 0000000..56aef5b --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/cloud_print_exception.js @@ -0,0 +1,28 @@ +// Copyright (c) 2011 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. + +// This test is invoked from a non-component app. So this call should throw an +// exception when we try and access the chromeAuthPrivate API. +var tests = [ + function exceptionSetCreds() { + var expectedException = + "Error: You do not have permission to use " + + "'chromeAuthPrivate.setCloudPrintCredentials'. Be sure to declare in " + + "your manifest what permissions you need."; + var userEmail = 'foo@gmail.com'; + var robotEmail = 'foorobot@googleusercontent.com'; + var credentials = '1/23546efa54'; + try { + chrome.chromeAuthPrivate.setCloudPrintCredentials( + userEmail, robotEmail, credentials); + } catch (err) { + chrome.test.assertEq(expectedException, err.toString()); + chrome.test.succeed(); + return; + } + chrome.test.fail(); + } +]; + +chrome.test.runTests(tests); diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/manifest.json b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/manifest.json new file mode 100644 index 0000000..6d4da5e --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_app/manifest.json @@ -0,0 +1,9 @@ +{ + "name": "Cloud Print Installed App", + "version": "0.1", + "description": "Cloud Print Installed App Test For Failure", + "background_page": "background.html", + "permissions": [ + "chromeAuthPrivate" + ] +} diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/background.html b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/background.html new file mode 100644 index 0000000..22bb9da --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/background.html @@ -0,0 +1 @@ +<script src="cloud_print_fail.js"></script> diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/cloud_print_fail.js b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/cloud_print_fail.js new file mode 100644 index 0000000..c5db1102b6 --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/cloud_print_fail.js @@ -0,0 +1,19 @@ +// Copyright (c) 2011 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. + +// This test is invoked from an installed component app. Since we have an +// explicit URL check in the API, this should fail. +var tests = [ + function failureSetCreds() { + var expectedError = "Cannot call this API from a non-cloudprint URL." + var userEmail = 'foo@gmail.com'; + var robotEmail = 'foorobot@googleusercontent.com'; + var credentials = '1/23546efa54'; + chrome.chromeAuthPrivate.setCloudPrintCredentials( + userEmail, robotEmail, credentials, + chrome.test.callbackFail(expectedError)); + } +]; + +chrome.test.runTests(tests); diff --git a/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/manifest.json b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/manifest.json new file mode 100644 index 0000000..63a1f10 --- /dev/null +++ b/chrome/test/data/extensions/api_test/chrome_auth_private/installed_component_app/manifest.json @@ -0,0 +1,10 @@ +{ + "key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCp40PYAXfSDlzCW1f5MDzRW64h0YhgV7MX8Frem0vO1ZAlq/mlUO4KxwkF2AZliFScO4Cc3CYpO6jpHXwz27tUwaN46C/LzYO7u/kb2piOep8gClvZ64EMnDv5PIoIeZlOJhkpnfs/5FbQt5sqT9avXX7YfLCLBJBql0U/V5615wIDAQAB", + "name": "Cloud Print Installed Component App", + "version": "0.1", + "description": "Cloud Print App Test For Failure", + "background_page": "background.html", + "permissions": [ + "chromeAuthPrivate" + ] +} |