Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.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" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 | 257 |
| 258 // This plugin isn't loaded by any plugin process, so create a new process. | 258 // This plugin isn't loaded by any plugin process, so create a new process. |
| 259 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); | 259 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
| 260 if (!new_host->Init(info)) { | 260 if (!new_host->Init(info)) { |
| 261 NOTREACHED(); // Init is not expected to fail. | 261 NOTREACHED(); // Init is not expected to fail. |
| 262 return NULL; | 262 return NULL; |
| 263 } | 263 } |
| 264 return new_host.release(); | 264 return new_host.release(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 #if defined(ENABLE_PLUGINS) | |
|
jam
2012/12/17 17:54:53
what would be the point of including this file whe
| |
| 267 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( | 268 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( |
| 268 const FilePath& plugin_path, | 269 const FilePath& plugin_path, |
| 269 const FilePath& profile_data_directory, | 270 const FilePath& profile_data_directory, |
| 270 PpapiPluginProcessHost::PluginClient* client) { | 271 PpapiPluginProcessHost::PluginClient* client) { |
| 271 #if defined(ENABLE_PLUGINS) | |
| 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 273 | 273 |
| 274 PpapiPluginProcessHost* plugin_host = | 274 PpapiPluginProcessHost* plugin_host = |
| 275 FindPpapiPluginProcess(plugin_path, profile_data_directory); | 275 FindPpapiPluginProcess(plugin_path, profile_data_directory); |
| 276 if (plugin_host) | 276 if (plugin_host) |
| 277 return plugin_host; | 277 return plugin_host; |
| 278 | 278 |
| 279 // Validate that the plugin is actually registered. | 279 // Validate that the plugin is actually registered. |
| 280 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); | 280 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
| 281 if (!info) | 281 if (!info) |
| 282 return NULL; | 282 return NULL; |
| 283 | 283 |
| 284 // This plugin isn't loaded by any plugin process, so create a new process. | 284 // This plugin isn't loaded by any plugin process, so create a new process. |
| 285 return PpapiPluginProcessHost::CreatePluginHost( | 285 return PpapiPluginProcessHost::CreatePluginHost( |
| 286 *info, profile_data_directory, | 286 *info, profile_data_directory, |
| 287 client->GetResourceContext()->GetHostResolver()); | 287 client->GetResourceContext()->GetHostResolver()); |
| 288 #else | |
| 289 return NULL; | |
| 290 #endif | |
| 291 } | 288 } |
| 292 | 289 |
| 293 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( | 290 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( |
| 294 const FilePath& plugin_path) { | 291 const FilePath& plugin_path) { |
| 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 296 | 293 |
| 297 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); | 294 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
| 298 if (plugin_host) | 295 if (plugin_host) |
| 299 return plugin_host; | 296 return plugin_host; |
| 300 | 297 |
| 301 // Validate that the plugin is actually registered. | 298 // Validate that the plugin is actually registered. |
| 302 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); | 299 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
| 303 if (!info) | 300 if (!info) |
| 304 return NULL; | 301 return NULL; |
| 305 | 302 |
| 306 // TODO(ddorwin): Uncomment once out of process is supported. | 303 // TODO(ddorwin): Uncomment once out of process is supported. |
| 307 // DCHECK(info->is_out_of_process); | 304 // DCHECK(info->is_out_of_process); |
| 308 | 305 |
| 309 // This broker isn't loaded by any broker process, so create a new process. | 306 // This broker isn't loaded by any broker process, so create a new process. |
| 310 return PpapiPluginProcessHost::CreateBrokerHost(*info); | 307 return PpapiPluginProcessHost::CreateBrokerHost(*info); |
| 311 } | 308 } |
| 309 #endif // defined(ENABLE_PLUGINS) | |
| 312 | 310 |
| 313 void PluginServiceImpl::OpenChannelToNpapiPlugin( | 311 void PluginServiceImpl::OpenChannelToNpapiPlugin( |
| 314 int render_process_id, | 312 int render_process_id, |
| 315 int render_view_id, | 313 int render_view_id, |
| 316 const GURL& url, | 314 const GURL& url, |
| 317 const GURL& page_url, | 315 const GURL& page_url, |
| 318 const std::string& mime_type, | 316 const std::string& mime_type, |
| 319 PluginProcessHost::Client* client) { | 317 PluginProcessHost::Client* client) { |
| 320 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 318 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 321 DCHECK(!ContainsKey(pending_plugin_clients_, client)); | 319 DCHECK(!ContainsKey(pending_plugin_clients_, client)); |
| 322 pending_plugin_clients_.insert(client); | 320 pending_plugin_clients_.insert(client); |
| 323 | 321 |
| 324 // Make sure plugins are loaded if necessary. | 322 // Make sure plugins are loaded if necessary. |
| 325 PluginServiceFilterParams params = { | 323 PluginServiceFilterParams params = { |
| 326 render_process_id, | 324 render_process_id, |
| 327 render_view_id, | 325 render_view_id, |
| 328 page_url, | 326 page_url, |
| 329 client->GetResourceContext() | 327 client->GetResourceContext() |
| 330 }; | 328 }; |
| 331 GetPlugins(base::Bind( | 329 GetPlugins(base::Bind( |
| 332 &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, | 330 &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, |
| 333 base::Unretained(this), params, url, mime_type, client)); | 331 base::Unretained(this), params, url, mime_type, client)); |
| 334 } | 332 } |
| 335 | 333 |
| 336 void PluginServiceImpl::OpenChannelToPpapiPlugin( | 334 void PluginServiceImpl::OpenChannelToPpapiPlugin( |
| 337 const FilePath& plugin_path, | 335 const FilePath& plugin_path, |
| 338 const FilePath& profile_data_directory, | 336 const FilePath& profile_data_directory, |
| 339 PpapiPluginProcessHost::PluginClient* client) { | 337 PpapiPluginProcessHost::PluginClient* client) { |
| 338 #if defined(ENABLE_PLUGINS) | |
| 340 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( | 339 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
| 341 plugin_path, profile_data_directory, client); | 340 plugin_path, profile_data_directory, client); |
| 342 if (plugin_host) { | 341 if (plugin_host) { |
| 343 plugin_host->OpenChannelToPlugin(client); | 342 plugin_host->OpenChannelToPlugin(client); |
| 344 } else { | 343 } else { |
| 345 // Send error. | 344 // Send error. |
| 346 client->OnPpapiChannelOpened(IPC::ChannelHandle(), 0); | 345 client->OnPpapiChannelOpened(IPC::ChannelHandle(), 0); |
| 347 } | 346 } |
| 347 #endif // defined(ENABLE_PLUGINS) | |
| 348 } | 348 } |
| 349 | 349 |
| 350 void PluginServiceImpl::OpenChannelToPpapiBroker( | 350 void PluginServiceImpl::OpenChannelToPpapiBroker( |
| 351 const FilePath& path, | 351 const FilePath& path, |
| 352 PpapiPluginProcessHost::BrokerClient* client) { | 352 PpapiPluginProcessHost::BrokerClient* client) { |
| 353 #if defined(ENABLE_PLUGINS) | 353 #if defined(ENABLE_PLUGINS) |
| 354 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); | 354 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); |
| 355 if (plugin_host) { | 355 if (plugin_host) { |
| 356 plugin_host->OpenChannelToPlugin(client); | 356 plugin_host->OpenChannelToPlugin(client); |
| 357 } else { | 357 } else { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 | 559 |
| 560 plugin_list_->RefreshPlugins(); | 560 plugin_list_->RefreshPlugins(); |
| 561 PurgePluginListCache(NULL, false); | 561 PurgePluginListCache(NULL, false); |
| 562 #else | 562 #else |
| 563 // This event should only get signaled on a Windows machine. | 563 // This event should only get signaled on a Windows machine. |
| 564 NOTREACHED(); | 564 NOTREACHED(); |
| 565 #endif // defined(OS_WIN) | 565 #endif // defined(OS_WIN) |
| 566 } | 566 } |
| 567 | 567 |
| 568 void PluginServiceImpl::RegisterPepperPlugins() { | 568 void PluginServiceImpl::RegisterPepperPlugins() { |
| 569 #if defined(ENABLE_PLUGINS) | |
| 569 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. | 570 // TODO(abarth): It seems like the PepperPluginRegistry should do this work. |
| 570 PepperPluginRegistry::ComputeList(&ppapi_plugins_); | 571 PepperPluginRegistry::ComputeList(&ppapi_plugins_); |
| 571 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { | 572 for (size_t i = 0; i < ppapi_plugins_.size(); ++i) { |
| 572 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); | 573 RegisterInternalPlugin(ppapi_plugins_[i].ToWebPluginInfo(), true); |
| 573 } | 574 } |
| 575 #endif | |
| 574 } | 576 } |
| 575 | 577 |
| 576 // There should generally be very few plugins so a brute-force search is fine. | 578 // There should generally be very few plugins so a brute-force search is fine. |
| 577 PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( | 579 PepperPluginInfo* PluginServiceImpl::GetRegisteredPpapiPluginInfo( |
| 578 const FilePath& plugin_path) { | 580 const FilePath& plugin_path) { |
| 579 PepperPluginInfo* info = NULL; | 581 PepperPluginInfo* info = NULL; |
| 582 #if !defined(ENABLE_PLUGINS) | |
| 583 return info; | |
| 584 #else | |
| 580 for (size_t i = 0; i < ppapi_plugins_.size(); i++) { | 585 for (size_t i = 0; i < ppapi_plugins_.size(); i++) { |
| 581 if (ppapi_plugins_[i].path == plugin_path) { | 586 if (ppapi_plugins_[i].path == plugin_path) { |
| 582 info = &ppapi_plugins_[i]; | 587 info = &ppapi_plugins_[i]; |
| 583 break; | 588 break; |
| 584 } | 589 } |
| 585 } | 590 } |
| 586 if (info) | 591 if (info) |
| 587 return info; | 592 return info; |
| 588 // We did not find the plugin in our list. But wait! the plugin can also | 593 // We did not find the plugin in our list. But wait! the plugin can also |
| 589 // be a latecomer, as it happens with pepper flash. This information | 594 // be a latecomer, as it happens with pepper flash. This information |
| 590 // can be obtained from the PluginList singleton and we can use it to | 595 // can be obtained from the PluginList singleton and we can use it to |
| 591 // construct it and add it to the list. This same deal needs to be done | 596 // construct it and add it to the list. This same deal needs to be done |
| 592 // in the renderer side in PepperPluginRegistry. | 597 // in the renderer side in PepperPluginRegistry. |
| 593 webkit::WebPluginInfo webplugin_info; | 598 webkit::WebPluginInfo webplugin_info; |
| 594 if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) | 599 if (!GetPluginInfoByPath(plugin_path, &webplugin_info)) |
| 595 return NULL; | 600 return NULL; |
| 596 PepperPluginInfo new_pepper_info; | 601 PepperPluginInfo new_pepper_info; |
| 597 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) | 602 if (!MakePepperPluginInfo(webplugin_info, &new_pepper_info)) |
| 598 return NULL; | 603 return NULL; |
| 599 ppapi_plugins_.push_back(new_pepper_info); | 604 ppapi_plugins_.push_back(new_pepper_info); |
| 600 return &ppapi_plugins_[ppapi_plugins_.size() - 1]; | 605 return &ppapi_plugins_[ppapi_plugins_.size() - 1]; |
| 606 #endif | |
| 601 } | 607 } |
| 602 | 608 |
| 603 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) | 609 #if defined(OS_POSIX) && !defined(OS_OPENBSD) && !defined(OS_ANDROID) |
| 604 // static | 610 // static |
| 605 void PluginServiceImpl::RegisterFilePathWatcher( | 611 void PluginServiceImpl::RegisterFilePathWatcher( |
| 606 FilePathWatcher* watcher, | 612 FilePathWatcher* watcher, |
| 607 const FilePath& path, | 613 const FilePath& path, |
| 608 FilePathWatcher::Delegate* delegate) { | 614 FilePathWatcher::Delegate* delegate) { |
| 609 bool result = watcher->Watch(path, delegate); | 615 bool result = watcher->Watch(path, delegate); |
| 610 DCHECK(result); | 616 DCHECK(result); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 void PluginServiceImpl::GetInternalPlugins( | 715 void PluginServiceImpl::GetInternalPlugins( |
| 710 std::vector<webkit::WebPluginInfo>* plugins) { | 716 std::vector<webkit::WebPluginInfo>* plugins) { |
| 711 plugin_list_->GetInternalPlugins(plugins); | 717 plugin_list_->GetInternalPlugins(plugins); |
| 712 } | 718 } |
| 713 | 719 |
| 714 webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() { | 720 webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() { |
| 715 return plugin_list_; | 721 return plugin_list_; |
| 716 } | 722 } |
| 717 | 723 |
| 718 } // namespace content | 724 } // namespace content |
| OLD | NEW |