| 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/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 <sstream> | |
| 14 #include <vector> | |
| 15 | 13 |
| 16 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 17 #include "base/debug_util.h" | 15 #include "base/debug_util.h" |
| 18 #include "base/file_util.h" | |
| 19 #include "base/logging.h" | 16 #include "base/logging.h" |
| 20 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 21 #include "base/process_util.h" | 18 #include "base/process_util.h" |
| 19 #include "base/rand_util.h" |
| 22 #include "base/shared_memory.h" | 20 #include "base/shared_memory.h" |
| 23 #include "base/singleton.h" | |
| 24 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 25 #include "base/thread.h" | 22 #include "base/thread.h" |
| 26 #include "chrome/app/result_codes.h" | 23 #include "chrome/app/result_codes.h" |
| 27 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/cache_manager_host.h" | 25 #include "chrome/browser/cache_manager_host.h" |
| 29 #include "chrome/browser/extensions/user_script_master.h" | 26 #include "chrome/browser/extensions/user_script_master.h" |
| 30 #include "chrome/browser/profile.h" | 27 #include "chrome/browser/profile.h" |
| 31 #include "chrome/browser/renderer_host/render_widget_helper.h" | 28 #include "chrome/browser/renderer_host/render_widget_helper.h" |
| 32 #include "chrome/browser/renderer_host/renderer_security_policy.h" | 29 #include "chrome/browser/renderer_host/renderer_security_policy.h" |
| 33 #include "chrome/browser/renderer_host/resource_message_filter.h" | 30 #include "chrome/browser/renderer_host/resource_message_filter.h" |
| 34 #include "chrome/browser/visitedlink_master.h" | 31 #include "chrome/browser/visitedlink_master.h" |
| 35 #include "chrome/common/chrome_paths.h" | |
| 36 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 37 #include "chrome/common/debug_flags.h" | 33 #include "chrome/common/debug_flags.h" |
| 38 #include "chrome/common/l10n_util.h" | |
| 39 #include "chrome/common/logging_chrome.h" | 34 #include "chrome/common/logging_chrome.h" |
| 40 #include "chrome/common/notification_service.h" | 35 #include "chrome/common/notification_service.h" |
| 41 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 42 #include "chrome/common/pref_service.h" | 37 #include "chrome/common/pref_service.h" |
| 43 #include "chrome/common/process_watcher.h" | 38 #include "chrome/common/process_watcher.h" |
| 44 #include "chrome/common/render_messages.h" | 39 #include "chrome/common/render_messages.h" |
| 45 #include "chrome/renderer/render_process.h" | 40 #include "chrome/renderer/render_process.h" |
| 46 #include "net/base/cookie_monster.h" | |
| 47 #include "net/base/net_util.h" | |
| 48 | 41 |
| 49 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 50 #include "chrome/browser/plugin_service.h" | 43 #include "chrome/browser/plugin_service.h" |
| 51 | 44 |
| 52 // TODO(port): see comment by the only usage of RenderViewHost in this file. | 45 // TODO(port): see comment by the only usage of RenderViewHost in this file. |
| 53 #include "chrome/browser/renderer_host/render_view_host.h" | 46 #include "chrome/browser/renderer_host/render_view_host.h" |
| 54 | 47 |
| 55 #include "chrome/browser/history/history.h" | 48 #include "chrome/browser/history/history.h" |
| 56 #include "chrome/browser/spellchecker.h" | 49 #include "chrome/browser/spellchecker.h" |
| 57 | 50 |
| 58 // Once the above TODO is finished, then this block is all Windows-specific | 51 // Once the above TODO is finished, then this block is all Windows-specific |
| 59 // files. | 52 // files. |
| 60 #include "base/win_util.h" | 53 #include "base/win_util.h" |
| 61 #include "chrome/common/win_util.h" | 54 #include "chrome/common/win_util.h" |
| 62 #include "chrome/browser/sandbox_policy.h" | 55 #include "chrome/browser/sandbox_policy.h" |
| 63 #include "chrome/common/win_util.h" | |
| 64 #include "sandbox/src/sandbox.h" | 56 #include "sandbox/src/sandbox.h" |
| 65 #elif defined(OS_POSIX) | 57 #elif defined(OS_POSIX) |
| 66 // TODO(port): Remove temporary scaffolding after porting the above headers. | 58 // TODO(port): Remove temporary scaffolding after porting the above headers. |
| 67 #include "chrome/common/temp_scaffolding_stubs.h" | 59 #include "chrome/common/temp_scaffolding_stubs.h" |
| 68 #endif | 60 #endif |
| 69 | 61 |
| 70 #include "SkBitmap.h" | 62 #include "skia/include/SkBitmap.h" |
| 71 | 63 |
| 72 #include "generated_resources.h" | 64 #include "generated_resources.h" |
| 73 | 65 |
| 74 namespace { | 66 namespace { |
| 75 | 67 |
| 76 // ---------------------------------------------------------------------------- | 68 // ---------------------------------------------------------------------------- |
| 77 | 69 |
| 78 class RendererMainThread : public base::Thread { | 70 class RendererMainThread : public base::Thread { |
| 79 public: | 71 public: |
| 80 explicit RendererMainThread(const std::wstring& channel_id) | 72 explicit RendererMainThread(const std::wstring& channel_id) |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 | 134 |
| 143 PrefService* prefs = profile->GetPrefs(); | 135 PrefService* prefs = profile->GetPrefs(); |
| 144 prefs->AddPrefObserver(prefs::kBlockPopups, this); | 136 prefs->AddPrefObserver(prefs::kBlockPopups, this); |
| 145 widget_helper_->set_block_popups( | 137 widget_helper_->set_block_popups( |
| 146 profile->GetPrefs()->GetBoolean(prefs::kBlockPopups)); | 138 profile->GetPrefs()->GetBoolean(prefs::kBlockPopups)); |
| 147 | 139 |
| 148 NotificationService::current()->AddObserver(this, | 140 NotificationService::current()->AddObserver(this, |
| 149 NotificationType::USER_SCRIPTS_LOADED, | 141 NotificationType::USER_SCRIPTS_LOADED, |
| 150 NotificationService::AllSources()); | 142 NotificationService::AllSources()); |
| 151 | 143 |
| 152 // Note: When we create the BrowserRenderProcessHost, it's technically backgro
unded, | 144 // Note: When we create the BrowserRenderProcessHost, it's technically |
| 153 // because it has no visible listeners. But the process doesn't | 145 // backgrounded, because it has no visible listeners. But the process |
| 154 // actually exist yet, so we'll Background it later, after creation. | 146 // doesn't actually exist yet, so we'll Background it later, after |
| 147 // creation. |
| 155 } | 148 } |
| 156 | 149 |
| 157 BrowserRenderProcessHost::~BrowserRenderProcessHost() { | 150 BrowserRenderProcessHost::~BrowserRenderProcessHost() { |
| 158 // Some tests hold BrowserRenderProcessHost in a scoped_ptr, so we must call | 151 // Some tests hold BrowserRenderProcessHost in a scoped_ptr, so we must call |
| 159 // Unregister here as well as in response to Release(). | 152 // Unregister here as well as in response to Release(). |
| 160 Unregister(); | 153 Unregister(); |
| 161 | 154 |
| 162 // We may have some unsent messages at this point, but that's OK. | 155 // We may have some unsent messages at this point, but that's OK. |
| 163 channel_.reset(); | 156 channel_.reset(); |
| 164 | 157 |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 InitVisitedLinks(); | 412 InitVisitedLinks(); |
| 420 InitUserScripts(); | 413 InitUserScripts(); |
| 421 | 414 |
| 422 if (max_page_id_ != -1) | 415 if (max_page_id_ != -1) |
| 423 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); | 416 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); |
| 424 | 417 |
| 425 return true; | 418 return true; |
| 426 } | 419 } |
| 427 | 420 |
| 428 #if defined(OS_WIN) | 421 #if defined(OS_WIN) |
| 429 bool BrowserRenderProcessHost::SpawnChild(const CommandLine& command_line, | 422 bool BrowserRenderProcessHost::SpawnChild(const CommandLine& command_line, |
| 430 IPC::SyncChannel* channel, base::ProcessHandle* process_handle) { | 423 IPC::SyncChannel* channel, base::ProcessHandle* process_handle) { |
| 431 return base::LaunchApp(command_line, false, false, process_handle); | 424 return base::LaunchApp(command_line, false, false, process_handle); |
| 432 } | 425 } |
| 433 #elif defined(OS_POSIX) | 426 #elif defined(OS_POSIX) |
| 434 bool BrowserRenderProcessHost::SpawnChild(const CommandLine& command_line, | 427 bool BrowserRenderProcessHost::SpawnChild(const CommandLine& command_line, |
| 435 IPC::SyncChannel* channel, base::ProcessHandle* process_handle) { | 428 IPC::SyncChannel* channel, base::ProcessHandle* process_handle) { |
| 436 base::file_handle_mapping_vector fds_to_map; | 429 base::file_handle_mapping_vector fds_to_map; |
| 437 int src_fd = -1, dest_fd = -1; | 430 int src_fd = -1, dest_fd = -1; |
| 438 channel->GetClientFileDescriptorMapping(&src_fd, &dest_fd); | 431 channel->GetClientFileDescriptorMapping(&src_fd, &dest_fd); |
| 439 if (src_fd > -1) | 432 if (src_fd > -1) |
| 440 fds_to_map.push_back(std::pair<int,int>(src_fd, dest_fd)); | 433 fds_to_map.push_back(std::pair<int, int>(src_fd, dest_fd)); |
| 441 return base::LaunchApp(command_line.argv(), fds_to_map, false, process_handle)
; | 434 return base::LaunchApp(command_line.argv(), fds_to_map, false, |
| 435 process_handle); |
| 442 } | 436 } |
| 443 #endif | 437 #endif |
| 444 | 438 |
| 445 int BrowserRenderProcessHost::GetNextRoutingID() { | 439 int BrowserRenderProcessHost::GetNextRoutingID() { |
| 446 return widget_helper_->GetNextRoutingID(); | 440 return widget_helper_->GetNextRoutingID(); |
| 447 } | 441 } |
| 448 | 442 |
| 449 void BrowserRenderProcessHost::CancelResourceRequests(int render_widget_id) { | 443 void BrowserRenderProcessHost::CancelResourceRequests(int render_widget_id) { |
| 450 widget_helper_->CancelResourceRequests(render_widget_id); | 444 widget_helper_->CancelResourceRequests(render_widget_id); |
| 451 } | 445 } |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 795 // child processes determine the pid of the parent. | 789 // child processes determine the pid of the parent. |
| 796 // Build the channel ID. This is composed of a unique identifier for the | 790 // Build the channel ID. This is composed of a unique identifier for the |
| 797 // parent browser process, an identifier for the renderer/plugin instance, | 791 // parent browser process, an identifier for the renderer/plugin instance, |
| 798 // and a random component. We use a random component so that a hacked child | 792 // and a random component. We use a random component so that a hacked child |
| 799 // process can't cause denial of service by causing future named pipe creation | 793 // process can't cause denial of service by causing future named pipe creation |
| 800 // to fail. | 794 // to fail. |
| 801 return StringPrintf(L"%d.%x.%d", | 795 return StringPrintf(L"%d.%x.%d", |
| 802 base::GetCurrentProcId(), instance, | 796 base::GetCurrentProcId(), instance, |
| 803 base::RandInt(0, std::numeric_limits<int>::max())); | 797 base::RandInt(0, std::numeric_limits<int>::max())); |
| 804 } | 798 } |
| OLD | NEW |