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