diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-09 15:31:03 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-09 15:31:03 +0000 |
commit | c079356c84c9fbcc63d93830c0600047b53e5763 (patch) | |
tree | 141a3bb1cb93159744ba92b62983a43946bda4bf /chrome/browser/extensions/extension_preference_api.cc | |
parent | e46a9e38c55c7544fa3974de39663a63d168eb43 (diff) | |
download | chromium_src-c079356c84c9fbcc63d93830c0600047b53e5763.zip chromium_src-c079356c84c9fbcc63d93830c0600047b53e5763.tar.gz chromium_src-c079356c84c9fbcc63d93830c0600047b53e5763.tar.bz2 |
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
Diffstat (limited to 'chrome/browser/extensions/extension_preference_api.cc')
-rw-r--r-- | chrome/browser/extensions/extension_preference_api.cc | 45 |
1 files changed, 36 insertions, 9 deletions
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<DictionaryValue> 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; |