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> |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "base/shared_memory.h" | 23 #include "base/shared_memory.h" |
24 #include "base/singleton.h" | 24 #include "base/singleton.h" |
25 #include "base/string_util.h" | 25 #include "base/string_util.h" |
26 #include "base/sys_info.h" | 26 #include "base/sys_info.h" |
27 #include "base/thread.h" | 27 #include "base/thread.h" |
28 #include "base/win_util.h" | 28 #include "base/win_util.h" |
29 #include "chrome/app/result_codes.h" | 29 #include "chrome/app/result_codes.h" |
30 #include "chrome/browser/browser.h" | 30 #include "chrome/browser/browser.h" |
31 #include "chrome/browser/browser_process.h" | 31 #include "chrome/browser/browser_process.h" |
32 #include "chrome/browser/cache_manager_host.h" | 32 #include "chrome/browser/cache_manager_host.h" |
| 33 #include "chrome/browser/extensions/user_script_master.h" |
33 #include "chrome/browser/history/history.h" | 34 #include "chrome/browser/history/history.h" |
34 #include "chrome/browser/plugin_service.h" | 35 #include "chrome/browser/plugin_service.h" |
35 #include "chrome/browser/render_widget_helper.h" | 36 #include "chrome/browser/render_widget_helper.h" |
36 #include "chrome/browser/render_view_host.h" | 37 #include "chrome/browser/render_view_host.h" |
37 #include "chrome/browser/renderer_security_policy.h" | 38 #include "chrome/browser/renderer_security_policy.h" |
38 #include "chrome/browser/resource_message_filter.h" | 39 #include "chrome/browser/resource_message_filter.h" |
39 #include "chrome/browser/sandbox_policy.h" | 40 #include "chrome/browser/sandbox_policy.h" |
40 #include "chrome/browser/spellchecker.h" | 41 #include "chrome/browser/spellchecker.h" |
41 #include "chrome/browser/visitedlink_master.h" | 42 #include "chrome/browser/visitedlink_master.h" |
42 #include "chrome/browser/greasemonkey_master.h" | |
43 #include "chrome/browser/web_contents.h" | 43 #include "chrome/browser/web_contents.h" |
44 #include "chrome/common/chrome_constants.h" | 44 #include "chrome/common/chrome_constants.h" |
45 #include "chrome/common/chrome_paths.h" | 45 #include "chrome/common/chrome_paths.h" |
46 #include "chrome/common/chrome_switches.h" | 46 #include "chrome/common/chrome_switches.h" |
47 #include "chrome/common/debug_flags.h" | 47 #include "chrome/common/debug_flags.h" |
48 #include "chrome/common/l10n_util.h" | 48 #include "chrome/common/l10n_util.h" |
49 #include "chrome/common/logging_chrome.h" | 49 #include "chrome/common/logging_chrome.h" |
50 #include "chrome/common/pref_names.h" | 50 #include "chrome/common/pref_names.h" |
51 #include "chrome/common/pref_service.h" | 51 #include "chrome/common/pref_service.h" |
52 #include "chrome/common/process_watcher.h" | 52 #include "chrome/common/process_watcher.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 160 |
161 CacheManagerHost::GetInstance()->Add(host_id_); | 161 CacheManagerHost::GetInstance()->Add(host_id_); |
162 RendererSecurityPolicy::GetInstance()->Add(host_id_); | 162 RendererSecurityPolicy::GetInstance()->Add(host_id_); |
163 | 163 |
164 PrefService* prefs = profile->GetPrefs(); | 164 PrefService* prefs = profile->GetPrefs(); |
165 prefs->AddPrefObserver(prefs::kBlockPopups, this); | 165 prefs->AddPrefObserver(prefs::kBlockPopups, this); |
166 widget_helper_->set_block_popups( | 166 widget_helper_->set_block_popups( |
167 profile->GetPrefs()->GetBoolean(prefs::kBlockPopups)); | 167 profile->GetPrefs()->GetBoolean(prefs::kBlockPopups)); |
168 | 168 |
169 NotificationService::current()->AddObserver(this, | 169 NotificationService::current()->AddObserver(this, |
170 NOTIFY_GREASEMONKEY_SCRIPTS_LOADED, | 170 NOTIFY_USER_SCRIPTS_LOADED, NotificationService::AllSources()); |
171 NotificationService::AllSources()); | |
172 | 171 |
173 // Note: When we create the RenderProcessHost, it's technically backgrounded, | 172 // Note: When we create the RenderProcessHost, it's technically backgrounded, |
174 // because it has no visible listeners. But the process doesn't | 173 // because it has no visible listeners. But the process doesn't |
175 // actually exist yet, so we'll Background it later, after creation. | 174 // actually exist yet, so we'll Background it later, after creation. |
176 } | 175 } |
177 | 176 |
178 RenderProcessHost::~RenderProcessHost() { | 177 RenderProcessHost::~RenderProcessHost() { |
179 // Some tests hold RenderProcessHost in a scoped_ptr, so we must call | 178 // Some tests hold RenderProcessHost in a scoped_ptr, so we must call |
180 // Unregister here as well as in response to Release(). | 179 // Unregister here as well as in response to Release(). |
181 Unregister(); | 180 Unregister(); |
182 | 181 |
183 // We may have some unsent messages at this point, but that's OK. | 182 // We may have some unsent messages at this point, but that's OK. |
184 channel_.reset(); | 183 channel_.reset(); |
185 | 184 |
186 if (process_.handle() && !run_renderer_in_process_) { | 185 if (process_.handle() && !run_renderer_in_process_) { |
187 watcher_.StopWatching(); | 186 watcher_.StopWatching(); |
188 ProcessWatcher::EnsureProcessTerminated(process_.handle()); | 187 ProcessWatcher::EnsureProcessTerminated(process_.handle()); |
189 } | 188 } |
190 | 189 |
191 profile_->GetPrefs()->RemovePrefObserver(prefs::kBlockPopups, this); | 190 profile_->GetPrefs()->RemovePrefObserver(prefs::kBlockPopups, this); |
192 | 191 |
193 NotificationService::current()->RemoveObserver(this, | 192 NotificationService::current()->RemoveObserver(this, |
194 NOTIFY_GREASEMONKEY_SCRIPTS_LOADED, | 193 NOTIFY_USER_SCRIPTS_LOADED, NotificationService::AllSources()); |
195 NotificationService::AllSources()); | |
196 } | 194 } |
197 | 195 |
198 void RenderProcessHost::Unregister() { | 196 void RenderProcessHost::Unregister() { |
199 if (host_id_ >= 0) { | 197 if (host_id_ >= 0) { |
200 CacheManagerHost::GetInstance()->Remove(host_id_); | 198 CacheManagerHost::GetInstance()->Remove(host_id_); |
201 RendererSecurityPolicy::GetInstance()->Remove(host_id_); | 199 RendererSecurityPolicy::GetInstance()->Remove(host_id_); |
202 all_hosts.Remove(host_id_); | 200 all_hosts.Remove(host_id_); |
203 host_id_ = -1; | 201 host_id_ = -1; |
204 } | 202 } |
205 } | 203 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 switches::kDebugPrint, | 269 switches::kDebugPrint, |
272 switches::kAllowAllActiveX, | 270 switches::kAllowAllActiveX, |
273 switches::kMemoryProfiling, | 271 switches::kMemoryProfiling, |
274 switches::kEnableWatchdog, | 272 switches::kEnableWatchdog, |
275 switches::kMessageLoopHistogrammer, | 273 switches::kMessageLoopHistogrammer, |
276 switches::kEnableDCHECK, | 274 switches::kEnableDCHECK, |
277 switches::kSilentDumpOnDCHECK, | 275 switches::kSilentDumpOnDCHECK, |
278 switches::kDisablePopupBlocking, | 276 switches::kDisablePopupBlocking, |
279 switches::kUseLowFragHeapCrt, | 277 switches::kUseLowFragHeapCrt, |
280 switches::kGearsInRenderer, | 278 switches::kGearsInRenderer, |
281 switches::kEnableGreasemonkey, | 279 switches::kEnableUserScripts, |
282 switches::kEnableVideo, | 280 switches::kEnableVideo, |
283 }; | 281 }; |
284 | 282 |
285 for (int i = 0; i < arraysize(switch_names); ++i) { | 283 for (int i = 0; i < arraysize(switch_names); ++i) { |
286 if (browser_command_line.HasSwitch(switch_names[i])) { | 284 if (browser_command_line.HasSwitch(switch_names[i])) { |
287 CommandLine::AppendSwitchWithValue( | 285 CommandLine::AppendSwitchWithValue( |
288 &cmd_line, switch_names[i], | 286 &cmd_line, switch_names[i], |
289 browser_command_line.GetSwitchValue(switch_names[i])); | 287 browser_command_line.GetSwitchValue(switch_names[i])); |
290 } | 288 } |
291 } | 289 } |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 427 } |
430 | 428 |
431 watcher_.StartWatching(process_.handle(), this); | 429 watcher_.StartWatching(process_.handle(), this); |
432 } | 430 } |
433 } | 431 } |
434 | 432 |
435 // Now that the process is created, set it's backgrounding accordingly. | 433 // Now that the process is created, set it's backgrounding accordingly. |
436 SetBackgrounded(backgrounded_); | 434 SetBackgrounded(backgrounded_); |
437 | 435 |
438 InitVisitedLinks(); | 436 InitVisitedLinks(); |
439 InitGreasemonkeyScripts(); | 437 InitUserScripts(); |
440 | 438 |
441 if (max_page_id_ != -1) | 439 if (max_page_id_ != -1) |
442 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); | 440 channel_->Send(new ViewMsg_SetNextPageID(max_page_id_ + 1)); |
443 | 441 |
444 return true; | 442 return true; |
445 } | 443 } |
446 | 444 |
447 base::ProcessHandle RenderProcessHost::GetRendererProcessHandle() { | 445 base::ProcessHandle RenderProcessHost::GetRendererProcessHandle() { |
448 if (run_renderer_in_process_) | 446 if (run_renderer_in_process_) |
449 return base::Process::Current().handle(); | 447 return base::Process::Current().handle(); |
450 return process_.handle(); | 448 return process_.handle(); |
451 } | 449 } |
452 | 450 |
453 void RenderProcessHost::InitVisitedLinks() { | 451 void RenderProcessHost::InitVisitedLinks() { |
454 VisitedLinkMaster* visitedlink_master = profile_->GetVisitedLinkMaster(); | 452 VisitedLinkMaster* visitedlink_master = profile_->GetVisitedLinkMaster(); |
455 if (!visitedlink_master) { | 453 if (!visitedlink_master) { |
456 return; | 454 return; |
457 } | 455 } |
458 | 456 |
459 base::SharedMemoryHandle handle_for_process = NULL; | 457 base::SharedMemoryHandle handle_for_process = NULL; |
460 visitedlink_master->ShareToProcess(GetRendererProcessHandle(), | 458 visitedlink_master->ShareToProcess(GetRendererProcessHandle(), |
461 &handle_for_process); | 459 &handle_for_process); |
462 DCHECK(handle_for_process); | 460 DCHECK(handle_for_process); |
463 if (handle_for_process) { | 461 if (handle_for_process) { |
464 channel_->Send(new ViewMsg_VisitedLink_NewTable(handle_for_process)); | 462 channel_->Send(new ViewMsg_VisitedLink_NewTable(handle_for_process)); |
465 } | 463 } |
466 } | 464 } |
467 | 465 |
468 void RenderProcessHost::InitGreasemonkeyScripts() { | 466 void RenderProcessHost::InitUserScripts() { |
469 CommandLine command_line; | 467 CommandLine command_line; |
470 if (!command_line.HasSwitch(switches::kEnableGreasemonkey)) { | 468 if (!command_line.HasSwitch(switches::kEnableUserScripts)) { |
471 return; | 469 return; |
472 } | 470 } |
473 | 471 |
474 // TODO(aa): Figure out lifetime and ownership of this object | 472 // TODO(aa): Figure out lifetime and ownership of this object |
475 // - VisitedLinkMaster is owned by Profile, but there has been talk of | 473 // - VisitedLinkMaster is owned by Profile, but there has been talk of |
476 // having scripts live elsewhere besides the profile. | 474 // having scripts live elsewhere besides the profile. |
477 // - File IO should be asynchronous (see VisitedLinkMaster), but how do we | 475 // - File IO should be asynchronous (see VisitedLinkMaster), but how do we |
478 // get scripts to the first renderer without blocking startup? Should we | 476 // get scripts to the first renderer without blocking startup? Should we |
479 // cache some information across restarts? | 477 // cache some information across restarts? |
480 GreasemonkeyMaster* greasemonkey_master = profile_->GetGreasemonkeyMaster(); | 478 UserScriptMaster* user_script_master = profile_->GetUserScriptMaster(); |
481 if (!greasemonkey_master) { | 479 if (!user_script_master) { |
482 return; | 480 return; |
483 } | 481 } |
484 | 482 |
485 if (!greasemonkey_master->ScriptsReady()) { | 483 if (!user_script_master->ScriptsReady()) { |
486 // No scripts ready. :( | 484 // No scripts ready. :( |
487 return; | 485 return; |
488 } | 486 } |
489 | 487 |
490 // Update the renderer process with the current scripts. | 488 // Update the renderer process with the current scripts. |
491 SendGreasemonkeyScriptsUpdate(greasemonkey_master->GetSharedMemory()); | 489 SendUserScriptsUpdate(user_script_master->GetSharedMemory()); |
492 } | 490 } |
493 | 491 |
494 void RenderProcessHost::SendGreasemonkeyScriptsUpdate( | 492 void RenderProcessHost::SendUserScriptsUpdate( |
495 base::SharedMemory *shared_memory) { | 493 base::SharedMemory *shared_memory) { |
496 base::SharedMemoryHandle handle_for_process = NULL; | 494 base::SharedMemoryHandle handle_for_process = NULL; |
497 shared_memory->ShareToProcess(GetRendererProcessHandle(), | 495 shared_memory->ShareToProcess(GetRendererProcessHandle(), |
498 &handle_for_process); | 496 &handle_for_process); |
499 DCHECK(handle_for_process); | 497 DCHECK(handle_for_process); |
500 if (handle_for_process) { | 498 if (handle_for_process) { |
501 channel_->Send(new ViewMsg_Greasemonkey_NewScripts(handle_for_process)); | 499 channel_->Send(new ViewMsg_UserScripts_NewScripts(handle_for_process)); |
502 } | 500 } |
503 } | 501 } |
504 | 502 |
505 void RenderProcessHost::Attach(IPC::Channel::Listener* listener, | 503 void RenderProcessHost::Attach(IPC::Channel::Listener* listener, |
506 int routing_id) { | 504 int routing_id) { |
507 listeners_.AddWithID(listener, routing_id); | 505 listeners_.AddWithID(listener, routing_id); |
508 } | 506 } |
509 | 507 |
510 void RenderProcessHost::Release(int listener_id) { | 508 void RenderProcessHost::Release(int listener_id) { |
511 DCHECK(listeners_.Lookup(listener_id) != NULL); | 509 DCHECK(listeners_.Lookup(listener_id) != NULL); |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); | 810 std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); |
813 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); | 811 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); |
814 if (*pref_name_in == prefs::kBlockPopups) { | 812 if (*pref_name_in == prefs::kBlockPopups) { |
815 widget_helper_->set_block_popups( | 813 widget_helper_->set_block_popups( |
816 profile()->GetPrefs()->GetBoolean(prefs::kBlockPopups)); | 814 profile()->GetPrefs()->GetBoolean(prefs::kBlockPopups)); |
817 } else { | 815 } else { |
818 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; | 816 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; |
819 } | 817 } |
820 break; | 818 break; |
821 } | 819 } |
822 case NOTIFY_GREASEMONKEY_SCRIPTS_LOADED: { | 820 case NOTIFY_USER_SCRIPTS_LOADED: { |
823 base::SharedMemory* shared_memory = | 821 base::SharedMemory* shared_memory = |
824 Details<base::SharedMemory>(details).ptr(); | 822 Details<base::SharedMemory>(details).ptr(); |
825 DCHECK(shared_memory); | 823 DCHECK(shared_memory); |
826 if (shared_memory) { | 824 if (shared_memory) { |
827 SendGreasemonkeyScriptsUpdate(shared_memory); | 825 SendUserScriptsUpdate(shared_memory); |
828 } | 826 } |
829 break; | 827 break; |
830 } | 828 } |
831 default: { | 829 default: { |
832 NOTREACHED(); | 830 NOTREACHED(); |
833 break; | 831 break; |
834 } | 832 } |
835 } | 833 } |
836 } | 834 } |
837 | 835 |
838 // static | 836 // static |
839 bool RenderProcessHost::ShouldTryToUseExistingProcessHost() { | 837 bool RenderProcessHost::ShouldTryToUseExistingProcessHost() { |
840 unsigned int renderer_process_count = | 838 unsigned int renderer_process_count = |
841 static_cast<unsigned int>(all_hosts.size()); | 839 static_cast<unsigned int>(all_hosts.size()); |
842 | 840 |
843 // NOTE: Sometimes it's necessary to create more render processes than | 841 // NOTE: Sometimes it's necessary to create more render processes than |
844 // GetMaxRendererProcessCount(), for instance when we want to create | 842 // GetMaxRendererProcessCount(), for instance when we want to create |
845 // a renderer process for a profile that has no existing renderers. | 843 // a renderer process for a profile that has no existing renderers. |
846 // This is OK in moderation, since the GetMaxRendererProcessCount() | 844 // This is OK in moderation, since the GetMaxRendererProcessCount() |
847 // is conservative. | 845 // is conservative. |
848 | 846 |
849 return run_renderer_in_process() || | 847 return run_renderer_in_process() || |
850 (renderer_process_count >= GetMaxRendererProcessCount()); | 848 (renderer_process_count >= GetMaxRendererProcessCount()); |
851 } | 849 } |
852 | 850 |
OLD | NEW |