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

Side by Side Diff: content/browser/plugin_service_impl.cc

Issue 9019004: Rename PluginService to PluginServiceImpl. (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
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 #include "content/browser/plugin_service.h" 5 #include "content/browser/plugin_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/message_loop_proxy.h" 12 #include "base/message_loop_proxy.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
(...skipping 20 matching lines...) Expand all
36 #include "webkit/plugins/npapi/plugin_constants_win.h" 36 #include "webkit/plugins/npapi/plugin_constants_win.h"
37 #include "webkit/plugins/npapi/plugin_group.h" 37 #include "webkit/plugins/npapi/plugin_group.h"
38 #include "webkit/plugins/npapi/plugin_list.h" 38 #include "webkit/plugins/npapi/plugin_list.h"
39 #include "webkit/plugins/webplugininfo.h" 39 #include "webkit/plugins/webplugininfo.h"
40 40
41 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) 41 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
42 using ::base::files::FilePathWatcher; 42 using ::base::files::FilePathWatcher;
43 #endif 43 #endif
44 44
45 using content::BrowserThread; 45 using content::BrowserThread;
46 using content::PluginService;
46 using content::PluginServiceFilter; 47 using content::PluginServiceFilter;
47 48
48 namespace { 49 namespace {
49 50
50 // Helper function that merely runs the callback with the result. Called on the 51 // Helper function that merely runs the callback with the result. Called on the
51 // thread on which the original GetPlugins() call was made. 52 // thread on which the original GetPlugins() call was made.
52 static void RunGetPluginsCallback( 53 static void RunGetPluginsCallback(
53 const PluginService::GetPluginsCallback& callback, 54 const PluginService::GetPluginsCallback& callback,
54 const std::vector<webkit::WebPluginInfo>& result) { 55 const std::vector<webkit::WebPluginInfo>& result) {
55 callback.Run(result); 56 callback.Run(result);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 // TODO(pastarmovj): Add some sensible error handling. Maybe silently 106 // TODO(pastarmovj): Add some sensible error handling. Maybe silently
106 // stopping the watcher would be enough. Or possibly restart it. 107 // stopping the watcher would be enough. Or possibly restart it.
107 NOTREACHED(); 108 NOTREACHED();
108 } 109 }
109 }; 110 };
110 #endif 111 #endif
111 112
112 namespace content { 113 namespace content {
113 // static 114 // static
114 PluginService* PluginService::GetInstance() { 115 PluginService* PluginService::GetInstance() {
115 return ::PluginService::GetInstance(); 116 return PluginServiceImpl::GetInstance();
116 } 117 }
117 118
118 void PluginService::PurgePluginListCache(BrowserContext* browser_context, 119 void PluginService::PurgePluginListCache(BrowserContext* browser_context,
119 bool reload_pages) { 120 bool reload_pages) {
120 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator(); 121 for (RenderProcessHost::iterator it = RenderProcessHost::AllHostsIterator();
121 !it.IsAtEnd(); it.Advance()) { 122 !it.IsAtEnd(); it.Advance()) {
122 RenderProcessHost* host = it.GetCurrentValue(); 123 RenderProcessHost* host = it.GetCurrentValue();
123 if (!browser_context || host->GetBrowserContext() == browser_context) 124 if (!browser_context || host->GetBrowserContext() == browser_context)
124 host->Send(new ViewMsg_PurgePluginListCache(reload_pages)); 125 host->Send(new ViewMsg_PurgePluginListCache(reload_pages));
125 } 126 }
126 } 127 }
127 128
128 } // namespace content 129 } // namespace content
129 130
130 // static 131 // static
131 PluginService* PluginService::GetInstance() { 132 PluginServiceImpl* PluginServiceImpl::GetInstance() {
132 return Singleton<PluginService>::get(); 133 return Singleton<PluginServiceImpl>::get();
133 } 134 }
134 135
135 PluginService::PluginService() 136 PluginServiceImpl::PluginServiceImpl()
136 : plugin_list_(NULL), 137 : plugin_list_(NULL),
137 ui_locale_( 138 ui_locale_(
138 content::GetContentClient()->browser()->GetApplicationLocale()), 139 content::GetContentClient()->browser()->GetApplicationLocale()),
139 filter_(NULL) { 140 filter_(NULL) {
140 } 141 }
141 142
142 PluginService::~PluginService() { 143 PluginServiceImpl::~PluginServiceImpl() {
143 #if defined(OS_WIN) 144 #if defined(OS_WIN)
144 // Release the events since they're owned by RegKey, not WaitableEvent. 145 // Release the events since they're owned by RegKey, not WaitableEvent.
145 hkcu_watcher_.StopWatching(); 146 hkcu_watcher_.StopWatching();
146 hklm_watcher_.StopWatching(); 147 hklm_watcher_.StopWatching();
147 if (hkcu_event_.get()) 148 if (hkcu_event_.get())
148 hkcu_event_->Release(); 149 hkcu_event_->Release();
149 if (hklm_event_.get()) 150 if (hklm_event_.get())
150 hklm_event_->Release(); 151 hklm_event_->Release();
151 #endif 152 #endif
152 // Make sure no plugin channel requests have been leaked. 153 // Make sure no plugin channel requests have been leaked.
153 DCHECK(pending_plugin_clients_.empty()); 154 DCHECK(pending_plugin_clients_.empty());
154 } 155 }
155 156
156 void PluginService::Init() { 157 void PluginServiceImpl::Init() {
157 if (!plugin_list_) 158 if (!plugin_list_)
158 plugin_list_ = webkit::npapi::PluginList::Singleton(); 159 plugin_list_ = webkit::npapi::PluginList::Singleton();
159 160
160 plugin_list_->set_will_load_plugins_callback( 161 plugin_list_->set_will_load_plugins_callback(
161 base::Bind(&WillLoadPluginsCallback)); 162 base::Bind(&WillLoadPluginsCallback));
162 163
163 RegisterPepperPlugins(); 164 RegisterPepperPlugins();
164 165
165 content::GetContentClient()->AddNPAPIPlugins(plugin_list_); 166 content::GetContentClient()->AddNPAPIPlugins(plugin_list_);
166 167
167 // Load any specified on the command line as well. 168 // Load any specified on the command line as well.
168 const CommandLine* command_line = CommandLine::ForCurrentProcess(); 169 const CommandLine* command_line = CommandLine::ForCurrentProcess();
169 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin); 170 FilePath path = command_line->GetSwitchValuePath(switches::kLoadPlugin);
170 if (!path.empty()) 171 if (!path.empty())
171 AddExtraPluginPath(path); 172 AddExtraPluginPath(path);
172 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir); 173 path = command_line->GetSwitchValuePath(switches::kExtraPluginDir);
173 if (!path.empty()) 174 if (!path.empty())
174 plugin_list_->AddExtraPluginDir(path); 175 plugin_list_->AddExtraPluginDir(path);
175 176
176 #if defined(OS_MACOSX) 177 #if defined(OS_MACOSX)
177 // We need to know when the browser comes forward so we can bring modal plugin 178 // We need to know when the browser comes forward so we can bring modal plugin
178 // windows forward too. 179 // windows forward too.
179 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED, 180 registrar_.Add(this, content::NOTIFICATION_APP_ACTIVATED,
180 content::NotificationService::AllSources()); 181 content::NotificationService::AllSources());
181 #endif 182 #endif
182 } 183 }
183 184
184 void PluginService::StartWatchingPlugins() { 185 void PluginServiceImpl::StartWatchingPlugins() {
185 // Start watching for changes in the plugin list. This means watching 186 // Start watching for changes in the plugin list. This means watching
186 // for changes in the Windows registry keys and on both Windows and POSIX 187 // for changes in the Windows registry keys and on both Windows and POSIX
187 // watch for changes in the paths that are expected to contain plugins. 188 // watch for changes in the paths that are expected to contain plugins.
188 #if defined(OS_WIN) 189 #if defined(OS_WIN)
189 if (hkcu_key_.Create(HKEY_CURRENT_USER, 190 if (hkcu_key_.Create(HKEY_CURRENT_USER,
190 webkit::npapi::kRegistryMozillaPlugins, 191 webkit::npapi::kRegistryMozillaPlugins,
191 KEY_NOTIFY) == ERROR_SUCCESS) { 192 KEY_NOTIFY) == ERROR_SUCCESS) {
192 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) { 193 if (hkcu_key_.StartWatching() == ERROR_SUCCESS) {
193 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event())); 194 hkcu_event_.reset(new base::WaitableEvent(hkcu_key_.watch_event()));
194 hkcu_watcher_.StartWatching(hkcu_event_.get(), this); 195 hkcu_watcher_.StartWatching(hkcu_event_.get(), this);
(...skipping 23 matching lines...) Expand all
218 // We don't watch for file changes in windows now but if this should ever 219 // We don't watch for file changes in windows now but if this should ever
219 // be extended to Windows these lines might save some time of debugging. 220 // be extended to Windows these lines might save some time of debugging.
220 #if defined(OS_WIN) 221 #if defined(OS_WIN)
221 if (!plugin_dirs[i].IsAbsolute()) 222 if (!plugin_dirs[i].IsAbsolute())
222 continue; 223 continue;
223 #endif 224 #endif
224 FilePathWatcher* watcher = new FilePathWatcher(); 225 FilePathWatcher* watcher = new FilePathWatcher();
225 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value(); 226 VLOG(1) << "Watching for changes in: " << plugin_dirs[i].value();
226 BrowserThread::PostTask( 227 BrowserThread::PostTask(
227 BrowserThread::FILE, FROM_HERE, 228 BrowserThread::FILE, FROM_HERE,
228 base::Bind(&PluginService::RegisterFilePathWatcher, watcher, 229 base::Bind(&PluginServiceImpl::RegisterFilePathWatcher, watcher,
229 plugin_dirs[i], file_watcher_delegate_)); 230 plugin_dirs[i], file_watcher_delegate_));
230 file_watchers_.push_back(watcher); 231 file_watchers_.push_back(watcher);
231 } 232 }
232 #endif 233 #endif
233 } 234 }
234 235
235 const std::string& PluginService::GetUILocale() { 236 const std::string& PluginServiceImpl::GetUILocale() {
236 return ui_locale_; 237 return ui_locale_;
237 } 238 }
238 239
239 PluginProcessHost* PluginService::FindNpapiPluginProcess( 240 PluginProcessHost* PluginServiceImpl::FindNpapiPluginProcess(
240 const FilePath& plugin_path) { 241 const FilePath& plugin_path) {
241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
242 243
243 for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_PLUGIN); 244 for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_PLUGIN);
244 !iter.Done(); ++iter) { 245 !iter.Done(); ++iter) {
245 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter); 246 PluginProcessHost* plugin = static_cast<PluginProcessHost*>(*iter);
246 if (plugin->info().path == plugin_path) 247 if (plugin->info().path == plugin_path)
247 return plugin; 248 return plugin;
248 } 249 }
249 250
250 return NULL; 251 return NULL;
251 } 252 }
252 253
253 PpapiPluginProcessHost* PluginService::FindPpapiPluginProcess( 254 PpapiPluginProcessHost* PluginServiceImpl::FindPpapiPluginProcess(
254 const FilePath& plugin_path) { 255 const FilePath& plugin_path) {
255 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
256 257
257 for (BrowserChildProcessHost::Iterator iter( 258 for (BrowserChildProcessHost::Iterator iter(
258 content::PROCESS_TYPE_PPAPI_PLUGIN); 259 content::PROCESS_TYPE_PPAPI_PLUGIN);
259 !iter.Done(); ++iter) { 260 !iter.Done(); ++iter) {
260 PpapiPluginProcessHost* plugin = 261 PpapiPluginProcessHost* plugin =
261 static_cast<PpapiPluginProcessHost*>(*iter); 262 static_cast<PpapiPluginProcessHost*>(*iter);
262 if (plugin->plugin_path() == plugin_path) 263 if (plugin->plugin_path() == plugin_path)
263 return plugin; 264 return plugin;
264 } 265 }
265 266
266 return NULL; 267 return NULL;
267 } 268 }
268 269
269 PpapiPluginProcessHost* PluginService::FindPpapiBrokerProcess( 270 PpapiPluginProcessHost* PluginServiceImpl::FindPpapiBrokerProcess(
270 const FilePath& broker_path) { 271 const FilePath& broker_path) {
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
272 273
273 for (BrowserChildProcessHost::Iterator iter( 274 for (BrowserChildProcessHost::Iterator iter(
274 content::PROCESS_TYPE_PPAPI_BROKER); 275 content::PROCESS_TYPE_PPAPI_BROKER);
275 !iter.Done(); ++iter) { 276 !iter.Done(); ++iter) {
276 PpapiPluginProcessHost* broker = 277 PpapiPluginProcessHost* broker =
277 static_cast<PpapiPluginProcessHost*>(*iter); 278 static_cast<PpapiPluginProcessHost*>(*iter);
278 if (broker->plugin_path() == broker_path) 279 if (broker->plugin_path() == broker_path)
279 return broker; 280 return broker;
280 } 281 }
281 282
282 return NULL; 283 return NULL;
283 } 284 }
284 285
285 PluginProcessHost* PluginService::FindOrStartNpapiPluginProcess( 286 PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess(
286 const FilePath& plugin_path) { 287 const FilePath& plugin_path) {
287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 288 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
288 289
289 PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); 290 PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path);
290 if (plugin_host) 291 if (plugin_host)
291 return plugin_host; 292 return plugin_host;
292 293
293 webkit::WebPluginInfo info; 294 webkit::WebPluginInfo info;
294 if (!GetPluginInfoByPath(plugin_path, &info)) { 295 if (!GetPluginInfoByPath(plugin_path, &info)) {
295 return NULL; 296 return NULL;
296 } 297 }
297 298
298 // This plugin isn't loaded by any plugin process, so create a new process. 299 // This plugin isn't loaded by any plugin process, so create a new process.
299 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); 300 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost());
300 if (!new_host->Init(info, ui_locale_)) { 301 if (!new_host->Init(info, ui_locale_)) {
301 NOTREACHED(); // Init is not expected to fail. 302 NOTREACHED(); // Init is not expected to fail.
302 return NULL; 303 return NULL;
303 } 304 }
304 return new_host.release(); 305 return new_host.release();
305 } 306 }
306 307
307 PpapiPluginProcessHost* PluginService::FindOrStartPpapiPluginProcess( 308 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess(
308 const FilePath& plugin_path, 309 const FilePath& plugin_path,
309 PpapiPluginProcessHost::PluginClient* client) { 310 PpapiPluginProcessHost::PluginClient* client) {
310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
311 312
312 PpapiPluginProcessHost* plugin_host = FindPpapiPluginProcess(plugin_path); 313 PpapiPluginProcessHost* plugin_host = FindPpapiPluginProcess(plugin_path);
313 if (plugin_host) 314 if (plugin_host)
314 return plugin_host; 315 return plugin_host;
315 316
316 // Validate that the plugin is actually registered. 317 // Validate that the plugin is actually registered.
317 content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); 318 content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
318 if (!info) 319 if (!info)
319 return NULL; 320 return NULL;
320 321
321 // This plugin isn't loaded by any plugin process, so create a new process. 322 // This plugin isn't loaded by any plugin process, so create a new process.
322 return PpapiPluginProcessHost::CreatePluginHost( 323 return PpapiPluginProcessHost::CreatePluginHost(
323 *info, 324 *info,
324 client->GetResourceContext()->host_resolver()); 325 client->GetResourceContext()->host_resolver());
325 } 326 }
326 327
327 PpapiPluginProcessHost* PluginService::FindOrStartPpapiBrokerProcess( 328 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess(
328 const FilePath& plugin_path) { 329 const FilePath& plugin_path) {
329 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
330 331
331 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); 332 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path);
332 if (plugin_host) 333 if (plugin_host)
333 return plugin_host; 334 return plugin_host;
334 335
335 // Validate that the plugin is actually registered. 336 // Validate that the plugin is actually registered.
336 content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); 337 content::PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path);
337 if (!info) 338 if (!info)
338 return NULL; 339 return NULL;
339 340
340 // TODO(ddorwin): Uncomment once out of process is supported. 341 // TODO(ddorwin): Uncomment once out of process is supported.
341 // DCHECK(info->is_out_of_process); 342 // DCHECK(info->is_out_of_process);
342 343
343 // This broker isn't loaded by any broker process, so create a new process. 344 // This broker isn't loaded by any broker process, so create a new process.
344 return PpapiPluginProcessHost::CreateBrokerHost(*info); 345 return PpapiPluginProcessHost::CreateBrokerHost(*info);
345 } 346 }
346 347
347 void PluginService::OpenChannelToNpapiPlugin( 348 void PluginServiceImpl::OpenChannelToNpapiPlugin(
348 int render_process_id, 349 int render_process_id,
349 int render_view_id, 350 int render_view_id,
350 const GURL& url, 351 const GURL& url,
351 const GURL& page_url, 352 const GURL& page_url,
352 const std::string& mime_type, 353 const std::string& mime_type,
353 PluginProcessHost::Client* client) { 354 PluginProcessHost::Client* client) {
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 355 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
355 DCHECK(!ContainsKey(pending_plugin_clients_, client)); 356 DCHECK(!ContainsKey(pending_plugin_clients_, client));
356 pending_plugin_clients_.insert(client); 357 pending_plugin_clients_.insert(client);
357 358
358 // Make sure plugins are loaded if necessary. 359 // Make sure plugins are loaded if necessary.
359 content::PluginServiceFilterParams params = { 360 content::PluginServiceFilterParams params = {
360 render_process_id, 361 render_process_id,
361 render_view_id, 362 render_view_id,
362 page_url, 363 page_url,
363 &client->GetResourceContext() 364 &client->GetResourceContext()
364 }; 365 };
365 GetPlugins( 366 GetPlugins(base::Bind(
366 base::Bind(&PluginService::ForwardGetAllowedPluginForOpenChannelToPlugin, 367 &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin,
367 base::Unretained(this), params, url, mime_type, client)); 368 base::Unretained(this), params, url, mime_type, client));
368 } 369 }
369 370
370 void PluginService::OpenChannelToPpapiPlugin( 371 void PluginServiceImpl::OpenChannelToPpapiPlugin(
371 const FilePath& path, 372 const FilePath& path,
372 PpapiPluginProcessHost::PluginClient* client) { 373 PpapiPluginProcessHost::PluginClient* client) {
373 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( 374 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess(
374 path, client); 375 path, client);
375 if (plugin_host) 376 if (plugin_host)
376 plugin_host->OpenChannelToPlugin(client); 377 plugin_host->OpenChannelToPlugin(client);
377 else // Send error. 378 else // Send error.
378 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); 379 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle());
379 } 380 }
380 381
381 void PluginService::OpenChannelToPpapiBroker( 382 void PluginServiceImpl::OpenChannelToPpapiBroker(
382 const FilePath& path, 383 const FilePath& path,
383 PpapiPluginProcessHost::BrokerClient* client) { 384 PpapiPluginProcessHost::BrokerClient* client) {
384 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); 385 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path);
385 if (plugin_host) 386 if (plugin_host)
386 plugin_host->OpenChannelToPlugin(client); 387 plugin_host->OpenChannelToPlugin(client);
387 else // Send error. 388 else // Send error.
388 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle()); 389 client->OnChannelOpened(base::kNullProcessHandle, IPC::ChannelHandle());
389 } 390 }
390 391
391 void PluginService::CancelOpenChannelToNpapiPlugin( 392 void PluginServiceImpl::CancelOpenChannelToNpapiPlugin(
392 PluginProcessHost::Client* client) { 393 PluginProcessHost::Client* client) {
393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
394 DCHECK(ContainsKey(pending_plugin_clients_, client)); 395 DCHECK(ContainsKey(pending_plugin_clients_, client));
395 pending_plugin_clients_.erase(client); 396 pending_plugin_clients_.erase(client);
396 } 397 }
397 398
398 void PluginService::ForwardGetAllowedPluginForOpenChannelToPlugin( 399 void PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin(
399 const content::PluginServiceFilterParams& params, 400 const content::PluginServiceFilterParams& params,
400 const GURL& url, 401 const GURL& url,
401 const std::string& mime_type, 402 const std::string& mime_type,
402 PluginProcessHost::Client* client, 403 PluginProcessHost::Client* client,
403 const std::vector<webkit::WebPluginInfo>&) { 404 const std::vector<webkit::WebPluginInfo>&) {
404 GetAllowedPluginForOpenChannelToPlugin(params.render_process_id, 405 GetAllowedPluginForOpenChannelToPlugin(params.render_process_id,
405 params.render_view_id, url, params.page_url, mime_type, client, 406 params.render_view_id, url, params.page_url, mime_type, client,
406 params.resource_context); 407 params.resource_context);
407 } 408 }
408 409
409 void PluginService::GetAllowedPluginForOpenChannelToPlugin( 410 void PluginServiceImpl::GetAllowedPluginForOpenChannelToPlugin(
410 int render_process_id, 411 int render_process_id,
411 int render_view_id, 412 int render_view_id,
412 const GURL& url, 413 const GURL& url,
413 const GURL& page_url, 414 const GURL& page_url,
414 const std::string& mime_type, 415 const std::string& mime_type,
415 PluginProcessHost::Client* client, 416 PluginProcessHost::Client* client,
416 const content::ResourceContext* resource_context) { 417 const content::ResourceContext* resource_context) {
417 webkit::WebPluginInfo info; 418 webkit::WebPluginInfo info;
418 bool allow_wildcard = true; 419 bool allow_wildcard = true;
419 bool found = GetPluginInfo( 420 bool found = GetPluginInfo(
420 render_process_id, render_view_id, *resource_context, 421 render_process_id, render_view_id, *resource_context,
421 url, page_url, mime_type, allow_wildcard, 422 url, page_url, mime_type, allow_wildcard,
422 NULL, &info, NULL); 423 NULL, &info, NULL);
423 FilePath plugin_path; 424 FilePath plugin_path;
424 if (found) 425 if (found)
425 plugin_path = info.path; 426 plugin_path = info.path;
426 427
427 // Now we jump back to the IO thread to finish opening the channel. 428 // Now we jump back to the IO thread to finish opening the channel.
428 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 429 BrowserThread::PostTask(
429 base::Bind(&PluginService::FinishOpenChannelToPlugin, 430 BrowserThread::IO, FROM_HERE,
431 base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin,
430 base::Unretained(this), plugin_path, client)); 432 base::Unretained(this), plugin_path, client));
431 } 433 }
432 434
433 void PluginService::FinishOpenChannelToPlugin( 435 void PluginServiceImpl::FinishOpenChannelToPlugin(
434 const FilePath& plugin_path, 436 const FilePath& plugin_path,
435 PluginProcessHost::Client* client) { 437 PluginProcessHost::Client* client) {
436 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 438 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
437 439
438 // Make sure it hasn't been canceled yet. 440 // Make sure it hasn't been canceled yet.
439 if (!ContainsKey(pending_plugin_clients_, client)) 441 if (!ContainsKey(pending_plugin_clients_, client))
440 return; 442 return;
441 pending_plugin_clients_.erase(client); 443 pending_plugin_clients_.erase(client);
442 444
443 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); 445 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path);
444 if (plugin_host) { 446 if (plugin_host) {
445 client->OnFoundPluginProcessHost(plugin_host); 447 client->OnFoundPluginProcessHost(plugin_host);
446 plugin_host->OpenChannelToPlugin(client); 448 plugin_host->OpenChannelToPlugin(client);
447 } else { 449 } else {
448 client->OnError(); 450 client->OnError();
449 } 451 }
450 } 452 }
451 453
452 bool PluginService::GetPluginInfoArray( 454 bool PluginServiceImpl::GetPluginInfoArray(
453 const GURL& url, 455 const GURL& url,
454 const std::string& mime_type, 456 const std::string& mime_type,
455 bool allow_wildcard, 457 bool allow_wildcard,
456 std::vector<webkit::WebPluginInfo>* plugins, 458 std::vector<webkit::WebPluginInfo>* plugins,
457 std::vector<std::string>* actual_mime_types) { 459 std::vector<std::string>* actual_mime_types) {
458 bool use_stale = false; 460 bool use_stale = false;
459 plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard, 461 plugin_list_->GetPluginInfoArray(url, mime_type, allow_wildcard,
460 &use_stale, plugins, actual_mime_types); 462 &use_stale, plugins, actual_mime_types);
461 return use_stale; 463 return use_stale;
462 } 464 }
463 465
464 bool PluginService::GetPluginInfo(int render_process_id, 466 bool PluginServiceImpl::GetPluginInfo(int render_process_id,
465 int render_view_id, 467 int render_view_id,
466 const content::ResourceContext& context, 468 const content::ResourceContext& context,
467 const GURL& url, 469 const GURL& url,
468 const GURL& page_url, 470 const GURL& page_url,
469 const std::string& mime_type, 471 const std::string& mime_type,
470 bool allow_wildcard, 472 bool allow_wildcard,
471 bool* is_stale, 473 bool* is_stale,
472 webkit::WebPluginInfo* info, 474 webkit::WebPluginInfo* info,
473 std::string* actual_mime_type) { 475 std::string* actual_mime_type) {
474 std::vector<webkit::WebPluginInfo> plugins; 476 std::vector<webkit::WebPluginInfo> plugins;
475 std::vector<std::string> mime_types; 477 std::vector<std::string> mime_types;
476 bool stale = GetPluginInfoArray( 478 bool stale = GetPluginInfoArray(
477 url, mime_type, allow_wildcard, &plugins, &mime_types); 479 url, mime_type, allow_wildcard, &plugins, &mime_types);
478 if (is_stale) 480 if (is_stale)
479 *is_stale = stale; 481 *is_stale = stale;
480 if (plugins.size() > 1 && 482 if (plugins.size() > 1 &&
481 plugins.back().path == 483 plugins.back().path ==
482 FilePath(webkit::npapi::kDefaultPluginLibraryName)) { 484 FilePath(webkit::npapi::kDefaultPluginLibraryName)) {
483 // If there is at least one plug-in handling the required MIME type (apart 485 // If there is at least one plug-in handling the required MIME type (apart
(...skipping 10 matching lines...) Expand all
494 &plugins[i])) { 496 &plugins[i])) {
495 *info = plugins[i]; 497 *info = plugins[i];
496 if (actual_mime_type) 498 if (actual_mime_type)
497 *actual_mime_type = mime_types[i]; 499 *actual_mime_type = mime_types[i];
498 return true; 500 return true;
499 } 501 }
500 } 502 }
501 return false; 503 return false;
502 } 504 }
503 505
504 bool PluginService::GetPluginInfoByPath(const FilePath& plugin_path, 506 bool PluginServiceImpl::GetPluginInfoByPath(const FilePath& plugin_path,
505 webkit::WebPluginInfo* info) { 507 webkit::WebPluginInfo* info) {
506 std::vector<webkit::WebPluginInfo> plugins; 508 std::vector<webkit::WebPluginInfo> plugins;
507 plugin_list_->GetPluginsIfNoRefreshNeeded(&plugins); 509 plugin_list_->GetPluginsIfNoRefreshNeeded(&plugins);
508 510
509 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin(); 511 for (std::vector<webkit::WebPluginInfo>::iterator it = plugins.begin();
510 it != plugins.end(); 512 it != plugins.end();
511 ++it) { 513 ++it) {
512 if (it->path == plugin_path) { 514 if (it->path == plugin_path) {
513 *info = *it; 515 *info = *it;
514 return true; 516 return true;
515 } 517 }
516 } 518 }
517 519
518 return false; 520 return false;
519 } 521 }
520 522
521 void PluginService::GetPlugins(const GetPluginsCallback& callback) { 523 void PluginServiceImpl::GetPlugins(const GetPluginsCallback& callback) {
522 scoped_refptr<base::MessageLoopProxy> target_loop( 524 scoped_refptr<base::MessageLoopProxy> target_loop(
523 MessageLoop::current()->message_loop_proxy()); 525 MessageLoop::current()->message_loop_proxy());
524 526
525 #if defined(OS_WIN) 527 #if defined(OS_WIN)
526 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 528 BrowserThread::PostTask(
527 base::Bind(&PluginService::GetPluginsInternal, base::Unretained(this), 529 BrowserThread::FILE, FROM_HERE,
530 base::Bind(&PluginServiceImpl::GetPluginsInternal, base::Unretained(this),
528 target_loop, callback)); 531 target_loop, callback));
529 #else 532 #else
530 std::vector<webkit::WebPluginInfo> cached_plugins; 533 std::vector<webkit::WebPluginInfo> cached_plugins;
531 if (plugin_list_->GetPluginsIfNoRefreshNeeded(&cached_plugins)) { 534 if (plugin_list_->GetPluginsIfNoRefreshNeeded(&cached_plugins)) {
532 // Can't assume the caller is reentrant. 535 // Can't assume the caller is reentrant.
533 target_loop->PostTask(FROM_HERE, 536 target_loop->PostTask(FROM_HERE,
534 base::Bind(&RunGetPluginsCallback, callback, cached_plugins)); 537 base::Bind(&RunGetPluginsCallback, callback, cached_plugins));
535 } else { 538 } else {
536 // If we switch back to loading plugins in process, then we need to make 539 // If we switch back to loading plugins in process, then we need to make
537 // sure g_thread_init() gets called since plugins may call glib at load. 540 // sure g_thread_init() gets called since plugins may call glib at load.
538 if (!plugin_loader_.get()) 541 if (!plugin_loader_.get())
539 plugin_loader_ = new PluginLoaderPosix; 542 plugin_loader_ = new PluginLoaderPosix;
540 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 543 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
541 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_, 544 base::Bind(&PluginLoaderPosix::LoadPlugins, plugin_loader_,
542 target_loop, callback)); 545 target_loop, callback));
543 } 546 }
544 #endif 547 #endif
545 } 548 }
546 549
547 void PluginService::GetPluginGroups(const GetPluginGroupsCallback& callback) { 550 void PluginServiceImpl::GetPluginGroups(
551 const GetPluginGroupsCallback& callback) {
548 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback)); 552 GetPlugins(base::Bind(&GetPluginsForGroupsCallback, callback));
549 } 553 }
550 554
551 void PluginService::GetPluginsInternal( 555 void PluginServiceImpl::GetPluginsInternal(
552 base::MessageLoopProxy* target_loop, 556 base::MessageLoopProxy* target_loop,
553 const PluginService::GetPluginsCallback& callback) { 557 const PluginService::GetPluginsCallback& callback) {
554 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); 558 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
555 559
556 std::vector<webkit::WebPluginInfo> plugins; 560 std::vector<webkit::WebPluginInfo> plugins;
557 plugin_list_->GetPlugins(&plugins); 561 plugin_list_->GetPlugins(&plugins);
558 562
559 target_loop->PostTask(FROM_HERE, 563 target_loop->PostTask(FROM_HERE,
560 base::Bind(&RunGetPluginsCallback, callback, plugins)); 564 base::Bind(&RunGetPluginsCallback, callback, plugins));
561 } 565 }
562 566
563 void PluginService::OnWaitableEventSignaled( 567 void PluginServiceImpl::OnWaitableEventSignaled(
564 base::WaitableEvent* waitable_event) { 568 base::WaitableEvent* waitable_event) {
565 #if defined(OS_WIN) 569 #if defined(OS_WIN)
566 if (waitable_event == hkcu_event_.get()) { 570 if (waitable_event == hkcu_event_.get()) {
567 hkcu_key_.StartWatching(); 571 hkcu_key_.StartWatching();
568 } else { 572 } else {
569 hklm_key_.StartWatching(); 573 hklm_key_.StartWatching();
570 } 574 }
571 575
572 plugin_list_->RefreshPlugins(); 576 plugin_list_->RefreshPlugins();
573 PurgePluginListCache(NULL, false); 577 PurgePluginListCache(NULL, false);
574 #else 578 #else
575 // This event should only get signaled on a Windows machine. 579 // This event should only get signaled on a Windows machine.
576 NOTREACHED(); 580 NOTREACHED();
577 #endif // defined(OS_WIN) 581 #endif // defined(OS_WIN)
578 } 582 }
579 583
580 void PluginService::Observe(int type, 584 void PluginServiceImpl::Observe(int type,
581 const content::NotificationSource& source, 585 const content::NotificationSource& source,
582 const content::NotificationDetails& details) { 586 const content::NotificationDetails& details) {
583 #if defined(OS_MACOSX) 587 #if defined(OS_MACOSX)
584 if (type == content::NOTIFICATION_APP_ACTIVATED) { 588 if (type == content::NOTIFICATION_APP_ACTIVATED) {
585 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 589 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
586 base::Bind(&NotifyPluginsOfActivation)); 590 base::Bind(&NotifyPluginsOfActivation));
587 return; 591 return;
588 } 592 }
589 #endif 593 #endif
590 NOTREACHED(); 594 NOTREACHED();
591 } 595 }
592 596
593 void PluginService::RegisterPepperPlugins() { 597 void PluginServiceImpl::RegisterPepperPlugins() {
594 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. 598 // TODO(abarth): It seems like the PepperPluginRegistry should do this work.
595 PepperPluginRegistry::ComputeList(&ppapi_plugins_); 599 PepperPluginRegistry::ComputeList(&ppapi_plugins_);
596 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { 600 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) {
597 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo()); 601 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo());
598 } 602 }
599 } 603 }
600 604
601 // There should generally be very few plugins so a brute-force search is fine. 605 // There should generally be very few plugins so a brute-force search is fine.
602 content::PepperPluginInfo* PluginService::GetRegisteredPpapiPluginInfo( 606 content::PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo(
603 const FilePath& plugin_path) { 607 const FilePath& plugin_path) {
604 content::PepperPluginInfo* info = NULL; 608 content::PepperPluginInfo* info = NULL;
605 for (size_t i = 0; i < ppapi_plugins_.size(); i++) { 609 for (size_t i = 0; i < ppapi_plugins_.size(); i++) {
606 if (ppapi_plugins_[i].path == plugin_path) { 610 if (ppapi_plugins_[i].path == plugin_path) {
607 info = &ppapi_plugins_[i]; 611 info = &ppapi_plugins_[i];
608 break; 612 break;
609 } 613 }
610 } 614 }
611 if (info) 615 if (info)
612 return info; 616 return info;
613 // We did not find the plugin in our list. But wait! the plugin can also 617 // We did not find the plugin in our list. But wait! the plugin can also
614 // be a latecomer, as it happens with pepper flash. This information 618 // be a latecomer, as it happens with pepper flash. This information
615 // can be obtained from the PluginList singleton and we can use it to 619 // can be obtained from the PluginList singleton and we can use it to
616 // construct it and add it to the list. This same deal needs to be done 620 // construct it and add it to the list. This same deal needs to be done
617 // in the renderer side in PepperPluginRegistry. 621 // in the renderer side in PepperPluginRegistry.
618 webkit::WebPluginInfo webplugin_info; 622 webkit::WebPluginInfo webplugin_info;
619 if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) 623 if (!GetPluginInfoByPath(plugin_path, &webplugin_info))
620 return NULL; 624 return NULL;
621 content::PepperPluginInfo new_pepper_info; 625 content::PepperPluginInfo new_pepper_info;
622 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) 626 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info))
623 return NULL; 627 return NULL;
624 ppapi_plugins_.push_back(new_pepper_info); 628 ppapi_plugins_.push_back(new_pepper_info);
625 return &ppapi_plugins_[ppapi_plugins_.size() - 1]; 629 return &ppapi_plugins_[ppapi_plugins_.size() - 1];
626 } 630 }
627 631
628 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD) 632 #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_OPENBSD)
629 // static 633 // static
630 void PluginService::RegisterFilePathWatcher( 634 void PluginServiceImpl::RegisterFilePathWatcher(
631 FilePathWatcher *watcher, 635 FilePathWatcher *watcher,
632 const FilePath& path, 636 const FilePath& path,
633 FilePathWatcher::Delegate* delegate) { 637 FilePathWatcher::Delegate* delegate) {
634 bool result = watcher->Watch(path, delegate); 638 bool result = watcher->Watch(path, delegate);
635 DCHECK(result); 639 DCHECK(result);
636 } 640 }
637 #endif 641 #endif
638 642
639 void PluginService::SetFilter(content::PluginServiceFilter* filter) { 643 void PluginServiceImpl::SetFilter(content::PluginServiceFilter* filter) {
640 filter_ = filter; 644 filter_ = filter;
641 } 645 }
642 646
643 content::PluginServiceFilter* PluginService::GetFilter() { 647 content::PluginServiceFilter* PluginServiceImpl::GetFilter() {
644 return filter_; 648 return filter_;
645 } 649 }
646 650
647 void PluginService::RefreshPlugins() { 651 void PluginServiceImpl::RefreshPlugins() {
648 plugin_list_->RefreshPlugins(); 652 plugin_list_->RefreshPlugins();
649 } 653 }
650 654
651 void PluginService::AddExtraPluginPath(const FilePath& path) { 655 void PluginServiceImpl::AddExtraPluginPath(const FilePath& path) {
652 plugin_list_->AddExtraPluginPath(path); 656 plugin_list_->AddExtraPluginPath(path);
653 } 657 }
654 658
655 void PluginService::RemoveExtraPluginPath(const FilePath& path) { 659 void PluginServiceImpl::RemoveExtraPluginPath(const FilePath& path) {
656 plugin_list_->RemoveExtraPluginPath(path); 660 plugin_list_->RemoveExtraPluginPath(path);
657 } 661 }
658 662
659 void PluginService::UnregisterInternalPlugin(const FilePath& path) { 663 void PluginServiceImpl::UnregisterInternalPlugin(const FilePath& path) {
660 plugin_list_->UnregisterInternalPlugin(path); 664 plugin_list_->UnregisterInternalPlugin(path);
661 } 665 }
662 666
663 void PluginService::SetPluginListForTesting( 667 void PluginServiceImpl::SetPluginListForTesting(
664 webkit::npapi::PluginList* plugin_list) { 668 webkit::npapi::PluginList* plugin_list) {
665 plugin_list_ = plugin_list; 669 plugin_list_ = plugin_list;
666 } 670 }
667 671
668 void PluginService::RegisterInternalPlugin(const webkit::WebPluginInfo& info) { 672 void PluginServiceImpl::RegisterInternalPlugin(
673 const webkit::WebPluginInfo& info) {
669 plugin_list_->RegisterInternalPlugin(info); 674 plugin_list_->RegisterInternalPlugin(info);
670 } 675 }
671 676
672 string16 PluginService::GetPluginGroupName(const std::string& plugin_name) { 677 string16 PluginServiceImpl::GetPluginGroupName(const std::string& plugin_name) {
673 return plugin_list_->GetPluginGroupName(plugin_name); 678 return plugin_list_->GetPluginGroupName(plugin_name);
674 } 679 }
675 680
676 webkit::npapi::PluginList* PluginService::GetPluginList() { 681 webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() {
677 return plugin_list_; 682 return plugin_list_;
678 } 683 }
OLDNEW
« no previous file with comments | « content/browser/plugin_service_impl.h ('k') | content/browser/plugin_service_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698