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 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | 15 #include "base/basictypes.h" |
| 16 #include "base/callback.h" |
16 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
17 #include "base/memory/singleton.h" | 18 #include "base/memory/singleton.h" |
18 #include "base/synchronization/waitable_event_watcher.h" | 19 #include "base/synchronization/waitable_event_watcher.h" |
19 #include "build/build_config.h" | 20 #include "build/build_config.h" |
20 #include "content/browser/plugin_process_host.h" | 21 #include "content/browser/plugin_process_host.h" |
21 #include "content/browser/ppapi_plugin_process_host.h" | 22 #include "content/browser/ppapi_plugin_process_host.h" |
22 #include "content/browser/ppapi_broker_process_host.h" | 23 #include "content/browser/ppapi_broker_process_host.h" |
23 #include "content/common/content_export.h" | 24 #include "content/common/content_export.h" |
24 #include "content/common/notification_observer.h" | 25 #include "content/common/notification_observer.h" |
25 #include "content/common/notification_registrar.h" | 26 #include "content/common/notification_registrar.h" |
26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
27 #include "ipc/ipc_channel_handle.h" | 28 #include "ipc/ipc_channel_handle.h" |
28 #include "webkit/plugins/webplugininfo.h" | |
29 | 29 |
30 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
31 #include "base/memory/scoped_ptr.h" | 31 #include "base/memory/scoped_ptr.h" |
32 #include "base/win/registry.h" | 32 #include "base/win/registry.h" |
33 #endif | 33 #endif |
34 | 34 |
35 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 35 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
36 #include "base/files/file_path_watcher.h" | 36 #include "base/files/file_path_watcher.h" |
37 #endif | 37 #endif |
38 | 38 |
39 struct PepperPluginInfo; | 39 struct PepperPluginInfo; |
40 class PluginDirWatcherDelegate; | 40 class PluginDirWatcherDelegate; |
41 | 41 |
| 42 namespace base { |
| 43 class MessageLoopProxy; |
| 44 } |
| 45 |
42 namespace content { | 46 namespace content { |
43 class ResourceContext; | 47 class ResourceContext; |
44 class PluginServiceFilter; | 48 class PluginServiceFilter; |
45 } | 49 } |
46 | 50 |
| 51 namespace webkit { |
| 52 namespace npapi { |
| 53 class MockPluginList; |
| 54 class PluginGroup; |
| 55 class PluginList; |
| 56 } |
| 57 } |
| 58 |
47 // This must be created on the main thread but it's only called on the IO/file | 59 // This must be created on the main thread but it's only called on the IO/file |
48 // thread. | 60 // thread. This is an asynchronous wrapper around the PluginList interface for |
| 61 // querying plugin information, and this should instead of that class in the |
| 62 // content layer and above. |
49 class CONTENT_EXPORT PluginService | 63 class CONTENT_EXPORT PluginService |
50 : public base::WaitableEventWatcher::Delegate, | 64 : public base::WaitableEventWatcher::Delegate, |
51 public NotificationObserver { | 65 public NotificationObserver { |
52 public: | 66 public: |
53 struct OverriddenPlugin { | 67 struct OverriddenPlugin { |
54 int render_process_id; | 68 int render_process_id; |
55 int render_view_id; | 69 int render_view_id; |
56 GURL url; // If empty, the override applies to all urls in render_view. | 70 GURL url; // If empty, the override applies to all urls in render_view. |
57 webkit::WebPluginInfo plugin; | 71 webkit::WebPluginInfo plugin; |
58 }; | 72 }; |
59 | 73 |
| 74 typedef base::Callback<void(const std::vector<webkit::WebPluginInfo>&)> |
| 75 GetPluginsCallback; |
| 76 typedef base::Callback<void(const std::vector<webkit::npapi::PluginGroup>&)> |
| 77 GetPluginGroupsCallback; |
| 78 |
60 // Returns the PluginService singleton. | 79 // Returns the PluginService singleton. |
61 static PluginService* GetInstance(); | 80 static PluginService* GetInstance(); |
62 | 81 |
63 // Starts watching for changes in the list of installed plug-ins. | 82 // Starts watching for changes in the list of installed plug-ins. |
64 void StartWatchingPlugins(); | 83 void StartWatchingPlugins(); |
65 | 84 |
66 // Gets the browser's UI locale. | 85 // Gets the browser's UI locale. |
67 const std::string& GetUILocale(); | 86 const std::string& GetUILocale(); |
68 | 87 |
69 // Returns the plugin process host corresponding to the plugin process that | 88 // Returns the plugin process host corresponding to the plugin process that |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 int render_view_id, | 127 int render_view_id, |
109 const content::ResourceContext& context, | 128 const content::ResourceContext& context, |
110 const GURL& url, | 129 const GURL& url, |
111 const GURL& page_url, | 130 const GURL& page_url, |
112 const std::string& mime_type, | 131 const std::string& mime_type, |
113 bool allow_wildcard, | 132 bool allow_wildcard, |
114 bool* use_stale, | 133 bool* use_stale, |
115 webkit::WebPluginInfo* info, | 134 webkit::WebPluginInfo* info, |
116 std::string* actual_mime_type); | 135 std::string* actual_mime_type); |
117 | 136 |
118 // Returns a list of all plug-ins available to the resource context. Must be | 137 // Marks the plugin list as dirty and will cause the plugins to be reloaded |
119 // called on the FILE thread. | 138 // on the next access through GetPlugins() or GetPluginGroups(). |
| 139 void RefreshPluginList(); |
| 140 |
| 141 // Asynchronously loads plugins and then calls back to the provided function |
| 142 // on the calling MessageLoop on completion. |
120 void GetPlugins(const content::ResourceContext& context, | 143 void GetPlugins(const content::ResourceContext& context, |
121 std::vector<webkit::WebPluginInfo>* plugins); | 144 const GetPluginsCallback& callback); |
| 145 // Variant of above, but does not perform filtering based on |context|. |
| 146 void GetPlugins(const GetPluginsCallback& callback); |
| 147 |
| 148 // Returns the list of cached plugin groups. This can be called from any |
| 149 // thread, but note that the data can be stale. |
| 150 void GetCachedPluginGroups(std::vector<webkit::npapi::PluginGroup>* groups); |
| 151 |
| 152 // Gets the list of plugin groups, reloading them from disk if marked as dirty |
| 153 // with RefreshPluginList(). |
| 154 void GetPluginGroups(const GetPluginGroupsCallback& callback); |
122 | 155 |
123 // Tells all the renderer processes to throw away their cache of the plugin | 156 // Tells all the renderer processes to throw away their cache of the plugin |
124 // list, and optionally also reload all the pages with plugins. | 157 // list, and optionally also reload all the pages with plugins. |
125 // NOTE: can only be called on the UI thread. | 158 // NOTE: can only be called on the UI thread. |
126 static void PurgePluginListCache(bool reload_pages); | 159 static void PurgePluginListCache(bool reload_pages); |
127 | 160 |
128 void set_filter(content::PluginServiceFilter* filter) { | 161 void set_filter(content::PluginServiceFilter* filter) { |
129 filter_ = filter; | 162 filter_ = filter; |
130 } | 163 } |
131 | 164 |
| 165 // Sets the PluginList for testing environments. Be sure to change back to |
| 166 // NULL at the end of the test! |
| 167 void SetPluginListForTesting(webkit::npapi::MockPluginList* plugin_list); |
| 168 |
132 private: | 169 private: |
133 friend struct DefaultSingletonTraits<PluginService>; | 170 friend struct DefaultSingletonTraits<PluginService>; |
134 | 171 |
135 // Creates the PluginService object, but doesn't actually build the plugin | 172 // Creates the PluginService object, but doesn't actually build the plugin |
136 // list yet. It's generated lazily. | 173 // list yet. It's generated lazily. |
137 PluginService(); | 174 PluginService(); |
138 virtual ~PluginService(); | 175 virtual ~PluginService(); |
139 | 176 |
| 177 // Returns the PluginList, either the singleton or the override. |
| 178 webkit::npapi::PluginList* GetPluginList(); |
| 179 |
140 // base::WaitableEventWatcher::Delegate implementation. | 180 // base::WaitableEventWatcher::Delegate implementation. |
141 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); | 181 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); |
142 | 182 |
143 // NotificationObserver implementation | 183 // NotificationObserver implementation |
144 virtual void Observe(int type, const NotificationSource& source, | 184 virtual void Observe(int type, const NotificationSource& source, |
145 const NotificationDetails& details); | 185 const NotificationDetails& details); |
146 | 186 |
147 void RegisterPepperPlugins(); | 187 void RegisterPepperPlugins(); |
148 | 188 |
149 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); | 189 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); |
150 | 190 |
| 191 // Function that is run on the FILE thread to load the plugins synchronously. |
| 192 void GetPluginsInternal(const content::ResourceContext* context, |
| 193 base::MessageLoopProxy* target_loop, |
| 194 const GetPluginsCallback& callback); |
| 195 |
151 // Helper so we can do the plugin lookup on the FILE thread. | 196 // Helper so we can do the plugin lookup on the FILE thread. |
152 void GetAllowedPluginForOpenChannelToPlugin( | 197 void GetAllowedPluginForOpenChannelToPlugin( |
153 int render_process_id, | 198 int render_process_id, |
154 int render_view_id, | 199 int render_view_id, |
155 const GURL& url, | 200 const GURL& url, |
156 const GURL& page_url, | 201 const GURL& page_url, |
157 const std::string& mime_type, | 202 const std::string& mime_type, |
158 PluginProcessHost::Client* client, | 203 PluginProcessHost::Client* client, |
159 const content::ResourceContext* resource_context); | 204 const content::ResourceContext* resource_context); |
160 | 205 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; | 237 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; |
193 #endif | 238 #endif |
194 | 239 |
195 std::vector<PepperPluginInfo> ppapi_plugins_; | 240 std::vector<PepperPluginInfo> ppapi_plugins_; |
196 | 241 |
197 // Weak pointer; outlives us. | 242 // Weak pointer; outlives us. |
198 content::PluginServiceFilter* filter_; | 243 content::PluginServiceFilter* filter_; |
199 | 244 |
200 std::set<PluginProcessHost::Client*> pending_plugin_clients_; | 245 std::set<PluginProcessHost::Client*> pending_plugin_clients_; |
201 | 246 |
| 247 // Alternate plugin list to use for testing environments. When NULL, defaults |
| 248 // to the singleton. |
| 249 webkit::npapi::PluginList* plugin_list_; |
| 250 |
202 DISALLOW_COPY_AND_ASSIGN(PluginService); | 251 DISALLOW_COPY_AND_ASSIGN(PluginService); |
203 }; | 252 }; |
204 | 253 |
205 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); | 254 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); |
206 | 255 |
207 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ | 256 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ |
OLD | NEW |