OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "content/browser/renderer_host/render_process_host_impl.h" | 8 #include "content/browser/renderer_host/render_process_host_impl.h" |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
922 visible_widgets_(0), | 922 visible_widgets_(0), |
923 is_process_backgrounded_(kLaunchingProcessIsBackgrounded), | 923 is_process_backgrounded_(kLaunchingProcessIsBackgrounded), |
924 boost_priority_for_pending_views_( | 924 boost_priority_for_pending_views_( |
925 kLaunchingProcessIsBoostedForPendingView), | 925 kLaunchingProcessIsBoostedForPendingView), |
926 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 926 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
927 browser_context_(browser_context), | 927 browser_context_(browser_context), |
928 storage_partition_impl_(storage_partition_impl), | 928 storage_partition_impl_(storage_partition_impl), |
929 sudden_termination_allowed_(true), | 929 sudden_termination_allowed_(true), |
930 ignore_input_events_(false), | 930 ignore_input_events_(false), |
931 is_for_guests_only_(is_for_guests_only), | 931 is_for_guests_only_(is_for_guests_only), |
932 can_become_dedicated_process_(true), | |
932 gpu_observer_registered_(false), | 933 gpu_observer_registered_(false), |
933 delayed_cleanup_needed_(false), | 934 delayed_cleanup_needed_(false), |
934 within_process_died_observer_(false), | 935 within_process_died_observer_(false), |
935 #if BUILDFLAG(ENABLE_WEBRTC) | 936 #if BUILDFLAG(ENABLE_WEBRTC) |
936 webrtc_eventlog_host_(id_), | 937 webrtc_eventlog_host_(id_), |
937 #endif | 938 #endif |
938 permission_service_context_(new PermissionServiceContext(this)), | 939 permission_service_context_(new PermissionServiceContext(this)), |
939 indexed_db_factory_(new IndexedDBDispatcherHost( | 940 indexed_db_factory_(new IndexedDBDispatcherHost( |
940 id_, | 941 id_, |
941 storage_partition_impl_->GetURLRequestContext(), | 942 storage_partition_impl_->GetURLRequestContext(), |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1753 is_never_suitable_for_reuse_ = true; | 1754 is_never_suitable_for_reuse_ = true; |
1754 } | 1755 } |
1755 | 1756 |
1756 bool RenderProcessHostImpl::MayReuseHost() { | 1757 bool RenderProcessHostImpl::MayReuseHost() { |
1757 if (is_never_suitable_for_reuse_) | 1758 if (is_never_suitable_for_reuse_) |
1758 return false; | 1759 return false; |
1759 | 1760 |
1760 return GetContentClient()->browser()->MayReuseHost(this); | 1761 return GetContentClient()->browser()->MayReuseHost(this); |
1761 } | 1762 } |
1762 | 1763 |
1764 bool RenderProcessHostImpl::CanBecomeDedicatedProcess() { | |
1765 return can_become_dedicated_process_; | |
1766 } | |
1767 | |
1768 void RenderProcessHostImpl::UnsetCanBecomeDedicatedProcess() { | |
1769 can_become_dedicated_process_ = false; | |
alexmos
2017/06/12 17:35:07
Note that I'm specifically not calling this in Inc
| |
1770 } | |
1771 | |
1763 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { | 1772 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { |
1764 return remote_route_provider_.get(); | 1773 return remote_route_provider_.get(); |
1765 } | 1774 } |
1766 | 1775 |
1767 void RenderProcessHostImpl::AddRoute(int32_t routing_id, | 1776 void RenderProcessHostImpl::AddRoute(int32_t routing_id, |
1768 IPC::Listener* listener) { | 1777 IPC::Listener* listener) { |
1769 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " | 1778 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " |
1770 << routing_id; | 1779 << routing_id; |
1771 listeners_.AddWithID(listener, routing_id); | 1780 listeners_.AddWithID(listener, routing_id); |
1772 } | 1781 } |
(...skipping 1070 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2843 return false; | 2852 return false; |
2844 | 2853 |
2845 // Check whether the given host and the intended site_url will be using the | 2854 // Check whether the given host and the intended site_url will be using the |
2846 // same StoragePartition, since a RenderProcessHost can only support a single | 2855 // same StoragePartition, since a RenderProcessHost can only support a single |
2847 // StoragePartition. This is relevant for packaged apps. | 2856 // StoragePartition. This is relevant for packaged apps. |
2848 StoragePartition* dest_partition = | 2857 StoragePartition* dest_partition = |
2849 BrowserContext::GetStoragePartitionForSite(browser_context, site_url); | 2858 BrowserContext::GetStoragePartitionForSite(browser_context, site_url); |
2850 if (!host->InSameStoragePartition(dest_partition)) | 2859 if (!host->InSameStoragePartition(dest_partition)) |
2851 return false; | 2860 return false; |
2852 | 2861 |
2853 // TODO(nick): Consult the SiteIsolationPolicy here. https://crbug.com/513036 | 2862 // TODO(nick): Consult the SiteIsolationPolicy here. https://crbug.com/513036 |
Charlie Reis
2017/06/12 23:08:17
Is this TODO resolved now?
alexmos
2017/06/14 22:39:04
Indeed, removed.
| |
2854 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 2863 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); |
2855 host->GetID()) != | 2864 if (policy->HasWebUIBindings(host->GetID()) != |
2856 WebUIControllerFactoryRegistry::GetInstance()->UseWebUIBindingsForURL( | 2865 WebUIControllerFactoryRegistry::GetInstance()->UseWebUIBindingsForURL( |
2857 browser_context, site_url)) { | 2866 browser_context, site_url)) { |
2858 return false; | 2867 return false; |
2859 } | 2868 } |
2860 | 2869 |
2870 // Sites requiring dedicated processes can only reuse a compatible process. | |
2871 if (policy->HasOriginLock(host->GetID())) { | |
2872 // If the process is already dedicated to a site, only allow the destination | |
2873 // URL to reuse this process if the URL's has the same site. | |
2874 return policy->IsLockedToOrigin(host->GetID(), site_url); | |
Charlie Reis
2017/06/12 23:08:17
I'm a little concerned about TOCTTOU problems here
alexmos
2017/06/14 22:39:05
Yes, good questions. Since we always set origin l
Charlie Reis
2017/06/17 23:13:53
I really like the enum idea, especially because it
alexmos
2017/06/19 20:03:58
Done.
| |
2875 } else if (!host->CanBecomeDedicatedProcess() && | |
2876 SiteInstanceImpl::DoesSiteRequireDedicatedProcess(browser_context, | |
2877 site_url)) { | |
2878 // Otherwise, if this process cannot host a site that requires a dedicated | |
2879 // process (e.g., if it has hosted any other content), it cannot be reused | |
2880 // if the destination site indeed requires a dedicated process. | |
2881 return false; | |
2882 } | |
2883 | |
2861 return GetContentClient()->browser()->IsSuitableHost(host, site_url); | 2884 return GetContentClient()->browser()->IsSuitableHost(host, site_url); |
2862 } | 2885 } |
2863 | 2886 |
2864 // static | 2887 // static |
2865 bool RenderProcessHost::run_renderer_in_process() { | 2888 bool RenderProcessHost::run_renderer_in_process() { |
2866 return g_run_renderer_in_process_; | 2889 return g_run_renderer_in_process_; |
2867 } | 2890 } |
2868 | 2891 |
2869 // static | 2892 // static |
2870 void RenderProcessHost::SetRunRendererInProcess(bool value) { | 2893 void RenderProcessHost::SetRunRendererInProcess(bool value) { |
(...skipping 24 matching lines...) Expand all Loading... | |
2895 // static | 2918 // static |
2896 RenderProcessHost* RenderProcessHost::FromID(int render_process_id) { | 2919 RenderProcessHost* RenderProcessHost::FromID(int render_process_id) { |
2897 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2920 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
2898 return g_all_hosts.Get().Lookup(render_process_id); | 2921 return g_all_hosts.Get().Lookup(render_process_id); |
2899 } | 2922 } |
2900 | 2923 |
2901 // static | 2924 // static |
2902 bool RenderProcessHost::ShouldTryToUseExistingProcessHost( | 2925 bool RenderProcessHost::ShouldTryToUseExistingProcessHost( |
2903 BrowserContext* browser_context, | 2926 BrowserContext* browser_context, |
2904 const GURL& url) { | 2927 const GURL& url) { |
2905 // This needs to be checked first to ensure that --single-process | |
2906 // and --site-per-process can be used together. | |
2907 if (run_renderer_in_process()) | 2928 if (run_renderer_in_process()) |
2908 return true; | 2929 return true; |
2909 | 2930 |
2910 // If --site-per-process is enabled, do not try to reuse renderer processes | |
2911 // when over the limit. | |
2912 // TODO(nick): This is overly conservative and isn't launchable. Move this | |
2913 // logic into IsSuitableHost, and check |url| against the URL the process is | |
2914 // dedicated to. This will allow pages from the same site to share, and will | |
2915 // also allow non-isolated sites to share processes. https://crbug.com/513036 | |
2916 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) | |
2917 return false; | |
2918 | |
2919 // NOTE: Sometimes it's necessary to create more render processes than | 2931 // NOTE: Sometimes it's necessary to create more render processes than |
2920 // GetMaxRendererProcessCount(), for instance when we want to create | 2932 // GetMaxRendererProcessCount(), for instance when we want to create |
2921 // a renderer process for a browser context that has no existing | 2933 // a renderer process for a browser context that has no existing |
2922 // renderers. This is OK in moderation, since the | 2934 // renderers. This is OK in moderation, since the |
2923 // GetMaxRendererProcessCount() is conservative. | 2935 // GetMaxRendererProcessCount() is conservative. |
2924 if (g_all_hosts.Get().size() >= GetMaxRendererProcessCount()) | 2936 if (g_all_hosts.Get().size() >= GetMaxRendererProcessCount()) |
2925 return true; | 2937 return true; |
2926 | 2938 |
2927 return GetContentClient()->browser()->ShouldTryToUseExistingProcessHost( | 2939 return GetContentClient()->browser()->ShouldTryToUseExistingProcessHost( |
2928 browser_context, url); | 2940 browser_context, url); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2984 | 2996 |
2985 // static | 2997 // static |
2986 RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSite( | 2998 RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSite( |
2987 BrowserContext* browser_context, | 2999 BrowserContext* browser_context, |
2988 const GURL& url) { | 3000 const GURL& url) { |
2989 // Look up the map of site to process for the given browser_context. | 3001 // Look up the map of site to process for the given browser_context. |
2990 SiteProcessMap* map = GetSiteProcessMapForBrowserContext(browser_context); | 3002 SiteProcessMap* map = GetSiteProcessMapForBrowserContext(browser_context); |
2991 | 3003 |
2992 // See if we have an existing process with appropriate bindings for this site. | 3004 // See if we have an existing process with appropriate bindings for this site. |
2993 // If not, the caller should create a new process and register it. | 3005 // If not, the caller should create a new process and register it. |
2994 std::string site = | 3006 GURL site_url = SiteInstance::GetSiteForURL(browser_context, url); |
2995 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); | 3007 RenderProcessHost* host = map->FindProcess(site_url.possibly_invalid_spec()); |
2996 RenderProcessHost* host = map->FindProcess(site); | |
2997 if (host && (!host->MayReuseHost() || | 3008 if (host && (!host->MayReuseHost() || |
2998 !IsSuitableHost(host, browser_context, url))) { | 3009 !IsSuitableHost(host, browser_context, site_url))) { |
alexmos
2017/06/12 17:35:07
After my IsSuitableHost modifications, a few exten
Charlie Reis
2017/06/12 23:08:17
Nice. Can you give an example of what the previou
alexmos
2017/06/14 22:39:05
Sorry, typo here - this should've just been "when
Charlie Reis
2017/06/17 23:13:52
I see now-- thanks!
alexmos
2017/06/19 20:03:58
Done - filed https://bugs.chromium.org/p/chromium/
| |
2999 // The registered process does not have an appropriate set of bindings for | 3010 // The registered process does not have an appropriate set of bindings for |
3000 // the url. Remove it from the map so we can register a better one. | 3011 // the url. Remove it from the map so we can register a better one. |
3001 RecordAction( | 3012 RecordAction( |
3002 base::UserMetricsAction("BindingsMismatch_GetProcessHostPerSite")); | 3013 base::UserMetricsAction("BindingsMismatch_GetProcessHostPerSite")); |
3003 map->RemoveProcess(host); | 3014 map->RemoveProcess(host); |
3004 host = NULL; | 3015 host = NULL; |
3005 } | 3016 } |
3006 | 3017 |
3007 return host; | 3018 return host; |
3008 } | 3019 } |
(...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3573 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3584 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
3574 | 3585 |
3575 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3586 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
3576 // Capture the error message in a crash key value. | 3587 // Capture the error message in a crash key value. |
3577 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3588 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
3578 bad_message::ReceivedBadMessage(render_process_id, | 3589 bad_message::ReceivedBadMessage(render_process_id, |
3579 bad_message::RPH_MOJO_PROCESS_ERROR); | 3590 bad_message::RPH_MOJO_PROCESS_ERROR); |
3580 } | 3591 } |
3581 | 3592 |
3582 } // namespace content | 3593 } // namespace content |
OLD | NEW |