Chromium Code Reviews| 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/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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 const std::string& event_name, | 73 const std::string& event_name, |
| 74 ListValue* args, | 74 ListValue* args, |
| 75 ExtensionAPIPermission::ID permission, | 75 ExtensionAPIPermission::ID permission, |
| 76 bool incognito, | 76 bool incognito, |
| 77 const std::string& browser_pref) { | 77 const std::string& browser_pref) { |
| 78 ExtensionEventRouter* router = profile->GetExtensionEventRouter(); | 78 ExtensionEventRouter* router = profile->GetExtensionEventRouter(); |
| 79 if (!router || !router->HasEventListener(event_name)) | 79 if (!router || !router->HasEventListener(event_name)) |
| 80 return; | 80 return; |
| 81 ExtensionService* extension_service = profile->GetExtensionService(); | 81 ExtensionService* extension_service = profile->GetExtensionService(); |
| 82 const ExtensionSet* extensions = extension_service->extensions(); | 82 const ExtensionSet* extensions = extension_service->extensions(); |
| 83 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); | |
| 83 for (ExtensionSet::const_iterator it = extensions->begin(); | 84 for (ExtensionSet::const_iterator it = extensions->begin(); |
| 84 it != extensions->end(); ++it) { | 85 it != extensions->end(); ++it) { |
| 85 std::string extension_id = (*it)->id(); | 86 std::string extension_id = (*it)->id(); |
| 86 // TODO(bauerb): Only iterate over registered event listeners. | 87 // TODO(bauerb): Only iterate over registered event listeners. |
| 87 if (router->ExtensionHasEventListener(extension_id, event_name) && | 88 if (router->ExtensionHasEventListener(extension_id, event_name) && |
| 88 (*it)->HasAPIPermission(permission) && | 89 (*it)->HasAPIPermission(permission) && |
| 89 (!incognito || extension_service->CanCrossIncognito(*it))) { | 90 (!incognito || (*it)->incognito_split_mode() || |
| 91 extension_service->CanCrossIncognito(*it))) { | |
|
Bernhard Bauer
2012/06/19 01:12:56
Nit: I think this needs to be indented by one less
mitchellwrosen
2012/06/20 18:28:26
Done.
| |
| 90 // Inject level of control key-value. | 92 // Inject level of control key-value. |
| 91 DictionaryValue* dict; | 93 DictionaryValue* dict; |
| 92 bool rv = args->GetDictionary(0, &dict); | 94 bool rv = args->GetDictionary(0, &dict); |
| 93 DCHECK(rv); | 95 DCHECK(rv); |
| 94 std::string level_of_control = | 96 std::string level_of_control = |
| 95 GetLevelOfControl(profile, extension_id, browser_pref, incognito); | 97 GetLevelOfControl(profile, extension_id, browser_pref, incognito); |
| 96 dict->SetString(kLevelOfControlKey, level_of_control); | 98 dict->SetString(kLevelOfControlKey, level_of_control); |
| 97 | |
| 98 std::string json_args; | 99 std::string json_args; |
| 99 base::JSONWriter::Write(args, &json_args); | 100 base::JSONWriter::Write(args, &json_args); |
| 101 | |
| 102 // If the extension is in incognito split mode, | |
| 103 // a) incognito pref changes are visible only to the incognito tabs | |
| 104 // b) regular pref chanes are visible only to the incognito tabs if the | |
|
Bernhard Bauer
2012/06/19 01:12:56
Nit: "pref changes"
mitchellwrosen
2012/06/20 18:28:26
Done.
| |
| 105 // incognito pref has not alredy been set | |
| 106 Profile* restrict_to_profile = NULL; | |
| 107 if ((*it)->incognito_split_mode()) { | |
| 108 if (incognito && extension_service->IsIncognitoEnabled(extension_id)) { | |
| 109 restrict_to_profile = profile->GetOffTheRecordProfile(); | |
| 110 } else if (!incognito && | |
| 111 extension_prefs->DoesExtensionControlIncognitoPref( | |
| 112 extension_id, | |
| 113 browser_pref)) { | |
| 114 restrict_to_profile = profile; | |
| 115 } | |
| 116 } | |
| 117 | |
| 100 router->DispatchEventToExtension( | 118 router->DispatchEventToExtension( |
| 101 extension_id, event_name, json_args, NULL, GURL()); | 119 extension_id, event_name, json_args, restrict_to_profile, GURL()); |
| 102 } | 120 } |
| 103 } | 121 } |
| 104 } | 122 } |
| 105 | 123 |
| 106 } // namespace extension_preference_helpers | 124 } // namespace extension_preference_helpers |
| OLD | NEW |