Chromium Code Reviews| 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 // 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_H_ | 8 #ifndef CONTENT_BROWSER_PLUGIN_SERVICE_H_ |
| 9 #define CONTENT_BROWSER_PLUGIN_SERVICE_H_ | 9 #define CONTENT_BROWSER_PLUGIN_SERVICE_H_ |
| 10 #pragma once | 10 #pragma once |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/file_path.h" | |
| 16 #include "base/hash_tables.h" | |
| 17 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 18 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 19 #include "base/synchronization/lock.h" | |
| 20 #include "base/synchronization/waitable_event_watcher.h" | 17 #include "base/synchronization/waitable_event_watcher.h" |
| 21 #include "build/build_config.h" | 18 #include "build/build_config.h" |
| 22 #include "content/browser/plugin_process_host.h" | 19 #include "content/browser/plugin_process_host.h" |
| 23 #include "content/browser/ppapi_plugin_process_host.h" | 20 #include "content/browser/ppapi_plugin_process_host.h" |
| 24 #include "content/browser/ppapi_broker_process_host.h" | 21 #include "content/browser/ppapi_broker_process_host.h" |
| 25 #include "content/common/notification_observer.h" | 22 #include "content/common/notification_observer.h" |
| 26 #include "content/common/notification_registrar.h" | 23 #include "content/common/notification_registrar.h" |
| 27 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
| 28 #include "ipc/ipc_channel_handle.h" | 25 #include "ipc/ipc_channel_handle.h" |
| 29 #include "webkit/plugins/npapi/webplugininfo.h" | 26 #include "webkit/plugins/npapi/webplugininfo.h" |
| 30 | 27 |
| 31 #if defined(OS_WIN) | 28 #if defined(OS_WIN) |
| 32 #include "base/memory/scoped_ptr.h" | 29 #include "base/memory/scoped_ptr.h" |
| 33 #include "base/win/registry.h" | 30 #include "base/win/registry.h" |
| 34 #endif | 31 #endif |
| 35 | 32 |
| 36 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 33 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 37 #include "base/files/file_path_watcher.h" | 34 #include "base/files/file_path_watcher.h" |
| 38 #endif | 35 #endif |
| 39 | 36 |
| 40 struct PepperPluginInfo; | 37 struct PepperPluginInfo; |
| 41 class PluginDirWatcherDelegate; | 38 class PluginDirWatcherDelegate; |
| 42 | 39 |
| 43 // This must be created on the main thread but it's only called on the IO/file | 40 // This must be created on the main thread but it's only called on the IO/file |
| 44 // thread. | 41 // thread. |
| 45 class PluginService | 42 class PluginService |
| 46 : public base::WaitableEventWatcher::Delegate, | 43 : public base::WaitableEventWatcher::Delegate, |
| 47 public NotificationObserver { | 44 public NotificationObserver { |
| 48 public: | 45 public: |
| 49 struct OverriddenPlugin { | 46 // Callback class to let the client filter the list of all installed plug-ins. |
| 50 int render_process_id; | 47 // This class is called on the FILE thread. |
| 51 int render_view_id; | 48 class Filter { |
|
jam
2011/08/01 03:25:44
please put this in a separate file. per the style
Bernhard Bauer
2011/08/01 16:06:12
Done (BTW, is there a rule for when we put content
jam
2011/08/01 17:25:04
everything in content should be in the content nam
Bernhard Bauer
2011/08/01 18:07:39
OK, done.
| |
| 52 GURL url; | 49 public: |
| 53 webkit::npapi::WebPluginInfo plugin; | 50 virtual ~Filter() {} |
| 51 // Whether to use |plugin|. The client can return false to disallow the | |
| 52 // plugin, or return true and optionally change the passed in plugin. | |
| 53 virtual bool ShouldUsePlugin(webkit::npapi::WebPluginInfo* plugin) = 0; | |
| 54 }; | 54 }; |
| 55 | 55 |
| 56 // Returns the PluginService singleton. | 56 // Returns the PluginService singleton. |
| 57 static PluginService* GetInstance(); | 57 static PluginService* GetInstance(); |
| 58 | 58 |
| 59 // Gets the browser's UI locale. | 59 // Gets the browser's UI locale. |
| 60 const std::string& GetUILocale(); | 60 const std::string& GetUILocale(); |
| 61 | 61 |
| 62 // Returns the plugin process host corresponding to the plugin process that | 62 // Returns the plugin process host corresponding to the plugin process that |
| 63 // has been started by this service. Returns NULL if no process has been | 63 // has been started by this service. Returns NULL if no process has been |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 77 PpapiPluginProcessHost::Client* client); | 77 PpapiPluginProcessHost::Client* client); |
| 78 PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess( | 78 PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess( |
| 79 const FilePath& plugin_path); | 79 const FilePath& plugin_path); |
| 80 | 80 |
| 81 // Opens a channel to a plugin process for the given mime type, starting | 81 // Opens a channel to a plugin process for the given mime type, starting |
| 82 // a new plugin process if necessary. This must be called on the IO thread | 82 // a new plugin process if necessary. This must be called on the IO thread |
| 83 // or else a deadlock can occur. | 83 // or else a deadlock can occur. |
| 84 void OpenChannelToNpapiPlugin(int render_process_id, | 84 void OpenChannelToNpapiPlugin(int render_process_id, |
| 85 int render_view_id, | 85 int render_view_id, |
| 86 const GURL& url, | 86 const GURL& url, |
| 87 const GURL& policy_url, | |
| 87 const std::string& mime_type, | 88 const std::string& mime_type, |
| 88 PluginProcessHost::Client* client); | 89 PluginProcessHost::Client* client); |
| 89 void OpenChannelToPpapiPlugin(const FilePath& path, | 90 void OpenChannelToPpapiPlugin(const FilePath& path, |
| 90 PpapiPluginProcessHost::Client* client); | 91 PpapiPluginProcessHost::Client* client); |
| 91 void OpenChannelToPpapiBroker(const FilePath& path, | 92 void OpenChannelToPpapiBroker(const FilePath& path, |
| 92 PpapiBrokerProcessHost::Client* client); | 93 PpapiBrokerProcessHost::Client* client); |
| 93 | 94 |
| 94 // Gets the plugin in the list of plugins that matches the given url and mime | 95 // Gets the plugin in the list of plugins that matches the given url and mime |
| 95 // type. Must be called on the FILE thread. | 96 // type. Must be called on the FILE thread. Takes ownership of |filter|. |
| 96 bool GetPluginInfo(int render_process_id, | 97 bool GetPluginInfo(const GURL& url, |
| 97 int render_view_id, | |
| 98 const GURL& url, | |
| 99 const std::string& mime_type, | 98 const std::string& mime_type, |
| 99 bool allow_wildcard, | |
| 100 Filter* filter, | |
| 101 bool* use_stale, | |
| 100 webkit::npapi::WebPluginInfo* info, | 102 webkit::npapi::WebPluginInfo* info, |
| 101 std::string* actual_mime_type); | 103 std::string* actual_mime_type); |
| 102 | 104 |
| 103 // Safe to be called from any thread. | 105 // Returns a list of installed plug-ins, filtering them with |filter|. |
| 104 void OverridePluginForTab(const OverriddenPlugin& plugin); | 106 // Must be called on the FILE thread. Takes ownership of |filter|. |
| 105 | 107 void GetPlugins(Filter* filter, |
| 106 // Restricts the given plugin to the the scheme and host of the given url. | 108 std::vector<webkit::npapi::WebPluginInfo>* plugins); |
| 107 // Call with an empty url to reset this. | |
| 108 // Can be called on any thread. | |
| 109 void RestrictPluginToUrl(const FilePath& plugin_path, const GURL& url); | |
| 110 | |
| 111 // Returns true if the given plugin is allowed to be used by a page with | |
| 112 // the given URL. | |
| 113 // Can be called on any thread. | |
| 114 bool PluginAllowedForURL(const FilePath& plugin_path, const GURL& url); | |
| 115 | 109 |
| 116 // Tells all the renderer processes to throw away their cache of the plugin | 110 // Tells all the renderer processes to throw away their cache of the plugin |
| 117 // list, and optionally also reload all the pages with plugins. | 111 // list, and optionally also reload all the pages with plugins. |
| 118 // NOTE: can only be called on the UI thread. | 112 // NOTE: can only be called on the UI thread. |
| 119 static void PurgePluginListCache(bool reload_pages); | 113 static void PurgePluginListCache(bool reload_pages); |
| 120 | 114 |
| 121 private: | 115 private: |
| 122 friend struct DefaultSingletonTraits<PluginService>; | 116 friend struct DefaultSingletonTraits<PluginService>; |
| 123 | 117 |
| 124 // Creates the PluginService object, but doesn't actually build the plugin | 118 // Creates the PluginService object, but doesn't actually build the plugin |
| 125 // list yet. It's generated lazily. | 119 // list yet. It's generated lazily. |
| 126 PluginService(); | 120 PluginService(); |
| 127 virtual ~PluginService(); | 121 virtual ~PluginService(); |
| 128 | 122 |
| 129 // base::WaitableEventWatcher::Delegate implementation. | 123 // base::WaitableEventWatcher::Delegate implementation. |
| 130 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); | 124 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); |
| 131 | 125 |
| 132 // NotificationObserver implementation | 126 // NotificationObserver implementation |
| 133 virtual void Observe(int type, const NotificationSource& source, | 127 virtual void Observe(int type, const NotificationSource& source, |
| 134 const NotificationDetails& details); | 128 const NotificationDetails& details); |
| 135 | 129 |
| 136 void RegisterPepperPlugins(); | 130 void RegisterPepperPlugins(); |
| 137 | 131 |
| 138 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); | 132 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); |
| 139 | 133 |
| 140 // Helper so we can do the plugin lookup on the FILE thread. | 134 // Helper so we can do the plugin lookup on the FILE thread. |
| 141 void GetAllowedPluginForOpenChannelToPlugin( | 135 void GetAllowedPluginForOpenChannelToPlugin( |
| 142 int render_process_id, | |
| 143 int render_view_id, | |
| 144 const GURL& url, | 136 const GURL& url, |
| 145 const std::string& mime_type, | 137 const std::string& mime_type, |
| 138 Filter* filter, | |
| 146 PluginProcessHost::Client* client); | 139 PluginProcessHost::Client* client); |
| 147 | 140 |
| 148 // Helper so we can finish opening the channel after looking up the | 141 // Helper so we can finish opening the channel after looking up the |
| 149 // plugin. | 142 // plugin. |
| 150 void FinishOpenChannelToPlugin( | 143 void FinishOpenChannelToPlugin( |
| 151 const FilePath& plugin_path, | 144 const FilePath& plugin_path, |
| 152 PluginProcessHost::Client* client); | 145 PluginProcessHost::Client* client); |
| 153 | 146 |
| 154 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 147 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 155 // Registers a new FilePathWatcher for a given path. | 148 // Registers a new FilePathWatcher for a given path. |
| 156 static void RegisterFilePathWatcher( | 149 static void RegisterFilePathWatcher( |
| 157 base::files::FilePathWatcher* watcher, | 150 base::files::FilePathWatcher* watcher, |
| 158 const FilePath& path, | 151 const FilePath& path, |
| 159 base::files::FilePathWatcher::Delegate* delegate); | 152 base::files::FilePathWatcher::Delegate* delegate); |
| 160 #endif | 153 #endif |
| 161 | 154 |
| 162 // The browser's UI locale. | 155 // The browser's UI locale. |
| 163 const std::string ui_locale_; | 156 const std::string ui_locale_; |
| 164 | 157 |
| 165 // Map of plugin paths to the origin they are restricted to. | |
| 166 base::Lock restricted_plugin_lock_; // Guards access to restricted_plugin_. | |
| 167 typedef base::hash_map<FilePath, GURL> RestrictedPluginMap; | |
| 168 RestrictedPluginMap restricted_plugin_; | |
| 169 | |
| 170 NotificationRegistrar registrar_; | 158 NotificationRegistrar registrar_; |
| 171 | 159 |
| 172 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
| 173 // Registry keys for getting notifications when new plugins are installed. | 161 // Registry keys for getting notifications when new plugins are installed. |
| 174 base::win::RegKey hkcu_key_; | 162 base::win::RegKey hkcu_key_; |
| 175 base::win::RegKey hklm_key_; | 163 base::win::RegKey hklm_key_; |
| 176 scoped_ptr<base::WaitableEvent> hkcu_event_; | 164 scoped_ptr<base::WaitableEvent> hkcu_event_; |
| 177 scoped_ptr<base::WaitableEvent> hklm_event_; | 165 scoped_ptr<base::WaitableEvent> hklm_event_; |
| 178 base::WaitableEventWatcher hkcu_watcher_; | 166 base::WaitableEventWatcher hkcu_watcher_; |
| 179 base::WaitableEventWatcher hklm_watcher_; | 167 base::WaitableEventWatcher hklm_watcher_; |
| 180 #endif | 168 #endif |
| 181 | 169 |
| 182 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 170 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 183 ScopedVector<base::files::FilePathWatcher> file_watchers_; | 171 ScopedVector<base::files::FilePathWatcher> file_watchers_; |
| 184 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; | 172 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; |
| 185 #endif | 173 #endif |
| 186 | 174 |
| 187 std::vector<PepperPluginInfo> ppapi_plugins_; | 175 std::vector<PepperPluginInfo> ppapi_plugins_; |
| 188 | 176 |
| 189 std::vector<OverriddenPlugin> overridden_plugins_; | |
| 190 base::Lock overridden_plugins_lock_; | |
| 191 | |
| 192 DISALLOW_COPY_AND_ASSIGN(PluginService); | 177 DISALLOW_COPY_AND_ASSIGN(PluginService); |
| 193 }; | 178 }; |
| 194 | 179 |
| 195 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); | 180 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); |
| 196 | 181 |
| 197 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ | 182 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ |
| OLD | NEW |