| 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 "chrome/browser/plugin_process_host.h" | 5 #include "chrome/browser/plugin_process_host.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 | 339 |
| 340 private: | 340 private: |
| 341 // |plugin_host_| is only valid if !this->revoked(). | 341 // |plugin_host_| is only valid if !this->revoked(). |
| 342 PluginProcessHost* plugin_host_; | 342 PluginProcessHost* plugin_host_; |
| 343 IPC::Message* reply_msg_; | 343 IPC::Message* reply_msg_; |
| 344 net::CompletionCallbackImpl<PluginResolveProxyHelper> callback_; | 344 net::CompletionCallbackImpl<PluginResolveProxyHelper> callback_; |
| 345 net::ProxyInfo proxy_info_; | 345 net::ProxyInfo proxy_info_; |
| 346 }; | 346 }; |
| 347 | 347 |
| 348 | 348 |
| 349 // Sends the reply to the create window message on the IO thread. |
| 350 class SendReplyTask : public Task { |
| 351 public: |
| 352 SendReplyTask(FilePath plugin_path, IPC::Message* reply_msg) |
| 353 : plugin_path_(plugin_path), reply_msg_(reply_msg) { } |
| 354 |
| 355 virtual void Run() { |
| 356 PluginProcessHost* plugin = |
| 357 PluginService::GetInstance()->FindPluginProcess(plugin_path_); |
| 358 if (!plugin) |
| 359 return; |
| 360 |
| 361 plugin->Send(reply_msg_); |
| 362 } |
| 363 |
| 364 private: |
| 365 FilePath plugin_path_; |
| 366 IPC::Message* reply_msg_; |
| 367 }; |
| 368 |
| 369 |
| 370 // Creates a child window of the given HWND on the UI thread. |
| 371 class CreateWindowTask : public Task { |
| 372 public: |
| 373 CreateWindowTask( |
| 374 FilePath plugin_path, HWND parent, IPC::Message* reply_msg) |
| 375 : plugin_path_(plugin_path), parent_(parent), reply_msg_(reply_msg) { } |
| 376 |
| 377 virtual void Run() { |
| 378 static ATOM window_class = 0; |
| 379 if (!window_class) { |
| 380 WNDCLASSEX wcex; |
| 381 wcex.cbSize = sizeof(WNDCLASSEX); |
| 382 wcex.style = CS_DBLCLKS; |
| 383 wcex.lpfnWndProc = DefWindowProc; |
| 384 wcex.cbClsExtra = 0; |
| 385 wcex.cbWndExtra = 0; |
| 386 wcex.hInstance = GetModuleHandle(NULL); |
| 387 wcex.hIcon = 0; |
| 388 wcex.hCursor = 0; |
| 389 wcex.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_WINDOW+1); |
| 390 wcex.lpszMenuName = 0; |
| 391 wcex.lpszClassName = L"NativeWindowClassWrapper"; |
| 392 wcex.hIconSm = 0; |
| 393 window_class = RegisterClassEx(&wcex); |
| 394 } |
| 395 |
| 396 HWND window = CreateWindowEx( |
| 397 WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR, |
| 398 MAKEINTATOM(window_class), 0, |
| 399 WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, |
| 400 0, 0, 0, 0, parent_, 0, GetModuleHandle(NULL), 0); |
| 401 |
| 402 PluginProcessHostMsg_CreateWindow::WriteReplyParams( |
| 403 reply_msg_, window); |
| 404 |
| 405 g_browser_process->io_thread()->message_loop()->PostTask( |
| 406 FROM_HERE, new SendReplyTask(plugin_path_, reply_msg_)); |
| 407 } |
| 408 |
| 409 private: |
| 410 FilePath plugin_path_; |
| 411 HWND parent_; |
| 412 IPC::Message* reply_msg_; |
| 413 }; |
| 414 |
| 415 // Destroys the given window on the UI thread. |
| 416 class DestroyWindowTask : public Task { |
| 417 public: |
| 418 DestroyWindowTask(HWND window) : window_(window) { } |
| 419 |
| 420 virtual void Run() { |
| 421 DestroyWindow(window_); |
| 422 } |
| 423 |
| 424 private: |
| 425 HWND window_; |
| 426 }; |
| 427 |
| 428 |
| 349 PluginProcessHost::PluginProcessHost(PluginService* plugin_service) | 429 PluginProcessHost::PluginProcessHost(PluginService* plugin_service) |
| 350 : process_(NULL), | 430 : process_(NULL), |
| 351 opening_channel_(false), | 431 opening_channel_(false), |
| 352 resource_dispatcher_host_(plugin_service->resource_dispatcher_host()), | 432 resource_dispatcher_host_(plugin_service->resource_dispatcher_host()), |
| 353 plugin_service_(plugin_service) { | 433 plugin_service_(plugin_service) { |
| 354 DCHECK(resource_dispatcher_host_); | 434 DCHECK(resource_dispatcher_host_); |
| 355 } | 435 } |
| 356 | 436 |
| 357 PluginProcessHost::~PluginProcessHost() { | 437 PluginProcessHost::~PluginProcessHost() { |
| 358 if (process_.handle()) { | 438 if (process_.handle()) { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginDataDir, | 652 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginDataDir, |
| 573 OnGetPluginDataDir) | 653 OnGetPluginDataDir) |
| 574 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource) | 654 IPC_MESSAGE_HANDLER(ViewHostMsg_RequestResource, OnRequestResource) |
| 575 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest) | 655 IPC_MESSAGE_HANDLER(ViewHostMsg_CancelRequest, OnCancelRequest) |
| 576 IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK) | 656 IPC_MESSAGE_HANDLER(ViewHostMsg_DataReceived_ACK, OnDataReceivedACK) |
| 577 IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK) | 657 IPC_MESSAGE_HANDLER(ViewHostMsg_UploadProgress_ACK, OnUploadProgressACK) |
| 578 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad) | 658 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_SyncLoad, OnSyncLoad) |
| 579 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies) | 659 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies) |
| 580 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, | 660 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, |
| 581 OnResolveProxy) | 661 OnResolveProxy) |
| 662 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_CreateWindow, |
| 663 OnCreateWindow) |
| 664 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_DestroyWindow, OnDestroyWindow) |
| 582 IPC_MESSAGE_UNHANDLED_ERROR() | 665 IPC_MESSAGE_UNHANDLED_ERROR() |
| 583 IPC_END_MESSAGE_MAP() | 666 IPC_END_MESSAGE_MAP() |
| 584 | 667 |
| 585 #ifdef IPC_MESSAGE_LOG_ENABLED | 668 #ifdef IPC_MESSAGE_LOG_ENABLED |
| 586 if (logger->Enabled()) | 669 if (logger->Enabled()) |
| 587 logger->OnPostDispatchMessage(msg, channel_id_); | 670 logger->OnPostDispatchMessage(msg, channel_id_); |
| 588 #endif | 671 #endif |
| 589 } | 672 } |
| 590 | 673 |
| 591 void PluginProcessHost::OnChannelConnected(int32 peer_pid) { | 674 void PluginProcessHost::OnChannelConnected(int32 peer_pid) { |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); | 914 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); |
| 832 uint32 data_len = static_cast<uint32>(data.size()); | 915 uint32 data_len = static_cast<uint32>(data.size()); |
| 833 chrome_plugin->functions().on_message(data_ptr, data_len); | 916 chrome_plugin->functions().on_message(data_ptr, data_len); |
| 834 } | 917 } |
| 835 } | 918 } |
| 836 | 919 |
| 837 void PluginProcessHost::OnGetPluginDataDir(std::wstring* retval) { | 920 void PluginProcessHost::OnGetPluginDataDir(std::wstring* retval) { |
| 838 *retval = plugin_service_->GetChromePluginDataDir(); | 921 *retval = plugin_service_->GetChromePluginDataDir(); |
| 839 } | 922 } |
| 840 | 923 |
| 924 void PluginProcessHost::OnCreateWindow(HWND parent, IPC::Message* reply_msg) { |
| 925 // Need to create this window on the UI thread. |
| 926 plugin_service_->main_message_loop()->PostTask(FROM_HERE, |
| 927 new CreateWindowTask(plugin_path_, parent, reply_msg)); |
| 928 } |
| 929 |
| 930 void PluginProcessHost::OnDestroyWindow(HWND window) { |
| 931 plugin_service_->main_message_loop()->PostTask(FROM_HERE, |
| 932 new DestroyWindowTask(window)); |
| 933 } |
| 934 |
| 841 void PluginProcessHost::Shutdown() { | 935 void PluginProcessHost::Shutdown() { |
| 842 | 936 |
| 843 Send(new PluginProcessMsg_BrowserShutdown); | 937 Send(new PluginProcessMsg_BrowserShutdown); |
| 844 } | 938 } |
| 845 | 939 |
| OLD | NEW |