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