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_system.h" | 5 #include "chrome/browser/extensions/extension_system.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/string_tokenizer.h" | 10 #include "base/string_tokenizer.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 36 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" |
37 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" | 37 #include "chrome/browser/ui/webui/extensions/extension_icon_source.h" |
38 #include "chrome/common/chrome_switches.h" | 38 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/extensions/extension.h" | 39 #include "chrome/common/extensions/extension.h" |
40 #include "chrome/common/extensions/features/feature.h" | 40 #include "chrome/common/extensions/features/feature.h" |
41 #include "chrome/common/pref_names.h" | 41 #include "chrome/common/pref_names.h" |
42 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
43 | 43 |
44 using content::BrowserThread; | 44 using content::BrowserThread; |
45 | 45 |
| 46 namespace extensions { |
| 47 |
46 // | 48 // |
47 // ExtensionSystem | 49 // ExtensionSystem |
48 // | 50 // |
49 | 51 |
50 ExtensionSystem::ExtensionSystem() { | 52 ExtensionSystem::ExtensionSystem() { |
51 // In lieu of a way for Feature to check whether it's running on the browser | 53 // In lieu of a way for Feature to check whether it's running on the browser |
52 // process, tell it. | 54 // process, tell it. |
53 // See http://crbug.com/126535. | 55 // See http://crbug.com/126535. |
54 extensions::Feature::SetChannelCheckingEnabled(true); | 56 Feature::SetChannelCheckingEnabled(true); |
55 } | 57 } |
56 | 58 |
57 ExtensionSystem::~ExtensionSystem() { | 59 ExtensionSystem::~ExtensionSystem() { |
58 } | 60 } |
59 | 61 |
60 // static | 62 // static |
61 ExtensionSystem* ExtensionSystem::Get(Profile* profile) { | 63 ExtensionSystem* ExtensionSystem::Get(Profile* profile) { |
62 return ExtensionSystemFactory::GetForProfile(profile); | 64 return ExtensionSystemFactory::GetForProfile(profile); |
63 } | 65 } |
64 | 66 |
(...skipping 13 matching lines...) Expand all Loading... |
78 void ExtensionSystemImpl::Shared::InitPrefs() { | 80 void ExtensionSystemImpl::Shared::InitPrefs() { |
79 bool extensions_disabled = | 81 bool extensions_disabled = |
80 profile_->GetPrefs()->GetBoolean(prefs::kDisableExtensions) || | 82 profile_->GetPrefs()->GetBoolean(prefs::kDisableExtensions) || |
81 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableExtensions); | 83 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableExtensions); |
82 extension_prefs_.reset(new ExtensionPrefs( | 84 extension_prefs_.reset(new ExtensionPrefs( |
83 profile_->GetPrefs(), | 85 profile_->GetPrefs(), |
84 profile_->GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), | 86 profile_->GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), |
85 ExtensionPrefValueMapFactory::GetForProfile(profile_))); | 87 ExtensionPrefValueMapFactory::GetForProfile(profile_))); |
86 extension_prefs_->Init(extensions_disabled); | 88 extension_prefs_->Init(extensions_disabled); |
87 | 89 |
88 state_store_.reset(new extensions::StateStore( | 90 state_store_.reset(new StateStore( |
89 profile_, | 91 profile_, |
90 profile_->GetPath().AppendASCII(ExtensionService::kStateStoreName))); | 92 profile_->GetPath().AppendASCII(ExtensionService::kStateStoreName))); |
91 } | 93 } |
92 | 94 |
93 void ExtensionSystemImpl::Shared::RegisterManagementPolicyProviders() { | 95 void ExtensionSystemImpl::Shared::RegisterManagementPolicyProviders() { |
94 DCHECK(extension_prefs_.get()); | 96 DCHECK(extension_prefs_.get()); |
95 management_policy_->RegisterProvider(extension_prefs_.get()); | 97 management_policy_->RegisterProvider(extension_prefs_.get()); |
96 } | 98 } |
97 | 99 |
98 void ExtensionSystemImpl::Shared::InitInfoMap() { | 100 void ExtensionSystemImpl::Shared::InitInfoMap() { |
99 // The ExtensionInfoMap needs to be created before the | 101 // The ExtensionInfoMap needs to be created before the |
100 // ExtensionProcessManager. | 102 // ExtensionProcessManager. |
101 extension_info_map_ = new ExtensionInfoMap(); | 103 extension_info_map_ = new ExtensionInfoMap(); |
102 } | 104 } |
103 | 105 |
104 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { | 106 void ExtensionSystemImpl::Shared::Init(bool extensions_enabled) { |
105 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 107 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
106 | 108 |
107 lazy_background_task_queue_.reset(new extensions::LazyBackgroundTaskQueue( | 109 lazy_background_task_queue_.reset(new LazyBackgroundTaskQueue(profile_)); |
108 profile_)); | |
109 extension_event_router_.reset(new ExtensionEventRouter(profile_)); | 110 extension_event_router_.reset(new ExtensionEventRouter(profile_)); |
110 extension_message_service_.reset(new ExtensionMessageService( | 111 extension_message_service_.reset(new ExtensionMessageService( |
111 lazy_background_task_queue_.get())); | 112 lazy_background_task_queue_.get())); |
112 extension_navigation_observer_.reset( | 113 extension_navigation_observer_.reset( |
113 new ExtensionNavigationObserver(profile_)); | 114 new ExtensionNavigationObserver(profile_)); |
114 | 115 |
115 ExtensionErrorReporter::Init(true); // allow noisy errors. | 116 ExtensionErrorReporter::Init(true); // allow noisy errors. |
116 | 117 |
117 user_script_master_ = new UserScriptMaster(profile_); | 118 user_script_master_ = new UserScriptMaster(profile_); |
118 | 119 |
119 bool autoupdate_enabled = true; | 120 bool autoupdate_enabled = true; |
120 #if defined(OS_CHROMEOS) | 121 #if defined(OS_CHROMEOS) |
121 if (!extensions_enabled) | 122 if (!extensions_enabled) |
122 autoupdate_enabled = false; | 123 autoupdate_enabled = false; |
123 else | 124 else |
124 autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession); | 125 autoupdate_enabled = !command_line->HasSwitch(switches::kGuestSession); |
125 #endif | 126 #endif |
126 extension_service_.reset(new ExtensionService( | 127 extension_service_.reset(new ExtensionService( |
127 profile_, | 128 profile_, |
128 CommandLine::ForCurrentProcess(), | 129 CommandLine::ForCurrentProcess(), |
129 profile_->GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), | 130 profile_->GetPath().AppendASCII(ExtensionService::kInstallDirectoryName), |
130 extension_prefs_.get(), | 131 extension_prefs_.get(), |
131 autoupdate_enabled, | 132 autoupdate_enabled, |
132 extensions_enabled)); | 133 extensions_enabled)); |
133 | 134 |
134 // These services must be registered before the ExtensionService tries to | 135 // These services must be registered before the ExtensionService tries to |
135 // load any extensions. | 136 // load any extensions. |
136 { | 137 { |
137 rules_registry_service_.reset( | 138 rules_registry_service_.reset(new RulesRegistryService(profile_)); |
138 new extensions::RulesRegistryService(profile_)); | |
139 rules_registry_service_->RegisterDefaultRulesRegistries(); | 139 rules_registry_service_->RegisterDefaultRulesRegistries(); |
140 | 140 |
141 management_policy_.reset(new extensions::ManagementPolicy); | 141 management_policy_.reset(new ManagementPolicy); |
142 RegisterManagementPolicyProviders(); | 142 RegisterManagementPolicyProviders(); |
143 } | 143 } |
144 | 144 |
145 extension_service_->component_loader()->AddDefaultComponentExtensions(); | 145 extension_service_->component_loader()->AddDefaultComponentExtensions(); |
146 if (command_line->HasSwitch(switches::kLoadComponentExtension)) { | 146 if (command_line->HasSwitch(switches::kLoadComponentExtension)) { |
147 CommandLine::StringType path_list = command_line->GetSwitchValueNative( | 147 CommandLine::StringType path_list = command_line->GetSwitchValueNative( |
148 switches::kLoadComponentExtension); | 148 switches::kLoadComponentExtension); |
149 StringTokenizerT<CommandLine::StringType, | 149 StringTokenizerT<CommandLine::StringType, |
150 CommandLine::StringType::const_iterator> t(path_list, | 150 CommandLine::StringType::const_iterator> t(path_list, |
151 FILE_PATH_LITERAL(",")); | 151 FILE_PATH_LITERAL(",")); |
(...skipping 11 matching lines...) Expand all Loading... |
163 if (extensions_enabled) { | 163 if (extensions_enabled) { |
164 // Load any extensions specified with --load-extension. | 164 // Load any extensions specified with --load-extension. |
165 // TODO(yoz): Seems like this should move into ExtensionService::Init. | 165 // TODO(yoz): Seems like this should move into ExtensionService::Init. |
166 // But maybe it's no longer important. | 166 // But maybe it's no longer important. |
167 if (command_line->HasSwitch(switches::kLoadExtension)) { | 167 if (command_line->HasSwitch(switches::kLoadExtension)) { |
168 CommandLine::StringType path_list = command_line->GetSwitchValueNative( | 168 CommandLine::StringType path_list = command_line->GetSwitchValueNative( |
169 switches::kLoadExtension); | 169 switches::kLoadExtension); |
170 StringTokenizerT<CommandLine::StringType, | 170 StringTokenizerT<CommandLine::StringType, |
171 CommandLine::StringType::const_iterator> t(path_list, | 171 CommandLine::StringType::const_iterator> t(path_list, |
172 FILE_PATH_LITERAL(",")); | 172 FILE_PATH_LITERAL(",")); |
173 scoped_refptr<extensions::UnpackedInstaller> installer = | 173 scoped_refptr<UnpackedInstaller> installer = |
174 extensions::UnpackedInstaller::Create(extension_service_.get()); | 174 UnpackedInstaller::Create(extension_service_.get()); |
175 while (t.GetNext()) { | 175 while (t.GetNext()) { |
176 installer->LoadFromCommandLine(FilePath(t.token())); | 176 installer->LoadFromCommandLine(FilePath(t.token())); |
177 } | 177 } |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 // Make the chrome://extension-icon/ resource available. | 181 // Make the chrome://extension-icon/ resource available. |
182 ChromeURLDataManager::AddDataSource(profile_, | 182 ChromeURLDataManager::AddDataSource(profile_, |
183 new ExtensionIconSource(profile_)); | 183 new ExtensionIconSource(profile_)); |
184 | 184 |
(...skipping 12 matching lines...) Expand all Loading... |
197 if (!command_line->HasSwitch(switches::kImport) && | 197 if (!command_line->HasSwitch(switches::kImport) && |
198 !command_line->HasSwitch(switches::kImportFromFile)) { | 198 !command_line->HasSwitch(switches::kImportFromFile)) { |
199 if (g_browser_process->profile_manager()->will_import()) { | 199 if (g_browser_process->profile_manager()->will_import()) { |
200 extension_service_->InitEventRoutersAfterImport(); | 200 extension_service_->InitEventRoutersAfterImport(); |
201 } else { | 201 } else { |
202 extension_service_->InitEventRouters(); | 202 extension_service_->InitEventRouters(); |
203 } | 203 } |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 extensions::StateStore* ExtensionSystemImpl::Shared::state_store() { | 207 StateStore* ExtensionSystemImpl::Shared::state_store() { |
208 return state_store_.get(); | 208 return state_store_.get(); |
209 } | 209 } |
210 | 210 |
211 ExtensionService* ExtensionSystemImpl::Shared::extension_service() { | 211 ExtensionService* ExtensionSystemImpl::Shared::extension_service() { |
212 return extension_service_.get(); | 212 return extension_service_.get(); |
213 } | 213 } |
214 | 214 |
215 extensions::ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { | 215 ManagementPolicy* ExtensionSystemImpl::Shared::management_policy() { |
216 return management_policy_.get(); | 216 return management_policy_.get(); |
217 } | 217 } |
218 | 218 |
219 UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { | 219 UserScriptMaster* ExtensionSystemImpl::Shared::user_script_master() { |
220 return user_script_master_.get(); | 220 return user_script_master_.get(); |
221 } | 221 } |
222 | 222 |
223 ExtensionInfoMap* ExtensionSystemImpl::Shared::info_map() { | 223 ExtensionInfoMap* ExtensionSystemImpl::Shared::info_map() { |
224 return extension_info_map_.get(); | 224 return extension_info_map_.get(); |
225 } | 225 } |
226 | 226 |
227 extensions::LazyBackgroundTaskQueue* | 227 LazyBackgroundTaskQueue* |
228 ExtensionSystemImpl::Shared::lazy_background_task_queue() { | 228 ExtensionSystemImpl::Shared::lazy_background_task_queue() { |
229 return lazy_background_task_queue_.get(); | 229 return lazy_background_task_queue_.get(); |
230 } | 230 } |
231 | 231 |
232 ExtensionMessageService* ExtensionSystemImpl::Shared::message_service() { | 232 ExtensionMessageService* ExtensionSystemImpl::Shared::message_service() { |
233 return extension_message_service_.get(); | 233 return extension_message_service_.get(); |
234 } | 234 } |
235 | 235 |
236 ExtensionEventRouter* ExtensionSystemImpl::Shared::event_router() { | 236 ExtensionEventRouter* ExtensionSystemImpl::Shared::event_router() { |
237 return extension_event_router_.get(); | 237 return extension_event_router_.get(); |
238 } | 238 } |
239 | 239 |
240 extensions::RulesRegistryService* | 240 RulesRegistryService* ExtensionSystemImpl::Shared::rules_registry_service() { |
241 ExtensionSystemImpl::Shared::rules_registry_service() { | |
242 return rules_registry_service_.get(); | 241 return rules_registry_service_.get(); |
243 } | 242 } |
244 | 243 |
245 // | 244 // |
246 // ExtensionSystemImpl | 245 // ExtensionSystemImpl |
247 // | 246 // |
248 | 247 |
249 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) | 248 ExtensionSystemImpl::ExtensionSystemImpl(Profile* profile) |
250 : profile_(profile), | 249 : profile_(profile), |
251 extension_devtools_manager_(NULL) { | 250 extension_devtools_manager_(NULL) { |
(...skipping 20 matching lines...) Expand all Loading... |
272 | 271 |
273 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 272 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
274 if (command_line->HasSwitch( | 273 if (command_line->HasSwitch( |
275 switches::kEnableExtensionTimelineApi)) { | 274 switches::kEnableExtensionTimelineApi)) { |
276 extension_devtools_manager_ = new ExtensionDevToolsManager(profile_); | 275 extension_devtools_manager_ = new ExtensionDevToolsManager(profile_); |
277 } | 276 } |
278 | 277 |
279 shared_->InitInfoMap(); | 278 shared_->InitInfoMap(); |
280 | 279 |
281 extension_process_manager_.reset(ExtensionProcessManager::Create(profile_)); | 280 extension_process_manager_.reset(ExtensionProcessManager::Create(profile_)); |
282 alarm_manager_.reset(new extensions::AlarmManager(profile_, | 281 alarm_manager_.reset(new AlarmManager(profile_, |
283 &base::Time::Now)); | 282 &base::Time::Now)); |
284 | 283 |
285 shared_->Init(extensions_enabled); | 284 shared_->Init(extensions_enabled); |
286 } | 285 } |
287 | 286 |
288 ExtensionService* ExtensionSystemImpl::extension_service() { | 287 ExtensionService* ExtensionSystemImpl::extension_service() { |
289 return shared_->extension_service(); | 288 return shared_->extension_service(); |
290 } | 289 } |
291 | 290 |
292 extensions::ManagementPolicy* ExtensionSystemImpl::management_policy() { | 291 ManagementPolicy* ExtensionSystemImpl::management_policy() { |
293 return shared_->management_policy(); | 292 return shared_->management_policy(); |
294 } | 293 } |
295 | 294 |
296 UserScriptMaster* ExtensionSystemImpl::user_script_master() { | 295 UserScriptMaster* ExtensionSystemImpl::user_script_master() { |
297 return shared_->user_script_master(); | 296 return shared_->user_script_master(); |
298 } | 297 } |
299 | 298 |
300 ExtensionDevToolsManager* ExtensionSystemImpl::devtools_manager() { | 299 ExtensionDevToolsManager* ExtensionSystemImpl::devtools_manager() { |
301 // TODO(mpcomplete): in incognito, figure out whether we should | 300 // TODO(mpcomplete): in incognito, figure out whether we should |
302 // return the original profile's version. | 301 // return the original profile's version. |
303 return extension_devtools_manager_.get(); | 302 return extension_devtools_manager_.get(); |
304 } | 303 } |
305 | 304 |
306 ExtensionProcessManager* ExtensionSystemImpl::process_manager() { | 305 ExtensionProcessManager* ExtensionSystemImpl::process_manager() { |
307 return extension_process_manager_.get(); | 306 return extension_process_manager_.get(); |
308 } | 307 } |
309 | 308 |
310 extensions::AlarmManager* ExtensionSystemImpl::alarm_manager() { | 309 AlarmManager* ExtensionSystemImpl::alarm_manager() { |
311 return alarm_manager_.get(); | 310 return alarm_manager_.get(); |
312 } | 311 } |
313 | 312 |
314 extensions::StateStore* ExtensionSystemImpl::state_store() { | 313 StateStore* ExtensionSystemImpl::state_store() { |
315 return shared_->state_store(); | 314 return shared_->state_store(); |
316 } | 315 } |
317 | 316 |
318 ExtensionInfoMap* ExtensionSystemImpl::info_map() { | 317 ExtensionInfoMap* ExtensionSystemImpl::info_map() { |
319 return shared_->info_map(); | 318 return shared_->info_map(); |
320 } | 319 } |
321 | 320 |
322 extensions::LazyBackgroundTaskQueue* | 321 LazyBackgroundTaskQueue* ExtensionSystemImpl::lazy_background_task_queue() { |
323 ExtensionSystemImpl::lazy_background_task_queue() { | |
324 return shared_->lazy_background_task_queue(); | 322 return shared_->lazy_background_task_queue(); |
325 } | 323 } |
326 | 324 |
327 ExtensionMessageService* ExtensionSystemImpl::message_service() { | 325 ExtensionMessageService* ExtensionSystemImpl::message_service() { |
328 return shared_->message_service(); | 326 return shared_->message_service(); |
329 } | 327 } |
330 | 328 |
331 ExtensionEventRouter* ExtensionSystemImpl::event_router() { | 329 ExtensionEventRouter* ExtensionSystemImpl::event_router() { |
332 return shared_->event_router(); | 330 return shared_->event_router(); |
333 } | 331 } |
334 | 332 |
335 extensions::RulesRegistryService* | 333 RulesRegistryService* ExtensionSystemImpl::rules_registry_service() { |
336 ExtensionSystemImpl::rules_registry_service() { | |
337 return shared_->rules_registry_service(); | 334 return shared_->rules_registry_service(); |
338 } | 335 } |
339 | 336 |
340 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( | 337 void ExtensionSystemImpl::RegisterExtensionWithRequestContexts( |
341 const extensions::Extension* extension) { | 338 const Extension* extension) { |
342 base::Time install_time; | 339 base::Time install_time; |
343 if (extension->location() != extensions::Extension::COMPONENT) { | 340 if (extension->location() != Extension::COMPONENT) { |
344 install_time = extension_service()->extension_prefs()-> | 341 install_time = extension_service()->extension_prefs()-> |
345 GetInstallTime(extension->id()); | 342 GetInstallTime(extension->id()); |
346 } | 343 } |
347 bool incognito_enabled = | 344 bool incognito_enabled = |
348 extension_service()->IsIncognitoEnabled(extension->id()); | 345 extension_service()->IsIncognitoEnabled(extension->id()); |
349 BrowserThread::PostTask( | 346 BrowserThread::PostTask( |
350 BrowserThread::IO, FROM_HERE, | 347 BrowserThread::IO, FROM_HERE, |
351 base::Bind(&ExtensionInfoMap::AddExtension, info_map(), | 348 base::Bind(&ExtensionInfoMap::AddExtension, info_map(), |
352 make_scoped_refptr(extension), install_time, | 349 make_scoped_refptr(extension), install_time, |
353 incognito_enabled)); | 350 incognito_enabled)); |
354 } | 351 } |
355 | 352 |
356 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( | 353 void ExtensionSystemImpl::UnregisterExtensionWithRequestContexts( |
357 const std::string& extension_id, | 354 const std::string& extension_id, |
358 const extension_misc::UnloadedExtensionReason reason) { | 355 const extension_misc::UnloadedExtensionReason reason) { |
359 BrowserThread::PostTask( | 356 BrowserThread::PostTask( |
360 BrowserThread::IO, FROM_HERE, | 357 BrowserThread::IO, FROM_HERE, |
361 base::Bind(&ExtensionInfoMap::RemoveExtension, info_map(), | 358 base::Bind(&ExtensionInfoMap::RemoveExtension, info_map(), |
362 extension_id, reason)); | 359 extension_id, reason)); |
363 } | 360 } |
| 361 |
| 362 } // namespace extensions |
OLD | NEW |