| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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" | |
| 6 | |
| 7 #include "chrome/browser/plugin_process_host.h" | 5 #include "chrome/browser/plugin_process_host.h" |
| 8 | 6 |
| 9 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 10 #include <windows.h> | 8 #include <windows.h> |
| 9 #elif defined(OS_POSIX) |
| 10 #include <utility> // for pair<> |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "app/app_switches.h" | 15 #include "app/app_switches.h" |
| 16 #include "app/gfx/native_widget_types.h" | 16 #include "app/gfx/native_widget_types.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #if defined(OS_POSIX) | |
| 19 #include "base/global_descriptors_posix.h" | |
| 20 #endif | |
| 21 #include "base/file_path.h" | 18 #include "base/file_path.h" |
| 22 #include "base/file_util.h" | 19 #include "base/file_util.h" |
| 23 #include "base/file_version_info.h" | |
| 24 #include "base/logging.h" | 20 #include "base/logging.h" |
| 25 #include "base/path_service.h" | 21 #include "base/path_service.h" |
| 26 #include "base/process_util.h" | 22 #include "base/process_util.h" |
| 27 #include "base/scoped_ptr.h" | |
| 28 #include "base/string_util.h" | 23 #include "base/string_util.h" |
| 29 #include "base/thread.h" | |
| 30 #include "chrome/browser/browser.h" | |
| 31 #include "chrome/browser/browser_list.h" | |
| 32 #include "chrome/browser/browser_process.h" | |
| 33 #include "chrome/browser/browser_window.h" | |
| 34 #include "chrome/browser/child_process_security_policy.h" | 24 #include "chrome/browser/child_process_security_policy.h" |
| 35 #include "chrome/browser/chrome_plugin_browsing_context.h" | 25 #include "chrome/browser/chrome_plugin_browsing_context.h" |
| 36 #include "chrome/browser/chrome_thread.h" | 26 #include "chrome/browser/chrome_thread.h" |
| 37 #include "chrome/browser/net/url_request_context_getter.h" | 27 #include "chrome/browser/net/url_request_context_getter.h" |
| 38 #include "chrome/browser/net/url_request_tracking.h" | 28 #include "chrome/browser/net/url_request_tracking.h" |
| 39 #include "chrome/browser/plugin_service.h" | 29 #include "chrome/browser/plugin_service.h" |
| 40 #include "chrome/browser/profile.h" | 30 #include "chrome/browser/profile.h" |
| 41 #include "chrome/browser/renderer_host/browser_render_process_host.h" | |
| 42 #include "chrome/browser/renderer_host/render_process_host.h" | |
| 43 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 31 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 32 #include "chrome/common/chrome_descriptors.h" |
| 44 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 45 #include "chrome/common/chrome_plugin_lib.h" | 34 #include "chrome/common/chrome_plugin_lib.h" |
| 46 #include "chrome/common/chrome_switches.h" | 35 #include "chrome/common/chrome_switches.h" |
| 47 #include "chrome/common/logging_chrome.h" | 36 #include "chrome/common/logging_chrome.h" |
| 48 #include "chrome/common/plugin_messages.h" | 37 #include "chrome/common/plugin_messages.h" |
| 49 #include "chrome/common/render_messages.h" | 38 #include "chrome/common/render_messages.h" |
| 50 #include "ipc/ipc_channel_handle.h" | |
| 51 #include "ipc/ipc_descriptors.h" | 39 #include "ipc/ipc_descriptors.h" |
| 52 #include "ipc/ipc_switches.h" | 40 #include "ipc/ipc_switches.h" |
| 53 #include "net/base/file_stream.h" | 41 #include "net/base/file_stream.h" |
| 54 #include "net/base/io_buffer.h" | 42 #include "net/base/io_buffer.h" |
| 55 #include "net/url_request/url_request.h" | 43 #include "net/url_request/url_request.h" |
| 56 #include "net/url_request/url_request_context.h" | 44 #include "net/url_request/url_request_context.h" |
| 57 #include "webkit/glue/plugins/plugin_constants_win.h" | |
| 58 | 45 |
| 59 #if defined(OS_WIN) | 46 #if defined(OS_WIN) |
| 60 #include "app/win_util.h" | 47 #include "app/win_util.h" |
| 61 #include "chrome/browser/sandbox_policy.h" | 48 #include "chrome/browser/sandbox_policy.h" |
| 62 #include "sandbox/src/sandbox.h" | 49 #include "sandbox/src/sandbox.h" |
| 50 #include "webkit/glue/plugins/plugin_constants_win.h" |
| 63 #endif | 51 #endif |
| 64 | 52 |
| 65 #if defined(OS_POSIX) | 53 #if defined(OS_POSIX) |
| 54 #include "base/global_descriptors_posix.h" |
| 66 #include "ipc/ipc_channel_posix.h" | 55 #include "ipc/ipc_channel_posix.h" |
| 67 #endif | 56 #endif |
| 68 | 57 |
| 69 #if defined(OS_LINUX) | 58 #if defined(OS_LINUX) |
| 70 #include "app/gfx/gtk_native_view_id_manager.h" | 59 #include "app/gfx/gtk_native_view_id_manager.h" |
| 60 #include "chrome/browser/crash_handler_host_linux.h" |
| 71 #endif | 61 #endif |
| 72 | 62 |
| 73 #if defined(OS_MACOSX) | 63 #if defined(OS_MACOSX) |
| 74 #include "base/mac_util.h" | 64 #include "base/mac_util.h" |
| 75 #include "chrome/common/plugin_carbon_interpose_constants_mac.h" | 65 #include "chrome/common/plugin_carbon_interpose_constants_mac.h" |
| 76 #endif | 66 #endif |
| 77 | 67 |
| 78 static const char kDefaultPluginFinderURL[] = | 68 static const char kDefaultPluginFinderURL[] = |
| 79 "https://dl-ssl.google.com/edgedl/chrome/plugins/plugins2.xml"; | 69 "https://dl-ssl.google.com/edgedl/chrome/plugins/plugins2.xml"; |
| 80 | 70 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 // The buffer passed off to URLRequest::Read. | 105 // The buffer passed off to URLRequest::Read. |
| 116 scoped_refptr<net::IOBuffer> download_file_buffer_; | 106 scoped_refptr<net::IOBuffer> download_file_buffer_; |
| 117 // TODO(port): this comment doesn't describe the situation on Posix. | 107 // TODO(port): this comment doesn't describe the situation on Posix. |
| 118 // The window handle for sending the WM_COPYDATA notification, | 108 // The window handle for sending the WM_COPYDATA notification, |
| 119 // indicating that the download completed. | 109 // indicating that the download completed. |
| 120 gfx::NativeWindow download_file_caller_window_; | 110 gfx::NativeWindow download_file_caller_window_; |
| 121 | 111 |
| 122 std::string download_url_; | 112 std::string download_url_; |
| 123 int download_source_child_unique_id_; | 113 int download_source_child_unique_id_; |
| 124 | 114 |
| 125 DISALLOW_EVIL_CONSTRUCTORS(PluginDownloadUrlHelper); | 115 DISALLOW_COPY_AND_ASSIGN(PluginDownloadUrlHelper); |
| 126 }; | 116 }; |
| 127 | 117 |
| 128 PluginDownloadUrlHelper::PluginDownloadUrlHelper( | 118 PluginDownloadUrlHelper::PluginDownloadUrlHelper( |
| 129 const std::string& download_url, | 119 const std::string& download_url, |
| 130 int source_child_unique_id, | 120 int source_child_unique_id, |
| 131 gfx::NativeWindow caller_window) | 121 gfx::NativeWindow caller_window) |
| 132 : download_file_request_(NULL), | 122 : download_file_request_(NULL), |
| 133 download_file_buffer_(new net::IOBuffer(kDownloadFileBufferSize)), | 123 download_file_buffer_(new net::IOBuffer(kDownloadFileBufferSize)), |
| 134 download_file_caller_window_(caller_window), | 124 download_file_caller_window_(caller_window), |
| 135 download_url_(download_url), | 125 download_url_(download_url), |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 426 | 416 |
| 427 cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, | 417 cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, |
| 428 ASCIIToWide(channel_id())); | 418 ASCIIToWide(channel_id())); |
| 429 | 419 |
| 430 SetCrashReporterCommandLine(&cmd_line); | 420 SetCrashReporterCommandLine(&cmd_line); |
| 431 | 421 |
| 432 base::ProcessHandle process = 0; | 422 base::ProcessHandle process = 0; |
| 433 #if defined(OS_WIN) | 423 #if defined(OS_WIN) |
| 434 process = sandbox::StartProcess(&cmd_line); | 424 process = sandbox::StartProcess(&cmd_line); |
| 435 #else | 425 #else |
| 426 process = InitHelperPosix(cmd_line); |
| 427 #endif // OS_WIN |
| 428 |
| 429 if (!process) |
| 430 return false; |
| 431 SetHandle(process); |
| 432 |
| 433 FilePath gears_path; |
| 434 if (PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_path)) { |
| 435 FilePath::StringType gears_path_lc = StringToLowerASCII(gears_path.value()); |
| 436 FilePath::StringType plugin_path_lc = |
| 437 StringToLowerASCII(info.path.value()); |
| 438 if (plugin_path_lc == gears_path_lc) { |
| 439 // Give Gears plugins "background" priority. See |
| 440 // http://b/issue?id=1280317. |
| 441 SetProcessBackgrounded(); |
| 442 } |
| 443 } |
| 444 |
| 445 return true; |
| 446 } |
| 447 |
| 448 #if defined(OS_POSIX) |
| 449 base::ProcessHandle PluginProcessHost::InitHelperPosix( |
| 450 const CommandLine& cmd_line) { |
| 451 base::ProcessHandle process = 0; |
| 436 // This code is duplicated with browser_render_process_host.cc, but | 452 // This code is duplicated with browser_render_process_host.cc, but |
| 437 // there's not a good place to de-duplicate it. | 453 // there's not a good place to de-duplicate it. |
| 438 base::file_handle_mapping_vector fds_to_map; | 454 base::file_handle_mapping_vector fds_to_map; |
| 439 const int ipcfd = channel().GetClientFileDescriptor(); | 455 const int ipcfd = channel().GetClientFileDescriptor(); |
| 440 if (ipcfd > -1) | 456 if (ipcfd > -1) |
| 441 fds_to_map.push_back(std::pair<int, int>( | 457 fds_to_map.push_back(std::pair<int, int>( |
| 442 ipcfd, kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); | 458 ipcfd, kPrimaryIPCChannel + base::GlobalDescriptors::kBaseDescriptor)); |
| 443 base::environment_vector env; | 459 base::environment_vector env; |
| 444 #if defined(OS_MACOSX) | 460 #if defined(OS_MACOSX) |
| 445 // Add our interposing library for Carbon. This is stripped back out in | 461 // Add our interposing library for Carbon. This is stripped back out in |
| 446 // plugin_main.cc, so changes here should be reflected there. | 462 // plugin_main.cc, so changes here should be reflected there. |
| 447 std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath); | 463 std::string interpose_list(plugin_interpose_strings::kInterposeLibraryPath); |
| 448 const char* existing_list = | 464 const char* existing_list = |
| 449 getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey); | 465 getenv(plugin_interpose_strings::kDYLDInsertLibrariesKey); |
| 450 if (existing_list) { | 466 if (existing_list) { |
| 451 interpose_list.insert(0, ":"); | 467 interpose_list.insert(0, ":"); |
| 452 interpose_list.insert(0, existing_list); | 468 interpose_list.insert(0, existing_list); |
| 453 } | 469 } |
| 454 env.push_back(std::pair<const char*, const char*>( | 470 env.push_back(std::pair<const char*, const char*>( |
| 455 plugin_interpose_strings::kDYLDInsertLibrariesKey, | 471 plugin_interpose_strings::kDYLDInsertLibrariesKey, |
| 456 interpose_list.c_str())); | 472 interpose_list.c_str())); |
| 473 #elif defined(OS_LINUX) |
| 474 const int crash_signal_fd = |
| 475 Singleton<PluginCrashHandlerHostLinux>()->GetDeathSignalSocket(); |
| 476 if (crash_signal_fd >= 0) { |
| 477 fds_to_map.push_back(std::pair<int, uint32_t>(crash_signal_fd, |
| 478 kCrashDumpSignal + 3)); |
| 479 } |
| 457 #endif // OS_MACOSX | 480 #endif // OS_MACOSX |
| 458 if (!base::LaunchApp(cmd_line.argv(), env, fds_to_map, false, &process)) | 481 if (!base::LaunchApp(cmd_line.argv(), env, fds_to_map, false, &process)) |
| 459 return false; | 482 process = 0; |
| 460 #endif // OS_WIN | 483 return process; |
| 461 | |
| 462 if (!process) | |
| 463 return false; | |
| 464 SetHandle(process); | |
| 465 | |
| 466 FilePath gears_path; | |
| 467 if (PathService::Get(chrome::FILE_GEARS_PLUGIN, &gears_path)) { | |
| 468 FilePath::StringType gears_path_lc = StringToLowerASCII(gears_path.value()); | |
| 469 FilePath::StringType plugin_path_lc = | |
| 470 StringToLowerASCII(info.path.value()); | |
| 471 if (plugin_path_lc == gears_path_lc) { | |
| 472 // Give Gears plugins "background" priority. See | |
| 473 // http://b/issue?id=1280317. | |
| 474 SetProcessBackgrounded(); | |
| 475 } | |
| 476 } | |
| 477 | |
| 478 return true; | |
| 479 } | 484 } |
| 485 #endif // OS_POSIX |
| 480 | 486 |
| 481 void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { | 487 void PluginProcessHost::OnMessageReceived(const IPC::Message& msg) { |
| 482 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) | 488 IPC_BEGIN_MESSAGE_MAP(PluginProcessHost, msg) |
| 483 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) | 489 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_ChannelCreated, OnChannelCreated) |
| 484 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginFinderUrl, | 490 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetPluginFinderUrl, |
| 485 OnGetPluginFinderUrl) | 491 OnGetPluginFinderUrl) |
| 486 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginMessage, OnPluginMessage) | 492 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_PluginMessage, OnPluginMessage) |
| 487 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies) | 493 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_GetCookies, OnGetCookies) |
| 488 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_AccessFiles, OnAccessFiles) | 494 IPC_MESSAGE_HANDLER(PluginProcessHostMsg_AccessFiles, OnAccessFiles) |
| 489 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, | 495 IPC_MESSAGE_HANDLER_DELAY_REPLY(PluginProcessHostMsg_ResolveProxy, |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 const std::vector<uint8>& data) { | 678 const std::vector<uint8>& data) { |
| 673 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); | 679 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 674 | 680 |
| 675 ChromePluginLib *chrome_plugin = ChromePluginLib::Find(info_.path); | 681 ChromePluginLib *chrome_plugin = ChromePluginLib::Find(info_.path); |
| 676 if (chrome_plugin) { | 682 if (chrome_plugin) { |
| 677 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); | 683 void *data_ptr = const_cast<void*>(reinterpret_cast<const void*>(&data[0])); |
| 678 uint32 data_len = static_cast<uint32>(data.size()); | 684 uint32 data_len = static_cast<uint32>(data.size()); |
| 679 chrome_plugin->functions().on_message(data_ptr, data_len); | 685 chrome_plugin->functions().on_message(data_ptr, data_len); |
| 680 } | 686 } |
| 681 } | 687 } |
| OLD | NEW |