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 12 matching lines...) Expand all Loading... |
23 | 23 |
24 const char kNotControllable[] = "not_controllable"; | 24 const char kNotControllable[] = "not_controllable"; |
25 const char kControlledByOtherExtensions[] = "controlled_by_other_extensions"; | 25 const char kControlledByOtherExtensions[] = "controlled_by_other_extensions"; |
26 const char kControllableByThisExtension[] = "controllable_by_this_extension"; | 26 const char kControllableByThisExtension[] = "controllable_by_this_extension"; |
27 const char kControlledByThisExtension[] = "controlled_by_this_extension"; | 27 const char kControlledByThisExtension[] = "controlled_by_this_extension"; |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 namespace extension_preference_helpers { | 31 namespace extension_preference_helpers { |
32 | 32 |
33 bool StringToScope(const std::string& s, ExtensionPrefsScope* scope) { | 33 bool StringToScope(const std::string& s, |
| 34 extensions::ExtensionPrefsScope* scope) { |
34 if (s == kRegular) | 35 if (s == kRegular) |
35 *scope = kExtensionPrefsScopeRegular; | 36 *scope = extensions::kExtensionPrefsScopeRegular; |
36 else if (s == kRegularOnly) | 37 else if (s == kRegularOnly) |
37 *scope = kExtensionPrefsScopeRegularOnly; | 38 *scope = extensions::kExtensionPrefsScopeRegularOnly; |
38 else if (s == kIncognitoPersistent) | 39 else if (s == kIncognitoPersistent) |
39 *scope = kExtensionPrefsScopeIncognitoPersistent; | 40 *scope = extensions::kExtensionPrefsScopeIncognitoPersistent; |
40 else if (s == kIncognitoSessionOnly) | 41 else if (s == kIncognitoSessionOnly) |
41 *scope = kExtensionPrefsScopeIncognitoSessionOnly; | 42 *scope = extensions::kExtensionPrefsScopeIncognitoSessionOnly; |
42 else | 43 else |
43 return false; | 44 return false; |
44 return true; | 45 return true; |
45 } | 46 } |
46 | 47 |
47 const char* GetLevelOfControl( | 48 const char* GetLevelOfControl( |
48 Profile* profile, | 49 Profile* profile, |
49 const std::string& extension_id, | 50 const std::string& extension_id, |
50 const std::string& browser_pref, | 51 const std::string& browser_pref, |
51 bool incognito) { | 52 bool incognito) { |
52 PrefService* prefs = incognito ? profile->GetOffTheRecordPrefs() | 53 PrefService* prefs = incognito ? profile->GetOffTheRecordPrefs() |
53 : profile->GetPrefs(); | 54 : profile->GetPrefs(); |
54 bool from_incognito = false; | 55 bool from_incognito = false; |
55 bool* from_incognito_ptr = incognito ? &from_incognito : NULL; | 56 bool* from_incognito_ptr = incognito ? &from_incognito : NULL; |
56 const PrefService::Preference* pref = | 57 const PrefService::Preference* pref = |
57 prefs->FindPreference(browser_pref.c_str()); | 58 prefs->FindPreference(browser_pref.c_str()); |
58 CHECK(pref); | 59 CHECK(pref); |
59 ExtensionPrefs* ep = profile->GetExtensionService()->extension_prefs(); | 60 extensions::ExtensionPrefs* ep = |
| 61 profile->GetExtensionService()->extension_prefs(); |
60 | 62 |
61 if (!pref->IsExtensionModifiable()) | 63 if (!pref->IsExtensionModifiable()) |
62 return kNotControllable; | 64 return kNotControllable; |
63 | 65 |
64 if (ep->DoesExtensionControlPref(extension_id, | 66 if (ep->DoesExtensionControlPref(extension_id, |
65 browser_pref, | 67 browser_pref, |
66 from_incognito_ptr)) { | 68 from_incognito_ptr)) { |
67 return kControlledByThisExtension; | 69 return kControlledByThisExtension; |
68 } | 70 } |
69 | 71 |
70 if (ep->CanExtensionControlPref(extension_id, browser_pref, incognito)) | 72 if (ep->CanExtensionControlPref(extension_id, browser_pref, incognito)) |
71 return kControllableByThisExtension; | 73 return kControllableByThisExtension; |
72 | 74 |
73 return kControlledByOtherExtensions; | 75 return kControlledByOtherExtensions; |
74 } | 76 } |
75 | 77 |
76 void DispatchEventToExtensions( | 78 void DispatchEventToExtensions( |
77 Profile* profile, | 79 Profile* profile, |
78 const std::string& event_name, | 80 const std::string& event_name, |
79 ListValue* args, | 81 ListValue* args, |
80 extensions::APIPermission::ID permission, | 82 extensions::APIPermission::ID permission, |
81 bool incognito, | 83 bool incognito, |
82 const std::string& browser_pref) { | 84 const std::string& browser_pref) { |
83 ExtensionEventRouter* router = profile->GetExtensionEventRouter(); | 85 ExtensionEventRouter* router = profile->GetExtensionEventRouter(); |
84 if (!router || !router->HasEventListener(event_name)) | 86 if (!router || !router->HasEventListener(event_name)) |
85 return; | 87 return; |
86 ExtensionService* extension_service = profile->GetExtensionService(); | 88 ExtensionService* extension_service = profile->GetExtensionService(); |
87 const ExtensionSet* extensions = extension_service->extensions(); | 89 const ExtensionSet* extensions = extension_service->extensions(); |
88 ExtensionPrefs* extension_prefs = extension_service->extension_prefs(); | 90 extensions::ExtensionPrefs* extension_prefs = |
| 91 extension_service->extension_prefs(); |
89 for (ExtensionSet::const_iterator it = extensions->begin(); | 92 for (ExtensionSet::const_iterator it = extensions->begin(); |
90 it != extensions->end(); ++it) { | 93 it != extensions->end(); ++it) { |
91 std::string extension_id = (*it)->id(); | 94 std::string extension_id = (*it)->id(); |
92 // TODO(bauerb): Only iterate over registered event listeners. | 95 // TODO(bauerb): Only iterate over registered event listeners. |
93 if (router->ExtensionHasEventListener(extension_id, event_name) && | 96 if (router->ExtensionHasEventListener(extension_id, event_name) && |
94 (*it)->HasAPIPermission(permission) && | 97 (*it)->HasAPIPermission(permission) && |
95 (!incognito || (*it)->incognito_split_mode() || | 98 (!incognito || (*it)->incognito_split_mode() || |
96 extension_service->CanCrossIncognito(*it))) { | 99 extension_service->CanCrossIncognito(*it))) { |
97 // Inject level of control key-value. | 100 // Inject level of control key-value. |
98 DictionaryValue* dict; | 101 DictionaryValue* dict; |
(...skipping 24 matching lines...) Expand all Loading... |
123 } | 126 } |
124 } | 127 } |
125 | 128 |
126 router->DispatchEventToExtension( | 129 router->DispatchEventToExtension( |
127 extension_id, event_name, json_args, restrict_to_profile, GURL()); | 130 extension_id, event_name, json_args, restrict_to_profile, GURL()); |
128 } | 131 } |
129 } | 132 } |
130 } | 133 } |
131 | 134 |
132 } // namespace extension_preference_helpers | 135 } // namespace extension_preference_helpers |
OLD | NEW |