From c079356c84c9fbcc63d93830c0600047b53e5763 Mon Sep 17 00:00:00 2001 From: "bauerb@chromium.org" Date: Wed, 9 Mar 2011 15:31:03 +0000 Subject: Add ability to find out whether an extension pref value is coming from incognito preferences. If the incognito flag in the request details is set, we now return an incognito parameter from experimental.preference.get that specifies whether the value is coming from the incognito preferences or the regular ones. Also, return an error if an extension that isn't enabled in incognito mode is trying to access incognito preferences. BUG=73994 TEST=ExtensionApiTest.* Review URL: http://codereview.chromium.org/6628081 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@77465 0039d316-1c4b-4281-b951-d872f2087c98 --- .../browser/extensions/extension_preference_api.cc | 45 +++++++++++++++++----- 1 file changed, 36 insertions(+), 9 deletions(-) (limited to 'chrome/browser/extensions/extension_preference_api.cc') diff --git a/chrome/browser/extensions/extension_preference_api.cc b/chrome/browser/extensions/extension_preference_api.cc index 7472e41..088c8cf 100644 --- a/chrome/browser/extensions/extension_preference_api.cc +++ b/chrome/browser/extensions/extension_preference_api.cc @@ -25,6 +25,14 @@ const char kControlledByOtherExtensions[] = "ControlledByOtherExtensions"; const char kControllableByThisExtension[] = "ControllableByThisExtension"; const char kControlledByThisExtension[] = "ControlledByThisExtension"; +const char kIncognito[] = "incognito"; +const char kIncognitoSpecific[] = "incognitoSpecific"; +const char kLevelOfControl[] = "levelOfControl"; +const char kValue[] = "value"; + +const char kIncognitoErrorMessage[] = + "You do not have permission to access incognito preferences."; + PrefMappingEntry pref_mapping[] = { { "blockThirdPartyCookies", prefs::kBlockThirdPartyCookies, @@ -108,8 +116,13 @@ bool GetPreferenceFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); bool incognito = false; - if (details->HasKey("incognito")) - EXTENSION_FUNCTION_VALIDATE(details->GetBoolean("incognito", &incognito)); + if (details->HasKey(kIncognito)) + EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); + + if (incognito && !include_incognito()) { + error_ = kIncognitoErrorMessage; + return false; + } PrefService* prefs = incognito ? profile_->GetOffTheRecordPrefs() : profile_->GetPrefs(); @@ -129,8 +142,14 @@ bool GetPreferenceFunction::RunImpl() { std::string level_of_control = GetLevelOfControl(browser_pref, incognito); scoped_ptr result(new DictionaryValue); - result->Set("value", pref->GetValue()->DeepCopy()); - result->Set("levelOfControl", Value::CreateStringValue(level_of_control)); + result->Set(kValue, pref->GetValue()->DeepCopy()); + result->Set(kLevelOfControl, Value::CreateStringValue(level_of_control)); + if (incognito) { + ExtensionPrefs* ep = profile_->GetExtensionService()->extension_prefs(); + result->Set( + kIncognitoSpecific, + Value::CreateBooleanValue(ep->HasIncognitoPrefValue(browser_pref))); + } result_.reset(result.release()); return true; } @@ -144,11 +163,16 @@ bool SetPreferenceFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); Value* value = NULL; - EXTENSION_FUNCTION_VALIDATE(details->Get("value", &value)); + EXTENSION_FUNCTION_VALIDATE(details->Get(kValue, &value)); bool incognito = false; - if (details->HasKey("incognito")) - EXTENSION_FUNCTION_VALIDATE(details->GetBoolean("incognito", &incognito)); + if (details->HasKey(kIncognito)) + EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); + + if (incognito && !include_incognito()) { + error_ = kIncognitoErrorMessage; + return false; + } std::string browser_pref; std::string permission; @@ -180,8 +204,11 @@ bool ClearPreferenceFunction::RunImpl() { EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); bool incognito = false; - if (details->HasKey("incognito")) - EXTENSION_FUNCTION_VALIDATE(details->GetBoolean("incognito", &incognito)); + if (details->HasKey(kIncognito)) + EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); + + // We don't check incognito permissions here, as an extension should be always + // allowed to clear its own settings. std::string browser_pref; std::string permission; -- cgit v1.1