Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(340)

Side by Side Diff: chrome/browser/extensions/api/preference/preference_helpers.cc

Issue 25366003: Moved some functions off ExtensionService into a new file extension_util. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile failures Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/event_router.h" 11 #include "chrome/browser/extensions/event_router.h"
12 #include "chrome/browser/extensions/extension_prefs.h" 12 #include "chrome/browser/extensions/extension_prefs.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_system.h" 14 #include "chrome/browser/extensions/extension_system.h"
15 #include "chrome/browser/extensions/extension_util.h"
15 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/common/extensions/incognito_handler.h" 17 #include "chrome/common/extensions/incognito_handler.h"
17 18
18 namespace extensions { 19 namespace extensions {
19 namespace preference_helpers { 20 namespace preference_helpers {
20 21
21 namespace { 22 namespace {
22 23
23 const char kIncognitoPersistent[] = "incognito_persistent"; 24 const char kIncognitoPersistent[] = "incognito_persistent";
24 const char kIncognitoSessionOnly[] = "incognito_session_only"; 25 const char kIncognitoSessionOnly[] = "incognito_session_only";
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 ExtensionService* extension_service = 96 ExtensionService* extension_service =
96 ExtensionSystem::Get(profile)->extension_service(); 97 ExtensionSystem::Get(profile)->extension_service();
97 const ExtensionSet* extensions = extension_service->extensions(); 98 const ExtensionSet* extensions = extension_service->extensions();
98 for (ExtensionSet::const_iterator it = extensions->begin(); 99 for (ExtensionSet::const_iterator it = extensions->begin();
99 it != extensions->end(); ++it) { 100 it != extensions->end(); ++it) {
100 std::string extension_id = (*it)->id(); 101 std::string extension_id = (*it)->id();
101 // TODO(bauerb): Only iterate over registered event listeners. 102 // TODO(bauerb): Only iterate over registered event listeners.
102 if (router->ExtensionHasEventListener(extension_id, event_name) && 103 if (router->ExtensionHasEventListener(extension_id, event_name) &&
103 (*it)->HasAPIPermission(permission) && 104 (*it)->HasAPIPermission(permission) &&
104 (!incognito || IncognitoInfo::IsSplitMode(it->get()) || 105 (!incognito || IncognitoInfo::IsSplitMode(it->get()) ||
105 extension_service->CanCrossIncognito(it->get()))) { 106 extension_util::CanCrossIncognito(it->get(), extension_service))) {
106 // Inject level of control key-value. 107 // Inject level of control key-value.
107 base::DictionaryValue* dict; 108 base::DictionaryValue* dict;
108 bool rv = args->GetDictionary(0, &dict); 109 bool rv = args->GetDictionary(0, &dict);
109 DCHECK(rv); 110 DCHECK(rv);
110 std::string level_of_control = 111 std::string level_of_control =
111 GetLevelOfControl(profile, extension_id, browser_pref, incognito); 112 GetLevelOfControl(profile, extension_id, browser_pref, incognito);
112 dict->SetString(kLevelOfControlKey, level_of_control); 113 dict->SetString(kLevelOfControlKey, level_of_control);
113 114
114 // If the extension is in incognito split mode, 115 // If the extension is in incognito split mode,
115 // a) incognito pref changes are visible only to the incognito tabs 116 // a) incognito pref changes are visible only to the incognito tabs
116 // b) regular pref changes are visible only to the incognito tabs if the 117 // b) regular pref changes are visible only to the incognito tabs if the
117 // incognito pref has not alredy been set 118 // incognito pref has not alredy been set
118 Profile* restrict_to_profile = NULL; 119 Profile* restrict_to_profile = NULL;
119 bool from_incognito = false; 120 bool from_incognito = false;
120 if (IncognitoInfo::IsSplitMode(it->get())) { 121 if (IncognitoInfo::IsSplitMode(it->get())) {
121 if (incognito && extension_service->IsIncognitoEnabled(extension_id)) { 122 if (incognito &&
123 extension_util::IsIncognitoEnabled(extension_id,
124 extension_service)) {
122 restrict_to_profile = profile->GetOffTheRecordProfile(); 125 restrict_to_profile = profile->GetOffTheRecordProfile();
123 } else if (!incognito && 126 } else if (!incognito &&
124 PreferenceAPI::Get(profile)->DoesExtensionControlPref( 127 PreferenceAPI::Get(profile)->DoesExtensionControlPref(
125 extension_id, 128 extension_id,
126 browser_pref, 129 browser_pref,
127 &from_incognito) && 130 &from_incognito) &&
128 from_incognito) { 131 from_incognito) {
129 restrict_to_profile = profile; 132 restrict_to_profile = profile;
130 } 133 }
131 } 134 }
132 135
133 scoped_ptr<base::ListValue> args_copy(args->DeepCopy()); 136 scoped_ptr<base::ListValue> args_copy(args->DeepCopy());
134 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass())); 137 scoped_ptr<Event> event(new Event(event_name, args_copy.Pass()));
135 event->restrict_to_profile = restrict_to_profile; 138 event->restrict_to_profile = restrict_to_profile;
136 router->DispatchEventToExtension(extension_id, event.Pass()); 139 router->DispatchEventToExtension(extension_id, event.Pass());
137 } 140 }
138 } 141 }
139 } 142 }
140 143
141 } // namespace preference_helpers 144 } // namespace preference_helpers
142 } // namespace extensions 145 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/module/module.cc ('k') | chrome/browser/extensions/api/tabs/windows_event_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698