Commit 046559c8 authored by Dave Tapuska's avatar Dave Tapuska Committed by Commit Bot

Convert AwViewMsg_SetBackgroundColor to a mojom message.

There are a series of messages that are sent to the LocalMainFrame
of the webview. This maps SetBackgroundColor onto one of those messages.
Other targeted messages will be converted in followup CLs.

BUG=993189

Change-Id: I221d0c9be378c731d0bb3a11e508bda8ba0dc849
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2518798
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824926}
parent e8213017
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#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/web_contents.h" #include "content/public/browser/web_contents.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
namespace android_webview { namespace android_webview {
...@@ -104,9 +105,8 @@ void AwRenderViewHostExt::SetBackgroundColor(SkColor c) { ...@@ -104,9 +105,8 @@ void AwRenderViewHostExt::SetBackgroundColor(SkColor c) {
if (background_color_ == c) if (background_color_ == c)
return; return;
background_color_ = c; background_color_ = c;
if (web_contents()->GetRenderViewHost()) { if (local_main_frame_remote_) {
web_contents()->GetMainFrame()->Send(new AwViewMsg_SetBackgroundColor( local_main_frame_remote_->SetBackgroundColor(background_color_);
web_contents()->GetMainFrame()->GetRoutingID(), background_color_));
} }
} }
...@@ -144,8 +144,11 @@ void AwRenderViewHostExt::ClearImageRequests() { ...@@ -144,8 +144,11 @@ void AwRenderViewHostExt::ClearImageRequests() {
void AwRenderViewHostExt::RenderFrameCreated( void AwRenderViewHostExt::RenderFrameCreated(
content::RenderFrameHost* frame_host) { content::RenderFrameHost* frame_host) {
if (!frame_host->GetParent()) { if (!frame_host->GetParent()) {
frame_host->Send(new AwViewMsg_SetBackgroundColor( local_main_frame_remote_.reset();
frame_host->GetRoutingID(), background_color_)); frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
local_main_frame_remote_.BindNewEndpointAndPassReceiver());
local_main_frame_remote_->SetBackgroundColor(background_color_);
} }
} }
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "android_webview/common/aw_hit_test_data.h" #include "android_webview/common/aw_hit_test_data.h"
#include "android_webview/common/mojom/frame.mojom.h"
#include "base/callback_forward.h" #include "base/callback_forward.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -118,6 +120,9 @@ class AwRenderViewHostExt : public content::WebContentsObserver { ...@@ -118,6 +120,9 @@ class AwRenderViewHostExt : public content::WebContentsObserver {
// Some WebView users might want to show their own error pages / logic. // Some WebView users might want to show their own error pages / logic.
bool will_suppress_error_page_ = false; bool will_suppress_error_page_ = false;
// Associated channel to the webview LocalMainFrame extensions.
mojo::AssociatedRemote<mojom::LocalMainFrame> local_main_frame_remote_;
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt); DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt);
......
...@@ -64,7 +64,13 @@ mojom("mojom") { ...@@ -64,7 +64,13 @@ mojom("mojom") {
# We don't want Blink variants of bindings to be generated. # We don't want Blink variants of bindings to be generated.
disable_variants = true disable_variants = true
sources = [ "mojom/renderer.mojom" ] sources = [
"mojom/frame.mojom",
"mojom/renderer.mojom",
]
public_deps = [ "//mojo/public/mojom/base" ] public_deps = [
"//mojo/public/mojom/base",
"//skia/public/mojom",
]
} }
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module android_webview.mojom;
import "skia/public/mojom/skcolor.mojom";
// Similar to blink::mojom::LocalMainFrame. This interface adds additional
// things that webview needs from the main frame.
interface LocalMainFrame {
// Sets the base background color for this view.
SetBackgroundColor(skia.mojom.SkColor color);
};
...@@ -71,10 +71,6 @@ IPC_MESSAGE_ROUTED0(AwViewMsg_ResetScrollAndScaleState) ...@@ -71,10 +71,6 @@ IPC_MESSAGE_ROUTED0(AwViewMsg_ResetScrollAndScaleState)
IPC_MESSAGE_ROUTED1(AwViewMsg_SetInitialPageScale, IPC_MESSAGE_ROUTED1(AwViewMsg_SetInitialPageScale,
double /* page_scale_factor */) double /* page_scale_factor */)
// Sets the base background color for this view.
IPC_MESSAGE_ROUTED1(AwViewMsg_SetBackgroundColor,
SkColor)
IPC_MESSAGE_CONTROL1(AwViewMsg_SetJsOnlineProperty, IPC_MESSAGE_CONTROL1(AwViewMsg_SetJsOnlineProperty,
bool /* network_up */) bool /* network_up */)
......
...@@ -162,6 +162,12 @@ AwRenderFrameExt::AwRenderFrameExt(content::RenderFrame* render_frame) ...@@ -162,6 +162,12 @@ AwRenderFrameExt::AwRenderFrameExt(content::RenderFrame* render_frame)
if (content_capture::features::IsContentCaptureEnabled()) if (content_capture::features::IsContentCaptureEnabled())
new content_capture::ContentCaptureSender(render_frame, &registry_); new content_capture::ContentCaptureSender(render_frame, &registry_);
// If we are the main frame register an additional mojo interface.
if (render_frame->IsMainFrame()) {
registry_.AddInterface(base::BindRepeating(
&AwRenderFrameExt::BindLocalMainFrame, base::Unretained(this)));
}
// Add myself to the RenderFrame => AwRenderFrameExt register. // Add myself to the RenderFrame => AwRenderFrameExt register.
GetFrameExtMap()->emplace(render_frame, this); GetFrameExtMap()->emplace(render_frame, this);
} }
...@@ -228,7 +234,6 @@ bool AwRenderFrameExt::OnMessageReceived(const IPC::Message& message) { ...@@ -228,7 +234,6 @@ bool AwRenderFrameExt::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AwViewMsg_ResetScrollAndScaleState, IPC_MESSAGE_HANDLER(AwViewMsg_ResetScrollAndScaleState,
OnResetScrollAndScaleState) OnResetScrollAndScaleState)
IPC_MESSAGE_HANDLER(AwViewMsg_SetInitialPageScale, OnSetInitialPageScale) IPC_MESSAGE_HANDLER(AwViewMsg_SetInitialPageScale, OnSetInitialPageScale)
IPC_MESSAGE_HANDLER(AwViewMsg_SetBackgroundColor, OnSetBackgroundColor)
IPC_MESSAGE_HANDLER(AwViewMsg_SmoothScroll, OnSmoothScroll) IPC_MESSAGE_HANDLER(AwViewMsg_SmoothScroll, OnSmoothScroll)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP() IPC_END_MESSAGE_MAP()
...@@ -329,7 +334,7 @@ void AwRenderFrameExt::OnSetInitialPageScale(double page_scale_factor) { ...@@ -329,7 +334,7 @@ void AwRenderFrameExt::OnSetInitialPageScale(double page_scale_factor) {
webview->SetInitialPageScaleOverride(page_scale_factor); webview->SetInitialPageScaleOverride(page_scale_factor);
} }
void AwRenderFrameExt::OnSetBackgroundColor(SkColor c) { void AwRenderFrameExt::SetBackgroundColor(SkColor c) {
blink::WebView* webview = GetWebView(); blink::WebView* webview = GetWebView();
if (!webview) if (!webview)
return; return;
...@@ -365,4 +370,9 @@ void AwRenderFrameExt::OnDestruct() { ...@@ -365,4 +370,9 @@ void AwRenderFrameExt::OnDestruct() {
delete this; delete this;
} }
void AwRenderFrameExt::BindLocalMainFrame(
mojo::PendingAssociatedReceiver<mojom::LocalMainFrame> pending_receiver) {
local_main_frame_receiver_.Bind(std::move(pending_receiver));
}
} // namespace android_webview } // namespace android_webview
...@@ -5,8 +5,11 @@ ...@@ -5,8 +5,11 @@
#ifndef ANDROID_WEBVIEW_RENDERER_AW_RENDER_FRAME_EXT_H_ #ifndef ANDROID_WEBVIEW_RENDERER_AW_RENDER_FRAME_EXT_H_
#define ANDROID_WEBVIEW_RENDERER_AW_RENDER_FRAME_EXT_H_ #define ANDROID_WEBVIEW_RENDERER_AW_RENDER_FRAME_EXT_H_
#include "android_webview/common/mojom/frame.mojom.h"
#include "base/macros.h" #include "base/macros.h"
#include "content/public/renderer/render_frame_observer.h" #include "content/public/renderer/render_frame_observer.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h" #include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/point_f.h" #include "ui/gfx/geometry/point_f.h"
...@@ -24,7 +27,8 @@ namespace android_webview { ...@@ -24,7 +27,8 @@ namespace android_webview {
// Render process side of AwRenderViewHostExt, this provides cross-process // Render process side of AwRenderViewHostExt, this provides cross-process
// implementation of miscellaneous WebView functions that we need to poke // implementation of miscellaneous WebView functions that we need to poke
// WebKit directly to implement (and that aren't needed in the chrome app). // WebKit directly to implement (and that aren't needed in the chrome app).
class AwRenderFrameExt : public content::RenderFrameObserver { class AwRenderFrameExt : public content::RenderFrameObserver,
mojom::LocalMainFrame {
public: public:
explicit AwRenderFrameExt(content::RenderFrame* render_frame); explicit AwRenderFrameExt(content::RenderFrame* render_frame);
...@@ -53,16 +57,22 @@ class AwRenderFrameExt : public content::RenderFrameObserver { ...@@ -53,16 +57,22 @@ class AwRenderFrameExt : public content::RenderFrameObserver {
void OnSetInitialPageScale(double page_scale_factor); void OnSetInitialPageScale(double page_scale_factor);
void OnSetBackgroundColor(SkColor c);
void OnSmoothScroll(int target_x, int target_y, base::TimeDelta duration); void OnSmoothScroll(int target_x, int target_y, base::TimeDelta duration);
// mojom::LocalMainFrame overrides:
void SetBackgroundColor(SkColor c) override;
void BindLocalMainFrame(
mojo::PendingAssociatedReceiver<mojom::LocalMainFrame> pending_receiver);
blink::WebView* GetWebView(); blink::WebView* GetWebView();
blink::WebFrameWidget* GetWebFrameWidget(); blink::WebFrameWidget* GetWebFrameWidget();
url::Origin last_origin_; url::Origin last_origin_;
blink::AssociatedInterfaceRegistry registry_; blink::AssociatedInterfaceRegistry registry_;
mojo::AssociatedReceiver<mojom::LocalMainFrame> local_main_frame_receiver_{
this};
DISALLOW_COPY_AND_ASSIGN(AwRenderFrameExt); DISALLOW_COPY_AND_ASSIGN(AwRenderFrameExt);
}; };
......
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