| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/browser/plugin_service.h" | 5 #include "content/browser/plugin_service.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/synchronization/waitable_event.h" | 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_plugin_host.h" | |
| 18 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 19 #include "chrome/browser/plugin_updater.h" | 18 #include "chrome/browser/plugin_updater.h" |
| 20 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 21 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
| 22 #include "chrome/common/chrome_plugin_lib.h" | |
| 23 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/default_plugin.h" | 22 #include "chrome/common/default_plugin.h" |
| 25 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
| 26 #include "chrome/common/logging_chrome.h" | 24 #include "chrome/common/logging_chrome.h" |
| 27 #include "chrome/common/pepper_plugin_registry.h" | 25 #include "chrome/common/pepper_plugin_registry.h" |
| 28 #include "chrome/common/plugin_messages.h" | 26 #include "chrome/common/plugin_messages.h" |
| 29 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
| 30 #include "content/browser/browser_thread.h" | 28 #include "content/browser/browser_thread.h" |
| 31 #include "content/browser/ppapi_plugin_process_host.h" | 29 #include "content/browser/ppapi_plugin_process_host.h" |
| 32 #include "content/browser/renderer_host/render_process_host.h" | 30 #include "content/browser/renderer_host/render_process_host.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 68 } |
| 71 virtual void OnError() { | 69 virtual void OnError() { |
| 72 // TODO(pastarmovj): Add some sensible error handling. Maybe silently | 70 // TODO(pastarmovj): Add some sensible error handling. Maybe silently |
| 73 // stopping the watcher would be enough. Or possibly restart it. | 71 // stopping the watcher would be enough. Or possibly restart it. |
| 74 NOTREACHED(); | 72 NOTREACHED(); |
| 75 } | 73 } |
| 76 }; | 74 }; |
| 77 #endif | 75 #endif |
| 78 | 76 |
| 79 // static | 77 // static |
| 80 bool PluginService::enable_chrome_plugins_ = true; | |
| 81 | |
| 82 // static | |
| 83 void PluginService::InitGlobalInstance(Profile* profile) { | 78 void PluginService::InitGlobalInstance(Profile* profile) { |
| 84 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 79 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 85 | 80 |
| 86 // We first group the plugins and then figure out which groups to | 81 // We first group the plugins and then figure out which groups to |
| 87 // enable or disable. | 82 // enable or disable. |
| 88 PluginUpdater::GetInstance()->UpdatePluginGroupsStateFromPrefs(profile); | 83 PluginUpdater::GetInstance()->UpdatePluginGroupsStateFromPrefs(profile); |
| 89 | |
| 90 // Have Chrome plugins write their data to the profile directory. | |
| 91 GetInstance()->SetChromePluginDataDir(profile->GetPath()); | |
| 92 } | 84 } |
| 93 | 85 |
| 94 // static | 86 // static |
| 95 PluginService* PluginService::GetInstance() { | 87 PluginService* PluginService::GetInstance() { |
| 96 return Singleton<PluginService>::get(); | 88 return Singleton<PluginService>::get(); |
| 97 } | 89 } |
| 98 | 90 |
| 99 // static | |
| 100 void PluginService::EnableChromePlugins(bool enable) { | |
| 101 enable_chrome_plugins_ = enable; | |
| 102 } | |
| 103 | |
| 104 PluginService::PluginService() | 91 PluginService::PluginService() |
| 105 : main_message_loop_(MessageLoop::current()), | 92 : main_message_loop_(MessageLoop::current()), |
| 106 resource_dispatcher_host_(NULL), | 93 resource_dispatcher_host_(NULL), |
| 107 ui_locale_(g_browser_process->GetApplicationLocale()) { | 94 ui_locale_(g_browser_process->GetApplicationLocale()) { |
| 108 RegisterPepperPlugins(); | 95 RegisterPepperPlugins(); |
| 109 | 96 |
| 110 // Have the NPAPI plugin list search for Chrome plugins as well. | |
| 111 ChromePluginLib::RegisterPluginsWithNPAPI(); | |
| 112 | |
| 113 // Load any specified on the command line as well. | 97 // Load any specified on the command line as well. |
| 114 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 98 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 115 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); | 99 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); |
| 116 if (!path.empty()) | 100 if (!path.empty()) |
| 117 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); | 101 webkit::npapi::PluginList::Singleton()->AddExtraPluginPath(path); |
| 118 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); | 102 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); |
| 119 if (!path.empty()) | 103 if (!path.empty()) |
| 120 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); | 104 webkit::npapi::PluginList::Singleton()->AddExtraPluginDir(path); |
| 121 | 105 |
| 122 chrome::RegisterInternalDefaultPlugin(); | 106 chrome::RegisterInternalDefaultPlugin(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // Release the events since they're owned by RegKey, not WaitableEvent. | 195 // Release the events since they're owned by RegKey, not WaitableEvent. |
| 212 hkcu_watcher_.StopWatching(); | 196 hkcu_watcher_.StopWatching(); |
| 213 hklm_watcher_.StopWatching(); | 197 hklm_watcher_.StopWatching(); |
| 214 if (hkcu_event_.get()) | 198 if (hkcu_event_.get()) |
| 215 hkcu_event_->Release(); | 199 hkcu_event_->Release(); |
| 216 if (hklm_event_.get()) | 200 if (hklm_event_.get()) |
| 217 hklm_event_->Release(); | 201 hklm_event_->Release(); |
| 218 #endif | 202 #endif |
| 219 } | 203 } |
| 220 | 204 |
| 221 void PluginService::LoadChromePlugins( | |
| 222 ResourceDispatcherHost* resource_dispatcher_host) { | |
| 223 if (!enable_chrome_plugins_) | |
| 224 return; | |
| 225 | |
| 226 resource_dispatcher_host_ = resource_dispatcher_host; | |
| 227 ChromePluginLib::LoadChromePlugins(GetCPBrowserFuncsForBrowser()); | |
| 228 } | |
| 229 | |
| 230 void PluginService::SetChromePluginDataDir(const FilePath& data_dir) { | |
| 231 chrome_plugin_data_dir_ = data_dir; | |
| 232 } | |
| 233 | |
| 234 const FilePath& PluginService::GetChromePluginDataDir() { | |
| 235 return chrome_plugin_data_dir_; | |
| 236 } | |
| 237 | |
| 238 const std::string& PluginService::GetUILocale() { | 205 const std::string& PluginService::GetUILocale() { |
| 239 return ui_locale_; | 206 return ui_locale_; |
| 240 } | 207 } |
| 241 | 208 |
| 242 PluginProcessHost* PluginService::FindNpapiPluginProcess( | 209 PluginProcessHost* PluginService::FindNpapiPluginProcess( |
| 243 const FilePath& plugin_path) { | 210 const FilePath& plugin_path) { |
| 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 245 | 212 |
| 246 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); | 213 for (BrowserChildProcessHost::Iterator iter(ChildProcessInfo::PLUGIN_PROCESS); |
| 247 !iter.Done(); ++iter) { | 214 !iter.Done(); ++iter) { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 #if defined(OS_LINUX) | 546 #if defined(OS_LINUX) |
| 580 // static | 547 // static |
| 581 void PluginService::RegisterFilePathWatcher( | 548 void PluginService::RegisterFilePathWatcher( |
| 582 FilePathWatcher *watcher, | 549 FilePathWatcher *watcher, |
| 583 const FilePath& path, | 550 const FilePath& path, |
| 584 FilePathWatcher::Delegate* delegate) { | 551 FilePathWatcher::Delegate* delegate) { |
| 585 bool result = watcher->Watch(path, delegate); | 552 bool result = watcher->Watch(path, delegate); |
| 586 DCHECK(result); | 553 DCHECK(result); |
| 587 } | 554 } |
| 588 #endif | 555 #endif |
| OLD | NEW |