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