Chromium Code Reviews| Index: 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 4b57a12bb3e1707d74647bf55aadf97558739e6d..8a1d5af0ef6644494446e2cba52b5234879829b2 100644 |
| --- a/chrome/browser/extensions/extension_preference_api.cc |
| +++ b/chrome/browser/extensions/extension_preference_api.cc |
| @@ -13,6 +13,7 @@ |
| #include "base/values.h" |
| #include "chrome/browser/extensions/extension_event_router.h" |
| #include "chrome/browser/extensions/extension_prefs.h" |
| +#include "chrome/browser/extensions/extension_prefs_scope.h" |
| #include "chrome/browser/extensions/extension_proxy_api.h" |
| #include "chrome/browser/extensions/extension_service.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -35,7 +36,10 @@ const char kControlledByThisExtension[] = "ControlledByThisExtension"; |
| const char kIncognito[] = "incognito"; |
| const char kIncognitoSpecific[] = "incognitoSpecific"; |
| +const char kScope[] = "scope"; |
| const char kLevelOfControl[] = "levelOfControl"; |
| +const char kRegular[] = "regular"; |
| +const char kIncognitoPersistent[] = "incognito_persistent"; |
| const char kValue[] = "value"; |
| const char kOnPrefChangeFormat[] = |
| @@ -109,6 +113,18 @@ const char* GetLevelOfControl( |
| return kControlledByOtherExtensions; |
| } |
| +extension_prefs_scope::Scope StringToScope(const std::string& s) { |
| + if (s == kRegular) { |
| + return extension_prefs_scope::kRegular; |
| + } else if (s == kIncognitoPersistent) { |
| + return extension_prefs_scope::kIncognitoPersistent; |
| + } else { |
| + // The extension API checks that no invalid string can be passed. |
| + NOTREACHED(); |
|
Bernhard Bauer
2011/05/25 00:43:00
In that case you should fail validation (EXTENSION
battre
2011/05/25 11:31:45
The EXTENSION_FUNCTION_VALIDATE style validation h
Bernhard Bauer
2011/05/25 17:48:35
As in, the Javascript API? That can be circumvente
Matt Perry
2011/05/25 18:40:42
Agreed. EXTENSION_FUNCTION_VALIDATE exists because
battre
2011/05/25 19:47:44
Done.
|
| + return extension_prefs_scope::kRegular; |
| + } |
| +} |
| + |
| class PrefMapping { |
| public: |
| static PrefMapping* GetInstance() { |
| @@ -346,12 +362,12 @@ bool SetPreferenceFunction::RunImpl() { |
| Value* value = NULL; |
| EXTENSION_FUNCTION_VALIDATE(details->Get(kValue, &value)); |
| - bool incognito = false; |
| - |
| - // TODO(battre): enable incognito preferences again. |
| - // if (details->HasKey(kIncognito)) |
| - // EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); |
| + std::string scope = kRegular; |
| + if (details->HasKey(kScope)) |
| + EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope)); |
| + // TODO(battre): add kIncognitoSessionOnly |
| + bool incognito = (scope == kIncognitoPersistent); |
| if (incognito && !include_incognito()) { |
| error_ = kIncognitoErrorMessage; |
| return false; |
| @@ -384,7 +400,7 @@ bool SetPreferenceFunction::RunImpl() { |
| } |
| prefs->SetExtensionControlledPref(extension_id(), |
| browser_pref, |
| - incognito, |
| + StringToScope(scope), |
| browserPrefValue); |
| return true; |
| } |
| @@ -397,11 +413,9 @@ bool ClearPreferenceFunction::RunImpl() { |
| DictionaryValue* details = NULL; |
| EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(1, &details)); |
| - bool incognito = false; |
| - |
| - // TODO(battre): enable incognito preferences again. |
| - // if (details->HasKey(kIncognito)) |
| - // EXTENSION_FUNCTION_VALIDATE(details->GetBoolean(kIncognito, &incognito)); |
| + std::string scope = kRegular; |
| + if (details->HasKey(kScope)) |
| + EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope)); |
| // We don't check incognito permissions here, as an extension should be always |
| // allowed to clear its own settings. |
| @@ -416,6 +430,7 @@ bool ClearPreferenceFunction::RunImpl() { |
| return false; |
| } |
| ExtensionPrefs* prefs = profile_->GetExtensionService()->extension_prefs(); |
| - prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, incognito); |
| + prefs->RemoveExtensionControlledPref(extension_id(), browser_pref, |
| + StringToScope(scope)); |
| return true; |
| } |