| 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 914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 visible_widgets_(0), | 925 visible_widgets_(0), |
| 926 is_process_backgrounded_(kLaunchingProcessIsBackgrounded), | 926 is_process_backgrounded_(kLaunchingProcessIsBackgrounded), |
| 927 boost_priority_for_pending_views_( | 927 boost_priority_for_pending_views_( |
| 928 kLaunchingProcessIsBoostedForPendingView), | 928 kLaunchingProcessIsBoostedForPendingView), |
| 929 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), | 929 id_(ChildProcessHostImpl::GenerateChildProcessUniqueId()), |
| 930 browser_context_(browser_context), | 930 browser_context_(browser_context), |
| 931 storage_partition_impl_(storage_partition_impl), | 931 storage_partition_impl_(storage_partition_impl), |
| 932 sudden_termination_allowed_(true), | 932 sudden_termination_allowed_(true), |
| 933 ignore_input_events_(false), | 933 ignore_input_events_(false), |
| 934 is_for_guests_only_(is_for_guests_only), | 934 is_for_guests_only_(is_for_guests_only), |
| 935 is_unused_(true), |
| 935 gpu_observer_registered_(false), | 936 gpu_observer_registered_(false), |
| 936 delayed_cleanup_needed_(false), | 937 delayed_cleanup_needed_(false), |
| 937 within_process_died_observer_(false), | 938 within_process_died_observer_(false), |
| 938 #if BUILDFLAG(ENABLE_WEBRTC) | 939 #if BUILDFLAG(ENABLE_WEBRTC) |
| 939 webrtc_eventlog_host_(id_), | 940 webrtc_eventlog_host_(id_), |
| 940 #endif | 941 #endif |
| 941 permission_service_context_(new PermissionServiceContext(this)), | 942 permission_service_context_(new PermissionServiceContext(this)), |
| 942 indexed_db_factory_(new IndexedDBDispatcherHost( | 943 indexed_db_factory_(new IndexedDBDispatcherHost( |
| 943 id_, | 944 id_, |
| 944 storage_partition_impl_->GetURLRequestContext(), | 945 storage_partition_impl_->GetURLRequestContext(), |
| (...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1795 is_never_suitable_for_reuse_ = true; | 1796 is_never_suitable_for_reuse_ = true; |
| 1796 } | 1797 } |
| 1797 | 1798 |
| 1798 bool RenderProcessHostImpl::MayReuseHost() { | 1799 bool RenderProcessHostImpl::MayReuseHost() { |
| 1799 if (is_never_suitable_for_reuse_) | 1800 if (is_never_suitable_for_reuse_) |
| 1800 return false; | 1801 return false; |
| 1801 | 1802 |
| 1802 return GetContentClient()->browser()->MayReuseHost(this); | 1803 return GetContentClient()->browser()->MayReuseHost(this); |
| 1803 } | 1804 } |
| 1804 | 1805 |
| 1806 bool RenderProcessHostImpl::IsUnused() { |
| 1807 return is_unused_; |
| 1808 } |
| 1809 |
| 1810 void RenderProcessHostImpl::SetIsUsed() { |
| 1811 is_unused_ = false; |
| 1812 } |
| 1813 |
| 1805 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { | 1814 mojom::RouteProvider* RenderProcessHostImpl::GetRemoteRouteProvider() { |
| 1806 return remote_route_provider_.get(); | 1815 return remote_route_provider_.get(); |
| 1807 } | 1816 } |
| 1808 | 1817 |
| 1809 void RenderProcessHostImpl::AddRoute(int32_t routing_id, | 1818 void RenderProcessHostImpl::AddRoute(int32_t routing_id, |
| 1810 IPC::Listener* listener) { | 1819 IPC::Listener* listener) { |
| 1811 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " | 1820 CHECK(!listeners_.Lookup(routing_id)) << "Found Routing ID Conflict: " |
| 1812 << routing_id; | 1821 << routing_id; |
| 1813 listeners_.AddWithID(listener, routing_id); | 1822 listeners_.AddWithID(listener, routing_id); |
| 1814 } | 1823 } |
| (...skipping 1085 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2900 return false; | 2909 return false; |
| 2901 | 2910 |
| 2902 // Check whether the given host and the intended site_url will be using the | 2911 // Check whether the given host and the intended site_url will be using the |
| 2903 // same StoragePartition, since a RenderProcessHost can only support a single | 2912 // same StoragePartition, since a RenderProcessHost can only support a single |
| 2904 // StoragePartition. This is relevant for packaged apps. | 2913 // StoragePartition. This is relevant for packaged apps. |
| 2905 StoragePartition* dest_partition = | 2914 StoragePartition* dest_partition = |
| 2906 BrowserContext::GetStoragePartitionForSite(browser_context, site_url); | 2915 BrowserContext::GetStoragePartitionForSite(browser_context, site_url); |
| 2907 if (!host->InSameStoragePartition(dest_partition)) | 2916 if (!host->InSameStoragePartition(dest_partition)) |
| 2908 return false; | 2917 return false; |
| 2909 | 2918 |
| 2910 // TODO(nick): Consult the SiteIsolationPolicy here. https://crbug.com/513036 | 2919 auto* policy = ChildProcessSecurityPolicyImpl::GetInstance(); |
| 2911 if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( | 2920 if (policy->HasWebUIBindings(host->GetID()) != |
| 2912 host->GetID()) != | |
| 2913 WebUIControllerFactoryRegistry::GetInstance()->UseWebUIBindingsForURL( | 2921 WebUIControllerFactoryRegistry::GetInstance()->UseWebUIBindingsForURL( |
| 2914 browser_context, site_url)) { | 2922 browser_context, site_url)) { |
| 2915 return false; | 2923 return false; |
| 2916 } | 2924 } |
| 2917 | 2925 |
| 2926 // Sites requiring dedicated processes can only reuse a compatible process. |
| 2927 if (policy->HasOriginLock(host->GetID())) { |
| 2928 // If the process is already dedicated to a site, only allow the destination |
| 2929 // URL to reuse this process if the URL's has the same site. |
| 2930 return policy->IsLockedToOrigin(host->GetID(), site_url); |
| 2931 } else if (!host->IsUnused() && |
| 2932 SiteInstanceImpl::ShouldLockToOrigin(browser_context, site_url)) { |
| 2933 // Otherwise, if this process has been used to host any other content, it |
| 2934 // cannot be reused if the destination site indeed requires a dedicated |
| 2935 // process and can be locked to just that site. |
| 2936 return false; |
| 2937 } |
| 2938 |
| 2918 return GetContentClient()->browser()->IsSuitableHost(host, site_url); | 2939 return GetContentClient()->browser()->IsSuitableHost(host, site_url); |
| 2919 } | 2940 } |
| 2920 | 2941 |
| 2921 // static | 2942 // static |
| 2922 bool RenderProcessHost::run_renderer_in_process() { | 2943 bool RenderProcessHost::run_renderer_in_process() { |
| 2923 return g_run_renderer_in_process_; | 2944 return g_run_renderer_in_process_; |
| 2924 } | 2945 } |
| 2925 | 2946 |
| 2926 // static | 2947 // static |
| 2927 void RenderProcessHost::SetRunRendererInProcess(bool value) { | 2948 void RenderProcessHost::SetRunRendererInProcess(bool value) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2952 // static | 2973 // static |
| 2953 RenderProcessHost* RenderProcessHost::FromID(int render_process_id) { | 2974 RenderProcessHost* RenderProcessHost::FromID(int render_process_id) { |
| 2954 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 2975 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 2955 return g_all_hosts.Get().Lookup(render_process_id); | 2976 return g_all_hosts.Get().Lookup(render_process_id); |
| 2956 } | 2977 } |
| 2957 | 2978 |
| 2958 // static | 2979 // static |
| 2959 bool RenderProcessHost::ShouldTryToUseExistingProcessHost( | 2980 bool RenderProcessHost::ShouldTryToUseExistingProcessHost( |
| 2960 BrowserContext* browser_context, | 2981 BrowserContext* browser_context, |
| 2961 const GURL& url) { | 2982 const GURL& url) { |
| 2962 // This needs to be checked first to ensure that --single-process | |
| 2963 // and --site-per-process can be used together. | |
| 2964 if (run_renderer_in_process()) | 2983 if (run_renderer_in_process()) |
| 2965 return true; | 2984 return true; |
| 2966 | 2985 |
| 2967 // If --site-per-process is enabled, do not try to reuse renderer processes | |
| 2968 // when over the limit. | |
| 2969 // TODO(nick): This is overly conservative and isn't launchable. Move this | |
| 2970 // logic into IsSuitableHost, and check |url| against the URL the process is | |
| 2971 // dedicated to. This will allow pages from the same site to share, and will | |
| 2972 // also allow non-isolated sites to share processes. https://crbug.com/513036 | |
| 2973 if (SiteIsolationPolicy::UseDedicatedProcessesForAllSites()) | |
| 2974 return false; | |
| 2975 | |
| 2976 // NOTE: Sometimes it's necessary to create more render processes than | 2986 // NOTE: Sometimes it's necessary to create more render processes than |
| 2977 // GetMaxRendererProcessCount(), for instance when we want to create | 2987 // GetMaxRendererProcessCount(), for instance when we want to create |
| 2978 // a renderer process for a browser context that has no existing | 2988 // a renderer process for a browser context that has no existing |
| 2979 // renderers. This is OK in moderation, since the | 2989 // renderers. This is OK in moderation, since the |
| 2980 // GetMaxRendererProcessCount() is conservative. | 2990 // GetMaxRendererProcessCount() is conservative. |
| 2981 if (g_all_hosts.Get().size() >= GetMaxRendererProcessCount()) | 2991 if (g_all_hosts.Get().size() >= GetMaxRendererProcessCount()) |
| 2982 return true; | 2992 return true; |
| 2983 | 2993 |
| 2984 return GetContentClient()->browser()->ShouldTryToUseExistingProcessHost( | 2994 return GetContentClient()->browser()->ShouldTryToUseExistingProcessHost( |
| 2985 browser_context, url); | 2995 browser_context, url); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3040 } | 3050 } |
| 3041 | 3051 |
| 3042 // static | 3052 // static |
| 3043 RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSite( | 3053 RenderProcessHost* RenderProcessHostImpl::GetProcessHostForSite( |
| 3044 BrowserContext* browser_context, | 3054 BrowserContext* browser_context, |
| 3045 const GURL& url) { | 3055 const GURL& url) { |
| 3046 // Look up the map of site to process for the given browser_context. | 3056 // Look up the map of site to process for the given browser_context. |
| 3047 SiteProcessMap* map = GetSiteProcessMapForBrowserContext(browser_context); | 3057 SiteProcessMap* map = GetSiteProcessMapForBrowserContext(browser_context); |
| 3048 | 3058 |
| 3049 // See if we have an existing process with appropriate bindings for this site. | 3059 // See if we have an existing process with appropriate bindings for this site. |
| 3050 // If not, the caller should create a new process and register it. | 3060 // If not, the caller should create a new process and register it. Note that |
| 3051 std::string site = | 3061 // IsSuitableHost expects a site URL rather than the full |url|. |
| 3052 SiteInstance::GetSiteForURL(browser_context, url).possibly_invalid_spec(); | 3062 GURL site_url = SiteInstance::GetSiteForURL(browser_context, url); |
| 3053 RenderProcessHost* host = map->FindProcess(site); | 3063 RenderProcessHost* host = map->FindProcess(site_url.possibly_invalid_spec()); |
| 3054 if (host && (!host->MayReuseHost() || | 3064 if (host && (!host->MayReuseHost() || |
| 3055 !IsSuitableHost(host, browser_context, url))) { | 3065 !IsSuitableHost(host, browser_context, site_url))) { |
| 3056 // The registered process does not have an appropriate set of bindings for | 3066 // The registered process does not have an appropriate set of bindings for |
| 3057 // the url. Remove it from the map so we can register a better one. | 3067 // the url. Remove it from the map so we can register a better one. |
| 3058 RecordAction( | 3068 RecordAction( |
| 3059 base::UserMetricsAction("BindingsMismatch_GetProcessHostPerSite")); | 3069 base::UserMetricsAction("BindingsMismatch_GetProcessHostPerSite")); |
| 3060 map->RemoveProcess(host); | 3070 map->RemoveProcess(host); |
| 3061 host = NULL; | 3071 host = NULL; |
| 3062 } | 3072 } |
| 3063 | 3073 |
| 3064 return host; | 3074 return host; |
| 3065 } | 3075 } |
| (...skipping 563 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3629 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; | 3639 LOG(ERROR) << "Terminating render process for bad Mojo message: " << error; |
| 3630 | 3640 |
| 3631 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. | 3641 // The ReceivedBadMessage call below will trigger a DumpWithoutCrashing. |
| 3632 // Capture the error message in a crash key value. | 3642 // Capture the error message in a crash key value. |
| 3633 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); | 3643 base::debug::ScopedCrashKey error_key_value("mojo-message-error", error); |
| 3634 bad_message::ReceivedBadMessage(render_process_id, | 3644 bad_message::ReceivedBadMessage(render_process_id, |
| 3635 bad_message::RPH_MOJO_PROCESS_ERROR); | 3645 bad_message::RPH_MOJO_PROCESS_ERROR); |
| 3636 } | 3646 } |
| 3637 | 3647 |
| 3638 } // namespace content | 3648 } // namespace content |
| OLD | NEW |