[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // This class responds to requests from renderers for the list of plugins, and |
| 6 | // also a proxy object for plugin instances. |
| 7 | |
| 8 | #ifndef CONTENT_BROWSER_PLUGIN_SERVICE_H_ |
| 9 | #define CONTENT_BROWSER_PLUGIN_SERVICE_H_ |
| 10 | #pragma once |
| 11 | |
| 12 | #include <string> |
[email protected] | 6b14feb | 2011-08-16 11:22:56 | [diff] [blame] | 13 | #include <vector> |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 14 | |
| 15 | #include "base/basictypes.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 16 | #include "base/memory/scoped_vector.h" |
| 17 | #include "base/memory/singleton.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 18 | #include "base/synchronization/waitable_event_watcher.h" |
| 19 | #include "build/build_config.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 20 | #include "content/browser/plugin_process_host.h" |
| 21 | #include "content/browser/ppapi_plugin_process_host.h" |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 22 | #include "content/browser/ppapi_broker_process_host.h" |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 23 | #include "content/common/content_export.h" |
[email protected] | 7f070d4 | 2011-03-09 20:25:32 | [diff] [blame] | 24 | #include "content/common/notification_observer.h" |
| 25 | #include "content/common/notification_registrar.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 26 | #include "googleurl/src/gurl.h" |
| 27 | #include "ipc/ipc_channel_handle.h" |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 28 | #include "webkit/plugins/webplugininfo.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 29 | |
| 30 | #if defined(OS_WIN) |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 31 | #include "base/memory/scoped_ptr.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 32 | #include "base/win/registry.h" |
| 33 | #endif |
| 34 | |
[email protected] | e63c4d7 | 2011-05-31 22:38:29 | [diff] [blame] | 35 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 36 | #include "base/files/file_path_watcher.h" |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 37 | #endif |
| 38 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 39 | struct PepperPluginInfo; |
| 40 | class PluginDirWatcherDelegate; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 41 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 42 | namespace content { |
| 43 | class ResourceContext; |
| 44 | class PluginServiceFilter; |
| 45 | } |
| 46 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 47 | // This must be created on the main thread but it's only called on the IO/file |
| 48 | // thread. |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 49 | class CONTENT_EXPORT PluginService |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 50 | : public base::WaitableEventWatcher::Delegate, |
| 51 | public NotificationObserver { |
| 52 | public: |
| 53 | struct OverriddenPlugin { |
| 54 | int render_process_id; |
| 55 | int render_view_id; |
[email protected] | 6b14feb | 2011-08-16 11:22:56 | [diff] [blame] | 56 | GURL url; // If empty, the override applies to all urls in render_view. |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 57 | webkit::WebPluginInfo plugin; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 58 | }; |
| 59 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 60 | // Returns the PluginService singleton. |
| 61 | static PluginService* GetInstance(); |
| 62 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 63 | // Starts watching for changes in the list of installed plug-ins. |
| 64 | void StartWatchingPlugins(); |
| 65 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 66 | // Gets the browser's UI locale. |
| 67 | const std::string& GetUILocale(); |
| 68 | |
| 69 | // Returns the plugin process host corresponding to the plugin process that |
| 70 | // has been started by this service. Returns NULL if no process has been |
| 71 | // started. |
| 72 | PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path); |
| 73 | PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 74 | PpapiBrokerProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 75 | |
| 76 | // Returns the plugin process host corresponding to the plugin process that |
| 77 | // has been started by this service. This will start a process to host the |
| 78 | // 'plugin_path' if needed. If the process fails to start, the return value |
| 79 | // is NULL. Must be called on the IO thread. |
| 80 | PluginProcessHost* FindOrStartNpapiPluginProcess( |
| 81 | const FilePath& plugin_path); |
| 82 | PpapiPluginProcessHost* FindOrStartPpapiPluginProcess( |
[email protected] | d259a8e | 2011-05-18 22:31:09 | [diff] [blame] | 83 | const FilePath& plugin_path, |
| 84 | PpapiPluginProcessHost::Client* client); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 85 | PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess( |
| 86 | const FilePath& plugin_path); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 87 | |
| 88 | // Opens a channel to a plugin process for the given mime type, starting |
| 89 | // a new plugin process if necessary. This must be called on the IO thread |
| 90 | // or else a deadlock can occur. |
| 91 | void OpenChannelToNpapiPlugin(int render_process_id, |
| 92 | int render_view_id, |
| 93 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 94 | const GURL& page_url, |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 95 | const std::string& mime_type, |
| 96 | PluginProcessHost::Client* client); |
| 97 | void OpenChannelToPpapiPlugin(const FilePath& path, |
| 98 | PpapiPluginProcessHost::Client* client); |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 99 | void OpenChannelToPpapiBroker(const FilePath& path, |
| 100 | PpapiBrokerProcessHost::Client* client); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 101 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 102 | // Cancels opening a channel to a NPAPI plugin. |
| 103 | void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client); |
| 104 | |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 105 | // Gets the plugin in the list of plugins that matches the given url and mime |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 106 | // type. Must be called on the FILE thread if |use_stale| is NULL. |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 107 | bool GetPluginInfo(int render_process_id, |
| 108 | int render_view_id, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 109 | const content::ResourceContext& context, |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 110 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 111 | const GURL& page_url, |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 112 | const std::string& mime_type, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 113 | bool allow_wildcard, |
| 114 | bool* use_stale, |
[email protected] | 91d9f3d | 2011-08-14 05:24:44 | [diff] [blame] | 115 | webkit::WebPluginInfo* info, |
[email protected] | 11e1c18 | 2011-05-17 20:26:27 | [diff] [blame] | 116 | std::string* actual_mime_type); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 117 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 118 | // Returns a list of all plug-ins available to the resource context. Must be |
| 119 | // called on the FILE thread. |
| 120 | void GetPlugins(const content::ResourceContext& context, |
| 121 | std::vector<webkit::WebPluginInfo>* plugins); |
[email protected] | 2de30759 | 2011-04-05 21:16:58 | [diff] [blame] | 122 | |
| 123 | // Tells all the renderer processes to throw away their cache of the plugin |
| 124 | // list, and optionally also reload all the pages with plugins. |
| 125 | // NOTE: can only be called on the UI thread. |
| 126 | static void PurgePluginListCache(bool reload_pages); |
| 127 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 128 | void set_filter(content::PluginServiceFilter* filter) { |
| 129 | filter_ = filter; |
| 130 | } |
| 131 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 132 | private: |
| 133 | friend struct DefaultSingletonTraits<PluginService>; |
| 134 | |
| 135 | // Creates the PluginService object, but doesn't actually build the plugin |
| 136 | // list yet. It's generated lazily. |
| 137 | PluginService(); |
[email protected] | 3690ebe0 | 2011-05-25 09:08:19 | [diff] [blame] | 138 | virtual ~PluginService(); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 139 | |
| 140 | // base::WaitableEventWatcher::Delegate implementation. |
| 141 | virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); |
| 142 | |
| 143 | // NotificationObserver implementation |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 144 | virtual void Observe(int type, const NotificationSource& source, |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 145 | const NotificationDetails& details); |
| 146 | |
| 147 | void RegisterPepperPlugins(); |
| 148 | |
[email protected] | eb415bf0e | 2011-04-14 02:45:42 | [diff] [blame] | 149 | PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); |
| 150 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 151 | // Helper so we can do the plugin lookup on the FILE thread. |
| 152 | void GetAllowedPluginForOpenChannelToPlugin( |
| 153 | int render_process_id, |
| 154 | int render_view_id, |
| 155 | const GURL& url, |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 156 | const GURL& page_url, |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 157 | const std::string& mime_type, |
| 158 | PluginProcessHost::Client* client); |
| 159 | |
| 160 | // Helper so we can finish opening the channel after looking up the |
| 161 | // plugin. |
| 162 | void FinishOpenChannelToPlugin( |
| 163 | const FilePath& plugin_path, |
| 164 | PluginProcessHost::Client* client); |
| 165 | |
[email protected] | e63c4d7 | 2011-05-31 22:38:29 | [diff] [blame] | 166 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 167 | // Registers a new FilePathWatcher for a given path. |
| 168 | static void RegisterFilePathWatcher( |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 169 | base::files::FilePathWatcher* watcher, |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 170 | const FilePath& path, |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 171 | base::files::FilePathWatcher::Delegate* delegate); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 172 | #endif |
| 173 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 174 | // The browser's UI locale. |
| 175 | const std::string ui_locale_; |
| 176 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 177 | NotificationRegistrar registrar_; |
| 178 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 179 | #if defined(OS_WIN) |
| 180 | // Registry keys for getting notifications when new plugins are installed. |
| 181 | base::win::RegKey hkcu_key_; |
| 182 | base::win::RegKey hklm_key_; |
| 183 | scoped_ptr<base::WaitableEvent> hkcu_event_; |
| 184 | scoped_ptr<base::WaitableEvent> hklm_event_; |
| 185 | base::WaitableEventWatcher hkcu_watcher_; |
| 186 | base::WaitableEventWatcher hklm_watcher_; |
| 187 | #endif |
| 188 | |
[email protected] | e63c4d7 | 2011-05-31 22:38:29 | [diff] [blame] | 189 | #if defined(OS_POSIX) && !defined(OS_MACOSX) |
[email protected] | 493c800 | 2011-04-14 16:56:01 | [diff] [blame] | 190 | ScopedVector<base::files::FilePathWatcher> file_watchers_; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 191 | scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; |
| 192 | #endif |
| 193 | |
| 194 | std::vector<PepperPluginInfo> ppapi_plugins_; |
| 195 | |
[email protected] | dfba876 | 2011-09-02 12:49:54 | [diff] [blame] | 196 | // Weak pointer; outlives us. |
| 197 | content::PluginServiceFilter* filter_; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 198 | |
[email protected] | 4befe759 | 2011-09-14 22:49:09 | [diff] [blame] | 199 | std::set<PluginProcessHost::Client*> pending_plugin_clients_; |
| 200 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 201 | DISALLOW_COPY_AND_ASSIGN(PluginService); |
| 202 | }; |
| 203 | |
| 204 | DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); |
| 205 | |
| 206 | #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ |