Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Unified Diff: chrome/browser/extensions/extension_preference_api.cc

Issue 7065033: Support persistent incognito preferences (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 2f81eaf0cb0d4bc356d456f14362a664d01e8dc1..4c60348d7f34fe12ffc16f9dad086fc20d6a057c 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 kOnPrefChangeEffectiveFormat[] =
@@ -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();
+ 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;
}

Powered by Google App Engine
This is Rietveld 408576698