| 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 const FilePath& broker_path) { | 252 const FilePath& broker_path) { |
| 253 for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) { | 253 for (PpapiBrokerProcessHostIterator iter; !iter.Done(); ++iter) { |
| 254 if (iter->plugin_path() == broker_path) | 254 if (iter->plugin_path() == broker_path) |
| 255 return *iter; | 255 return *iter; |
| 256 } | 256 } |
| 257 | 257 |
| 258 return NULL; | 258 return NULL; |
| 259 } | 259 } |
| 260 | 260 |
| 261 PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess( | 261 PluginProcessHost* PluginServiceImpl::FindOrStartNpapiPluginProcess( |
| 262 int render_process_id, |
| 262 const FilePath& plugin_path) { | 263 const FilePath& plugin_path) { |
| 263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 264 | 265 |
| 266 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 267 return NULL; |
| 268 |
| 265 PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); | 269 PluginProcessHost* plugin_host = FindNpapiPluginProcess(plugin_path); |
| 266 if (plugin_host) | 270 if (plugin_host) |
| 267 return plugin_host; | 271 return plugin_host; |
| 268 | 272 |
| 269 webkit::WebPluginInfo info; | 273 webkit::WebPluginInfo info; |
| 270 if (!GetPluginInfoByPath(plugin_path, &info)) { | 274 if (!GetPluginInfoByPath(plugin_path, &info)) { |
| 271 return NULL; | 275 return NULL; |
| 272 } | 276 } |
| 273 | 277 |
| 274 // This plugin isn't loaded by any plugin process, so create a new process. | 278 // This plugin isn't loaded by any plugin process, so create a new process. |
| 275 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); | 279 scoped_ptr<PluginProcessHost> new_host(new PluginProcessHost()); |
| 276 if (!new_host->Init(info)) { | 280 if (!new_host->Init(info)) { |
| 277 NOTREACHED(); // Init is not expected to fail. | 281 NOTREACHED(); // Init is not expected to fail. |
| 278 return NULL; | 282 return NULL; |
| 279 } | 283 } |
| 280 return new_host.release(); | 284 return new_host.release(); |
| 281 } | 285 } |
| 282 | 286 |
| 283 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( | 287 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiPluginProcess( |
| 288 int render_process_id, |
| 284 const FilePath& plugin_path, | 289 const FilePath& plugin_path, |
| 285 const FilePath& profile_data_directory, | 290 const FilePath& profile_data_directory, |
| 286 PpapiPluginProcessHost::PluginClient* client) { | 291 PpapiPluginProcessHost::PluginClient* client) { |
| 287 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 288 | 293 |
| 294 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 295 return NULL; |
| 296 |
| 289 PpapiPluginProcessHost* plugin_host = | 297 PpapiPluginProcessHost* plugin_host = |
| 290 FindPpapiPluginProcess(plugin_path, profile_data_directory); | 298 FindPpapiPluginProcess(plugin_path, profile_data_directory); |
| 291 if (plugin_host) | 299 if (plugin_host) |
| 292 return plugin_host; | 300 return plugin_host; |
| 293 | 301 |
| 294 // Validate that the plugin is actually registered. | 302 // Validate that the plugin is actually registered. |
| 295 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); | 303 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
| 296 if (!info) | 304 if (!info) |
| 297 return NULL; | 305 return NULL; |
| 298 | 306 |
| 299 // This plugin isn't loaded by any plugin process, so create a new process. | 307 // This plugin isn't loaded by any plugin process, so create a new process. |
| 300 return PpapiPluginProcessHost::CreatePluginHost( | 308 return PpapiPluginProcessHost::CreatePluginHost( |
| 301 *info, profile_data_directory, | 309 *info, profile_data_directory, |
| 302 client->GetResourceContext()->GetHostResolver()); | 310 client->GetResourceContext()->GetHostResolver()); |
| 303 } | 311 } |
| 304 | 312 |
| 305 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( | 313 PpapiPluginProcessHost* PluginServiceImpl::FindOrStartPpapiBrokerProcess( |
| 314 int render_process_id, |
| 306 const FilePath& plugin_path) { | 315 const FilePath& plugin_path) { |
| 307 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 316 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 308 | 317 |
| 318 if (filter_ && !filter_->CanLoadPlugin(render_process_id, plugin_path)) |
| 319 return NULL; |
| 320 |
| 309 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); | 321 PpapiPluginProcessHost* plugin_host = FindPpapiBrokerProcess(plugin_path); |
| 310 if (plugin_host) | 322 if (plugin_host) |
| 311 return plugin_host; | 323 return plugin_host; |
| 312 | 324 |
| 313 // Validate that the plugin is actually registered. | 325 // Validate that the plugin is actually registered. |
| 314 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); | 326 PepperPluginInfo* info = GetRegisteredPpapiPluginInfo(plugin_path); |
| 315 if (!info) | 327 if (!info) |
| 316 return NULL; | 328 return NULL; |
| 317 | 329 |
| 318 // TODO(ddorwin): Uncomment once out of process is supported. | 330 // TODO(ddorwin): Uncomment once out of process is supported. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 339 render_view_id, | 351 render_view_id, |
| 340 page_url, | 352 page_url, |
| 341 client->GetResourceContext() | 353 client->GetResourceContext() |
| 342 }; | 354 }; |
| 343 GetPlugins(base::Bind( | 355 GetPlugins(base::Bind( |
| 344 &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, | 356 &PluginServiceImpl::ForwardGetAllowedPluginForOpenChannelToPlugin, |
| 345 base::Unretained(this), params, url, mime_type, client)); | 357 base::Unretained(this), params, url, mime_type, client)); |
| 346 } | 358 } |
| 347 | 359 |
| 348 void PluginServiceImpl::OpenChannelToPpapiPlugin( | 360 void PluginServiceImpl::OpenChannelToPpapiPlugin( |
| 361 int render_process_id, |
| 349 const FilePath& plugin_path, | 362 const FilePath& plugin_path, |
| 350 const FilePath& profile_data_directory, | 363 const FilePath& profile_data_directory, |
| 351 PpapiPluginProcessHost::PluginClient* client) { | 364 PpapiPluginProcessHost::PluginClient* client) { |
| 352 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( | 365 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiPluginProcess( |
| 353 plugin_path, profile_data_directory, client); | 366 render_process_id, plugin_path, profile_data_directory, client); |
| 354 if (plugin_host) { | 367 if (plugin_host) { |
| 355 plugin_host->OpenChannelToPlugin(client); | 368 plugin_host->OpenChannelToPlugin(client); |
| 356 } else { | 369 } else { |
| 357 // Send error. | 370 // Send error. |
| 358 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); | 371 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
| 359 } | 372 } |
| 360 } | 373 } |
| 361 | 374 |
| 362 void PluginServiceImpl::OpenChannelToPpapiBroker( | 375 void PluginServiceImpl::OpenChannelToPpapiBroker( |
| 376 int render_process_id, |
| 363 const FilePath& path, | 377 const FilePath& path, |
| 364 PpapiPluginProcessHost::BrokerClient* client) { | 378 PpapiPluginProcessHost::BrokerClient* client) { |
| 365 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess(path); | 379 PpapiPluginProcessHost* plugin_host = FindOrStartPpapiBrokerProcess( |
| 380 render_process_id, path); |
| 366 if (plugin_host) { | 381 if (plugin_host) { |
| 367 plugin_host->OpenChannelToPlugin(client); | 382 plugin_host->OpenChannelToPlugin(client); |
| 368 } else { | 383 } else { |
| 369 // Send error. | 384 // Send error. |
| 370 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); | 385 client->OnPpapiChannelOpened(IPC::ChannelHandle(), base::kNullProcessId, 0); |
| 371 } | 386 } |
| 372 } | 387 } |
| 373 | 388 |
| 374 void PluginServiceImpl::CancelOpenChannelToNpapiPlugin( | 389 void PluginServiceImpl::CancelOpenChannelToNpapiPlugin( |
| 375 PluginProcessHost::Client* client) { | 390 PluginProcessHost::Client* client) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 404 url, page_url, mime_type, allow_wildcard, | 419 url, page_url, mime_type, allow_wildcard, |
| 405 NULL, &info, NULL); | 420 NULL, &info, NULL); |
| 406 FilePath plugin_path; | 421 FilePath plugin_path; |
| 407 if (found) | 422 if (found) |
| 408 plugin_path = info.path; | 423 plugin_path = info.path; |
| 409 | 424 |
| 410 // Now we jump back to the IO thread to finish opening the channel. | 425 // Now we jump back to the IO thread to finish opening the channel. |
| 411 BrowserThread::PostTask( | 426 BrowserThread::PostTask( |
| 412 BrowserThread::IO, FROM_HERE, | 427 BrowserThread::IO, FROM_HERE, |
| 413 base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin, | 428 base::Bind(&PluginServiceImpl::FinishOpenChannelToPlugin, |
| 414 base::Unretained(this), plugin_path, client)); | 429 base::Unretained(this), |
| 430 render_process_id, |
| 431 plugin_path, |
| 432 client)); |
| 415 } | 433 } |
| 416 | 434 |
| 417 void PluginServiceImpl::FinishOpenChannelToPlugin( | 435 void PluginServiceImpl::FinishOpenChannelToPlugin( |
| 436 int render_process_id, |
| 418 const FilePath& plugin_path, | 437 const FilePath& plugin_path, |
| 419 PluginProcessHost::Client* client) { | 438 PluginProcessHost::Client* client) { |
| 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 421 | 440 |
| 422 // Make sure it hasn't been canceled yet. | 441 // Make sure it hasn't been canceled yet. |
| 423 if (!ContainsKey(pending_plugin_clients_, client)) | 442 if (!ContainsKey(pending_plugin_clients_, client)) |
| 424 return; | 443 return; |
| 425 pending_plugin_clients_.erase(client); | 444 pending_plugin_clients_.erase(client); |
| 426 | 445 |
| 427 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess(plugin_path); | 446 PluginProcessHost* plugin_host = FindOrStartNpapiPluginProcess( |
| 447 render_process_id, plugin_path); |
| 428 if (plugin_host) { | 448 if (plugin_host) { |
| 429 client->OnFoundPluginProcessHost(plugin_host); | 449 client->OnFoundPluginProcessHost(plugin_host); |
| 430 plugin_host->OpenChannelToPlugin(client); | 450 plugin_host->OpenChannelToPlugin(client); |
| 431 } else { | 451 } else { |
| 432 client->OnError(); | 452 client->OnError(); |
| 433 } | 453 } |
| 434 } | 454 } |
| 435 | 455 |
| 436 bool PluginServiceImpl::GetPluginInfoArray( | 456 bool PluginServiceImpl::GetPluginInfoArray( |
| 437 const GURL& url, | 457 const GURL& url, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 456 webkit::WebPluginInfo* info, | 476 webkit::WebPluginInfo* info, |
| 457 std::string* actual_mime_type) { | 477 std::string* actual_mime_type) { |
| 458 std::vector<webkit::WebPluginInfo> plugins; | 478 std::vector<webkit::WebPluginInfo> plugins; |
| 459 std::vector<std::string> mime_types; | 479 std::vector<std::string> mime_types; |
| 460 bool stale = GetPluginInfoArray( | 480 bool stale = GetPluginInfoArray( |
| 461 url, mime_type, allow_wildcard, &plugins, &mime_types); | 481 url, mime_type, allow_wildcard, &plugins, &mime_types); |
| 462 if (is_stale) | 482 if (is_stale) |
| 463 *is_stale = stale; | 483 *is_stale = stale; |
| 464 | 484 |
| 465 for (size_t i = 0; i < plugins.size(); ++i) { | 485 for (size_t i = 0; i < plugins.size(); ++i) { |
| 466 if (!filter_ || filter_->ShouldUsePlugin(render_process_id, | 486 if (!filter_ || filter_->IsPluginEnabled(render_process_id, |
| 467 render_view_id, | 487 render_view_id, |
| 468 context, | 488 context, |
| 469 url, | 489 url, |
| 470 page_url, | 490 page_url, |
| 471 &plugins[i])) { | 491 &plugins[i])) { |
| 472 *info = plugins[i]; | 492 *info = plugins[i]; |
| 473 if (actual_mime_type) | 493 if (actual_mime_type) |
| 474 *actual_mime_type = mime_types[i]; | 494 *actual_mime_type = mime_types[i]; |
| 475 return true; | 495 return true; |
| 476 } | 496 } |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 void PluginServiceImpl::GetInternalPlugins( | 740 void PluginServiceImpl::GetInternalPlugins( |
| 721 std::vector<webkit::WebPluginInfo>* plugins) { | 741 std::vector<webkit::WebPluginInfo>* plugins) { |
| 722 plugin_list_->GetInternalPlugins(plugins); | 742 plugin_list_->GetInternalPlugins(plugins); |
| 723 } | 743 } |
| 724 | 744 |
| 725 webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() { | 745 webkit::npapi::PluginList* PluginServiceImpl::GetPluginList() { |
| 726 return plugin_list_; | 746 return plugin_list_; |
| 727 } | 747 } |
| 728 | 748 |
| 729 } // namespace content | 749 } // namespace content |
| OLD | NEW |