| 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 // This class responds to requests from renderers for the list of plugins, and | 5 // This class responds to requests from renderers for the list of plugins, and |
| 6 // also a proxy object for plugin instances. | 6 // also a proxy object for plugin instances. |
| 7 | 7 |
| 8 #ifndef CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ | 8 #ifndef CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ |
| 9 #define CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ | 9 #define CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ |
| 10 | 10 |
| 11 #if !defined(ENABLE_PLUGINS) | 11 #if !defined(ENABLE_PLUGINS) |
| 12 #error "Plugins should be enabled" | 12 #error "Plugins should be enabled" |
| 13 #endif | 13 #endif |
| 14 | 14 |
| 15 #include <map> | 15 #include <map> |
| 16 #include <set> | 16 #include <set> |
| 17 #include <vector> | 17 #include <vector> |
| 18 | 18 |
| 19 #include "base/compiler_specific.h" | 19 #include "base/compiler_specific.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/scoped_vector.h" |
| 22 #include "base/memory/singleton.h" | 22 #include "base/memory/singleton.h" |
| 23 #include "base/synchronization/waitable_event_watcher.h" | 23 #include "base/synchronization/waitable_event_watcher.h" |
| 24 #include "base/threading/sequenced_worker_pool.h" | 24 #include "base/threading/sequenced_worker_pool.h" |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
| 27 #include "content/browser/plugin_process_host.h" | |
| 28 #include "content/browser/ppapi_plugin_process_host.h" | 27 #include "content/browser/ppapi_plugin_process_host.h" |
| 29 #include "content/common/content_export.h" | 28 #include "content/common/content_export.h" |
| 30 #include "content/public/browser/plugin_service.h" | 29 #include "content/public/browser/plugin_service.h" |
| 31 #include "content/public/common/pepper_plugin_info.h" | 30 #include "content/public/common/pepper_plugin_info.h" |
| 32 #include "ipc/ipc_channel_handle.h" | 31 #include "ipc/ipc_channel_handle.h" |
| 33 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 34 | 33 |
| 35 #if defined(OS_WIN) | 34 #if defined(OS_WIN) |
| 36 #include "base/memory/scoped_ptr.h" | 35 #include "base/memory/scoped_ptr.h" |
| 37 #include "base/win/registry.h" | 36 #include "base/win/registry.h" |
| 38 #endif | 37 #endif |
| 39 | 38 |
| 40 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) | 39 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
| 41 #include "base/files/file_path_watcher.h" | 40 #include "base/files/file_path_watcher.h" |
| 42 #endif | 41 #endif |
| 43 | 42 |
| 44 namespace base { | 43 namespace base { |
| 45 class SingleThreadTaskRunner; | 44 class SingleThreadTaskRunner; |
| 46 } | 45 } |
| 47 | 46 |
| 48 namespace content { | 47 namespace content { |
| 49 class BrowserContext; | 48 class BrowserContext; |
| 50 class PluginDirWatcherDelegate; | 49 class PluginDirWatcherDelegate; |
| 51 class PluginLoaderPosix; | |
| 52 class PluginServiceFilter; | 50 class PluginServiceFilter; |
| 53 class ResourceContext; | 51 class ResourceContext; |
| 54 struct PepperPluginInfo; | 52 struct PepperPluginInfo; |
| 55 | 53 |
| 56 // base::Bind() has limited arity, and the filter-related methods tend to | |
| 57 // surpass that limit. | |
| 58 struct PluginServiceFilterParams { | |
| 59 int render_process_id; | |
| 60 int render_frame_id; | |
| 61 GURL page_url; | |
| 62 ResourceContext* resource_context; | |
| 63 }; | |
| 64 | |
| 65 class CONTENT_EXPORT PluginServiceImpl | 54 class CONTENT_EXPORT PluginServiceImpl |
| 66 : NON_EXPORTED_BASE(public PluginService) { | 55 : NON_EXPORTED_BASE(public PluginService) { |
| 67 public: | 56 public: |
| 68 // Returns the PluginServiceImpl singleton. | 57 // Returns the PluginServiceImpl singleton. |
| 69 static PluginServiceImpl* GetInstance(); | 58 static PluginServiceImpl* GetInstance(); |
| 70 | 59 |
| 71 // PluginService implementation: | 60 // PluginService implementation: |
| 72 void Init() override; | 61 void Init() override; |
| 73 void StartWatchingPlugins() override; | |
| 74 bool GetPluginInfoArray(const GURL& url, | 62 bool GetPluginInfoArray(const GURL& url, |
| 75 const std::string& mime_type, | 63 const std::string& mime_type, |
| 76 bool allow_wildcard, | 64 bool allow_wildcard, |
| 77 std::vector<WebPluginInfo>* info, | 65 std::vector<WebPluginInfo>* info, |
| 78 std::vector<std::string>* actual_mime_types) override; | 66 std::vector<std::string>* actual_mime_types) override; |
| 79 bool GetPluginInfo(int render_process_id, | 67 bool GetPluginInfo(int render_process_id, |
| 80 int render_frame_id, | 68 int render_frame_id, |
| 81 ResourceContext* context, | 69 ResourceContext* context, |
| 82 const GURL& url, | 70 const GURL& url, |
| 83 const GURL& page_url, | 71 const GURL& page_url, |
| 84 const std::string& mime_type, | 72 const std::string& mime_type, |
| 85 bool allow_wildcard, | 73 bool allow_wildcard, |
| 86 bool* is_stale, | 74 bool* is_stale, |
| 87 WebPluginInfo* info, | 75 WebPluginInfo* info, |
| 88 std::string* actual_mime_type) override; | 76 std::string* actual_mime_type) override; |
| 89 bool GetPluginInfoByPath(const base::FilePath& plugin_path, | 77 bool GetPluginInfoByPath(const base::FilePath& plugin_path, |
| 90 WebPluginInfo* info) override; | 78 WebPluginInfo* info) override; |
| 91 base::string16 GetPluginDisplayNameByPath( | 79 base::string16 GetPluginDisplayNameByPath( |
| 92 const base::FilePath& path) override; | 80 const base::FilePath& path) override; |
| 93 void GetPlugins(const GetPluginsCallback& callback) override; | 81 void GetPlugins(const GetPluginsCallback& callback) override; |
| 94 PepperPluginInfo* GetRegisteredPpapiPluginInfo( | 82 PepperPluginInfo* GetRegisteredPpapiPluginInfo( |
| 95 const base::FilePath& plugin_path) override; | 83 const base::FilePath& plugin_path) override; |
| 96 void SetFilter(PluginServiceFilter* filter) override; | 84 void SetFilter(PluginServiceFilter* filter) override; |
| 97 PluginServiceFilter* GetFilter() override; | 85 PluginServiceFilter* GetFilter() override; |
| 98 void ForcePluginShutdown(const base::FilePath& plugin_path) override; | |
| 99 bool IsPluginUnstable(const base::FilePath& plugin_path) override; | 86 bool IsPluginUnstable(const base::FilePath& plugin_path) override; |
| 100 void RefreshPlugins() override; | 87 void RefreshPlugins() override; |
| 101 void AddExtraPluginPath(const base::FilePath& path) override; | |
| 102 void RemoveExtraPluginPath(const base::FilePath& path) override; | |
| 103 void AddExtraPluginDir(const base::FilePath& path) override; | |
| 104 void RegisterInternalPlugin(const WebPluginInfo& info, | 88 void RegisterInternalPlugin(const WebPluginInfo& info, |
| 105 bool add_at_beginning) override; | 89 bool add_at_beginning) override; |
| 106 void UnregisterInternalPlugin(const base::FilePath& path) override; | 90 void UnregisterInternalPlugin(const base::FilePath& path) override; |
| 107 void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override; | 91 void GetInternalPlugins(std::vector<WebPluginInfo>* plugins) override; |
| 108 bool NPAPIPluginsSupported() override; | |
| 109 void DisablePluginsDiscoveryForTesting() override; | |
| 110 #if defined(OS_MACOSX) | |
| 111 void AppActivated() override; | |
| 112 #endif | |
| 113 bool PpapiDevChannelSupported(BrowserContext* browser_context, | 92 bool PpapiDevChannelSupported(BrowserContext* browser_context, |
| 114 const GURL& document_url) override; | 93 const GURL& document_url) override; |
| 115 | 94 |
| 116 // Returns the plugin process host corresponding to the plugin process that | 95 // Returns the plugin process host corresponding to the plugin process that |
| 117 // has been started by this service. This will start a process to host the | 96 // has been started by this service. This will start a process to host the |
| 118 // 'plugin_path' if needed. If the process fails to start, the return value | 97 // 'plugin_path' if needed. If the process fails to start, the return value |
| 119 // is NULL. Must be called on the IO thread. | 98 // is NULL. Must be called on the IO thread. |
| 120 PluginProcessHost* FindOrStartNpapiPluginProcess( | |
| 121 int render_process_id, const base::FilePath& plugin_path); | |
| 122 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess( | 99 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess( |
| 123 int render_process_id, | 100 int render_process_id, |
| 124 const base::FilePath& plugin_path, | 101 const base::FilePath& plugin_path, |
| 125 const base::FilePath& profile_data_directory); | 102 const base::FilePath& profile_data_directory); |
| 126 PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess( | 103 PpapiPluginProcessHost* FindOrStartPpapiBrokerProcess( |
| 127 int render_process_id, const base::FilePath& plugin_path); | 104 int render_process_id, const base::FilePath& plugin_path); |
| 128 | 105 |
| 129 // Opens a channel to a plugin process for the given mime type, starting | 106 // Opens a channel to a plugin process for the given mime type, starting |
| 130 // a new plugin process if necessary. This must be called on the IO thread | 107 // a new plugin process if necessary. This must be called on the IO thread |
| 131 // or else a deadlock can occur. | 108 // or else a deadlock can occur. |
| 132 void OpenChannelToNpapiPlugin(int render_process_id, | |
| 133 int render_frame_id, | |
| 134 const GURL& url, | |
| 135 const GURL& page_url, | |
| 136 const std::string& mime_type, | |
| 137 PluginProcessHost::Client* client); | |
| 138 void OpenChannelToPpapiPlugin(int render_process_id, | 109 void OpenChannelToPpapiPlugin(int render_process_id, |
| 139 const base::FilePath& plugin_path, | 110 const base::FilePath& plugin_path, |
| 140 const base::FilePath& profile_data_directory, | 111 const base::FilePath& profile_data_directory, |
| 141 PpapiPluginProcessHost::PluginClient* client); | 112 PpapiPluginProcessHost::PluginClient* client); |
| 142 void OpenChannelToPpapiBroker(int render_process_id, | 113 void OpenChannelToPpapiBroker(int render_process_id, |
| 143 const base::FilePath& path, | 114 const base::FilePath& path, |
| 144 PpapiPluginProcessHost::BrokerClient* client); | 115 PpapiPluginProcessHost::BrokerClient* client); |
| 145 | 116 |
| 146 // Cancels opening a channel to a NPAPI plugin. | |
| 147 void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client); | |
| 148 | |
| 149 // Used to monitor plugin stability. | 117 // Used to monitor plugin stability. |
| 150 void RegisterPluginCrash(const base::FilePath& plugin_path); | 118 void RegisterPluginCrash(const base::FilePath& plugin_path); |
| 151 | 119 |
| 152 private: | 120 private: |
| 153 friend struct base::DefaultSingletonTraits<PluginServiceImpl>; | 121 friend struct base::DefaultSingletonTraits<PluginServiceImpl>; |
| 154 | 122 |
| 155 // Creates the PluginServiceImpl object, but doesn't actually build the plugin | 123 // Creates the PluginServiceImpl object, but doesn't actually build the plugin |
| 156 // list yet. It's generated lazily. | 124 // list yet. It's generated lazily. |
| 157 PluginServiceImpl(); | 125 PluginServiceImpl(); |
| 158 ~PluginServiceImpl() override; | 126 ~PluginServiceImpl() override; |
| 159 | 127 |
| 160 #if defined(OS_WIN) | 128 #if defined(OS_WIN) |
| 161 void OnKeyChanged(base::win::RegKey* key); | 129 void OnKeyChanged(base::win::RegKey* key); |
| 162 #endif | 130 #endif |
| 163 | 131 |
| 164 // Returns the plugin process host corresponding to the plugin process that | 132 // Returns the plugin process host corresponding to the plugin process that |
| 165 // has been started by this service. Returns NULL if no process has been | 133 // has been started by this service. Returns NULL if no process has been |
| 166 // started. | 134 // started. |
| 167 PluginProcessHost* FindNpapiPluginProcess(const base::FilePath& plugin_path); | |
| 168 PpapiPluginProcessHost* FindPpapiPluginProcess( | 135 PpapiPluginProcessHost* FindPpapiPluginProcess( |
| 169 const base::FilePath& plugin_path, | 136 const base::FilePath& plugin_path, |
| 170 const base::FilePath& profile_data_directory); | 137 const base::FilePath& profile_data_directory); |
| 171 PpapiPluginProcessHost* FindPpapiBrokerProcess( | 138 PpapiPluginProcessHost* FindPpapiBrokerProcess( |
| 172 const base::FilePath& broker_path); | 139 const base::FilePath& broker_path); |
| 173 | 140 |
| 174 void RegisterPepperPlugins(); | 141 void RegisterPepperPlugins(); |
| 175 | 142 |
| 176 // Run on the blocking pool to load the plugins synchronously. | 143 // Run on the blocking pool to load the plugins synchronously. |
| 177 void GetPluginsInternal(base::SingleThreadTaskRunner* target_task_runner, | 144 void GetPluginsInternal(base::SingleThreadTaskRunner* target_task_runner, |
| 178 const GetPluginsCallback& callback); | 145 const GetPluginsCallback& callback); |
| 179 | 146 |
| 180 #if defined(OS_POSIX) | |
| 181 void GetPluginsOnIOThread(base::SingleThreadTaskRunner* target_task_runner, | |
| 182 const GetPluginsCallback& callback); | |
| 183 #endif | |
| 184 | |
| 185 // Binding directly to GetAllowedPluginForOpenChannelToPlugin() isn't possible | |
| 186 // because more arity is needed <http://crbug.com/98542>. This just forwards. | |
| 187 void ForwardGetAllowedPluginForOpenChannelToPlugin( | |
| 188 const PluginServiceFilterParams& params, | |
| 189 const GURL& url, | |
| 190 const std::string& mime_type, | |
| 191 PluginProcessHost::Client* client, | |
| 192 const std::vector<WebPluginInfo>&); | |
| 193 // Helper so we can do the plugin lookup on the FILE thread. | |
| 194 void GetAllowedPluginForOpenChannelToPlugin( | |
| 195 int render_process_id, | |
| 196 int render_frame_id, | |
| 197 const GURL& url, | |
| 198 const GURL& page_url, | |
| 199 const std::string& mime_type, | |
| 200 PluginProcessHost::Client* client, | |
| 201 ResourceContext* resource_context); | |
| 202 | |
| 203 // Helper so we can finish opening the channel after looking up the | |
| 204 // plugin. | |
| 205 void FinishOpenChannelToPlugin(int render_process_id, | |
| 206 const base::FilePath& plugin_path, | |
| 207 PluginProcessHost::Client* client); | |
| 208 | |
| 209 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) | |
| 210 // Registers a new FilePathWatcher for a given path. | |
| 211 static void RegisterFilePathWatcher(base::FilePathWatcher* watcher, | |
| 212 const base::FilePath& path); | |
| 213 #endif | |
| 214 | |
| 215 #if defined(OS_WIN) | |
| 216 // Registry keys for getting notifications when new plugins are installed. | |
| 217 base::win::RegKey hkcu_key_; | |
| 218 base::win::RegKey hklm_key_; | |
| 219 #endif | |
| 220 | |
| 221 bool npapi_plugins_enabled_; | |
| 222 | |
| 223 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) | |
| 224 ScopedVector<base::FilePathWatcher> file_watchers_; | |
| 225 #endif | |
| 226 | |
| 227 std::vector<PepperPluginInfo> ppapi_plugins_; | 147 std::vector<PepperPluginInfo> ppapi_plugins_; |
| 228 | 148 |
| 229 // Weak pointer; outlives us. | 149 // Weak pointer; outlives us. |
| 230 PluginServiceFilter* filter_; | 150 PluginServiceFilter* filter_; |
| 231 | 151 |
| 232 std::set<PluginProcessHost::Client*> pending_plugin_clients_; | |
| 233 | |
| 234 // Used to sequentialize loading plugins from disk. | 152 // Used to sequentialize loading plugins from disk. |
| 235 base::SequencedWorkerPool::SequenceToken plugin_list_token_; | 153 base::SequencedWorkerPool::SequenceToken plugin_list_token_; |
| 236 | 154 |
| 237 #if defined(OS_POSIX) | |
| 238 scoped_refptr<PluginLoaderPosix> plugin_loader_; | |
| 239 #endif | |
| 240 | |
| 241 // Used to detect if a given plugin is crashing over and over. | 155 // Used to detect if a given plugin is crashing over and over. |
| 242 std::map<base::FilePath, std::vector<base::Time> > crash_times_; | 156 std::map<base::FilePath, std::vector<base::Time> > crash_times_; |
| 243 | 157 |
| 244 DISALLOW_COPY_AND_ASSIGN(PluginServiceImpl); | 158 DISALLOW_COPY_AND_ASSIGN(PluginServiceImpl); |
| 245 }; | 159 }; |
| 246 | 160 |
| 247 } // namespace content | 161 } // namespace content |
| 248 | 162 |
| 249 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ | 163 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_IMPL_H_ |
| OLD | NEW |