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