Skip to content

Commit

Permalink
Convert AwViewMsg_SetBackgroundColor to a mojom message.
Browse files Browse the repository at this point in the history
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: Bo <boliu@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824926}
  • Loading branch information
dtapuska authored and Commit Bot committed Nov 6, 2020
1 parent e821301 commit 046559c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 16 deletions.
13 changes: 8 additions & 5 deletions android_webview/browser/renderer_host/aw_render_view_host_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"

namespace android_webview {

Expand Down Expand Up @@ -104,9 +105,8 @@ void AwRenderViewHostExt::SetBackgroundColor(SkColor c) {
if (background_color_ == c)
return;
background_color_ = c;
if (web_contents()->GetRenderViewHost()) {
web_contents()->GetMainFrame()->Send(new AwViewMsg_SetBackgroundColor(
web_contents()->GetMainFrame()->GetRoutingID(), background_color_));
if (local_main_frame_remote_) {
local_main_frame_remote_->SetBackgroundColor(background_color_);
}
}

Expand Down Expand Up @@ -144,8 +144,11 @@ void AwRenderViewHostExt::ClearImageRequests() {
void AwRenderViewHostExt::RenderFrameCreated(
content::RenderFrameHost* frame_host) {
if (!frame_host->GetParent()) {
frame_host->Send(new AwViewMsg_SetBackgroundColor(
frame_host->GetRoutingID(), background_color_));
local_main_frame_remote_.reset();
frame_host->GetRemoteAssociatedInterfaces()->GetInterface(
local_main_frame_remote_.BindNewEndpointAndPassReceiver());

local_main_frame_remote_->SetBackgroundColor(background_color_);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
#include "content/public/browser/web_contents_observer.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/macros.h"
#include "base/sequence_checker.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/point_f.h"
#include "ui/gfx/geometry/size.h"
Expand Down Expand Up @@ -118,6 +120,9 @@ class AwRenderViewHostExt : public content::WebContentsObserver {
// Some WebView users might want to show their own error pages / logic.
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_);

DISALLOW_COPY_AND_ASSIGN(AwRenderViewHostExt);
Expand Down
10 changes: 8 additions & 2 deletions android_webview/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ mojom("mojom") {
# We don't want Blink variants of bindings to be generated.
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",
]
}
15 changes: 15 additions & 0 deletions android_webview/common/mojom/frame.mojom
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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);
};
4 changes: 0 additions & 4 deletions android_webview/common/render_view_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ IPC_MESSAGE_ROUTED0(AwViewMsg_ResetScrollAndScaleState)
IPC_MESSAGE_ROUTED1(AwViewMsg_SetInitialPageScale,
double /* page_scale_factor */)

// Sets the base background color for this view.
IPC_MESSAGE_ROUTED1(AwViewMsg_SetBackgroundColor,
SkColor)

IPC_MESSAGE_CONTROL1(AwViewMsg_SetJsOnlineProperty,
bool /* network_up */)

Expand Down
14 changes: 12 additions & 2 deletions android_webview/renderer/aw_render_frame_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ AwRenderFrameExt::AwRenderFrameExt(content::RenderFrame* render_frame)
if (content_capture::features::IsContentCaptureEnabled())
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.
GetFrameExtMap()->emplace(render_frame, this);
}
Expand Down Expand Up @@ -228,7 +234,6 @@ bool AwRenderFrameExt::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AwViewMsg_ResetScrollAndScaleState,
OnResetScrollAndScaleState)
IPC_MESSAGE_HANDLER(AwViewMsg_SetInitialPageScale, OnSetInitialPageScale)
IPC_MESSAGE_HANDLER(AwViewMsg_SetBackgroundColor, OnSetBackgroundColor)
IPC_MESSAGE_HANDLER(AwViewMsg_SmoothScroll, OnSmoothScroll)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
Expand Down Expand Up @@ -329,7 +334,7 @@ void AwRenderFrameExt::OnSetInitialPageScale(double page_scale_factor) {
webview->SetInitialPageScaleOverride(page_scale_factor);
}

void AwRenderFrameExt::OnSetBackgroundColor(SkColor c) {
void AwRenderFrameExt::SetBackgroundColor(SkColor c) {
blink::WebView* webview = GetWebView();
if (!webview)
return;
Expand Down Expand Up @@ -365,4 +370,9 @@ void AwRenderFrameExt::OnDestruct() {
delete this;
}

void AwRenderFrameExt::BindLocalMainFrame(
mojo::PendingAssociatedReceiver<mojom::LocalMainFrame> pending_receiver) {
local_main_frame_receiver_.Bind(std::move(pending_receiver));
}

} // namespace android_webview
16 changes: 13 additions & 3 deletions android_webview/renderer/aw_render_frame_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
#ifndef 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 "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/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/point_f.h"
Expand All @@ -24,7 +27,8 @@ 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 AwRenderFrameExt : public content::RenderFrameObserver {
class AwRenderFrameExt : public content::RenderFrameObserver,
mojom::LocalMainFrame {
public:
explicit AwRenderFrameExt(content::RenderFrame* render_frame);

Expand Down Expand Up @@ -53,16 +57,22 @@ class AwRenderFrameExt : public content::RenderFrameObserver {

void OnSetInitialPageScale(double page_scale_factor);

void OnSetBackgroundColor(SkColor c);

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::WebFrameWidget* GetWebFrameWidget();

url::Origin last_origin_;

blink::AssociatedInterfaceRegistry registry_;
mojo::AssociatedReceiver<mojom::LocalMainFrame> local_main_frame_receiver_{
this};

DISALLOW_COPY_AND_ASSIGN(AwRenderFrameExt);
};
Expand Down

0 comments on commit 046559c

Please sign in to comment.