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 8a1d5af0ef6644494446e2cba52b5234879829b2..8e2650aa9478fdb5aee249539225acdd5beea18f 100644 |
| --- a/chrome/browser/extensions/extension_preference_api.cc |
| +++ b/chrome/browser/extensions/extension_preference_api.cc |
| @@ -40,6 +40,7 @@ const char kScope[] = "scope"; |
| const char kLevelOfControl[] = "levelOfControl"; |
| const char kRegular[] = "regular"; |
| const char kIncognitoPersistent[] = "incognito_persistent"; |
| +const char kIncognitoSessionOnly[] = "incognito_session_only"; |
| const char kValue[] = "value"; |
| const char kOnPrefChangeFormat[] = |
| @@ -48,6 +49,10 @@ const char kOnPrefChangeFormat[] = |
| const char kIncognitoErrorMessage[] = |
| "You do not have permission to access incognito preferences."; |
| +const char kIncognitoSessionOnlyErrorMessage[] = |
| + "You cannot set 'session-only incognito' preferences when no incognito " |
|
Matt Perry
2011/05/24 22:07:17
Reword: "You cannot set a preference with scope 'i
battre
2011/05/25 11:51:30
Done.
|
| + "window exists."; |
| + |
| const char kPermissionErrorMessage[] = |
| "You do not have permission to access the preference '%s'. " |
| "Be sure to declare in your manifest what permissions you need."; |
| @@ -118,6 +123,8 @@ extension_prefs_scope::Scope StringToScope(const std::string& s) { |
| return extension_prefs_scope::kRegular; |
| } else if (s == kIncognitoPersistent) { |
| return extension_prefs_scope::kIncognitoPersistent; |
| + } else if (s == kIncognitoSessionOnly) { |
| + return extension_prefs_scope::kIncognitoSessionOnly; |
| } else { |
| // The extension API checks that no invalid string can be passed. |
| NOTREACHED(); |
| @@ -362,17 +369,25 @@ bool SetPreferenceFunction::RunImpl() { |
| Value* value = NULL; |
| EXTENSION_FUNCTION_VALIDATE(details->Get(kValue, &value)); |
| - std::string scope = kRegular; |
| + std::string scope_str = kRegular; |
| if (details->HasKey(kScope)) |
| - EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope)); |
| + EXTENSION_FUNCTION_VALIDATE(details->GetString(kScope, &scope_str)); |
| + |
| + extension_prefs_scope::Scope scope = StringToScope(scope_str); |
| - // TODO(battre): add kIncognitoSessionOnly |
| - bool incognito = (scope == kIncognitoPersistent); |
| + bool incognito = (scope == extension_prefs_scope::kIncognitoPersistent || |
| + scope == extension_prefs_scope::kIncognitoSessionOnly); |
| if (incognito && !include_incognito()) { |
| error_ = kIncognitoErrorMessage; |
| return false; |
| } |
| + if (scope == extension_prefs_scope::kIncognitoSessionOnly && |
| + !profile_->HasOffTheRecordProfile()) { |
| + error_ = kIncognitoSessionOnlyErrorMessage; |
| + return false; |
| + } |
| + |
| std::string browser_pref; |
| std::string permission; |
| EXTENSION_FUNCTION_VALIDATE( |
| @@ -400,7 +415,7 @@ bool SetPreferenceFunction::RunImpl() { |
| } |
| prefs->SetExtensionControlledPref(extension_id(), |
| browser_pref, |
| - StringToScope(scope), |
| + scope, |
| browserPrefValue); |
| return true; |
| } |