Skip to content

Commit

Permalink
Remove RenderViewObserver.
Browse files Browse the repository at this point in the history
Add a new blink::WebViewObserver to replace RenderViewObserver. The
listener now becomes a checked observer. These changes are necessary
to hopefully remove the RenderView class in the future.

BUG=1155202

Change-Id: I320bc311b796e658ca8332aa7be722be53dbc629
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2679661
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#851866}
  • Loading branch information
dtapuska authored and Chromium LUCI CQ committed Feb 8, 2021
1 parent af86e27 commit dd4996e
Show file tree
Hide file tree
Showing 29 changed files with 208 additions and 238 deletions.
2 changes: 1 addition & 1 deletion android_webview/renderer/aw_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void AwContentRendererClient::RenderFrameCreated(

void AwContentRendererClient::RenderViewCreated(
content::RenderView* render_view) {
AwRenderViewExt::RenderViewCreated(render_view);
AwRenderViewExt::WebViewCreated(render_view->GetWebView());
}

void AwContentRendererClient::PrepareErrorPage(
Expand Down
27 changes: 13 additions & 14 deletions android_webview/renderer/aw_render_view_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
#include "android_webview/renderer/aw_render_view_ext.h"
#include "android_webview/common/mojom/frame.mojom.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_view.h"

namespace android_webview {

AwRenderViewExt::AwRenderViewExt(content::RenderView* render_view)
: content::RenderViewObserver(render_view) {
DCHECK(render_view != nullptr);
AwRenderViewExt::AwRenderViewExt(blink::WebView* web_view)
: blink::WebViewObserver(web_view) {
DCHECK(web_view != nullptr);
}

AwRenderViewExt::~AwRenderViewExt() {}

// static
void AwRenderViewExt::RenderViewCreated(content::RenderView* render_view) {
new AwRenderViewExt(render_view); // |render_view| takes ownership.
void AwRenderViewExt::WebViewCreated(blink::WebView* web_view) {
new AwRenderViewExt(web_view); // |web_view| takes ownership.
}

void AwRenderViewExt::DidCommitCompositorFrame() {
Expand All @@ -38,24 +37,23 @@ void AwRenderViewExt::OnDestruct() {
}

void AwRenderViewExt::UpdateContentsSize() {
blink::WebView* webview = render_view()->GetWebView();
content::RenderFrame* main_render_frame = render_view()->GetMainRenderFrame();
blink::WebView* webview = GetWebView();
blink::WebFrame* main_frame = webview->MainFrame();

// Even without out-of-process iframes, we now create RemoteFrames for the
// main frame when you navigate cross-process, to create a placeholder in the
// old process. This is necessary to support things like postMessage across
// windows that have references to each other. The RemoteFrame will
// immediately go away if there aren't any active frames left in the old
// process. RenderView's main frame pointer will become null in the old
// process when it is no longer the active main frame.
if (!webview || !main_render_frame)
// process.
if (!main_frame->IsWebLocalFrame())
return;

if (!needs_contents_size_update_)
return;
needs_contents_size_update_ = false;

gfx::Size contents_size = main_render_frame->GetWebFrame()->DocumentSize();
gfx::Size contents_size = main_frame->ToWebLocalFrame()->DocumentSize();

// Fall back to contentsPreferredMinimumSize if the mainFrame is reporting a
// 0x0 size (this happens during initial load).
Expand All @@ -69,8 +67,9 @@ void AwRenderViewExt::UpdateContentsSize() {
last_sent_contents_size_ = contents_size;

mojo::AssociatedRemote<mojom::FrameHost> frame_host_remote;
main_render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
&frame_host_remote);
content::RenderFrame::FromWebFrame(main_frame->ToWebLocalFrame())
->GetRemoteAssociatedInterfaces()
->GetInterface(&frame_host_remote);
frame_host_remote->ContentsSizeChanged(contents_size);
}

Expand Down
10 changes: 5 additions & 5 deletions android_webview/renderer/aw_render_view_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define ANDROID_WEBVIEW_RENDERER_AW_RENDER_VIEW_EXT_H_

#include "base/timer/timer.h"
#include "content/public/renderer/render_view_observer.h"
#include "third_party/blink/public/web/web_view_observer.h"
#include "ui/gfx/geometry/size.h"

namespace android_webview {
Expand All @@ -18,15 +18,15 @@ namespace android_webview {
// Render process side of AwRenderViewHostExt, this provides cross-process
// implementation of miscellaneous WebView functions that we need to poke
// WebKit directly to implement (and that aren't needed in the chrome app).
class AwRenderViewExt : public content::RenderViewObserver {
class AwRenderViewExt : public blink::WebViewObserver {
public:
static void RenderViewCreated(content::RenderView* render_view);
static void WebViewCreated(blink::WebView* web_view);

private:
AwRenderViewExt(content::RenderView* render_view);
AwRenderViewExt(blink::WebView* web_view);
~AwRenderViewExt() override;

// RenderViewObserver:
// blink::WebViewObserver overrides.
void DidCommitCompositorFrame() override;
void DidUpdateMainFrameLayout() override;
void OnDestruct() override;
Expand Down
3 changes: 1 addition & 2 deletions chrome/renderer/chrome_content_renderer_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_frame_visitor.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_view_observer.h"
#include "extensions/buildflags/buildflags.h"
#include "ipc/ipc_sync_channel.h"
#include "media/base/media_switches.h"
Expand Down Expand Up @@ -648,7 +647,7 @@ void ChromeContentRendererClient::RenderFrameCreated(

void ChromeContentRendererClient::RenderViewCreated(
content::RenderView* render_view) {
new prerender::NoStatePrefetchClient(render_view);
new prerender::NoStatePrefetchClient(render_view->GetWebView());
}

SkBitmap* ChromeContentRendererClient::GetSadPluginBitmap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include "components/autofill/core/common/password_form_fill_data.h"
#include "components/autofill/core/common/renderer_id.h"
#include "content/public/renderer/render_frame_observer.h"
#include "content/public/renderer/render_view_observer.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@
#include "base/logging.h"
#include "components/no_state_prefetch/renderer/no_state_prefetch_helper.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
#include "third_party/blink/public/web/web_view.h"

namespace prerender {

NoStatePrefetchClient::NoStatePrefetchClient(content::RenderView* render_view)
: content::RenderViewObserver(render_view) {
DCHECK(render_view);
NoStatePrefetchClient::NoStatePrefetchClient(blink::WebView* web_view)
: blink::WebViewObserver(web_view) {
DCHECK(web_view);
DVLOG(5) << "NoStatePrefetchClient::NoStatePrefetchClient()";
render_view->GetWebView()->SetNoStatePrefetchClient(this);
web_view->SetNoStatePrefetchClient(this);
}

NoStatePrefetchClient::~NoStatePrefetchClient() = default;

bool NoStatePrefetchClient::IsPrefetchOnly() {
blink::WebFrame* main_frame = GetWebView()->MainFrame();
if (!main_frame->IsWebLocalFrame())
return false;
return NoStatePrefetchHelper::IsPrefetching(
render_view()->GetMainRenderFrame());
content::RenderFrame::FromWebFrame(main_frame->ToWebLocalFrame()));
}

void NoStatePrefetchClient::OnDestruct() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
#define COMPONENTS_NO_STATE_PREFETCH_RENDERER_NO_STATE_PREFETCH_CLIENT_H_

#include "base/compiler_specific.h"
#include "content/public/renderer/render_view_observer.h"
#include "third_party/blink/public/web/web_no_state_prefetch_client.h"
#include "third_party/blink/public/web/web_view_observer.h"

namespace prerender {

class NoStatePrefetchClient : public content::RenderViewObserver,
class NoStatePrefetchClient : public blink::WebViewObserver,
public blink::WebNoStatePrefetchClient {
public:
explicit NoStatePrefetchClient(content::RenderView* render_view);
explicit NoStatePrefetchClient(blink::WebView* web_view);

private:
~NoStatePrefetchClient() override;

// RenderViewObserver implementation.
// blink::WebViewObserver implementation.
void OnDestruct() override;

// Implements blink::WebNoStatePrefetchClient
Expand Down
17 changes: 9 additions & 8 deletions components/no_state_prefetch/renderer/prerender_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
#include "components/no_state_prefetch/renderer/no_state_prefetch_helper.h"
#include "content/public/common/page_visibility_state.h"
#include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.h"
#include "content/public/renderer/render_view_observer.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_view.h"
#include "third_party/blink/public/web/web_view_observer.h"

namespace prerender {

namespace {

// Defers media player loading in background pages until they're visible.
class MediaLoadDeferrer : public content::RenderViewObserver {
class MediaLoadDeferrer : public blink::WebViewObserver {
public:
MediaLoadDeferrer(content::RenderView* render_view,
MediaLoadDeferrer(blink::WebView* web_view,
base::OnceClosure continue_loading_cb)
: content::RenderViewObserver(render_view),
: blink::WebViewObserver(web_view),
continue_loading_cb_(std::move(continue_loading_cb)) {}
~MediaLoadDeferrer() override = default;

// content::RenderFrameObserver implementation:
// blink::WebViewObserver implementation:
void OnDestruct() override { delete this; }
void OnPageVisibilityChanged(
content::PageVisibilityState visibility_state) override {
Expand All @@ -50,11 +50,12 @@ bool DeferMediaLoad(content::RenderFrame* render_frame,
// when hidden to allow playlist-like functionality.
//
// NOTE: This is also used to defer media loading for NoStatePrefetch.
if ((render_frame->GetRenderView()->GetWebView()->GetVisibilityState() !=
if ((render_frame->GetWebFrame()->View()->GetVisibilityState() !=
content::PageVisibilityState::kVisible &&
!has_played_media_before) ||
prerender::NoStatePrefetchHelper::IsPrefetching(render_frame)) {
new MediaLoadDeferrer(render_frame->GetRenderView(), std::move(closure));
new MediaLoadDeferrer(render_frame->GetWebFrame()->View(),
std::move(closure));
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion components/plugins/renderer/plugin_placeholder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PluginPlaceholderBase::PluginPlaceholderBase(
const std::string& html_data)
: content::RenderFrameObserver(render_frame),
plugin_params_(params),
plugin_(WebViewPlugin::Create(render_frame->GetRenderView(),
plugin_(WebViewPlugin::Create(render_frame->GetWebFrame()->View(),
this,
render_frame
? render_frame->GetBlinkPreferences()
Expand Down
10 changes: 5 additions & 5 deletions components/plugins/renderer/webview_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ using blink::WebVector;
using blink::WebView;
using blink::web_pref::WebPreferences;

WebViewPlugin::WebViewPlugin(content::RenderView* render_view,
WebViewPlugin::WebViewPlugin(WebView* web_view,
WebViewPlugin::Delegate* delegate,
const WebPreferences& preferences)
: content::RenderViewObserver(render_view),
: blink::WebViewObserver(web_view),
delegate_(delegate),
container_(nullptr),
finished_loading_(false),
Expand All @@ -61,13 +61,13 @@ WebViewPlugin::WebViewPlugin(content::RenderView* render_view,
web_view_helper_(this, preferences) {}

// static
WebViewPlugin* WebViewPlugin::Create(content::RenderView* render_view,
WebViewPlugin* WebViewPlugin::Create(WebView* web_view,
WebViewPlugin::Delegate* delegate,
const WebPreferences& preferences,
const std::string& html_data,
const GURL& url) {
DCHECK(url.is_valid()) << "Blink requires the WebView to have a valid URL.";
WebViewPlugin* plugin = new WebViewPlugin(render_view, delegate, preferences);
WebViewPlugin* plugin = new WebViewPlugin(web_view, delegate, preferences);
// Loading may synchronously access |delegate| which could be
// uninitialized just yet, so load in another task.
plugin->GetTaskRunner()->PostTask(
Expand Down Expand Up @@ -136,7 +136,7 @@ void WebViewPlugin::Destroy() {
delegate_ = nullptr;
}
container_ = nullptr;
content::RenderViewObserver::Observe(nullptr);
blink::WebViewObserver::Observe(nullptr);
base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
}

Expand Down
15 changes: 5 additions & 10 deletions components/plugins/renderer/webview_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner_helpers.h"
#include "content/public/renderer/render_view_observer.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/blink/public/mojom/input/focus_type.mojom-forward.h"
Expand All @@ -24,6 +23,7 @@
#include "third_party/blink/public/web/web_non_composited_widget_client.h"
#include "third_party/blink/public/web/web_plugin.h"
#include "third_party/blink/public/web/web_view_client.h"
#include "third_party/blink/public/web/web_view_observer.h"
#include "ui/base/cursor/cursor.h"
#include "ui/base/ime/mojom/text_input_state.mojom.h"

Expand All @@ -35,19 +35,14 @@ class WebLocalFrame;
class WebMouseEvent;
}

namespace content {
class RenderView;
}

// This class implements the WebPlugin interface by forwarding drawing and
// handling input events to a WebView.
// It can be used as a placeholder for an actual plugin, using HTML for the UI.
// To show HTML data inside the WebViewPlugin,
// call web_view->mainFrame()->loadHTMLString() with the HTML data and a fake
// chrome:// URL as origin.

class WebViewPlugin : public blink::WebPlugin,
public content::RenderViewObserver {
class WebViewPlugin : public blink::WebPlugin, public blink::WebViewObserver {
public:
class Delegate {
public:
Expand All @@ -74,7 +69,7 @@ class WebViewPlugin : public blink::WebPlugin,
// and displaying |html_data|. |url| should be a (fake) data:text/html URL;
// it is only used for navigation and never actually resolved.
static WebViewPlugin* Create(
content::RenderView* render_view,
blink::WebView* web_view,
Delegate* delegate,
const blink::web_pref::WebPreferences& preferences,
const std::string& html_data,
Expand Down Expand Up @@ -123,14 +118,14 @@ class WebViewPlugin : public blink::WebPlugin,

private:
friend class base::DeleteHelper<WebViewPlugin>;
WebViewPlugin(content::RenderView* render_view,
WebViewPlugin(blink::WebView* web_view,
Delegate* delegate,
const blink::web_pref::WebPreferences& preferences);
~WebViewPlugin() override;

blink::WebView* web_view() { return web_view_helper_.web_view(); }

// content::RenderViewObserver methods:
// blink::WebViewObserver methods:
void OnDestruct() override {}
void OnZoomLevelChanged() override;

Expand Down
2 changes: 0 additions & 2 deletions content/public/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ target(link_target_type, "renderer_sources") {
"render_thread_observer.cc",
"render_thread_observer.h",
"render_view.h",
"render_view_observer.cc",
"render_view_observer.h",
"render_view_visitor.h",
"renderer_ppapi_host.h",
"url_loader_throttle_provider.h",
Expand Down
43 changes: 0 additions & 43 deletions content/public/renderer/render_view_observer.cc

This file was deleted.

Loading

0 comments on commit dd4996e

Please sign in to comment.