Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(474)

Side by Side Diff: content/browser/plugin_service.h

Issue 9006036: Create an API around PluginService and use it from Chrome. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/browser/plugin_loader_posix.cc ('k') | content/browser/plugin_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <set> 12 #include <set>
13 #include <string>
14 #include <vector>
15 13
16 #include "base/basictypes.h" 14 #include "base/basictypes.h"
17 #include "base/callback.h"
18 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
19 #include "base/memory/singleton.h" 16 #include "base/memory/singleton.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/common/content_export.h" 21 #include "content/common/content_export.h"
25 #include "content/public/browser/notification_observer.h" 22 #include "content/public/browser/notification_observer.h"
26 #include "content/public/browser/notification_registrar.h" 23 #include "content/public/browser/notification_registrar.h"
24 #include "content/public/browser/plugin_service.h"
27 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
28 #include "ipc/ipc_channel_handle.h" 26 #include "ipc/ipc_channel_handle.h"
29 27
30 #if defined(OS_WIN) 28 #if defined(OS_WIN)
31 #include "base/memory/scoped_ptr.h" 29 #include "base/memory/scoped_ptr.h"
32 #include "base/win/registry.h" 30 #include "base/win/registry.h"
33 #endif 31 #endif
34 32
35 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) 33 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
36 #include "base/files/file_path_watcher.h" 34 #include "base/files/file_path_watcher.h"
(...skipping 14 matching lines...) Expand all
51 struct PluginServiceFilterParams; 49 struct PluginServiceFilterParams;
52 } 50 }
53 51
54 namespace webkit { 52 namespace webkit {
55 namespace npapi { 53 namespace npapi {
56 class PluginGroup; 54 class PluginGroup;
57 class PluginList; 55 class PluginList;
58 } 56 }
59 } 57 }
60 58
61 // This must be created on the main thread but it's only called on the IO/file
62 // thread. This is an asynchronous wrapper around the PluginList interface for
63 // querying plugin information. This must be used instead of that to avoid
64 // doing expensive disk operations on the IO/UI threads.
65 class CONTENT_EXPORT PluginService 59 class CONTENT_EXPORT PluginService
66 : public base::WaitableEventWatcher::Delegate, 60 : public content::PluginService,
61 public base::WaitableEventWatcher::Delegate,
67 public content::NotificationObserver { 62 public content::NotificationObserver {
68 public: 63 public:
69 struct OverriddenPlugin {
70 int render_process_id;
71 int render_view_id;
72 GURL url; // If empty, the override applies to all urls in render_view.
73 webkit::WebPluginInfo plugin;
74 };
75
76 typedef base::Callback<void(const std::vector<webkit::WebPluginInfo>&)>
77 GetPluginsCallback;
78 typedef base::Callback<void(const std::vector<webkit::npapi::PluginGroup>&)>
79 GetPluginGroupsCallback;
80
81 // Returns the PluginService singleton. 64 // Returns the PluginService singleton.
82 static PluginService* GetInstance(); 65 static PluginService* GetInstance();
83 66
84 // Must be called on the instance to finish initialization. 67 // content::PluginService implementation:
85 void Init(); 68 virtual void Init() OVERRIDE;
86 69 virtual void StartWatchingPlugins() OVERRIDE;
87 // Starts watching for changes in the list of installed plug-ins. 70 virtual PluginProcessHost* FindNpapiPluginProcess(
88 void StartWatchingPlugins(); 71 const FilePath& plugin_path) OVERRIDE;
72 virtual bool GetPluginInfoArray(
73 const GURL& url,
74 const std::string& mime_type,
75 bool allow_wildcard,
76 std::vector<webkit::WebPluginInfo>* info,
77 std::vector<std::string>* actual_mime_types) OVERRIDE;
78 virtual bool GetPluginInfo(int render_process_id,
79 int render_view_id,
80 const content::ResourceContext& context,
81 const GURL& url,
82 const GURL& page_url,
83 const std::string& mime_type,
84 bool allow_wildcard,
85 bool* is_stale,
86 webkit::WebPluginInfo* info,
87 std::string* actual_mime_type) OVERRIDE;
88 virtual bool GetPluginInfoByPath(const FilePath& plugin_path,
89 webkit::WebPluginInfo* info) OVERRIDE;
90 virtual void GetPlugins(const GetPluginsCallback& callback) OVERRIDE;
91 virtual void GetPluginGroups(
92 const GetPluginGroupsCallback& callback) OVERRIDE;
93 virtual content::PepperPluginInfo* GetRegisteredPpapiPluginInfo(
94 const FilePath& plugin_path) OVERRIDE;
95 virtual void SetFilter(content::PluginServiceFilter* filter) OVERRIDE;
96 virtual content::PluginServiceFilter* GetFilter() OVERRIDE;
97 virtual void RefreshPlugins() OVERRIDE;
98 virtual void AddExtraPluginPath(const FilePath& path) OVERRIDE;
99 virtual void RemoveExtraPluginPath(const FilePath& path) OVERRIDE;
100 virtual void UnregisterInternalPlugin(const FilePath& path) OVERRIDE;
101 virtual void RegisterInternalPlugin(
102 const webkit::WebPluginInfo& info) OVERRIDE;
103 virtual string16 GetPluginGroupName(const std::string& plugin_name) OVERRIDE;
104 virtual webkit::npapi::PluginList* GetPluginList() OVERRIDE;
89 105
90 // Gets the browser's UI locale. 106 // Gets the browser's UI locale.
91 const std::string& GetUILocale(); 107 const std::string& GetUILocale();
92 108
93 // Returns the plugin process host corresponding to the plugin process that 109 // Like FindNpapiPluginProcess but for Pepper.
94 // has been started by this service. Returns NULL if no process has been
95 // started.
96 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path);
97 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path); 110 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path);
98 PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path); 111 PpapiPluginProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path);
99 112
100 // Returns the plugin process host corresponding to the plugin process that 113 // Returns the plugin process host corresponding to the plugin process that
101 // has been started by this service. This will start a process to host the 114 // has been started by this service. This will start a process to host the
102 // 'plugin_path' if needed. If the process fails to start, the return value 115 // 'plugin_path' if needed. If the process fails to start, the return value
103 // is NULL. Must be called on the IO thread. 116 // is NULL. Must be called on the IO thread.
104 PluginProcessHost* FindOrStartNpapiPluginProcess( 117 PluginProcessHost* FindOrStartNpapiPluginProcess(
105 const FilePath& plugin_path); 118 const FilePath& plugin_path);
106 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess( 119 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
(...skipping 12 matching lines...) Expand all
119 const std::string& mime_type, 132 const std::string& mime_type,
120 PluginProcessHost::Client* client); 133 PluginProcessHost::Client* client);
121 void OpenChannelToPpapiPlugin(const FilePath& path, 134 void OpenChannelToPpapiPlugin(const FilePath& path,
122 PpapiPluginProcessHost::PluginClient* client); 135 PpapiPluginProcessHost::PluginClient* client);
123 void OpenChannelToPpapiBroker(const FilePath& path, 136 void OpenChannelToPpapiBroker(const FilePath& path,
124 PpapiPluginProcessHost::BrokerClient* client); 137 PpapiPluginProcessHost::BrokerClient* client);
125 138
126 // Cancels opening a channel to a NPAPI plugin. 139 // Cancels opening a channel to a NPAPI plugin.
127 void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client); 140 void CancelOpenChannelToNpapiPlugin(PluginProcessHost::Client* client);
128 141
129 // Gets the plugin in the list of plugins that matches the given url and mime
130 // type. Returns true if the data is frome a stale plugin list, false if it
131 // is up to date. This can be called from any thread.
132 bool GetPluginInfoArray(const GURL& url,
133 const std::string& mime_type,
134 bool allow_wildcard,
135 std::vector<webkit::WebPluginInfo>* info,
136 std::vector<std::string>* actual_mime_types);
137
138 // Gets plugin info for an individual plugin and filters the plugins using
139 // the |context| and renderer IDs. This will report whether the data is stale
140 // via |is_stale| and returns whether or not the plugin can be found.
141 bool GetPluginInfo(int render_process_id,
142 int render_view_id,
143 const content::ResourceContext& context,
144 const GURL& url,
145 const GURL& page_url,
146 const std::string& mime_type,
147 bool allow_wildcard,
148 bool* is_stale,
149 webkit::WebPluginInfo* info,
150 std::string* actual_mime_type);
151
152 // Get plugin info by plugin path (including disabled plugins). Returns true
153 // if the plugin is found and WebPluginInfo has been filled in |info|. This
154 // will use cached data in the plugin list.
155 bool GetPluginInfoByPath(const FilePath& plugin_path,
156 webkit::WebPluginInfo* info);
157
158 // Asynchronously loads plugins if necessary and then calls back to the
159 // provided function on the calling MessageLoop on completion.
160 void GetPlugins(const GetPluginsCallback& callback);
161
162 // Asynchronously loads the list of plugin groups if necessary and then calls
163 // back to the provided function on the calling MessageLoop on completion.
164 void GetPluginGroups(const GetPluginGroupsCallback& callback);
165
166 // Returns information about a pepper plugin if it exists, otherwise NULL.
167 // The caller does not own the pointer, and it's not guaranteed to live past
168 // the call stack.
169 content::PepperPluginInfo* GetRegisteredPpapiPluginInfo(
170 const FilePath& plugin_path);
171
172 // Tells all the renderer processes associated with the given browser context
173 // to throw away their cache of the plugin list, and optionally also reload
174 // all the pages with plugins. If |browser_context| is NULL, purges the cache
175 // in all renderers.
176 // NOTE: can only be called on the UI thread.
177 static void PurgePluginListCache(content::BrowserContext* browser_context,
178 bool reload_pages);
179
180 void set_filter(content::PluginServiceFilter* filter) {
181 filter_ = filter;
182 }
183 content::PluginServiceFilter* filter() { return filter_; }
184
185 // The following functions are wrappers around webkit::npapi::PluginList.
186 // These must be used instead of those in order to ensure that we have a
187 // single global list in the component build and so that we don't
188 // accidentally load plugins in the wrong process or thread. Refer to
189 // PluginList for further documentation of these functions.
190 void RefreshPlugins();
191 void AddExtraPluginPath(const FilePath& path);
192 void RemoveExtraPluginPath(const FilePath& path);
193 void UnregisterInternalPlugin(const FilePath& path);
194 void RegisterInternalPlugin(const webkit::WebPluginInfo& info);
195 string16 GetPluginGroupName(const std::string& plugin_name);
196
197 // TODO(dpranke): This should be private.
198 webkit::npapi::PluginList* plugin_list() { return plugin_list_; }
199
200 void SetPluginListForTesting(webkit::npapi::PluginList* plugin_list); 142 void SetPluginListForTesting(webkit::npapi::PluginList* plugin_list);
201 143
202 private: 144 private:
203 friend struct DefaultSingletonTraits<PluginService>; 145 friend struct DefaultSingletonTraits<PluginService>;
204 146
205 // Creates the PluginService object, but doesn't actually build the plugin 147 // Creates the PluginService object, but doesn't actually build the plugin
206 // list yet. It's generated lazily. 148 // list yet. It's generated lazily.
207 PluginService(); 149 PluginService();
208 virtual ~PluginService(); 150 virtual ~PluginService();
209 151
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 #if defined(OS_POSIX) 229 #if defined(OS_POSIX)
288 scoped_refptr<PluginLoaderPosix> plugin_loader_; 230 scoped_refptr<PluginLoaderPosix> plugin_loader_;
289 #endif 231 #endif
290 232
291 DISALLOW_COPY_AND_ASSIGN(PluginService); 233 DISALLOW_COPY_AND_ASSIGN(PluginService);
292 }; 234 };
293 235
294 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); 236 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService);
295 237
296 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ 238 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_
OLDNEW
« no previous file with comments | « content/browser/plugin_loader_posix.cc ('k') | content/browser/plugin_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698