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

Unified Diff: extensions/browser/extension_pref_value_map.cc

Issue 184043024: Limit scope of settings API configuration and proxy permission (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move incognito permission test from ChromeExtensionsBrowserClient to ExtensionPrefs Created 6 years, 10 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: extensions/browser/extension_pref_value_map.cc
diff --git a/extensions/browser/extension_pref_value_map.cc b/extensions/browser/extension_pref_value_map.cc
index 5cba7e510a2afac21c3827a9ae09a97369ae5457..6507f1e3ad3d5f4fd9a7bc48e88fd38259b5b459 100644
--- a/extensions/browser/extension_pref_value_map.cc
+++ b/extensions/browser/extension_pref_value_map.cc
@@ -7,6 +7,7 @@
#include "base/prefs/pref_value_map.h"
#include "base/stl_util.h"
#include "base/values.h"
+#include "extensions/browser/extensions_browser_client.h"
using extensions::ExtensionPrefsScope;
@@ -15,6 +16,8 @@ struct ExtensionPrefValueMap::ExtensionEntry {
base::Time install_time;
// Whether extension is enabled in the profile.
bool enabled;
+ // Whether the extension has access to the incognito profile.
+ bool incognito_enabled;
// Extension controlled preferences for the regular profile.
PrefValueMap regular_profile_preferences;
// Extension controlled preferences that should *only* apply to the regular
@@ -28,8 +31,7 @@ struct ExtensionPrefValueMap::ExtensionEntry {
PrefValueMap incognito_profile_preferences_session_only;
};
-ExtensionPrefValueMap::ExtensionPrefValueMap() : destroyed_(false) {
-}
+ExtensionPrefValueMap::ExtensionPrefValueMap() : destroyed_(false) {}
ExtensionPrefValueMap::~ExtensionPrefValueMap() {
if (!destroyed_) {
@@ -74,6 +76,9 @@ bool ExtensionPrefValueMap::CanExtensionControlPref(
return false;
}
+ if (incognito && !ext->second->incognito_enabled)
+ return false;
+
ExtensionEntryMap::const_iterator winner =
GetEffectivePrefValueController(pref_key, incognito, NULL);
if (winner == entries_.end())
@@ -115,7 +120,8 @@ bool ExtensionPrefValueMap::DoesExtensionControlPref(
void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id,
const base::Time& install_time,
- bool is_enabled) {
+ bool is_enabled,
+ bool is_incognito_enabled) {
if (entries_.find(ext_id) == entries_.end()) {
entries_[ext_id] = new ExtensionEntry;
@@ -124,6 +130,7 @@ void ExtensionPrefValueMap::RegisterExtension(const std::string& ext_id,
}
entries_[ext_id]->enabled = is_enabled;
+ entries_[ext_id]->incognito_enabled = is_incognito_enabled;
}
void ExtensionPrefValueMap::UnregisterExtension(const std::string& ext_id) {
@@ -154,6 +161,22 @@ void ExtensionPrefValueMap::SetExtensionState(const std::string& ext_id,
NotifyPrefValueChanged(keys);
}
+void ExtensionPrefValueMap::SetExtensionIncognitoState(
+ const std::string& ext_id,
+ bool is_incognito_enabled) {
+ ExtensionEntryMap::const_iterator i = entries_.find(ext_id);
+ // This may happen when sync sets the extension state for an
+ // extension that is not installed.
+ if (i == entries_.end())
+ return;
+ if (i->second->incognito_enabled == is_incognito_enabled)
+ return;
+ std::set<std::string> keys; // keys set by this extension
+ GetExtensionControlledKeys(*(i->second), &keys);
+ i->second->incognito_enabled = is_incognito_enabled;
+ NotifyPrefValueChanged(keys);
+}
+
PrefValueMap* ExtensionPrefValueMap::GetExtensionPrefValueMap(
const std::string& ext_id,
ExtensionPrefsScope scope) {
@@ -230,7 +253,7 @@ const base::Value* ExtensionPrefValueMap::GetEffectivePrefValue(
const std::string& ext_id = winner->first;
// First search for incognito session only preferences.
- if (incognito) {
+ if (incognito && winner->second->incognito_enabled) {
const PrefValueMap* prefs = GetExtensionPrefValueMap(
ext_id, extensions::kExtensionPrefsScopeIncognitoSessionOnly);
prefs->GetValue(key, &value);
@@ -245,7 +268,12 @@ const base::Value* ExtensionPrefValueMap::GetEffectivePrefValue(
prefs->GetValue(key, &value);
if (value)
return value;
- } else {
+ } else if (incognito) {
+ // This branch is left blank intentionally.
+ // If we require an incognito preference value but the winning extension
+ // does not possess incognito permission, we fall back to its regular
+ // preference.
Bernhard Bauer 2014/03/04 17:31:18 Wait, this method is called with incognito == true
battre 2014/03/05 08:34:36 Done.
+ } else { // incognito == false.
// Regular-only preference.
const PrefValueMap* prefs = GetExtensionPrefValueMap(
ext_id, extensions::kExtensionPrefsScopeRegularOnly);
@@ -274,11 +302,14 @@ ExtensionPrefValueMap::GetEffectivePrefValueController(
const std::string& ext_id = i->first;
const base::Time& install_time = i->second->install_time;
const bool enabled = i->second->enabled;
+ const bool incognito_enabled = i->second->incognito_enabled;
if (!enabled)
continue;
if (install_time < winners_install_time)
continue;
+ if (incognito && !incognito_enabled)
+ continue;
const base::Value* value = NULL;
const PrefValueMap* prefs = GetExtensionPrefValueMap(

Powered by Google App Engine
This is Rietveld 408576698