From 3fe71e7fce5099287bf547820a0654db62ed1438 Mon Sep 17 00:00:00 2001 From: kundaji Date: Tue, 7 Oct 2014 09:53:19 -0700 Subject: [PATCH] Whitelist "reduce data usage" extension for internal preferences API. * Allow preference API to be called from whitelisted extensions, rather than limiting them to components. * Add spdy_proxy.enabled to preferences whitelist. * Add SHA-1 hash of reduce data usage extension id to whitelist for preferencesPrivate and types.private. BUG=384394 Review URL: https://codereview.chromium.org/430683002 Cr-Commit-Position: refs/heads/master@{#298507} --- .../extensions/api/preference/chrome_direct_setting.cc | 10 ---------- .../extensions/api/preference/chrome_direct_setting_api.cc | 13 ++++++------- chrome/common/extensions/api/_permission_features.json | 3 ++- chrome/common/extensions/api/preferences_private.json | 6 ++++++ extensions/common/api/_api_features.json | 8 +++++--- 5 files changed, 19 insertions(+), 21 deletions(-) diff --git a/chrome/browser/extensions/api/preference/chrome_direct_setting.cc b/chrome/browser/extensions/api/preference/chrome_direct_setting.cc index c61412380163..b64e6172ceb7 100644 --- a/chrome/browser/extensions/api/preference/chrome_direct_setting.cc +++ b/chrome/browser/extensions/api/preference/chrome_direct_setting.cc @@ -23,15 +23,9 @@ PrefService* DirectSettingFunctionBase::GetPrefService() { return GetProfile()->GetPrefs(); } -bool DirectSettingFunctionBase::IsCalledFromComponentExtension() { - return extension()->location() == Manifest::COMPONENT; -} - GetDirectSettingFunction::GetDirectSettingFunction() {} bool GetDirectSettingFunction::RunSync() { - EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); - std::string pref_key; EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) @@ -54,8 +48,6 @@ GetDirectSettingFunction::~GetDirectSettingFunction() {} SetDirectSettingFunction::SetDirectSettingFunction() {} bool SetDirectSettingFunction::RunSync() { - EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); - std::string pref_key; EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) @@ -85,8 +77,6 @@ SetDirectSettingFunction::~SetDirectSettingFunction() {} ClearDirectSettingFunction::ClearDirectSettingFunction() {} bool ClearDirectSettingFunction::RunSync() { - EXTENSION_FUNCTION_VALIDATE(IsCalledFromComponentExtension()); - std::string pref_key; EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &pref_key)); EXTENSION_FUNCTION_VALIDATE(ChromeDirectSettingAPI::Get(GetProfile()) diff --git a/chrome/browser/extensions/api/preference/chrome_direct_setting_api.cc b/chrome/browser/extensions/api/preference/chrome_direct_setting_api.cc index c83f80f354f1..4d3967139906 100644 --- a/chrome/browser/extensions/api/preference/chrome_direct_setting_api.cc +++ b/chrome/browser/extensions/api/preference/chrome_direct_setting_api.cc @@ -25,6 +25,7 @@ class PreferenceWhitelist { public: PreferenceWhitelist() { whitelist_.insert("googlegeolocationaccess.enabled"); + whitelist_.insert("spdy_proxy.enabled"); } ~PreferenceWhitelist() {} @@ -137,13 +138,11 @@ void ChromeDirectSettingAPI::OnPrefChanged( const ExtensionSet* extensions = extension_service->extensions(); for (ExtensionSet::const_iterator it = extensions->begin(); it != extensions->end(); ++it) { - if ((*it)->location() == Manifest::COMPONENT) { - std::string extension_id = (*it)->id(); - if (router->ExtensionHasEventListener(extension_id, event_name)) { - scoped_ptr args_copy(args.DeepCopy()); - scoped_ptr event(new Event(event_name, args_copy.Pass())); - router->DispatchEventToExtension(extension_id, event.Pass()); - } + const std::string& extension_id = (*it)->id(); + if (router->ExtensionHasEventListener(extension_id, event_name)) { + scoped_ptr args_copy(args.DeepCopy()); + scoped_ptr event(new Event(event_name, args_copy.Pass())); + router->DispatchEventToExtension(extension_id, event.Pass()); } } } diff --git a/chrome/common/extensions/api/_permission_features.json b/chrome/common/extensions/api/_permission_features.json index 5a1f0da7cfa5..2c243e5a49f0 100644 --- a/chrome/common/extensions/api/_permission_features.json +++ b/chrome/common/extensions/api/_permission_features.json @@ -829,7 +829,8 @@ "C41AD9DCD670210295614257EF8C9945AD68D86E", // Google Now "D5736E4B5CF695CB93A2FB57E4FDC6E5AFAB6FE2", // http://crbug.com/312900 "D57DE394F36DC1C3220E7604C575D29C51A6C495", // http://crbug.com/319444 - "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9" // http://crbug.com/371562 + "3F65507A3B39259B38C8173C6FFA3D12DF64CCE9", // http://crbug.com/371562 + "852290F2442EEE45EF673B8DA6090112079012A2" // http://crbug.com/375484 ] }, "principalsPrivate": { diff --git a/chrome/common/extensions/api/preferences_private.json b/chrome/common/extensions/api/preferences_private.json index 3660bee6bf82..6babb2c67ee5 100644 --- a/chrome/common/extensions/api/preferences_private.json +++ b/chrome/common/extensions/api/preferences_private.json @@ -12,6 +12,12 @@ "$ref": "types.private.ChromeDirectSetting", "value": ["googlegeolocationaccess.enabled", {"type":"boolean"}], "description": "If enabled, Google services can access the user's location. This preference's value is a boolean, defaulting to false." + }, + "spdyProxyEnabled": { + "nocompile": true, + "$ref": "types.private.ChromeDirectSetting", + "value": ["spdy_proxy.enabled", {"type":"boolean"}], + "description": "Flag to enable data usage reduction by sending requests via data reduction proxy. This preference's value is a boolean, defaulting to false." } }, "functions": [ diff --git a/extensions/common/api/_api_features.json b/extensions/common/api/_api_features.json index ba8ce62c3343..343000dac15a 100644 --- a/extensions/common/api/_api_features.json +++ b/extensions/common/api/_api_features.json @@ -261,9 +261,11 @@ "contexts": ["blessed_extension"] }, "types.private": { - "channel": "dev", - "extension_types": ["extension"], - "location": "component" + // preferencesPrivate is the only API that uses types.private. + // If any other APIs need it then they'll need to be added in + // separate rules. + "dependencies": ["permission:preferencesPrivate"], + "contexts": ["blessed_extension"] }, "usb": { "dependencies": ["permission:usb"], -- 2.11.4.GIT