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

Side by Side 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, 5 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_preference_helpers.h" 5 #include "chrome/browser/extensions/extension_preference_helpers.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_event_router.h" 9 #include "chrome/browser/extensions/extension_event_router.h"
10 #include "chrome/browser/extensions/extension_prefs.h" 10 #include "chrome/browser/extensions/extension_prefs.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 return true; 44 return true;
45 } 45 }
46 46
47 const char* GetLevelOfControl( 47 const char* GetLevelOfControl(
48 Profile* profile, 48 Profile* profile,
49 const std::string& extension_id, 49 const std::string& extension_id,
50 const std::string& browser_pref, 50 const std::string& browser_pref,
51 bool incognito) { 51 bool incognito) {
52 PrefService* prefs = incognito ? profile->GetOffTheRecordPrefs() 52 PrefService* prefs = incognito ? profile->GetOffTheRecordPrefs()
53 : profile->GetPrefs(); 53 : profile->GetPrefs();
54 bool from_incognito = false;
55 bool* from_incognito_ptr = incognito ? &from_incognito : NULL;
54 const PrefService::Preference* pref = 56 const PrefService::Preference* pref =
55 prefs->FindPreference(browser_pref.c_str()); 57 prefs->FindPreference(browser_pref.c_str());
56 CHECK(pref); 58 CHECK(pref);
57 ExtensionPrefs* ep = profile->GetExtensionService()->extension_prefs(); 59 ExtensionPrefs* ep = profile->GetExtensionService()->extension_prefs();
58 60
59 if (!pref->IsExtensionModifiable()) 61 if (!pref->IsExtensionModifiable())
60 return kNotControllable; 62 return kNotControllable;
61 63
62 if (ep->DoesExtensionControlPref(extension_id, browser_pref, incognito)) 64 if (ep->DoesExtensionControlPref(extension_id,
65 browser_pref,
66 from_incognito_ptr)) {
63 return kControlledByThisExtension; 67 return kControlledByThisExtension;
68 }
64 69
65 if (ep->CanExtensionControlPref(extension_id, browser_pref, incognito)) 70 if (ep->CanExtensionControlPref(extension_id, browser_pref, incognito))
66 return kControllableByThisExtension; 71 return kControllableByThisExtension;
67 72
68 return kControlledByOtherExtensions; 73 return kControlledByOtherExtensions;
69 } 74 }
70 75
71 void DispatchEventToExtensions( 76 void DispatchEventToExtensions(
72 Profile* profile, 77 Profile* profile,
73 const std::string& event_name, 78 const std::string& event_name,
74 ListValue* args, 79 ListValue* args,
75 ExtensionAPIPermission::ID permission, 80 ExtensionAPIPermission::ID permission,
76 bool incognito, 81 bool incognito,
77 const std::string& browser_pref) { 82 const std::string& browser_pref) {
78 ExtensionEventRouter* router = profile->GetExtensionEventRouter(); 83 ExtensionEventRouter* router = profile->GetExtensionEventRouter();
79 if (!router || !router->HasEventListener(event_name)) 84 if (!router || !router->HasEventListener(event_name))
80 return; 85 return;
81 ExtensionService* extension_service = profile->GetExtensionService(); 86 ExtensionService* extension_service = profile->GetExtensionService();
82 const ExtensionSet* extensions = extension_service->extensions(); 87 const ExtensionSet* extensions = extension_service->extensions();
88 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
83 for (ExtensionSet::const_iterator it = extensions->begin(); 89 for (ExtensionSet::const_iterator it = extensions->begin();
84 it != extensions->end(); ++it) { 90 it != extensions->end(); ++it) {
85 std::string extension_id = (*it)->id(); 91 std::string extension_id = (*it)->id();
86 // TODO(bauerb): Only iterate over registered event listeners. 92 // TODO(bauerb): Only iterate over registered event listeners.
87 if (router->ExtensionHasEventListener(extension_id, event_name) && 93 if (router->ExtensionHasEventListener(extension_id, event_name) &&
88 (*it)->HasAPIPermission(permission) && 94 (*it)->HasAPIPermission(permission) &&
89 (!incognito || extension_service->CanCrossIncognito(*it))) { 95 (!incognito || (*it)->incognito_split_mode() ||
96 extension_service->CanCrossIncognito(*it))) {
90 // Inject level of control key-value. 97 // Inject level of control key-value.
91 DictionaryValue* dict; 98 DictionaryValue* dict;
92 bool rv = args->GetDictionary(0, &dict); 99 bool rv = args->GetDictionary(0, &dict);
93 DCHECK(rv); 100 DCHECK(rv);
94 std::string level_of_control = 101 std::string level_of_control =
95 GetLevelOfControl(profile, extension_id, browser_pref, incognito); 102 GetLevelOfControl(profile, extension_id, browser_pref, incognito);
96 dict->SetString(kLevelOfControlKey, level_of_control); 103 dict->SetString(kLevelOfControlKey, level_of_control);
97
98 std::string json_args; 104 std::string json_args;
99 base::JSONWriter::Write(args, &json_args); 105 base::JSONWriter::Write(args, &json_args);
106
107 // If the extension is in incognito split mode,
108 // a) incognito pref changes are visible only to the incognito tabs
109 // b) regular pref changes are visible only to the incognito tabs if the
110 // incognito pref has not alredy been set
111 Profile* restrict_to_profile = NULL;
112 bool from_incognito = false;
113 if ((*it)->incognito_split_mode()) {
114 if (incognito && extension_service->IsIncognitoEnabled(extension_id)) {
115 restrict_to_profile = profile->GetOffTheRecordProfile();
116 } else if (!incognito &&
117 extension_prefs->DoesExtensionControlPref(
118 extension_id,
119 browser_pref,
120 &from_incognito) &&
121 from_incognito) {
122 restrict_to_profile = profile;
123 }
124 }
125
100 router->DispatchEventToExtension( 126 router->DispatchEventToExtension(
101 extension_id, event_name, json_args, NULL, GURL()); 127 extension_id, event_name, json_args, restrict_to_profile, GURL());
102 } 128 }
103 } 129 }
104 } 130 }
105 131
106 } // namespace extension_preference_helpers 132 } // namespace extension_preference_helpers
OLDNEW
« 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