| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-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 // Represents the browser side of the browser <--> renderer communication | 5 // Represents the browser side of the browser <--> renderer communication |
| 6 // channel. There will be one RenderProcessHost per renderer process. | 6 // channel. There will be one RenderProcessHost per renderer process. |
| 7 | 7 |
| 8 #include "chrome/browser/renderer_host/browser_render_process_host.h" | 8 #include "chrome/browser/renderer_host/browser_render_process_host.h" |
| 9 | 9 |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <limits> |
| 14 #include <vector> |
| 15 |
| 16 #if defined(OS_POSIX) |
| 17 #include <utility> // for pair<> |
| 18 #endif |
| 13 | 19 |
| 14 #include "app/app_switches.h" | 20 #include "app/app_switches.h" |
| 15 #if defined(OS_WIN) | |
| 16 #include "app/win_util.h" | |
| 17 #endif | |
| 18 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 19 #include "base/field_trial.h" | 22 #include "base/field_trial.h" |
| 20 #include "base/linked_ptr.h" | 23 #include "base/linked_ptr.h" |
| 21 #include "base/logging.h" | 24 #include "base/logging.h" |
| 22 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 23 #include "base/process_util.h" | 26 #include "base/process_util.h" |
| 24 #include "base/rand_util.h" | 27 #include "base/rand_util.h" |
| 25 #include "base/scoped_ptr.h" | 28 #include "base/scoped_ptr.h" |
| 26 #include "base/shared_memory.h" | 29 #include "base/shared_memory.h" |
| 27 #include "base/singleton.h" | 30 #include "base/singleton.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 47 #include "chrome/common/child_process_info.h" | 50 #include "chrome/common/child_process_info.h" |
| 48 #include "chrome/common/logging_chrome.h" | 51 #include "chrome/common/logging_chrome.h" |
| 49 #include "chrome/common/notification_service.h" | 52 #include "chrome/common/notification_service.h" |
| 50 #include "chrome/common/process_watcher.h" | 53 #include "chrome/common/process_watcher.h" |
| 51 #include "chrome/common/render_messages.h" | 54 #include "chrome/common/render_messages.h" |
| 52 #include "chrome/common/result_codes.h" | 55 #include "chrome/common/result_codes.h" |
| 53 #include "chrome/renderer/render_process.h" | 56 #include "chrome/renderer/render_process.h" |
| 54 #include "chrome/installer/util/google_update_settings.h" | 57 #include "chrome/installer/util/google_update_settings.h" |
| 55 #include "grit/generated_resources.h" | 58 #include "grit/generated_resources.h" |
| 56 | 59 |
| 57 #if defined(OS_LINUX) | 60 #if defined(OS_WIN) |
| 61 #include "app/win_util.h" |
| 62 #include "chrome/browser/sandbox_policy.h" |
| 63 #elif defined(OS_LINUX) |
| 64 #include "base/linux_util.h" |
| 58 #include "chrome/browser/zygote_host_linux.h" | 65 #include "chrome/browser/zygote_host_linux.h" |
| 59 #include "chrome/browser/renderer_host/render_crash_handler_host_linux.h" | 66 #include "chrome/browser/renderer_host/render_crash_handler_host_linux.h" |
| 60 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" | 67 #include "chrome/browser/renderer_host/render_sandbox_host_linux.h" |
| 61 #endif | 68 #endif |
| 62 | 69 |
| 63 using WebKit::WebCache; | 70 using WebKit::WebCache; |
| 64 | 71 |
| 65 #if defined(OS_WIN) | |
| 66 | |
| 67 // TODO(port): see comment by the only usage of RenderViewHost in this file. | |
| 68 #include "chrome/browser/renderer_host/render_view_host.h" | |
| 69 | |
| 70 | |
| 71 // Once the above TODO is finished, then this block is all Windows-specific | |
| 72 // files. | |
| 73 #include "base/win_util.h" | |
| 74 #include "chrome/browser/sandbox_policy.h" | |
| 75 #include "sandbox/src/sandbox.h" | |
| 76 #elif defined(OS_POSIX) | |
| 77 // TODO(port): Remove temporary scaffolding after porting the above headers. | |
| 78 #include "chrome/common/temp_scaffolding_stubs.h" | |
| 79 #endif | |
| 80 | |
| 81 #include "third_party/skia/include/core/SkBitmap.h" | 72 #include "third_party/skia/include/core/SkBitmap.h" |
| 82 | 73 |
| 83 | 74 |
| 84 // This class creates the IO thread for the renderer when running in | 75 // This class creates the IO thread for the renderer when running in |
| 85 // single-process mode. It's not used in multi-process mode. | 76 // single-process mode. It's not used in multi-process mode. |
| 86 class RendererMainThread : public base::Thread { | 77 class RendererMainThread : public base::Thread { |
| 87 public: | 78 public: |
| 88 explicit RendererMainThread(const std::string& channel_id) | 79 explicit RendererMainThread(const std::string& channel_id) |
| 89 : base::Thread("Chrome_InProcRendererThread"), | 80 : base::Thread("Chrome_InProcRendererThread"), |
| 90 channel_id_(channel_id), | 81 channel_id_(channel_id), |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 // launch the renderer child with some prefix (usually "gdb --args") | 385 // launch the renderer child with some prefix (usually "gdb --args") |
| 395 const std::wstring prefix = | 386 const std::wstring prefix = |
| 396 browser_command_line.GetSwitchValue(switches::kRendererCmdPrefix); | 387 browser_command_line.GetSwitchValue(switches::kRendererCmdPrefix); |
| 397 cmd_line.PrependWrapper(prefix); | 388 cmd_line.PrependWrapper(prefix); |
| 398 } | 389 } |
| 399 #endif // OS_POSIX | 390 #endif // OS_POSIX |
| 400 | 391 |
| 401 #if defined(OS_LINUX) | 392 #if defined(OS_LINUX) |
| 402 if (GoogleUpdateSettings::GetCollectStatsConsent()) | 393 if (GoogleUpdateSettings::GetCollectStatsConsent()) |
| 403 cmd_line.AppendSwitchWithValue(switches::kRendererCrashDump, | 394 cmd_line.AppendSwitchWithValue(switches::kRendererCrashDump, |
| 404 ASCIIToWide(google_update::linux_guid)); | 395 ASCIIToWide(google_update::linux_guid + |
| 396 "," + base::GetLinuxDistro())); |
| 405 #endif | 397 #endif |
| 406 | 398 |
| 407 cmd_line.AppendSwitchWithValue(switches::kProcessType, | 399 cmd_line.AppendSwitchWithValue(switches::kProcessType, |
| 408 switches::kRendererProcess); | 400 switches::kRendererProcess); |
| 409 | 401 |
| 410 cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, | 402 cmd_line.AppendSwitchWithValue(switches::kProcessChannelID, |
| 411 ASCIIToWide(channel_id)); | 403 ASCIIToWide(channel_id)); |
| 412 | 404 |
| 413 const std::wstring& profile_path = | 405 const std::wstring& profile_path = |
| 414 browser_command_line.GetSwitchValue(switches::kUserDataDir); | 406 browser_command_line.GetSwitchValue(switches::kUserDataDir); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 444 mapping.push_back(std::pair<uint32_t, int>(kPrimaryIPCChannel, ipcfd)); | 436 mapping.push_back(std::pair<uint32_t, int>(kPrimaryIPCChannel, ipcfd)); |
| 445 const int crash_signal_fd = | 437 const int crash_signal_fd = |
| 446 Singleton<RenderCrashHandlerHostLinux>()->GetDeathSignalSocket(); | 438 Singleton<RenderCrashHandlerHostLinux>()->GetDeathSignalSocket(); |
| 447 if (crash_signal_fd >= 0) { | 439 if (crash_signal_fd >= 0) { |
| 448 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal, | 440 mapping.push_back(std::pair<uint32_t, int>(kCrashDumpSignal, |
| 449 crash_signal_fd)); | 441 crash_signal_fd)); |
| 450 } | 442 } |
| 451 process = Singleton<ZygoteHost>()->ForkRenderer(cmd_line.argv(), mapping); | 443 process = Singleton<ZygoteHost>()->ForkRenderer(cmd_line.argv(), mapping); |
| 452 zygote_child_ = true; | 444 zygote_child_ = true; |
| 453 } else { | 445 } else { |
| 454 #endif | 446 #endif // defined(OS_LINUX) |
| 455 // NOTE: This code is duplicated with plugin_process_host.cc, but | 447 // NOTE: This code is duplicated with plugin_process_host.cc, but |
| 456 // there's not a good place to de-duplicate it. | 448 // there's not a good place to de-duplicate it. |
| 457 base::file_handle_mapping_vector fds_to_map; | 449 base::file_handle_mapping_vector fds_to_map; |
| 458 const int ipcfd = channel_->GetClientFileDescriptor(); | 450 const int ipcfd = channel_->GetClientFileDescriptor(); |
| 459 fds_to_map.push_back(std::make_pair(ipcfd, kPrimaryIPCChannel + 3)); | 451 fds_to_map.push_back(std::make_pair(ipcfd, kPrimaryIPCChannel + 3)); |
| 460 #if defined(OS_LINUX) | 452 #if defined(OS_LINUX) |
| 461 const int crash_signal_fd = | 453 const int crash_signal_fd = |
| 462 Singleton<RenderCrashHandlerHostLinux>()->GetDeathSignalSocket(); | 454 Singleton<RenderCrashHandlerHostLinux>()->GetDeathSignalSocket(); |
| 463 if (crash_signal_fd >= 0) { | 455 if (crash_signal_fd >= 0) { |
| 464 fds_to_map.push_back(std::make_pair(crash_signal_fd, | 456 fds_to_map.push_back(std::make_pair(crash_signal_fd, |
| 465 kCrashDumpSignal + 3)); | 457 kCrashDumpSignal + 3)); |
| 466 } | 458 } |
| 467 const int sandbox_fd = | 459 const int sandbox_fd = |
| 468 Singleton<RenderSandboxHostLinux>()->GetRendererSocket(); | 460 Singleton<RenderSandboxHostLinux>()->GetRendererSocket(); |
| 469 fds_to_map.push_back(std::make_pair(sandbox_fd, kSandboxIPCChannel + 3)); | 461 fds_to_map.push_back(std::make_pair(sandbox_fd, kSandboxIPCChannel + 3)); |
| 470 #endif | 462 #endif // defined(OS_LINUX) |
| 471 base::LaunchApp(cmd_line.argv(), fds_to_map, false, &process); | 463 base::LaunchApp(cmd_line.argv(), fds_to_map, false, &process); |
| 472 zygote_child_ = false; | 464 zygote_child_ = false; |
| 473 #if defined(OS_LINUX) | 465 #if defined(OS_LINUX) |
| 474 } | 466 } |
| 475 #endif | 467 #endif // defined(OS_LINUX) |
| 476 #endif | 468 #endif // defined(OS_WIN) |
| 477 | 469 |
| 478 if (!process) { | 470 if (!process) { |
| 479 channel_.reset(); | 471 channel_.reset(); |
| 480 return false; | 472 return false; |
| 481 } | 473 } |
| 482 process_.set_handle(process); | 474 process_.set_handle(process); |
| 483 SetProcessID(process_.pid()); | 475 SetProcessID(process_.pid()); |
| 484 } | 476 } |
| 485 | 477 |
| 486 resource_message_filter->Init(pid()); | 478 resource_message_filter->Init(pid()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 IPC::Message* msg) { | 512 IPC::Message* msg) { |
| 521 return widget_helper_->WaitForPaintMsg(render_widget_id, max_delay, msg); | 513 return widget_helper_->WaitForPaintMsg(render_widget_id, max_delay, msg); |
| 522 } | 514 } |
| 523 | 515 |
| 524 void BrowserRenderProcessHost::ReceivedBadMessage(uint16 msg_type) { | 516 void BrowserRenderProcessHost::ReceivedBadMessage(uint16 msg_type) { |
| 525 BadMessageTerminateProcess(msg_type, process_.handle()); | 517 BadMessageTerminateProcess(msg_type, process_.handle()); |
| 526 } | 518 } |
| 527 | 519 |
| 528 void BrowserRenderProcessHost::WidgetRestored() { | 520 void BrowserRenderProcessHost::WidgetRestored() { |
| 529 // Verify we were properly backgrounded. | 521 // Verify we were properly backgrounded. |
| 530 DCHECK(backgrounded_ == (visible_widgets_ == 0)); | 522 DCHECK_EQ(backgrounded_, (visible_widgets_ == 0)); |
| 531 visible_widgets_++; | 523 visible_widgets_++; |
| 532 visited_link_updater_->Update(this); | 524 visited_link_updater_->Update(this); |
| 533 SetBackgrounded(false); | 525 SetBackgrounded(false); |
| 534 } | 526 } |
| 535 | 527 |
| 536 void BrowserRenderProcessHost::WidgetHidden() { | 528 void BrowserRenderProcessHost::WidgetHidden() { |
| 537 // On startup, the browser will call Hide | 529 // On startup, the browser will call Hide |
| 538 if (backgrounded_) | 530 if (backgrounded_) |
| 539 return; | 531 return; |
| 540 | 532 |
| 541 DCHECK(backgrounded_ == (visible_widgets_ == 0)); | 533 DCHECK_EQ(backgrounded_, (visible_widgets_ == 0)); |
| 542 visible_widgets_--; | 534 visible_widgets_--; |
| 543 DCHECK(visible_widgets_ >= 0); | 535 DCHECK_GE(visible_widgets_, 0); |
| 544 if (visible_widgets_ == 0) { | 536 if (visible_widgets_ == 0) { |
| 545 DCHECK(!backgrounded_); | 537 DCHECK(!backgrounded_); |
| 546 SetBackgrounded(true); | 538 SetBackgrounded(true); |
| 547 } | 539 } |
| 548 } | 540 } |
| 549 | 541 |
| 550 void BrowserRenderProcessHost::AddWord(const std::wstring& word) { | 542 void BrowserRenderProcessHost::AddWord(const std::wstring& word) { |
| 551 base::Thread* io_thread = g_browser_process->io_thread(); | 543 base::Thread* io_thread = g_browser_process->io_thread(); |
| 552 if (profile()->GetSpellChecker()) { | 544 if (profile()->GetSpellChecker()) { |
| 553 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( | 545 io_thread->message_loop()->PostTask(FROM_HERE, NewRunnableMethod( |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 bool should_set_backgrounded = true; | 903 bool should_set_backgrounded = true; |
| 912 | 904 |
| 913 #if defined(OS_WIN) | 905 #if defined(OS_WIN) |
| 914 // The cbstext.dll loads as a global GetMessage hook in the browser process | 906 // The cbstext.dll loads as a global GetMessage hook in the browser process |
| 915 // and intercepts/unintercepts the kernel32 API SetPriorityClass in a | 907 // and intercepts/unintercepts the kernel32 API SetPriorityClass in a |
| 916 // background thread. If the UI thread invokes this API just when it is | 908 // background thread. If the UI thread invokes this API just when it is |
| 917 // intercepted the stack is messed up on return from the interceptor | 909 // intercepted the stack is messed up on return from the interceptor |
| 918 // which causes random crashes in the browser process. Our hack for now | 910 // which causes random crashes in the browser process. Our hack for now |
| 919 // is to not invoke the SetPriorityClass API if the dll is loaded. | 911 // is to not invoke the SetPriorityClass API if the dll is loaded. |
| 920 should_set_backgrounded = (GetModuleHandle(L"cbstext.dll") == NULL); | 912 should_set_backgrounded = (GetModuleHandle(L"cbstext.dll") == NULL); |
| 921 #endif // OS_WIN | 913 #endif // OS_WIN |
| 922 | 914 |
| 923 if (should_set_backgrounded) { | 915 if (should_set_backgrounded) { |
| 924 bool rv = process_.SetProcessBackgrounded(backgrounded); | 916 bool rv = process_.SetProcessBackgrounded(backgrounded); |
| 925 if (!rv) { | 917 if (!rv) { |
| 926 return; | 918 return; |
| 927 } | 919 } |
| 928 } | 920 } |
| 929 | 921 |
| 930 // Now tune the memory footprint of the renderer. | 922 // Now tune the memory footprint of the renderer. |
| 931 // If the OS needs to page, we'd rather it page idle renderers. | 923 // If the OS needs to page, we'd rather it page idle renderers. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 void BrowserRenderProcessHost::OnExtensionRemoveListener( | 970 void BrowserRenderProcessHost::OnExtensionRemoveListener( |
| 979 const std::string& event_name) { | 971 const std::string& event_name) { |
| 980 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> | 972 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> |
| 981 RemoveEventListener(event_name, pid()); | 973 RemoveEventListener(event_name, pid()); |
| 982 } | 974 } |
| 983 | 975 |
| 984 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { | 976 void BrowserRenderProcessHost::OnExtensionCloseChannel(int port_id) { |
| 985 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> | 977 ExtensionMessageService::GetInstance(profile()->GetRequestContext())-> |
| 986 CloseChannel(port_id); | 978 CloseChannel(port_id); |
| 987 } | 979 } |
| OLD | NEW |