| 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 |
| 40 namespace content { |
| 41 class ResourceContext; |
| 42 class PluginServiceFilter; |
| 43 } |
| 44 |
| 43 // This must be created on the main thread but it's only called on the IO/file | 45 // This must be created on the main thread but it's only called on the IO/file |
| 44 // thread. | 46 // thread. |
| 45 class PluginService | 47 class PluginService |
| 46 : public base::WaitableEventWatcher::Delegate, | 48 : public base::WaitableEventWatcher::Delegate, |
| 47 public NotificationObserver { | 49 public NotificationObserver { |
| 48 public: | 50 public: |
| 49 struct OverriddenPlugin { | |
| 50 int render_process_id; | |
| 51 int render_view_id; | |
| 52 GURL url; | |
| 53 webkit::npapi::WebPluginInfo plugin; | |
| 54 }; | |
| 55 | |
| 56 // Returns the PluginService singleton. | 51 // Returns the PluginService singleton. |
| 57 static PluginService* GetInstance(); | 52 static PluginService* GetInstance(); |
| 58 | 53 |
| 59 // Gets the browser's UI locale. | 54 // Gets the browser's UI locale. |
| 60 const std::string& GetUILocale(); | 55 const std::string& GetUILocale(); |
| 61 | 56 |
| 62 // Returns the plugin process host corresponding to the plugin process that | 57 // 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 | 58 // has been started by this service. Returns NULL if no process has been |
| 64 // started. | 59 // started. |
| 65 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path); | 60 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 77 PpapiPluginProcessHost::Client* client); | 72 PpapiPluginProcessHost::Client* client); |
| 78 PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess( | 73 PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess( |
| 79 const FilePath& plugin_path); | 74 const FilePath& plugin_path); |
| 80 | 75 |
| 81 // Opens a channel to a plugin process for the given mime type, starting | 76 // 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 | 77 // a new plugin process if necessary. This must be called on the IO thread |
| 83 // or else a deadlock can occur. | 78 // or else a deadlock can occur. |
| 84 void OpenChannelToNpapiPlugin(int render_process_id, | 79 void OpenChannelToNpapiPlugin(int render_process_id, |
| 85 int render_view_id, | 80 int render_view_id, |
| 86 const GURL& url, | 81 const GURL& url, |
| 82 const GURL& page_url, |
| 87 const std::string& mime_type, | 83 const std::string& mime_type, |
| 88 PluginProcessHost::Client* client); | 84 PluginProcessHost::Client* client); |
| 89 void OpenChannelToPpapiPlugin(const FilePath& path, | 85 void OpenChannelToPpapiPlugin(const FilePath& path, |
| 90 PpapiPluginProcessHost::Client* client); | 86 PpapiPluginProcessHost::Client* client); |
| 91 void OpenChannelToPpapiBroker(const FilePath& path, | 87 void OpenChannelToPpapiBroker(const FilePath& path, |
| 92 PpapiBrokerProcessHost::Client* client); | 88 PpapiBrokerProcessHost::Client* client); |
| 93 | 89 |
| 94 // Gets the plugin in the list of plugins that matches the given url and mime | 90 // Gets the plugin in the list of plugins that matches the given url and mime |
| 95 // type. Must be called on the FILE thread. | 91 // type. Must be called on the FILE thread if |use_stale| is NULL. |
| 96 bool GetPluginInfo(int render_process_id, | 92 bool GetPluginInfo(int render_process_id, |
| 97 int render_view_id, | 93 int render_view_id, |
| 94 const content::ResourceContext& context, |
| 98 const GURL& url, | 95 const GURL& url, |
| 96 const GURL& page_url, |
| 99 const std::string& mime_type, | 97 const std::string& mime_type, |
| 98 bool allow_wildcard, |
| 99 bool* use_stale, |
| 100 webkit::npapi::WebPluginInfo* info, | 100 webkit::npapi::WebPluginInfo* info, |
| 101 std::string* actual_mime_type); | 101 std::string* actual_mime_type); |
| 102 | 102 |
| 103 // Safe to be called from any thread. | 103 // Returns a list of all plug-ins available to the resource context. Must be |
| 104 void OverridePluginForTab(const OverriddenPlugin& plugin); | 104 // called on the FILE thread. |
| 105 | 105 void GetPlugins(const content::ResourceContext& context, |
| 106 // Restricts the given plugin to the the scheme and host of the given url. | 106 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 | 107 |
| 116 // Tells all the renderer processes to throw away their cache of the plugin | 108 // Tells all the renderer processes to throw away their cache of the plugin |
| 117 // list, and optionally also reload all the pages with plugins. | 109 // list, and optionally also reload all the pages with plugins. |
| 118 // NOTE: can only be called on the UI thread. | 110 // NOTE: can only be called on the UI thread. |
| 119 static void PurgePluginListCache(bool reload_pages); | 111 static void PurgePluginListCache(bool reload_pages); |
| 120 | 112 |
| 113 void set_filter(content::PluginServiceFilter* filter) { |
| 114 filter_ = filter; |
| 115 } |
| 116 |
| 121 private: | 117 private: |
| 122 friend struct DefaultSingletonTraits<PluginService>; | 118 friend struct DefaultSingletonTraits<PluginService>; |
| 123 | 119 |
| 124 // Creates the PluginService object, but doesn't actually build the plugin | 120 // Creates the PluginService object, but doesn't actually build the plugin |
| 125 // list yet. It's generated lazily. | 121 // list yet. It's generated lazily. |
| 126 PluginService(); | 122 PluginService(); |
| 127 virtual ~PluginService(); | 123 virtual ~PluginService(); |
| 128 | 124 |
| 129 // base::WaitableEventWatcher::Delegate implementation. | 125 // base::WaitableEventWatcher::Delegate implementation. |
| 130 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); | 126 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); |
| 131 | 127 |
| 132 // NotificationObserver implementation | 128 // NotificationObserver implementation |
| 133 virtual void Observe(int type, const NotificationSource& source, | 129 virtual void Observe(int type, const NotificationSource& source, |
| 134 const NotificationDetails& details); | 130 const NotificationDetails& details); |
| 135 | 131 |
| 136 void RegisterPepperPlugins(); | 132 void RegisterPepperPlugins(); |
| 137 | 133 |
| 138 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); | 134 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); |
| 139 | 135 |
| 140 // Helper so we can do the plugin lookup on the FILE thread. | 136 // Helper so we can do the plugin lookup on the FILE thread. |
| 141 void GetAllowedPluginForOpenChannelToPlugin( | 137 void GetAllowedPluginForOpenChannelToPlugin( |
| 142 int render_process_id, | 138 int render_process_id, |
| 143 int render_view_id, | 139 int render_view_id, |
| 144 const GURL& url, | 140 const GURL& url, |
| 141 const GURL& page_url, |
| 145 const std::string& mime_type, | 142 const std::string& mime_type, |
| 146 PluginProcessHost::Client* client); | 143 PluginProcessHost::Client* client); |
| 147 | 144 |
| 148 // Helper so we can finish opening the channel after looking up the | 145 // Helper so we can finish opening the channel after looking up the |
| 149 // plugin. | 146 // plugin. |
| 150 void FinishOpenChannelToPlugin( | 147 void FinishOpenChannelToPlugin( |
| 151 const FilePath& plugin_path, | 148 const FilePath& plugin_path, |
| 152 PluginProcessHost::Client* client); | 149 PluginProcessHost::Client* client); |
| 153 | 150 |
| 154 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 151 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 155 // Registers a new FilePathWatcher for a given path. | 152 // Registers a new FilePathWatcher for a given path. |
| 156 static void RegisterFilePathWatcher( | 153 static void RegisterFilePathWatcher( |
| 157 base::files::FilePathWatcher* watcher, | 154 base::files::FilePathWatcher* watcher, |
| 158 const FilePath& path, | 155 const FilePath& path, |
| 159 base::files::FilePathWatcher::Delegate* delegate); | 156 base::files::FilePathWatcher::Delegate* delegate); |
| 160 #endif | 157 #endif |
| 161 | 158 |
| 162 // The browser's UI locale. | 159 // The browser's UI locale. |
| 163 const std::string ui_locale_; | 160 const std::string ui_locale_; |
| 164 | 161 |
| 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_; | 162 NotificationRegistrar registrar_; |
| 171 | 163 |
| 172 #if defined(OS_WIN) | 164 #if defined(OS_WIN) |
| 173 // Registry keys for getting notifications when new plugins are installed. | 165 // Registry keys for getting notifications when new plugins are installed. |
| 174 base::win::RegKey hkcu_key_; | 166 base::win::RegKey hkcu_key_; |
| 175 base::win::RegKey hklm_key_; | 167 base::win::RegKey hklm_key_; |
| 176 scoped_ptr<base::WaitableEvent> hkcu_event_; | 168 scoped_ptr<base::WaitableEvent> hkcu_event_; |
| 177 scoped_ptr<base::WaitableEvent> hklm_event_; | 169 scoped_ptr<base::WaitableEvent> hklm_event_; |
| 178 base::WaitableEventWatcher hkcu_watcher_; | 170 base::WaitableEventWatcher hkcu_watcher_; |
| 179 base::WaitableEventWatcher hklm_watcher_; | 171 base::WaitableEventWatcher hklm_watcher_; |
| 180 #endif | 172 #endif |
| 181 | 173 |
| 182 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 174 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 183 ScopedVector<base::files::FilePathWatcher> file_watchers_; | 175 ScopedVector<base::files::FilePathWatcher> file_watchers_; |
| 184 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; | 176 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; |
| 185 #endif | 177 #endif |
| 186 | 178 |
| 187 std::vector<PepperPluginInfo> ppapi_plugins_; | 179 std::vector<PepperPluginInfo> ppapi_plugins_; |
| 188 | 180 |
| 189 std::vector<OverriddenPlugin> overridden_plugins_; | 181 // Weak pointer; singleton. |
| 190 base::Lock overridden_plugins_lock_; | 182 content::PluginServiceFilter* filter_; |
| 191 | 183 |
| 192 DISALLOW_COPY_AND_ASSIGN(PluginService); | 184 DISALLOW_COPY_AND_ASSIGN(PluginService); |
| 193 }; | 185 }; |
| 194 | 186 |
| 195 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); | 187 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); |
| 196 | 188 |
| 197 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ | 189 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ |
| OLD | NEW |