| 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 // 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/render_process_host.h" | 8 #include "chrome/browser/render_process_host.h" |
| 9 | 9 |
| 10 #include <windows.h> | 10 #include <windows.h> |
| 11 #include <wininet.h> | 11 #include <wininet.h> |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <sstream> | 13 #include <sstream> |
| 14 #include <vector> | 14 #include <vector> |
| 15 | 15 |
| 16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
| 17 #include "base/debug_util.h" | 17 #include "base/debug_util.h" |
| 18 #include "base/file_util.h" | 18 #include "base/file_util.h" |
| 19 #include "base/logging.h" | 19 #include "base/logging.h" |
| 20 #include "base/path_service.h" | 20 #include "base/path_service.h" |
| 21 #include "base/process_util.h" | 21 #include "base/process_util.h" |
| 22 #include "base/rand_util.h" | 22 #include "base/rand_util.h" |
| 23 #include "base/shared_memory.h" | 23 #include "base/shared_memory.h" |
| 24 #include "base/singleton.h" |
| 24 #include "base/string_util.h" | 25 #include "base/string_util.h" |
| 25 #include "base/sys_info.h" | 26 #include "base/sys_info.h" |
| 26 #include "base/thread.h" | 27 #include "base/thread.h" |
| 27 #include "base/win_util.h" | 28 #include "base/win_util.h" |
| 28 #include "chrome/app/result_codes.h" | 29 #include "chrome/app/result_codes.h" |
| 29 #include "chrome/browser/browser.h" | 30 #include "chrome/browser/browser.h" |
| 30 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
| 31 #include "chrome/browser/cache_manager_host.h" | 32 #include "chrome/browser/cache_manager_host.h" |
| 32 #include "chrome/browser/history/history.h" | 33 #include "chrome/browser/history/history.h" |
| 33 #include "chrome/browser/plugin_service.h" | 34 #include "chrome/browser/plugin_service.h" |
| 34 #include "chrome/browser/render_widget_helper.h" | 35 #include "chrome/browser/render_widget_helper.h" |
| 35 #include "chrome/browser/render_view_host.h" | 36 #include "chrome/browser/render_view_host.h" |
| 36 #include "chrome/browser/renderer_security_policy.h" | 37 #include "chrome/browser/renderer_security_policy.h" |
| 37 #include "chrome/browser/resource_message_filter.h" | 38 #include "chrome/browser/resource_message_filter.h" |
| 38 #include "chrome/browser/sandbox_policy.h" | 39 #include "chrome/browser/sandbox_policy.h" |
| 39 #include "chrome/browser/spellchecker.h" | 40 #include "chrome/browser/spellchecker.h" |
| 40 #include "chrome/browser/visitedlink_master.h" | 41 #include "chrome/browser/visitedlink_master.h" |
| 42 #include "chrome/browser/greasemonkey_master.h" |
| 41 #include "chrome/browser/web_contents.h" | 43 #include "chrome/browser/web_contents.h" |
| 42 #include "chrome/common/chrome_constants.h" | 44 #include "chrome/common/chrome_constants.h" |
| 43 #include "chrome/common/chrome_paths.h" | 45 #include "chrome/common/chrome_paths.h" |
| 44 #include "chrome/common/chrome_switches.h" | 46 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/debug_flags.h" | 47 #include "chrome/common/debug_flags.h" |
| 46 #include "chrome/common/l10n_util.h" | 48 #include "chrome/common/l10n_util.h" |
| 47 #include "chrome/common/logging_chrome.h" | 49 #include "chrome/common/logging_chrome.h" |
| 48 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
| 49 #include "chrome/common/pref_service.h" | 51 #include "chrome/common/pref_service.h" |
| 50 #include "chrome/common/process_watcher.h" | 52 #include "chrome/common/process_watcher.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 switches::kDebugPrint, | 263 switches::kDebugPrint, |
| 262 switches::kAllowAllActiveX, | 264 switches::kAllowAllActiveX, |
| 263 switches::kMemoryProfiling, | 265 switches::kMemoryProfiling, |
| 264 switches::kEnableWatchdog, | 266 switches::kEnableWatchdog, |
| 265 switches::kMessageLoopHistogrammer, | 267 switches::kMessageLoopHistogrammer, |
| 266 switches::kEnableDCHECK, | 268 switches::kEnableDCHECK, |
| 267 switches::kSilentDumpOnDCHECK, | 269 switches::kSilentDumpOnDCHECK, |
| 268 switches::kDisablePopupBlocking, | 270 switches::kDisablePopupBlocking, |
| 269 switches::kUseLowFragHeapCrt, | 271 switches::kUseLowFragHeapCrt, |
| 270 switches::kGearsInRenderer, | 272 switches::kGearsInRenderer, |
| 273 switches::kEnableGreasemonkey, |
| 271 }; | 274 }; |
| 272 | 275 |
| 273 for (int i = 0; i < arraysize(switch_names); ++i) { | 276 for (int i = 0; i < arraysize(switch_names); ++i) { |
| 274 if (browser_command_line.HasSwitch(switch_names[i])) { | 277 if (browser_command_line.HasSwitch(switch_names[i])) { |
| 275 CommandLine::AppendSwitchWithValue( | 278 CommandLine::AppendSwitchWithValue( |
| 276 &cmd_line, switch_names[i], | 279 &cmd_line, switch_names[i], |
| 277 browser_command_line.GetSwitchValue(switch_names[i])); | 280 browser_command_line.GetSwitchValue(switch_names[i])); |
| 278 } | 281 } |
| 279 } | 282 } |
| 280 | 283 |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 process_.set_handle(process); | 419 process_.set_handle(process); |
| 417 } | 420 } |
| 418 | 421 |
| 419 watcher_.StartWatching(process_.handle(), this); | 422 watcher_.StartWatching(process_.handle(), this); |
| 420 } | 423 } |
| 421 } | 424 } |
| 422 | 425 |
| 423 // Now that the process is created, set it's backgrounding accordingly. | 426 // Now that the process is created, set it's backgrounding accordingly. |
| 424 SetBackgrounded(backgrounded_); | 427 SetBackgrounded(backgrounded_); |
| 425 | 428 |
| 426 VisitedLinkMaster* visitedlink_master = profile_->GetVisitedLinkMaster(); | 429 // Send the process its initial VisitedLink and Greasemonkey data. |
| 427 if (visitedlink_master) { | 430 HANDLE target_process = process_.handle(); |
| 428 std::wstring history_table_name = visitedlink_master->GetSharedMemoryName(); | 431 if (!target_process) { |
| 429 SharedMemoryHandle handle_for_process = NULL; | 432 // Target process can be null if it's started with the --single-process |
| 430 HANDLE target_process = process_.handle(); | 433 // flag. |
| 431 if (!target_process) { | 434 target_process = GetCurrentProcess(); |
| 432 // Target process can be null if it's started with the --single-process | 435 } |
| 433 // flag. | |
| 434 target_process = GetCurrentProcess(); | |
| 435 } | |
| 436 | 436 |
| 437 visitedlink_master->ShareToProcess(target_process, &handle_for_process); | 437 InitVisitedLinks(target_process); |
| 438 DCHECK(handle_for_process); | 438 InitGreasemonkeyScripts(target_process); |
| 439 | |
| 440 channel_->Send(new ViewMsg_VisitedLink_NewTable(handle_for_process)); | |
| 441 } | |
| 442 | 439 |
| 443 if (max_page_id_ != -1) | 440 if (max_page_id_ != -1) |
| 444 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); | 441 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); |
| 445 | 442 |
| 446 return true; | 443 return true; |
| 447 } | 444 } |
| 448 | 445 |
| 446 void RenderProcessHost::InitVisitedLinks(HANDLE target_process) { |
| 447 VisitedLinkMaster* visitedlink_master = profile_->GetVisitedLinkMaster(); |
| 448 if (!visitedlink_master) return; |
| 449 |
| 450 SharedMemoryHandle handle_for_process = NULL; |
| 451 visitedlink_master->ShareToProcess(target_process, &handle_for_process); |
| 452 DCHECK(handle_for_process); |
| 453 if (handle_for_process) { |
| 454 channel_->Send(new ViewMsg_VisitedLink_NewTable(handle_for_process)); |
| 455 } |
| 456 } |
| 457 |
| 458 void RenderProcessHost::InitGreasemonkeyScripts(HANDLE target_process) { |
| 459 CommandLine command_line; |
| 460 if (!command_line.HasSwitch(switches::kEnableGreasemonkey)) return; |
| 461 |
| 462 // TODO(aa): Figure out lifetime and ownership of this object |
| 463 // - VisitedLinkMaster is owned by Profile, but there has been talk of |
| 464 // having scripts live elsewhere besides the profile. |
| 465 // - File IO should be asynchronous (see VisitedLinkMaster), but how do we |
| 466 // get scripts to the first renderer without blocking startup? Should we |
| 467 // cache some information across restarts? |
| 468 GreasemonkeyMaster* greasemonkey_master = |
| 469 Singleton<GreasemonkeyMaster>::get(); |
| 470 if (!greasemonkey_master) return; |
| 471 |
| 472 // TODO(aa): This does blocking IO. Move to background thread. |
| 473 greasemonkey_master->UpdateScripts(); |
| 474 |
| 475 SharedMemoryHandle handle_for_process = NULL; |
| 476 greasemonkey_master->ShareToProcess(target_process, &handle_for_process); |
| 477 DCHECK(handle_for_process); |
| 478 if (handle_for_process) { |
| 479 channel_->Send(new ViewMsg_Greasemonkey_NewScripts(handle_for_process)); |
| 480 } |
| 481 } |
| 482 |
| 449 void RenderProcessHost::Attach(IPC::Channel::Listener* listener, | 483 void RenderProcessHost::Attach(IPC::Channel::Listener* listener, |
| 450 int routing_id) { | 484 int routing_id) { |
| 451 listeners_.AddWithID(listener, routing_id); | 485 listeners_.AddWithID(listener, routing_id); |
| 452 } | 486 } |
| 453 | 487 |
| 454 void RenderProcessHost::Release(int listener_id) { | 488 void RenderProcessHost::Release(int listener_id) { |
| 455 DCHECK(listeners_.Lookup(listener_id) != NULL); | 489 DCHECK(listeners_.Lookup(listener_id) != NULL); |
| 456 listeners_.Remove(listener_id); | 490 listeners_.Remove(listener_id); |
| 457 | 491 |
| 458 // make sure that all associated resource requests are stopped. | 492 // make sure that all associated resource requests are stopped. |
| (...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 774 // NOTE: Sometimes it's necessary to create more render processes than | 808 // NOTE: Sometimes it's necessary to create more render processes than |
| 775 // GetMaxRendererProcessCount(), for instance when we want to create | 809 // GetMaxRendererProcessCount(), for instance when we want to create |
| 776 // a renderer process for a profile that has no existing renderers. | 810 // a renderer process for a profile that has no existing renderers. |
| 777 // This is OK in moderation, since the GetMaxRendererProcessCount() | 811 // This is OK in moderation, since the GetMaxRendererProcessCount() |
| 778 // is conservative. | 812 // is conservative. |
| 779 | 813 |
| 780 return run_renderer_in_process() || | 814 return run_renderer_in_process() || |
| 781 (renderer_process_count >= GetMaxRendererProcessCount()); | 815 (renderer_process_count >= GetMaxRendererProcessCount()); |
| 782 } | 816 } |
| 783 | 817 |
| OLD | NEW |