| 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(); | |
| 100 it != extensions->end(); ++it) { | |
| 101 std::string extension_id = (*it)->id(); | |
| 102 // TODO(bauerb): Only iterate over registered event listeners. | 98 // TODO(bauerb): Only iterate over registered event listeners. |
| 103 if (router->ExtensionHasEventListener(extension_id, event_name) && | 99 if (router->ExtensionHasEventListener(extension->id(), event_name) && |
| 104 (*it)->permissions_data()->HasAPIPermission(permission) && | 100 extension->permissions_data()->HasAPIPermission(permission) && |
| 105 (!incognito || IncognitoInfo::IsSplitMode(it->get()) || | 101 (!incognito || IncognitoInfo::IsSplitMode(extension.get()) || |
| 106 util::CanCrossIncognito(it->get(), profile))) { | 102 util::CanCrossIncognito(extension.get(), profile))) { |
| 107 // Inject level of control key-value. | 103 // Inject level of control key-value. |
| 108 base::DictionaryValue* dict; | 104 base::DictionaryValue* dict; |
| 109 bool rv = args->GetDictionary(0, &dict); | 105 bool rv = args->GetDictionary(0, &dict); |
| 110 DCHECK(rv); | 106 DCHECK(rv); |
| 111 std::string level_of_control = | 107 std::string level_of_control = |
| 112 GetLevelOfControl(profile, extension_id, browser_pref, incognito); | 108 GetLevelOfControl(profile, extension->id(), browser_pref, incognito); |
| 113 dict->SetString(kLevelOfControlKey, level_of_control); | 109 dict->SetString(kLevelOfControlKey, level_of_control); |
| 114 | 110 |
| 115 // If the extension is in incognito split mode, | 111 // If the extension is in incognito split mode, |
| 116 // a) incognito pref changes are visible only to the incognito tabs | 112 // 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 | 113 // b) regular pref changes are visible only to the incognito tabs if the |
| 118 // incognito pref has not alredy been set | 114 // incognito pref has not alredy been set |
| 119 Profile* restrict_to_profile = NULL; | 115 Profile* restrict_to_profile = NULL; |
| 120 bool from_incognito = false; | 116 bool from_incognito = false; |
| 121 if (IncognitoInfo::IsSplitMode(it->get())) { | 117 if (IncognitoInfo::IsSplitMode(extension.get())) { |
| 122 if (incognito && | 118 if (incognito && util::IsIncognitoEnabled(extension->id(), profile)) { |
| 123 util::IsIncognitoEnabled(extension_id, profile)) { | |
| 124 restrict_to_profile = profile->GetOffTheRecordProfile(); | 119 restrict_to_profile = profile->GetOffTheRecordProfile(); |
| 125 } else if (!incognito && | 120 } else if (!incognito && |
| 126 PreferenceAPI::Get(profile)->DoesExtensionControlPref( | 121 PreferenceAPI::Get(profile)->DoesExtensionControlPref( |
| 127 extension_id, | 122 extension->id(), browser_pref, &from_incognito) && |
| 128 browser_pref, | |
| 129 &from_incognito) && | |
| 130 from_incognito) { | 123 from_incognito) { |
| 131 restrict_to_profile = profile; | 124 restrict_to_profile = profile; |
| 132 } | 125 } |
| 133 } | 126 } |
| 134 | 127 |
| 135 scoped_ptr<base::ListValue> args_copy(args->DeepCopy()); | 128 scoped_ptr<base::ListValue> args_copy(args->DeepCopy()); |
| 136 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); | 129 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); |
| 137 event->restrict_to_browser_context = restrict_to_profile; | 130 event->restrict_to_browser_context = restrict_to_profile; |
| 138 router->DispatchEventToExtension(extension_id, event.Pass()); | 131 router->DispatchEventToExtension(extension->id(), event.Pass()); |
| 139 } | 132 } |
| 140 } | 133 } |
| 141 } | 134 } |
| 142 | 135 |
| 143 } // namespace preference_helpers | 136 } // namespace preference_helpers |
| 144 } // namespace extensions | 137 } // namespace extensions |
| OLD | NEW |