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

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

Issue 10559052: Split mode incognito extension can get misleading pref changed events from regular mode (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed some callbacks, other nits Created 8 years, 6 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_helpers.cc
diff --git a/chrome/browser/extensions/extension_preference_helpers.cc b/chrome/browser/extensions/extension_preference_helpers.cc
index 44fe036db95af8e20cfea3188ffdcd4183200c4f..bbfbd060fa66af726779f221da90f9b034a89ece 100644
--- a/chrome/browser/extensions/extension_preference_helpers.cc
+++ b/chrome/browser/extensions/extension_preference_helpers.cc
@@ -51,6 +51,8 @@ const char* GetLevelOfControl(
bool incognito) {
PrefService* prefs = incognito ? profile->GetOffTheRecordPrefs()
: profile->GetPrefs();
+ bool from_incognito = false;
+ bool* from_incognito_ptr = incognito ? &from_incognito : NULL;
const PrefService::Preference* pref =
prefs->FindPreference(browser_pref.c_str());
CHECK(pref);
@@ -59,8 +61,11 @@ const char* GetLevelOfControl(
if (!pref->IsExtensionModifiable())
return kNotControllable;
- if (ep->DoesExtensionControlPref(extension_id, browser_pref, incognito))
+ if (ep->DoesExtensionControlPref(extension_id,
+ browser_pref,
+ from_incognito_ptr)) {
return kControlledByThisExtension;
+ }
if (ep->CanExtensionControlPref(extension_id, browser_pref, incognito))
return kControllableByThisExtension;
@@ -80,13 +85,15 @@ void DispatchEventToExtensions(
return;
ExtensionService* extension_service = profile->GetExtensionService();
const ExtensionSet* extensions = extension_service->extensions();
+ ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
for (ExtensionSet::const_iterator it = extensions->begin();
it != extensions->end(); ++it) {
std::string extension_id = (*it)->id();
// TODO(bauerb): Only iterate over registered event listeners.
if (router->ExtensionHasEventListener(extension_id, event_name) &&
(*it)->HasAPIPermission(permission) &&
- (!incognito || extension_service->CanCrossIncognito(*it))) {
+ (!incognito || (*it)->incognito_split_mode() ||
+ extension_service->CanCrossIncognito(*it))) {
// Inject level of control key-value.
DictionaryValue* dict;
bool rv = args->GetDictionary(0, &dict);
@@ -94,11 +101,30 @@ void DispatchEventToExtensions(
std::string level_of_control =
GetLevelOfControl(profile, extension_id, browser_pref, incognito);
dict->SetString(kLevelOfControlKey, level_of_control);
-
std::string json_args;
base::JSONWriter::Write(args, &json_args);
+
+ // If the extension is in incognito split mode,
+ // a) incognito pref changes are visible only to the incognito tabs
+ // b) regular pref changes are visible only to the incognito tabs if the
+ // incognito pref has not alredy been set
+ Profile* restrict_to_profile = NULL;
+ bool from_incognito = false;
+ if ((*it)->incognito_split_mode()) {
+ if (incognito && extension_service->IsIncognitoEnabled(extension_id)) {
+ restrict_to_profile = profile->GetOffTheRecordProfile();
+ } else if (!incognito &&
+ extension_prefs->DoesExtensionControlPref(
+ extension_id,
+ browser_pref,
+ &from_incognito) &&
+ from_incognito) {
+ restrict_to_profile = profile;
+ }
+ }
+
router->DispatchEventToExtension(
- extension_id, event_name, json_args, NULL, GURL());
+ extension_id, event_name, json_args, restrict_to_profile, GURL());
}
}
}
« no previous file with comments | « chrome/browser/extensions/extension_preference_apitest.cc ('k') | chrome/browser/extensions/extension_prefs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698