| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #include "chrome/browser/plugin_process_host.h" | 7 #include "chrome/browser/plugin_process_host.h" |
| 8 | 8 |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <windows.h> | 10 #include <windows.h> |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 465 |
| 466 void PluginProcessHost::OpenChannelToPlugin( | 466 void PluginProcessHost::OpenChannelToPlugin( |
| 467 ResourceMessageFilter* renderer_message_filter, | 467 ResourceMessageFilter* renderer_message_filter, |
| 468 const std::string& mime_type, | 468 const std::string& mime_type, |
| 469 IPC::Message* reply_msg) { | 469 IPC::Message* reply_msg) { |
| 470 InstanceCreated(); | 470 InstanceCreated(); |
| 471 if (opening_channel()) { | 471 if (opening_channel()) { |
| 472 // The channel is already in the process of being opened. Put | 472 // The channel is already in the process of being opened. Put |
| 473 // this "open channel" request into a queue of requests that will | 473 // this "open channel" request into a queue of requests that will |
| 474 // be run once the channel is open. | 474 // be run once the channel is open. |
| 475 // | |
| 476 // On POSIX, we'll only create the pipe when we get around to actually | |
| 477 // making this request. So the socket fd is -1 for now. (On Windows, | |
| 478 // socket_fd is unused.) | |
| 479 int socket_fd = -1; | |
| 480 pending_requests_.push_back( | 475 pending_requests_.push_back( |
| 481 ChannelRequest(renderer_message_filter, mime_type, reply_msg, | 476 ChannelRequest(renderer_message_filter, mime_type, reply_msg)); |
| 482 socket_fd)); | |
| 483 return; | 477 return; |
| 484 } | 478 } |
| 485 | 479 |
| 486 // We already have an open channel, send a request right away to plugin. | 480 // We already have an open channel, send a request right away to plugin. |
| 487 RequestPluginChannel(renderer_message_filter, mime_type, reply_msg); | 481 RequestPluginChannel(renderer_message_filter, mime_type, reply_msg); |
| 488 } | 482 } |
| 489 | 483 |
| 490 void PluginProcessHost::OnGetCookies(uint32 request_context, | 484 void PluginProcessHost::OnGetCookies(uint32 request_context, |
| 491 const GURL& url, | 485 const GURL& url, |
| 492 std::string* cookies) { | 486 std::string* cookies) { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 | 520 |
| 527 URLRequestContext* PluginProcessHost::GetRequestContext( | 521 URLRequestContext* PluginProcessHost::GetRequestContext( |
| 528 uint32 request_id, | 522 uint32 request_id, |
| 529 const ViewHostMsg_Resource_Request& request_data) { | 523 const ViewHostMsg_Resource_Request& request_data) { |
| 530 return CPBrowsingContextManager::Instance()->ToURLRequestContext(request_id); | 524 return CPBrowsingContextManager::Instance()->ToURLRequestContext(request_id); |
| 531 } | 525 } |
| 532 | 526 |
| 533 void PluginProcessHost::RequestPluginChannel( | 527 void PluginProcessHost::RequestPluginChannel( |
| 534 ResourceMessageFilter* renderer_message_filter, | 528 ResourceMessageFilter* renderer_message_filter, |
| 535 const std::string& mime_type, IPC::Message* reply_msg) { | 529 const std::string& mime_type, IPC::Message* reply_msg) { |
| 536 // We're about to send the request for a plugin channel. | |
| 537 // On POSIX, we create the channel endpoints here, so we can send the | |
| 538 // endpoints to the plugin and renderer. | |
| 539 int plugin_fd = -1, renderer_fd = -1; | |
| 540 #if defined(OS_POSIX) | |
| 541 // On POSIX, we create the channel endpoints here. | |
| 542 IPC::SocketPair(&plugin_fd, &renderer_fd); | |
| 543 #endif | |
| 544 | |
| 545 // We can't send any sync messages from the browser because it might lead to | 530 // We can't send any sync messages from the browser because it might lead to |
| 546 // a hang. However this async messages must be answered right away by the | 531 // a hang. However this async messages must be answered right away by the |
| 547 // plugin process (i.e. unblocks a Send() call like a sync message) otherwise | 532 // plugin process (i.e. unblocks a Send() call like a sync message) otherwise |
| 548 // a deadlock can occur if the plugin creation request from the renderer is | 533 // a deadlock can occur if the plugin creation request from the renderer is |
| 549 // a result of a sync message by the plugin process. | 534 // a result of a sync message by the plugin process. |
| 550 PluginProcessMsg_CreateChannel* msg = new PluginProcessMsg_CreateChannel( | 535 PluginProcessMsg_CreateChannel* msg = new PluginProcessMsg_CreateChannel( |
| 551 #if defined(OS_POSIX) | |
| 552 // Takes ownership of plugin_fd. | |
| 553 base::FileDescriptor(plugin_fd, true), | |
| 554 #endif | |
| 555 renderer_message_filter->GetProcessId(), | 536 renderer_message_filter->GetProcessId(), |
| 556 renderer_message_filter->off_the_record()); | 537 renderer_message_filter->off_the_record()); |
| 557 msg->set_unblock(true); | 538 msg->set_unblock(true); |
| 558 if (Send(msg)) { | 539 if (Send(msg)) { |
| 559 sent_requests_.push(ChannelRequest( | 540 sent_requests_.push(ChannelRequest( |
| 560 renderer_message_filter, mime_type, reply_msg, renderer_fd)); | 541 renderer_message_filter, mime_type, reply_msg)); |
| 561 } else { | 542 } else { |
| 562 ReplyToRenderer(renderer_message_filter, IPC::ChannelHandle(), FilePath(), | 543 ReplyToRenderer(renderer_message_filter, IPC::ChannelHandle(), FilePath(), |
| 563 reply_msg); | 544 reply_msg); |
| 564 } | 545 } |
| 565 } | 546 } |
| 566 | 547 |
| 567 void PluginProcessHost::OnChannelCreated(const std::string& channel_name) { | 548 void PluginProcessHost::OnChannelCreated( |
| 549 const IPC::ChannelHandle& channel_handle) { |
| 568 const ChannelRequest& request = sent_requests_.front(); | 550 const ChannelRequest& request = sent_requests_.front(); |
| 569 IPC::ChannelHandle channel_handle(channel_name | 551 |
| 570 #if defined(OS_POSIX) | |
| 571 , base::FileDescriptor(request.socket, true) | |
| 572 #endif | |
| 573 ); | |
| 574 ReplyToRenderer(request.renderer_message_filter_.get(), | 552 ReplyToRenderer(request.renderer_message_filter_.get(), |
| 575 channel_handle, | 553 channel_handle, |
| 576 info_.path, | 554 info_.path, |
| 577 request.reply_msg); | 555 request.reply_msg); |
| 578 sent_requests_.pop(); | 556 sent_requests_.pop(); |
| 579 } | 557 } |
| 580 | 558 |
| 581 void PluginProcessHost::OnGetPluginFinderUrl(std::string* plugin_finder_url) { | 559 void PluginProcessHost::OnGetPluginFinderUrl(std::string* plugin_finder_url) { |
| 582 if (!plugin_finder_url) { | 560 if (!plugin_finder_url) { |
| 583 NOTREACHED(); | 561 NOTREACHED(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 594 DCHECK(MessageLoop::current() == | 572 DCHECK(MessageLoop::current() == |
| 595 ChromeThread::GetMessageLoop(ChromeThread::IO)); | 573 ChromeThread::GetMessageLoop(ChromeThread::IO)); |
| 596 | 574 |
| 597 ChromePluginLib *chrome_plugin = ChromePluginLib::Find(info_.path); | 575 ChromePluginLib *chrome_plugin = ChromePluginLib::Find(info_.path); |
| 598 if (chrome_plugin) { | 576 if (chrome_plugin) { |
| 599 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); | 577 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); |
| 600 uint32 data_len = static_cast<uint32>(data.size()); | 578 uint32 data_len = static_cast<uint32>(data.size()); |
| 601 chrome_plugin->functions().on_message(data_ptr, data_len); | 579 chrome_plugin->functions().on_message(data_ptr, data_len); |
| 602 } | 580 } |
| 603 } | 581 } |
| OLD | NEW |