OLD | NEW |
---|---|
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/api/preference/preference_helpers.h" | 5 #include "chrome/browser/extensions/api/preference/preference_helpers.h" |
6 | 6 |
7 #include "base/json/json_writer.h" | 7 #include "base/json/json_writer.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/extensions/api/preference/preference_api.h" | 10 #include "chrome/browser/extensions/api/preference/preference_api.h" |
11 #include "chrome/browser/extensions/extension_service.h" | |
12 #include "chrome/browser/extensions/extension_util.h" | 11 #include "chrome/browser/extensions/extension_util.h" |
13 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
14 #include "extensions/browser/event_router.h" | 13 #include "extensions/browser/event_router.h" |
15 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
16 #include "extensions/browser/extension_system.h" | 15 #include "extensions/browser/extension_registry.h" |
17 #include "extensions/common/manifest_handlers/incognito_info.h" | 16 #include "extensions/common/manifest_handlers/incognito_info.h" |
18 #include "extensions/common/permissions/permissions_data.h" | 17 #include "extensions/common/permissions/permissions_data.h" |
19 | 18 |
20 namespace extensions { | 19 namespace extensions { |
21 namespace preference_helpers { | 20 namespace preference_helpers { |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 const char kIncognitoPersistent[] = "incognito_persistent"; | 24 const char kIncognitoPersistent[] = "incognito_persistent"; |
26 const char kIncognitoSessionOnly[] = "incognito_session_only"; | 25 const char kIncognitoSessionOnly[] = "incognito_session_only"; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
86 void DispatchEventToExtensions( | 85 void DispatchEventToExtensions( |
87 Profile* profile, | 86 Profile* profile, |
88 const std::string& event_name, | 87 const std::string& event_name, |
89 base::ListValue* args, | 88 base::ListValue* args, |
90 APIPermission::ID permission, | 89 APIPermission::ID permission, |
91 bool incognito, | 90 bool incognito, |
92 const std::string& browser_pref) { | 91 const std::string& browser_pref) { |
93 EventRouter* router = EventRouter::Get(profile); | 92 EventRouter* router = EventRouter::Get(profile); |
94 if (!router || !router->HasEventListener(event_name)) | 93 if (!router || !router->HasEventListener(event_name)) |
95 return; | 94 return; |
96 ExtensionService* extension_service = | 95 |
97 ExtensionSystem::Get(profile)->extension_service(); | 96 for (const scoped_refptr<const extensions::Extension>& extension : |
98 const ExtensionSet* extensions = extension_service->extensions(); | 97 ExtensionRegistry::Get(profile)->enabled_extensions()) { |
99 for (ExtensionSet::const_iterator it = extensions->begin(); | 98 std::string extension_id = extension->id(); |
not at google - send to devlin
2014/11/11 20:20:09
String copy here looks unnecessary.
Reilly Grant (use Gerrit)
2014/11/11 20:55:31
Done.
| |
100 it != extensions->end(); ++it) { | |
101 std::string extension_id = (*it)->id(); | |
102 // TODO(bauerb): Only iterate over registered event listeners. | 99 // TODO(bauerb): Only iterate over registered event listeners. |
103 if (router->ExtensionHasEventListener(extension_id, event_name) && | 100 if (router->ExtensionHasEventListener(extension_id, event_name) && |
104 (*it)->permissions_data()->HasAPIPermission(permission) && | 101 extension->permissions_data()->HasAPIPermission(permission) && |
105 (!incognito || IncognitoInfo::IsSplitMode(it->get()) || | 102 (!incognito || IncognitoInfo::IsSplitMode(extension.get()) || |
106 util::CanCrossIncognito(it->get(), profile))) { | 103 util::CanCrossIncognito(extension.get(), profile))) { |
107 // Inject level of control key-value. | 104 // Inject level of control key-value. |
108 base::DictionaryValue* dict; | 105 base::DictionaryValue* dict; |
109 bool rv = args->GetDictionary(0, &dict); | 106 bool rv = args->GetDictionary(0, &dict); |
110 DCHECK(rv); | 107 DCHECK(rv); |
111 std::string level_of_control = | 108 std::string level_of_control = |
not at google - send to devlin
2014/11/11 20:20:09
And apparently this whole API is pretty loose with
| |
112 GetLevelOfControl(profile, extension_id, browser_pref, incognito); | 109 GetLevelOfControl(profile, extension_id, browser_pref, incognito); |
113 dict->SetString(kLevelOfControlKey, level_of_control); | 110 dict->SetString(kLevelOfControlKey, level_of_control); |
114 | 111 |
115 // If the extension is in incognito split mode, | 112 // If the extension is in incognito split mode, |
116 // a) incognito pref changes are visible only to the incognito tabs | 113 // a) incognito pref changes are visible only to the incognito tabs |
117 // b) regular pref changes are visible only to the incognito tabs if the | 114 // b) regular pref changes are visible only to the incognito tabs if the |
118 // incognito pref has not alredy been set | 115 // incognito pref has not alredy been set |
119 Profile* restrict_to_profile = NULL; | 116 Profile* restrict_to_profile = NULL; |
120 bool from_incognito = false; | 117 bool from_incognito = false; |
121 if (IncognitoInfo::IsSplitMode(it->get())) { | 118 if (IncognitoInfo::IsSplitMode(extension.get())) { |
122 if (incognito && | 119 if (incognito && |
123 util::IsIncognitoEnabled(extension_id, profile)) { | 120 util::IsIncognitoEnabled(extension_id, profile)) { |
124 restrict_to_profile = profile->GetOffTheRecordProfile(); | 121 restrict_to_profile = profile->GetOffTheRecordProfile(); |
125 } else if (!incognito && | 122 } else if (!incognito && |
126 PreferenceAPI::Get(profile)->DoesExtensionControlPref( | 123 PreferenceAPI::Get(profile)->DoesExtensionControlPref( |
127 extension_id, | 124 extension_id, |
128 browser_pref, | 125 browser_pref, |
129 &from_incognito) && | 126 &from_incognito) && |
130 from_incognito) { | 127 from_incognito) { |
131 restrict_to_profile = profile; | 128 restrict_to_profile = profile; |
132 } | 129 } |
133 } | 130 } |
134 | 131 |
135 scoped_ptr<base::ListValue> args_copy(args->DeepCopy()); | 132 scoped_ptr<base::ListValue> args_copy(args->DeepCopy()); |
136 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); | 133 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); |
137 event->restrict_to_browser_context = restrict_to_profile; | 134 event->restrict_to_browser_context = restrict_to_profile; |
138 router->DispatchEventToExtension(extension_id, event.Pass()); | 135 router->DispatchEventToExtension(extension_id, event.Pass()); |
139 } | 136 } |
140 } | 137 } |
141 } | 138 } |
142 | 139 |
143 } // namespace preference_helpers | 140 } // namespace preference_helpers |
144 } // namespace extensions | 141 } // namespace extensions |
OLD | NEW |