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

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

Issue 7387010: Add PluginServiceFilter interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit test Created 9 years, 3 months 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_process_host.h ('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 <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/file_path.h"
17 #include "base/hash_tables.h"
18 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
19 #include "base/memory/singleton.h" 17 #include "base/memory/singleton.h"
20 #include "base/synchronization/lock.h"
21 #include "base/synchronization/waitable_event_watcher.h" 18 #include "base/synchronization/waitable_event_watcher.h"
22 #include "build/build_config.h" 19 #include "build/build_config.h"
23 #include "content/browser/plugin_process_host.h" 20 #include "content/browser/plugin_process_host.h"
24 #include "content/browser/ppapi_plugin_process_host.h" 21 #include "content/browser/ppapi_plugin_process_host.h"
25 #include "content/browser/ppapi_broker_process_host.h" 22 #include "content/browser/ppapi_broker_process_host.h"
26 #include "content/common/notification_observer.h" 23 #include "content/common/notification_observer.h"
27 #include "content/common/notification_registrar.h" 24 #include "content/common/notification_registrar.h"
28 #include "googleurl/src/gurl.h" 25 #include "googleurl/src/gurl.h"
29 #include "ipc/ipc_channel_handle.h" 26 #include "ipc/ipc_channel_handle.h"
30 #include "webkit/plugins/webplugininfo.h" 27 #include "webkit/plugins/webplugininfo.h"
31 28
32 #if defined(OS_WIN) 29 #if defined(OS_WIN)
33 #include "base/memory/scoped_ptr.h" 30 #include "base/memory/scoped_ptr.h"
34 #include "base/win/registry.h" 31 #include "base/win/registry.h"
35 #endif 32 #endif
36 33
37 #if defined(OS_POSIX) && !defined(OS_MACOSX) 34 #if defined(OS_POSIX) && !defined(OS_MACOSX)
38 #include "base/files/file_path_watcher.h" 35 #include "base/files/file_path_watcher.h"
39 #endif 36 #endif
40 37
41 struct PepperPluginInfo; 38 struct PepperPluginInfo;
42 class PluginDirWatcherDelegate; 39 class PluginDirWatcherDelegate;
43 40
41 namespace content {
42 class ResourceContext;
43 class PluginServiceFilter;
44 }
45
44 // This must be created on the main thread but it's only called on the IO/file 46 // This must be created on the main thread but it's only called on the IO/file
45 // thread. 47 // thread.
46 class PluginService 48 class PluginService
47 : public base::WaitableEventWatcher::Delegate, 49 : public base::WaitableEventWatcher::Delegate,
48 public NotificationObserver { 50 public NotificationObserver {
49 public: 51 public:
50 struct OverriddenPlugin { 52 struct OverriddenPlugin {
51 int render_process_id; 53 int render_process_id;
52 int render_view_id; 54 int render_view_id;
53 GURL url; // If empty, the override applies to all urls in render_view. 55 GURL url; // If empty, the override applies to all urls in render_view.
54 webkit::WebPluginInfo plugin; 56 webkit::WebPluginInfo plugin;
55 }; 57 };
56 58
57 // Returns the PluginService singleton. 59 // Returns the PluginService singleton.
58 static PluginService* GetInstance(); 60 static PluginService* GetInstance();
59 61
62 // Starts watching for changes in the list of installed plug-ins.
63 void StartWatchingPlugins();
64
60 // Gets the browser's UI locale. 65 // Gets the browser's UI locale.
61 const std::string& GetUILocale(); 66 const std::string& GetUILocale();
62 67
63 // Returns the plugin process host corresponding to the plugin process that 68 // Returns the plugin process host corresponding to the plugin process that
64 // has been started by this service. Returns NULL if no process has been 69 // has been started by this service. Returns NULL if no process has been
65 // started. 70 // started.
66 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path); 71 PluginProcessHost* FindNpapiPluginProcess(const FilePath& plugin_path);
67 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path); 72 PpapiPluginProcessHost* FindPpapiPluginProcess(const FilePath& plugin_path);
68 PpapiBrokerProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path); 73 PpapiBrokerProcessHost* FindPpapiBrokerProcess(const FilePath& broker_path);
69 74
70 // Returns the plugin process host corresponding to the plugin process that 75 // Returns the plugin process host corresponding to the plugin process that
71 // has been started by this service. This will start a process to host the 76 // has been started by this service. This will start a process to host the
72 // 'plugin_path' if needed. If the process fails to start, the return value 77 // 'plugin_path' if needed. If the process fails to start, the return value
73 // is NULL. Must be called on the IO thread. 78 // is NULL. Must be called on the IO thread.
74 PluginProcessHost* FindOrStartNpapiPluginProcess( 79 PluginProcessHost* FindOrStartNpapiPluginProcess(
75 const FilePath& plugin_path); 80 const FilePath& plugin_path);
76 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess( 81 PpapiPluginProcessHost* FindOrStartPpapiPluginProcess(
77 const FilePath& plugin_path, 82 const FilePath& plugin_path,
78 PpapiPluginProcessHost::Client* client); 83 PpapiPluginProcessHost::Client* client);
79 PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess( 84 PpapiBrokerProcessHost* FindOrStartPpapiBrokerProcess(
80 const FilePath& plugin_path); 85 const FilePath& plugin_path);
81 86
82 // Opens a channel to a plugin process for the given mime type, starting 87 // Opens a channel to a plugin process for the given mime type, starting
83 // a new plugin process if necessary. This must be called on the IO thread 88 // a new plugin process if necessary. This must be called on the IO thread
84 // or else a deadlock can occur. 89 // or else a deadlock can occur.
85 void OpenChannelToNpapiPlugin(int render_process_id, 90 void OpenChannelToNpapiPlugin(int render_process_id,
86 int render_view_id, 91 int render_view_id,
87 const GURL& url, 92 const GURL& url,
93 const GURL& page_url,
88 const std::string& mime_type, 94 const std::string& mime_type,
89 PluginProcessHost::Client* client); 95 PluginProcessHost::Client* client);
90 void OpenChannelToPpapiPlugin(const FilePath& path, 96 void OpenChannelToPpapiPlugin(const FilePath& path,
91 PpapiPluginProcessHost::Client* client); 97 PpapiPluginProcessHost::Client* client);
92 void OpenChannelToPpapiBroker(const FilePath& path, 98 void OpenChannelToPpapiBroker(const FilePath& path,
93 PpapiBrokerProcessHost::Client* client); 99 PpapiBrokerProcessHost::Client* client);
94 100
95 // Gets the plugin in the list of plugins that matches the given url and mime 101 // Gets the plugin in the list of plugins that matches the given url and mime
96 // type. Must be called on the FILE thread. 102 // type. Must be called on the FILE thread if |use_stale| is NULL.
97 bool GetPluginInfo(int render_process_id, 103 bool GetPluginInfo(int render_process_id,
98 int render_view_id, 104 int render_view_id,
105 const content::ResourceContext& context,
99 const GURL& url, 106 const GURL& url,
107 const GURL& page_url,
100 const std::string& mime_type, 108 const std::string& mime_type,
109 bool allow_wildcard,
110 bool* use_stale,
101 webkit::WebPluginInfo* info, 111 webkit::WebPluginInfo* info,
102 std::string* actual_mime_type); 112 std::string* actual_mime_type);
103 113
104 // Safe to be called from any thread. 114 // Returns a list of all plug-ins available to the resource context. Must be
105 void OverridePluginForTab(const OverriddenPlugin& plugin); 115 // called on the FILE thread.
106 116 void GetPlugins(const content::ResourceContext& context,
107 // Restricts the given plugin to the the scheme and host of the given url. 117 std::vector<webkit::WebPluginInfo>* plugins);
108 // Call with an empty url to reset this.
109 // Can be called on any thread.
110 void RestrictPluginToUrl(const FilePath& plugin_path, const GURL& url);
111
112 // Returns true if the given plugin is allowed to be used by a page with
113 // the given URL.
114 // Can be called on any thread.
115 bool PluginAllowedForURL(const FilePath& plugin_path, const GURL& url);
116 118
117 // Tells all the renderer processes to throw away their cache of the plugin 119 // Tells all the renderer processes to throw away their cache of the plugin
118 // list, and optionally also reload all the pages with plugins. 120 // list, and optionally also reload all the pages with plugins.
119 // NOTE: can only be called on the UI thread. 121 // NOTE: can only be called on the UI thread.
120 static void PurgePluginListCache(bool reload_pages); 122 static void PurgePluginListCache(bool reload_pages);
121 123
124 void set_filter(content::PluginServiceFilter* filter) {
125 filter_ = filter;
126 }
127
122 private: 128 private:
123 friend struct DefaultSingletonTraits<PluginService>; 129 friend struct DefaultSingletonTraits<PluginService>;
124 130
125 // Creates the PluginService object, but doesn't actually build the plugin 131 // Creates the PluginService object, but doesn't actually build the plugin
126 // list yet. It's generated lazily. 132 // list yet. It's generated lazily.
127 PluginService(); 133 PluginService();
128 virtual ~PluginService(); 134 virtual ~PluginService();
129 135
130 // base::WaitableEventWatcher::Delegate implementation. 136 // base::WaitableEventWatcher::Delegate implementation.
131 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event); 137 virtual void OnWaitableEventSignaled(base::WaitableEvent* waitable_event);
132 138
133 // NotificationObserver implementation 139 // NotificationObserver implementation
134 virtual void Observe(int type, const NotificationSource& source, 140 virtual void Observe(int type, const NotificationSource& source,
135 const NotificationDetails& details); 141 const NotificationDetails& details);
136 142
137 void RegisterPepperPlugins(); 143 void RegisterPepperPlugins();
138 144
139 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path); 145 PepperPluginInfo* GetRegisteredPpapiPluginInfo(const FilePath& plugin_path);
140 146
141 // Helper so we can do the plugin lookup on the FILE thread. 147 // Helper so we can do the plugin lookup on the FILE thread.
142 void GetAllowedPluginForOpenChannelToPlugin( 148 void GetAllowedPluginForOpenChannelToPlugin(
143 int render_process_id, 149 int render_process_id,
144 int render_view_id, 150 int render_view_id,
145 const GURL& url, 151 const GURL& url,
152 const GURL& page_url,
146 const std::string& mime_type, 153 const std::string& mime_type,
147 PluginProcessHost::Client* client); 154 PluginProcessHost::Client* client);
148 155
149 // Helper so we can finish opening the channel after looking up the 156 // Helper so we can finish opening the channel after looking up the
150 // plugin. 157 // plugin.
151 void FinishOpenChannelToPlugin( 158 void FinishOpenChannelToPlugin(
152 const FilePath& plugin_path, 159 const FilePath& plugin_path,
153 PluginProcessHost::Client* client); 160 PluginProcessHost::Client* client);
154 161
155 #if defined(OS_POSIX) && !defined(OS_MACOSX) 162 #if defined(OS_POSIX) && !defined(OS_MACOSX)
156 // Registers a new FilePathWatcher for a given path. 163 // Registers a new FilePathWatcher for a given path.
157 static void RegisterFilePathWatcher( 164 static void RegisterFilePathWatcher(
158 base::files::FilePathWatcher* watcher, 165 base::files::FilePathWatcher* watcher,
159 const FilePath& path, 166 const FilePath& path,
160 base::files::FilePathWatcher::Delegate* delegate); 167 base::files::FilePathWatcher::Delegate* delegate);
161 #endif 168 #endif
162 169
163 // The browser's UI locale. 170 // The browser's UI locale.
164 const std::string ui_locale_; 171 const std::string ui_locale_;
165 172
166 // Map of plugin paths to the origin they are restricted to.
167 base::Lock restricted_plugin_lock_; // Guards access to restricted_plugin_.
168 typedef base::hash_map<FilePath, GURL> RestrictedPluginMap;
169 RestrictedPluginMap restricted_plugin_;
170
171 NotificationRegistrar registrar_; 173 NotificationRegistrar registrar_;
172 174
173 #if defined(OS_WIN) 175 #if defined(OS_WIN)
174 // Registry keys for getting notifications when new plugins are installed. 176 // Registry keys for getting notifications when new plugins are installed.
175 base::win::RegKey hkcu_key_; 177 base::win::RegKey hkcu_key_;
176 base::win::RegKey hklm_key_; 178 base::win::RegKey hklm_key_;
177 scoped_ptr<base::WaitableEvent> hkcu_event_; 179 scoped_ptr<base::WaitableEvent> hkcu_event_;
178 scoped_ptr<base::WaitableEvent> hklm_event_; 180 scoped_ptr<base::WaitableEvent> hklm_event_;
179 base::WaitableEventWatcher hkcu_watcher_; 181 base::WaitableEventWatcher hkcu_watcher_;
180 base::WaitableEventWatcher hklm_watcher_; 182 base::WaitableEventWatcher hklm_watcher_;
181 #endif 183 #endif
182 184
183 #if defined(OS_POSIX) && !defined(OS_MACOSX) 185 #if defined(OS_POSIX) && !defined(OS_MACOSX)
184 ScopedVector<base::files::FilePathWatcher> file_watchers_; 186 ScopedVector<base::files::FilePathWatcher> file_watchers_;
185 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_; 187 scoped_refptr<PluginDirWatcherDelegate> file_watcher_delegate_;
186 #endif 188 #endif
187 189
188 std::vector<PepperPluginInfo> ppapi_plugins_; 190 std::vector<PepperPluginInfo> ppapi_plugins_;
189 191
190 std::vector<OverriddenPlugin> overridden_plugins_; 192 // Weak pointer; outlives us.
191 base::Lock overridden_plugins_lock_; 193 content::PluginServiceFilter* filter_;
192 194
193 DISALLOW_COPY_AND_ASSIGN(PluginService); 195 DISALLOW_COPY_AND_ASSIGN(PluginService);
194 }; 196 };
195 197
196 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService); 198 DISABLE_RUNNABLE_METHOD_REFCOUNT(PluginService);
197 199
198 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_ 200 #endif // CONTENT_BROWSER_PLUGIN_SERVICE_H_
OLDNEW
« no previous file with comments | « content/browser/plugin_process_host.h ('k') | content/browser/plugin_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698