Commit 61fd3502 authored by Lukasz Anforowicz's avatar Lukasz Anforowicz Committed by Commit Bot

Removing callers of the WebContents::GetRenderProcessHost() method.

WebContents::GetRenderProcessHost is an API that doesn't behave as
expected with out-of-process iframes, as multiple processes can be
associated with a single WebContents.  This CL replaces callers of this
API, so that they go through an equivalent API that explicitly selects
which frame's process is needed.

This CL was started by using an ad-hoc clang-plugin that replaced
existing callsites of WebContents::GetRenderProcessHost() with a call to
something like wc->GetMainFrame()->GetProcess().  This was followed-up
by manually adding an include of render_frame_host.h and git cl format
and git cl lint and then a self-review with small tweaks (e.g. sometimes
using a wc->GetRenderViewHost()->GetProcess() is more appropriate).

This CL was uploaded by git cl split.

R=ekaramad@chromium.org

Bug: 666525
Change-Id: I8c9c9436301eabd31b5bfe1054956c63d5457dfc
Reviewed-on: https://chromium-review.googlesource.com/689107Reviewed-by: default avatarEhsan Karamad <ekaramad@chromium.org>
Commit-Queue: Łukasz Anforowicz <lukasza@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505399}
parent d4c2a8f3
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "extensions/browser/guest_view/extension_options/extension_options_guest.h" #include "extensions/browser/guest_view/extension_options/extension_options_guest.h"
#include <memory>
#include <string>
#include <utility> #include <utility>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
...@@ -12,6 +14,7 @@ ...@@ -12,6 +14,7 @@
#include "components/guest_view/browser/guest_view_event.h" #include "components/guest_view/browser/guest_view_event.h"
#include "components/guest_view/browser/guest_view_manager.h" #include "components/guest_view/browser/guest_view_manager.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/site_instance.h" #include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -226,8 +229,9 @@ void ExtensionOptionsGuest::DidFinishNavigation( ...@@ -226,8 +229,9 @@ void ExtensionOptionsGuest::DidFinishNavigation(
SetGuestZoomLevelToMatchEmbedder(); SetGuestZoomLevelToMatchEmbedder();
if (!url::IsSameOriginWith(navigation_handle->GetURL(), options_page_)) { if (!url::IsSameOriginWith(navigation_handle->GetURL(), options_page_)) {
bad_message::ReceivedBadMessage(web_contents()->GetRenderProcessHost(), bad_message::ReceivedBadMessage(
bad_message::EOG_BAD_ORIGIN); web_contents()->GetMainFrame()->GetProcess(),
bad_message::EOG_BAD_ORIGIN);
} }
} }
......
...@@ -4,12 +4,15 @@ ...@@ -4,12 +4,15 @@
#include "extensions/browser/guest_view/extension_view/extension_view_guest.h" #include "extensions/browser/guest_view/extension_view/extension_view_guest.h"
#include <memory>
#include <string>
#include <utility> #include <utility>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "components/crx_file/id_util.h" #include "components/crx_file/id_util.h"
#include "components/guest_view/browser/guest_view_event.h" #include "components/guest_view/browser/guest_view_event.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/common/result_codes.h" #include "content/public/common/result_codes.h"
#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/api/extensions_api_client.h"
...@@ -56,7 +59,7 @@ bool ExtensionViewGuest::NavigateGuest(const std::string& src, ...@@ -56,7 +59,7 @@ bool ExtensionViewGuest::NavigateGuest(const std::string& src,
if (!force_navigation && (url_ == url)) if (!force_navigation && (url_ == url))
return false; return false;
web_contents()->GetRenderProcessHost()->FilterURL(false, &url); web_contents()->GetMainFrame()->GetProcess()->FilterURL(false, &url);
web_contents()->GetController().LoadURL(url, content::Referrer(), web_contents()->GetController().LoadURL(url, content::Referrer(),
ui::PAGE_TRANSITION_AUTO_TOPLEVEL, ui::PAGE_TRANSITION_AUTO_TOPLEVEL,
std::string()); std::string());
......
...@@ -4,12 +4,14 @@ ...@@ -4,12 +4,14 @@
#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h" #include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
#include <memory>
#include <utility> #include <utility>
#include "components/guest_view/browser/guest_view_base.h" #include "components/guest_view/browser/guest_view_base.h"
#include "components/guest_view/browser/guest_view_manager.h" #include "components/guest_view/browser/guest_view_manager.h"
#include "components/guest_view/common/guest_view_constants.h" #include "components/guest_view/common/guest_view_constants.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/api/extensions_api_client.h"
...@@ -85,7 +87,7 @@ bool ExtensionsGuestViewManagerDelegate::IsGuestAvailableToContext( ...@@ -85,7 +87,7 @@ bool ExtensionsGuestViewManagerDelegate::IsGuestAvailableToContext(
owner_extension, owner_extension,
process_map->GetMostLikelyContextType( process_map->GetMostLikelyContextType(
owner_extension, owner_extension,
guest->owner_web_contents()->GetRenderProcessHost()->GetID()), guest->owner_web_contents()->GetMainFrame()->GetProcess()->GetID()),
guest->GetOwnerSiteURL()); guest->GetOwnerSiteURL());
return availability.is_available(); return availability.is_available();
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "extensions/browser/guest_view/web_view/web_view_apitest.h" #include "extensions/browser/guest_view/web_view/web_view_apitest.h"
#include <memory>
#include <string>
#include <utility> #include <utility>
#include "base/command_line.h" #include "base/command_line.h"
...@@ -17,6 +19,7 @@ ...@@ -17,6 +19,7 @@
#include "components/guest_view/browser/guest_view_manager_delegate.h" #include "components/guest_view/browser/guest_view_manager_delegate.h"
#include "components/guest_view/browser/guest_view_manager_factory.h" #include "components/guest_view/browser/guest_view_manager_factory.h"
#include "components/guest_view/browser/test_guest_view_manager.h" #include "components/guest_view/browser/test_guest_view_manager.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/common/content_features.h" #include "content/public/common/content_features.h"
#include "content/public/common/content_switches.h" #include "content/public/common/content_switches.h"
...@@ -689,7 +692,8 @@ IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestRemoveWebviewOnExit) { ...@@ -689,7 +692,8 @@ IN_PROC_BROWSER_TEST_F(WebViewAPITest, TestRemoveWebviewOnExit) {
"runTest('testRemoveWebviewOnExit')")); "runTest('testRemoveWebviewOnExit')"));
content::WebContents* guest_web_contents = GetGuestWebContents(); content::WebContents* guest_web_contents = GetGuestWebContents();
EXPECT_TRUE(guest_web_contents->GetRenderProcessHost()->IsForGuestsOnly()); EXPECT_TRUE(
guest_web_contents->GetMainFrame()->GetProcess()->IsForGuestsOnly());
ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied()); ASSERT_TRUE(guest_loaded_listener.WaitUntilSatisfied());
content::WebContentsDestroyedWatcher destroyed_watcher(guest_web_contents); content::WebContentsDestroyedWatcher destroyed_watcher(guest_web_contents);
......
...@@ -6,6 +6,9 @@ ...@@ -6,6 +6,9 @@
#include <stddef.h> #include <stddef.h>
#include <map>
#include <memory>
#include <string>
#include <utility> #include <utility>
#include "base/lazy_instance.h" #include "base/lazy_instance.h"
...@@ -25,6 +28,7 @@ ...@@ -25,6 +28,7 @@
#include "content/public/browser/native_web_keyboard_event.h" #include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h" #include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host.h" #include "content/public/browser/render_widget_host.h"
...@@ -320,7 +324,7 @@ void WebViewGuest::CreateWebContents( ...@@ -320,7 +324,7 @@ void WebViewGuest::CreateWebContents(
const base::DictionaryValue& create_params, const base::DictionaryValue& create_params,
const WebContentsCreatedCallback& callback) { const WebContentsCreatedCallback& callback) {
RenderProcessHost* owner_render_process_host = RenderProcessHost* owner_render_process_host =
owner_web_contents()->GetRenderProcessHost(); owner_web_contents()->GetMainFrame()->GetProcess();
std::string storage_partition_id; std::string storage_partition_id;
bool persist_storage = false; bool persist_storage = false;
ParsePartitionParam(create_params, &storage_partition_id, &persist_storage); ParsePartitionParam(create_params, &storage_partition_id, &persist_storage);
...@@ -393,7 +397,7 @@ void WebViewGuest::DidInitialize(const base::DictionaryValue& create_params) { ...@@ -393,7 +397,7 @@ void WebViewGuest::DidInitialize(const base::DictionaryValue& create_params) {
web_view_permission_helper_ = std::make_unique<WebViewPermissionHelper>(this); web_view_permission_helper_ = std::make_unique<WebViewPermissionHelper>(this);
rules_registry_id_ = GetOrGenerateRulesRegistryID( rules_registry_id_ = GetOrGenerateRulesRegistryID(
owner_web_contents()->GetRenderProcessHost()->GetID(), owner_web_contents()->GetMainFrame()->GetProcess()->GetID(),
view_instance_id()); view_instance_id());
// We must install the mapping from guests to WebViews prior to resuming // We must install the mapping from guests to WebViews prior to resuming
...@@ -484,7 +488,7 @@ void WebViewGuest::GuestDestroyed() { ...@@ -484,7 +488,7 @@ void WebViewGuest::GuestDestroyed() {
void WebViewGuest::GuestReady() { void WebViewGuest::GuestReady() {
// The guest RenderView should always live in an isolated guest process. // The guest RenderView should always live in an isolated guest process.
CHECK(web_contents()->GetRenderProcessHost()->IsForGuestsOnly()); CHECK(web_contents()->GetMainFrame()->GetProcess()->IsForGuestsOnly());
content::RenderFrameHost* main_frame = web_contents()->GetMainFrame(); content::RenderFrameHost* main_frame = web_contents()->GetMainFrame();
main_frame->Send( main_frame->Send(
new ExtensionMsg_SetFrameName(main_frame->GetRoutingID(), name_)); new ExtensionMsg_SetFrameName(main_frame->GetRoutingID(), name_));
...@@ -666,7 +670,7 @@ void WebViewGuest::NewGuestWebViewCallback(const content::OpenURLParams& params, ...@@ -666,7 +670,7 @@ void WebViewGuest::NewGuestWebViewCallback(const content::OpenURLParams& params,
void WebViewGuest::RendererResponsive(WebContents* source) { void WebViewGuest::RendererResponsive(WebContents* source) {
auto args = std::make_unique<base::DictionaryValue>(); auto args = std::make_unique<base::DictionaryValue>();
args->SetInteger(webview::kProcessId, args->SetInteger(webview::kProcessId,
web_contents()->GetRenderProcessHost()->GetID()); web_contents()->GetMainFrame()->GetProcess()->GetID());
DispatchEventToView(std::make_unique<GuestViewEvent>( DispatchEventToView(std::make_unique<GuestViewEvent>(
webview::kEventResponsive, std::move(args))); webview::kEventResponsive, std::move(args)));
} }
...@@ -676,7 +680,7 @@ void WebViewGuest::RendererUnresponsive( ...@@ -676,7 +680,7 @@ void WebViewGuest::RendererUnresponsive(
const content::WebContentsUnresponsiveState& unresponsive_state) { const content::WebContentsUnresponsiveState& unresponsive_state) {
auto args = std::make_unique<base::DictionaryValue>(); auto args = std::make_unique<base::DictionaryValue>();
args->SetInteger(webview::kProcessId, args->SetInteger(webview::kProcessId,
web_contents()->GetRenderProcessHost()->GetID()); web_contents()->GetMainFrame()->GetProcess()->GetID());
DispatchEventToView(std::make_unique<GuestViewEvent>( DispatchEventToView(std::make_unique<GuestViewEvent>(
webview::kEventUnresponsive, std::move(args))); webview::kEventUnresponsive, std::move(args)));
} }
...@@ -725,9 +729,9 @@ void WebViewGuest::Stop() { ...@@ -725,9 +729,9 @@ void WebViewGuest::Stop() {
void WebViewGuest::Terminate() { void WebViewGuest::Terminate() {
base::RecordAction(UserMetricsAction("WebView.Guest.Terminate")); base::RecordAction(UserMetricsAction("WebView.Guest.Terminate"));
base::ProcessHandle process_handle = base::ProcessHandle process_handle =
web_contents()->GetRenderProcessHost()->GetHandle(); web_contents()->GetMainFrame()->GetProcess()->GetHandle();
if (process_handle) if (process_handle)
web_contents()->GetRenderProcessHost()->Shutdown( web_contents()->GetMainFrame()->GetProcess()->Shutdown(
content::RESULT_CODE_KILLED, false); content::RESULT_CODE_KILLED, false);
} }
...@@ -746,7 +750,8 @@ bool WebViewGuest::ClearData(base::Time remove_since, ...@@ -746,7 +750,8 @@ bool WebViewGuest::ClearData(base::Time remove_since,
if (removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_CACHE) { if (removal_mask & webview::WEB_VIEW_REMOVE_DATA_MASK_CACHE) {
// First clear http cache data and then clear the rest in // First clear http cache data and then clear the rest in
// |ClearDataInternal|. // |ClearDataInternal|.
int render_process_id = web_contents()->GetRenderProcessHost()->GetID(); int render_process_id =
web_contents()->GetMainFrame()->GetProcess()->GetID();
// We need to clear renderer cache separately for our process because // We need to clear renderer cache separately for our process because
// StoragePartitionHttpCacheDataRemover::ClearData() does not clear that. // StoragePartitionHttpCacheDataRemover::ClearData() does not clear that.
web_cache::WebCacheManager::GetInstance()->ClearCacheForProcess( web_cache::WebCacheManager::GetInstance()->ClearCacheForProcess(
...@@ -831,7 +836,7 @@ void WebViewGuest::DidFinishNavigation( ...@@ -831,7 +836,7 @@ void WebViewGuest::DidFinishNavigation(
args->SetInteger(webview::kInternalEntryCount, args->SetInteger(webview::kInternalEntryCount,
web_contents()->GetController().GetEntryCount()); web_contents()->GetController().GetEntryCount());
args->SetInteger(webview::kInternalProcessId, args->SetInteger(webview::kInternalProcessId,
web_contents()->GetRenderProcessHost()->GetID()); web_contents()->GetMainFrame()->GetProcess()->GetID());
DispatchEventToView(std::make_unique<GuestViewEvent>( DispatchEventToView(std::make_unique<GuestViewEvent>(
webview::kEventLoadCommit, std::move(args))); webview::kEventLoadCommit, std::move(args)));
...@@ -863,7 +868,7 @@ void WebViewGuest::RenderProcessGone(base::TerminationStatus status) { ...@@ -863,7 +868,7 @@ void WebViewGuest::RenderProcessGone(base::TerminationStatus status) {
auto args = std::make_unique<base::DictionaryValue>(); auto args = std::make_unique<base::DictionaryValue>();
args->SetInteger(webview::kProcessId, args->SetInteger(webview::kProcessId,
web_contents()->GetRenderProcessHost()->GetID()); web_contents()->GetMainFrame()->GetProcess()->GetID());
args->SetString(webview::kReason, TerminationStatusToString(status)); args->SetString(webview::kReason, TerminationStatusToString(status));
DispatchEventToView( DispatchEventToView(
std::make_unique<GuestViewEvent>(webview::kEventExit, std::move(args))); std::make_unique<GuestViewEvent>(webview::kEventExit, std::move(args)));
...@@ -922,7 +927,7 @@ void WebViewGuest::PushWebViewStateToIOThread() { ...@@ -922,7 +927,7 @@ void WebViewGuest::PushWebViewStateToIOThread() {
WebViewRendererState::WebViewInfo web_view_info; WebViewRendererState::WebViewInfo web_view_info;
web_view_info.embedder_process_id = web_view_info.embedder_process_id =
owner_web_contents()->GetRenderProcessHost()->GetID(); owner_web_contents()->GetMainFrame()->GetProcess()->GetID();
web_view_info.instance_id = view_instance_id(); web_view_info.instance_id = view_instance_id();
web_view_info.partition_id = partition_id; web_view_info.partition_id = partition_id;
web_view_info.owner_host = owner_host(); web_view_info.owner_host = owner_host();
...@@ -939,7 +944,7 @@ void WebViewGuest::PushWebViewStateToIOThread() { ...@@ -939,7 +944,7 @@ void WebViewGuest::PushWebViewStateToIOThread() {
content::BrowserThread::IO, FROM_HERE, content::BrowserThread::IO, FROM_HERE,
base::Bind(&WebViewRendererState::AddGuest, base::Bind(&WebViewRendererState::AddGuest,
base::Unretained(WebViewRendererState::GetInstance()), base::Unretained(WebViewRendererState::GetInstance()),
web_contents()->GetRenderProcessHost()->GetID(), web_contents()->GetRenderViewHost()->GetProcess()->GetID(),
web_contents()->GetRenderViewHost()->GetRoutingID(), web_contents()->GetRenderViewHost()->GetRoutingID(),
web_view_info)); web_view_info));
} }
...@@ -951,7 +956,7 @@ void WebViewGuest::RemoveWebViewStateFromIOThread( ...@@ -951,7 +956,7 @@ void WebViewGuest::RemoveWebViewStateFromIOThread(
content::BrowserThread::IO, FROM_HERE, content::BrowserThread::IO, FROM_HERE,
base::Bind(&WebViewRendererState::RemoveGuest, base::Bind(&WebViewRendererState::RemoveGuest,
base::Unretained(WebViewRendererState::GetInstance()), base::Unretained(WebViewRendererState::GetInstance()),
web_contents->GetRenderProcessHost()->GetID(), web_contents->GetRenderViewHost()->GetProcess()->GetID(),
web_contents->GetRenderViewHost()->GetRoutingID())); web_contents->GetRenderViewHost()->GetRoutingID()));
} }
...@@ -995,7 +1000,7 @@ void WebViewGuest::SignalWhenReady(const base::Closure& callback) { ...@@ -995,7 +1000,7 @@ void WebViewGuest::SignalWhenReady(const base::Closure& callback) {
void WebViewGuest::WillAttachToEmbedder() { void WebViewGuest::WillAttachToEmbedder() {
rules_registry_id_ = GetOrGenerateRulesRegistryID( rules_registry_id_ = GetOrGenerateRulesRegistryID(
owner_web_contents()->GetRenderProcessHost()->GetID(), owner_web_contents()->GetMainFrame()->GetProcess()->GetID(),
view_instance_id()); view_instance_id());
// We must install the mapping from guests to WebViews prior to resuming // We must install the mapping from guests to WebViews prior to resuming
...@@ -1391,7 +1396,8 @@ void WebViewGuest::LoadURLWithParams( ...@@ -1391,7 +1396,8 @@ void WebViewGuest::LoadURLWithParams(
return; return;
GURL validated_url(url); GURL validated_url(url);
web_contents()->GetRenderProcessHost()->FilterURL(false, &validated_url); web_contents()->GetMainFrame()->GetProcess()->FilterURL(false,
&validated_url);
// As guests do not swap processes on navigation, only navigations to // As guests do not swap processes on navigation, only navigations to
// normal web URLs are supported. No protocol handlers are installed for // normal web URLs are supported. No protocol handlers are installed for
// other schemes (e.g., WebUI or extensions), and no permissions or bindings // other schemes (e.g., WebUI or extensions), and no permissions or bindings
...@@ -1463,9 +1469,9 @@ void WebViewGuest::OnWebViewNewWindowResponse( ...@@ -1463,9 +1469,9 @@ void WebViewGuest::OnWebViewNewWindowResponse(
int new_window_instance_id, int new_window_instance_id,
bool allow, bool allow,
const std::string& user_input) { const std::string& user_input) {
auto* guest = auto* guest = WebViewGuest::From(
WebViewGuest::From(owner_web_contents()->GetRenderProcessHost()->GetID(), owner_web_contents()->GetMainFrame()->GetProcess()->GetID(),
new_window_instance_id); new_window_instance_id);
if (!guest) if (!guest)
return; return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment