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/event_router.h" | 10 #include "chrome/browser/extensions/event_router.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 ExtensionService* extension_service = profile->GetExtensionService(); | 92 ExtensionService* extension_service = profile->GetExtensionService(); |
93 const ExtensionSet* extensions = extension_service->extensions(); | 93 const ExtensionSet* extensions = extension_service->extensions(); |
94 extensions::ExtensionPrefs* extension_prefs = | 94 extensions::ExtensionPrefs* extension_prefs = |
95 extension_service->extension_prefs(); | 95 extension_service->extension_prefs(); |
96 for (ExtensionSet::const_iterator it = extensions->begin(); | 96 for (ExtensionSet::const_iterator it = extensions->begin(); |
97 it != extensions->end(); ++it) { | 97 it != extensions->end(); ++it) { |
98 std::string extension_id = (*it)->id(); | 98 std::string extension_id = (*it)->id(); |
99 // TODO(bauerb): Only iterate over registered event listeners. | 99 // TODO(bauerb): Only iterate over registered event listeners. |
100 if (router->ExtensionHasEventListener(extension_id, event_name) && | 100 if (router->ExtensionHasEventListener(extension_id, event_name) && |
101 (*it)->HasAPIPermission(permission) && | 101 (*it)->HasAPIPermission(permission) && |
102 (!incognito || IncognitoInfo::IsSplitMode(*it) || | 102 (!incognito || IncognitoInfo::IsSplitMode(it->get()) || |
103 extension_service->CanCrossIncognito(*it))) { | 103 extension_service->CanCrossIncognito(it->get()))) { |
104 // Inject level of control key-value. | 104 // Inject level of control key-value. |
105 DictionaryValue* dict; | 105 DictionaryValue* dict; |
106 bool rv = args->GetDictionary(0, &dict); | 106 bool rv = args->GetDictionary(0, &dict); |
107 DCHECK(rv); | 107 DCHECK(rv); |
108 std::string level_of_control = | 108 std::string level_of_control = |
109 GetLevelOfControl(profile, extension_id, browser_pref, incognito); | 109 GetLevelOfControl(profile, extension_id, browser_pref, incognito); |
110 dict->SetString(kLevelOfControlKey, level_of_control); | 110 dict->SetString(kLevelOfControlKey, level_of_control); |
111 | 111 |
112 // If the extension is in incognito split mode, | 112 // If the extension is in incognito split mode, |
113 // a) incognito pref changes are visible only to the incognito tabs | 113 // a) incognito pref changes are visible only to the incognito tabs |
114 // 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 |
115 // incognito pref has not alredy been set | 115 // incognito pref has not alredy been set |
116 Profile* restrict_to_profile = NULL; | 116 Profile* restrict_to_profile = NULL; |
117 bool from_incognito = false; | 117 bool from_incognito = false; |
118 if (IncognitoInfo::IsSplitMode(*it)) { | 118 if (IncognitoInfo::IsSplitMode(it->get())) { |
119 if (incognito && extension_service->IsIncognitoEnabled(extension_id)) { | 119 if (incognito && extension_service->IsIncognitoEnabled(extension_id)) { |
120 restrict_to_profile = profile->GetOffTheRecordProfile(); | 120 restrict_to_profile = profile->GetOffTheRecordProfile(); |
121 } else if (!incognito && | 121 } else if (!incognito && |
122 extension_prefs->DoesExtensionControlPref( | 122 extension_prefs->DoesExtensionControlPref( |
123 extension_id, | 123 extension_id, |
124 browser_pref, | 124 browser_pref, |
125 &from_incognito) && | 125 &from_incognito) && |
126 from_incognito) { | 126 from_incognito) { |
127 restrict_to_profile = profile; | 127 restrict_to_profile = profile; |
128 } | 128 } |
129 } | 129 } |
130 | 130 |
131 scoped_ptr<ListValue> args_copy(args->DeepCopy()); | 131 scoped_ptr<ListValue> args_copy(args->DeepCopy()); |
132 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); | 132 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); |
133 event->restrict_to_profile = restrict_to_profile; | 133 event->restrict_to_profile = restrict_to_profile; |
134 router->DispatchEventToExtension(extension_id, event.Pass()); | 134 router->DispatchEventToExtension(extension_id, event.Pass()); |
135 } | 135 } |
136 } | 136 } |
137 } | 137 } |
138 | 138 |
139 } // namespace preference_helpers | 139 } // namespace preference_helpers |
140 } // namespace extensions | 140 } // namespace extensions |
OLD | NEW |