Commit 009ecd05 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Chromium LUCI CQ

Convert AwViewHostMsg_UpdateHitTestData to Mojo

This CL migrates AwViewHostMsg_UpdateHitTestData IPC
message to LocalMainFrameHost interface because the
IPC message has been used by 2 functions. So, this CL
adds the message to LocalMainFrameHost interface instead
of handling it as a reply callback.

To support the parameter, this CL moves AwHitTestData
struct and HitTestDataType enum to Mojo.

 - AwHitTestData -> android_webview::mojom::HitTestData
 - Type -> android_webview::mojom::HitTestDataType

Then, all uses of the native struct and enum are replaced
by the Mojo struct and type.

Bug: 1146495
Change-Id: I906e00f1f5f3e18556613b39eedb90bf845b164c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2574560Reviewed-by: default avatarBo <boliu@chromium.org>
Reviewed-by: default avatarNate Fischer <ntfschr@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Commit-Queue: Gyuyoung Kim <gyuyoung@igalia.com>
Cr-Commit-Position: refs/heads/master@{#836303}
parent 41858daf
...@@ -35,9 +35,9 @@ ...@@ -35,9 +35,9 @@
#include "android_webview/browser/permission/simple_permission_request.h" #include "android_webview/browser/permission/simple_permission_request.h"
#include "android_webview/browser/state_serializer.h" #include "android_webview/browser/state_serializer.h"
#include "android_webview/browser_jni_headers/AwContents_jni.h" #include "android_webview/browser_jni_headers/AwContents_jni.h"
#include "android_webview/common/aw_hit_test_data.h"
#include "android_webview/common/aw_switches.h" #include "android_webview/common/aw_switches.h"
#include "android_webview/common/devtools_instrumentation.h" #include "android_webview/common/devtools_instrumentation.h"
#include "android_webview/common/mojom/frame.mojom.h"
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "base/android/jni_array.h" #include "base/android/jni_array.h"
#include "base/android/jni_string.h" #include "base/android/jni_string.h"
...@@ -899,7 +899,8 @@ void AwContents::UpdateLastHitTestData(JNIEnv* env, ...@@ -899,7 +899,8 @@ void AwContents::UpdateLastHitTestData(JNIEnv* env,
if (!render_view_host_ext_->HasNewHitTestData()) if (!render_view_host_ext_->HasNewHitTestData())
return; return;
const AwHitTestData& data = render_view_host_ext_->GetLastHitTestData(); const android_webview::mojom::HitTestData& data =
render_view_host_ext_->GetLastHitTestData();
render_view_host_ext_->MarkHitTestDataRead(); render_view_host_ext_->MarkHitTestDataRead();
// Make sure to null the Java object if data is empty/invalid. // Make sure to null the Java object if data is empty/invalid.
...@@ -920,8 +921,9 @@ void AwContents::UpdateLastHitTestData(JNIEnv* env, ...@@ -920,8 +921,9 @@ void AwContents::UpdateLastHitTestData(JNIEnv* env,
if (data.img_src.is_valid()) if (data.img_src.is_valid())
img_src = ConvertUTF8ToJavaString(env, data.img_src.spec()); img_src = ConvertUTF8ToJavaString(env, data.img_src.spec());
Java_AwContents_updateHitTestData(env, obj, data.type, extra_data_for_type, Java_AwContents_updateHitTestData(env, obj, static_cast<jint>(data.type),
href, anchor_text, img_src); extra_data_for_type, href, anchor_text,
img_src);
} }
void AwContents::OnSizeChanged(JNIEnv* env, void AwContents::OnSizeChanged(JNIEnv* env,
......
...@@ -25,7 +25,8 @@ AwRenderViewHostExt::AwRenderViewHostExt(AwRenderViewHostExtClient* client, ...@@ -25,7 +25,8 @@ AwRenderViewHostExt::AwRenderViewHostExt(AwRenderViewHostExtClient* client,
: content::WebContentsObserver(contents), : content::WebContentsObserver(contents),
client_(client), client_(client),
background_color_(SK_ColorWHITE), background_color_(SK_ColorWHITE),
has_new_hit_test_data_(false) { has_new_hit_test_data_(false),
frame_host_receivers_(contents, this) {
DCHECK(client_); DCHECK(client_);
} }
...@@ -68,9 +69,9 @@ void AwRenderViewHostExt::RequestNewHitTestDataAt( ...@@ -68,9 +69,9 @@ void AwRenderViewHostExt::RequestNewHitTestDataAt(
local_main_frame_remote_->HitTest(touch_center, touch_area); local_main_frame_remote_->HitTest(touch_center, touch_area);
} }
const AwHitTestData& AwRenderViewHostExt::GetLastHitTestData() const { const mojom::HitTestData& AwRenderViewHostExt::GetLastHitTestData() const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return last_hit_test_data_; return *last_hit_test_data_;
} }
void AwRenderViewHostExt::SetTextZoomFactor(float factor) { void AwRenderViewHostExt::SetTextZoomFactor(float factor) {
...@@ -151,8 +152,6 @@ bool AwRenderViewHostExt::OnMessageReceived( ...@@ -151,8 +152,6 @@ bool AwRenderViewHostExt::OnMessageReceived(
bool handled = true; bool handled = true;
IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AwRenderViewHostExt, message, IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(AwRenderViewHostExt, message,
render_frame_host) render_frame_host)
IPC_MESSAGE_HANDLER(AwViewHostMsg_UpdateHitTestData,
OnUpdateHitTestData)
IPC_MESSAGE_HANDLER(AwViewHostMsg_OnContentsSizeChanged, IPC_MESSAGE_HANDLER(AwViewHostMsg_OnContentsSizeChanged,
OnContentsSizeChanged) OnContentsSizeChanged)
IPC_MESSAGE_UNHANDLED(handled = false) IPC_MESSAGE_UNHANDLED(handled = false)
...@@ -161,10 +160,10 @@ bool AwRenderViewHostExt::OnMessageReceived( ...@@ -161,10 +160,10 @@ bool AwRenderViewHostExt::OnMessageReceived(
return handled; return handled;
} }
void AwRenderViewHostExt::OnUpdateHitTestData( void AwRenderViewHostExt::UpdateHitTestData(
content::RenderFrameHost* render_frame_host, mojom::HitTestDataPtr hit_test_data) {
const AwHitTestData& hit_test_data) { content::RenderFrameHost* main_frame_host =
content::RenderFrameHost* main_frame_host = render_frame_host; frame_host_receivers_.GetCurrentTargetFrame();
while (main_frame_host->GetParent()) while (main_frame_host->GetParent())
main_frame_host = main_frame_host->GetParent(); main_frame_host = main_frame_host->GetParent();
...@@ -174,7 +173,7 @@ void AwRenderViewHostExt::OnUpdateHitTestData( ...@@ -174,7 +173,7 @@ void AwRenderViewHostExt::OnUpdateHitTestData(
return; return;
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
last_hit_test_data_ = hit_test_data; last_hit_test_data_ = std::move(hit_test_data);
has_new_hit_test_data_ = true; has_new_hit_test_data_ = true;
} }
......
...@@ -7,12 +7,13 @@ ...@@ -7,12 +7,13 @@
#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/mojom/frame.mojom.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 "content/public/browser/web_contents_receiver_set.h"
#include "mojo/public/cpp/bindings/associated_remote.h" #include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.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"
...@@ -33,7 +34,8 @@ class AwRenderViewHostExtClient { ...@@ -33,7 +34,8 @@ class AwRenderViewHostExtClient {
// Provides RenderViewHost wrapper functionality for sending WebView-specific // Provides RenderViewHost wrapper functionality for sending WebView-specific
// IPC messages to the renderer and from there to WebKit. // IPC messages to the renderer and from there to WebKit.
class AwRenderViewHostExt : public content::WebContentsObserver { class AwRenderViewHostExt : public content::WebContentsObserver,
mojom::FrameHost {
public: public:
// To send receive messages to a RenderView we take the WebContents instance, // To send receive messages to a RenderView we take the WebContents instance,
...@@ -58,7 +60,7 @@ class AwRenderViewHostExt : public content::WebContentsObserver { ...@@ -58,7 +60,7 @@ class AwRenderViewHostExt : public content::WebContentsObserver {
// Return |last_hit_test_data_|. Note that this is unavoidably racy; // Return |last_hit_test_data_|. Note that this is unavoidably racy;
// the corresponding public WebView API is as well. // the corresponding public WebView API is as well.
const AwHitTestData& GetLastHitTestData() const; const mojom::HitTestData& GetLastHitTestData() const;
// Sets the zoom factor for text only. Used in layout modes other than // Sets the zoom factor for text only. Used in layout modes other than
// Text Autosizing. // Text Autosizing.
...@@ -84,8 +86,11 @@ class AwRenderViewHostExt : public content::WebContentsObserver { ...@@ -84,8 +86,11 @@ class AwRenderViewHostExt : public content::WebContentsObserver {
void OnPageScaleFactorChanged(float page_scale_factor) override; void OnPageScaleFactorChanged(float page_scale_factor) override;
bool OnMessageReceived(const IPC::Message& message, bool OnMessageReceived(const IPC::Message& message,
content::RenderFrameHost* render_frame_host) override; content::RenderFrameHost* render_frame_host) override;
void OnUpdateHitTestData(content::RenderFrameHost* render_frame_host,
const AwHitTestData& hit_test_data); // mojom::FrameHost overrides:
void UpdateHitTestData(
android_webview::mojom::HitTestDataPtr hit_test_data) override;
void OnContentsSizeChanged(content::RenderFrameHost* render_frame_host, void OnContentsSizeChanged(content::RenderFrameHost* render_frame_host,
const gfx::Size& contents_size); const gfx::Size& contents_size);
...@@ -98,13 +103,15 @@ class AwRenderViewHostExt : public content::WebContentsObserver { ...@@ -98,13 +103,15 @@ class AwRenderViewHostExt : public content::WebContentsObserver {
// Authoritative copy of hit test data on the browser side. This is updated // Authoritative copy of hit test data on the browser side. This is updated
// as a result of DoHitTest called explicitly or when the FocusedNodeChanged // as a result of DoHitTest called explicitly or when the FocusedNodeChanged
// is called in AwRenderViewExt. // is called in AwRenderViewExt.
AwHitTestData last_hit_test_data_; android_webview::mojom::HitTestDataPtr last_hit_test_data_;
bool has_new_hit_test_data_; bool has_new_hit_test_data_;
// 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;
content::WebContentsFrameReceiverSet<mojom::FrameHost> frame_host_receivers_;
// Associated channel to the webview LocalMainFrame extensions. // Associated channel to the webview LocalMainFrame extensions.
mojo::AssociatedRemote<mojom::LocalMainFrame> local_main_frame_remote_; mojo::AssociatedRemote<mojom::LocalMainFrame> local_main_frame_remote_;
......
...@@ -14,8 +14,6 @@ source_set("common") { ...@@ -14,8 +14,6 @@ source_set("common") {
"aw_descriptors.h", "aw_descriptors.h",
"aw_features.cc", "aw_features.cc",
"aw_features.h", "aw_features.h",
"aw_hit_test_data.cc",
"aw_hit_test_data.h",
"aw_media_drm_bridge_client.cc", "aw_media_drm_bridge_client.cc",
"aw_media_drm_bridge_client.h", "aw_media_drm_bridge_client.h",
"aw_paths.cc", "aw_paths.cc",
...@@ -73,5 +71,6 @@ mojom("mojom") { ...@@ -73,5 +71,6 @@ mojom("mojom") {
"//mojo/public/mojom/base", "//mojo/public/mojom/base",
"//skia/public/mojom", "//skia/public/mojom",
"//ui/gfx/geometry/mojom", "//ui/gfx/geometry/mojom",
"//url/mojom:url_mojom_gurl",
] ]
} }
// Copyright (c) 2012 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.
#include "android_webview/common/aw_hit_test_data.h"
namespace android_webview {
AwHitTestData::AwHitTestData() : type(UNKNOWN_TYPE) {}
AwHitTestData::~AwHitTestData() {}
} // namespace android_webview
// Copyright (c) 2012 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.
#ifndef ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
#define ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
#include "base/strings/string16.h"
#include "url/gurl.h"
namespace android_webview {
// Holdes all hit test data needed by public WebView APIs.
// The Java counter part to this is AwContents.HitTestData.
struct AwHitTestData {
// Matches exactly with constants in WebView.HitTestResult, with deprecated
// values removed.
enum Type {
// Default type where nothing we are interested in is hit.
// |extra_data_for_type| will be empty. All other values should be emtpy
// except the special case described below.
// For special case of invalid or javascript scheme url that would
// otherwise be type an LINK type, |href| will contain the javascript
// string in the href attribute, and |anchor_text| and |img_src| contain
// their normal values for the respective type.
UNKNOWN_TYPE = 0,
// Special case urls for SRC_LINK_TYPE below. Each type corresponds to a
// different prefix in content url_constants. |extra_data_for_type| will
// contain the url but with the prefix removed. |href| will contain the
// exact href attribute string. Other fields are the same as SRC_LINK_TYPE.
PHONE_TYPE = 2,
GEO_TYPE = 3,
EMAIL_TYPE = 4,
// Hit on a pure image (without links). |extra_data_for_type|, |href|,
// and |anchor_text| will be empty. |img_src| will contain the absolute
// source url of the image.
IMAGE_TYPE = 5,
// Hit on a link with valid and non-javascript url and without embedded
// image. |extra_data_for_type| and |href| will be the valid absolute url
// of the link. |anchor_text| will contain the anchor text if the link is
// an anchor tag. |img_src| will be empty.
// Note 1: If the link url is invalid or javascript scheme, then the type
// will be UNKNOWN_TYPE.
// Note 2: Note that this matches SRC_ANCHOR_TYPE in the public WebView
// Java API, but the actual tag can be something other than <a>, such as
// <link> or <area>.
// Note 3: |href| is not the raw attribute string, but the absolute link
// url.
SRC_LINK_TYPE = 7,
// Same as SRC_LINK_TYPE except the link contains an image. |img_src| and
// |extra_data_for_type| will contain the absolute valid url of the image
// source. |href| will be the valid absolute url of the link. |anchor_text|
// will be empty. All notes from SRC_LINK_TYPE apply.
SRC_IMAGE_LINK_TYPE = 8,
// Hit on an editable text input element. All other values will be empty.
EDIT_TEXT_TYPE = 9,
};
// For all strings/GURLs, empty/invalid will become null upon conversion to
// Java.
int type; // Only values from enum Type above.
std::string extra_data_for_type;
base::string16 href;
base::string16 anchor_text;
GURL img_src;
AwHitTestData();
~AwHitTestData();
};
} // namespace android_webview
#endif // ANDROID_WEBVIEW_COMMON_AW_HIT_TEST_DATA_H_
...@@ -4,8 +4,75 @@ ...@@ -4,8 +4,75 @@
module android_webview.mojom; module android_webview.mojom;
import "mojo/public/mojom/base/string16.mojom";
import "skia/public/mojom/skcolor.mojom"; import "skia/public/mojom/skcolor.mojom";
import "ui/gfx/geometry/mojom/geometry.mojom"; import "ui/gfx/geometry/mojom/geometry.mojom";
import "url/mojom/url.mojom";
enum HitTestDataType{
// Default type where nothing we are interested in is hit.
// |extra_data_for_type| will be empty. All other values should be emtpy
// except the special case described below.
// For special case of invalid or javascript scheme url that would
// otherwise be type an LINK type, |href| will contain the javascript
// string in the href attribute, and |anchor_text| and |img_src| contain
// their normal values for the respective type.
kUnknown = 0,
// Special case urls for kSrcLink below. Each type corresponds to a
// different prefix in content url_constants. |extra_data_for_type| will
// contain the url but with the prefix removed. |href| will contain the
// exact href attribute string. Other fields are the same as kSrcLink.
kPhone = 2,
kGeo = 3,
kEmail = 4,
// Hit on a pure image (without links). |extra_data_for_type|, |href|,
// and |anchor_text| will be empty. |img_src| will contain the absolute
// source url of the image.
kImage = 5,
// Hit on a link with valid and non-javascript url and without embedded
// image. |extra_data_for_type| and |href| will be the valid absolute url
// of the link. |anchor_text| will contain the anchor text if the link is
// an anchor tag. |img_src| will be empty.
// Note 1: If the link url is invalid or javascript scheme, then the type
// will be UNKNOWN_TYPE.
// Note 2: Note that this matches SRC_ANCHOR_TYPE in the public WebView
// Java API, but the actual tag can be something other than <a>, such as
// <link> or <area>.
// Note 3: |href| is not the raw attribute string, but the absolute link
// url.
kSrcLink = 7,
// Same as kSrcLink except the link contains an image. |img_src| and
// |extra_data_for_type| will contain the absolute valid url of the image
// source. |href| will be the valid absolute url of the link. |anchor_text|
// will be empty. All notes from kSrcLink apply.
kSrcImageLink = 8,
// Hit on an editable text input element. All other values will be empty.
kEditText = 9,
};
// Holds all hit test data needed by public WebView APIs.
// The Java counter part to this is AwContents.HitTestData.
struct HitTestData {
// The type of the hit test.
HitTestDataType type;
// The extra type of the hit test.
string extra_data_for_type;
// The valid absolute url of the link.
mojo_base.mojom.String16 href;
// The anchor text of the link
mojo_base.mojom.String16 anchor_text;
// The valid absolute url of the image source.
url.mojom.Url img_src;
};
// Similar to blink::mojom::LocalMainFrame. This interface adds additional // Similar to blink::mojom::LocalMainFrame. This interface adds additional
// things that webview needs from the main frame. // things that webview needs from the main frame.
...@@ -19,11 +86,18 @@ interface LocalMainFrame { ...@@ -19,11 +86,18 @@ interface LocalMainFrame {
// view (ie 0,0 is not the top left of the page if the page is scrolled). // view (ie 0,0 is not the top left of the page if the page is scrolled).
// AwRenderViewHostExt::OnUpdateHitTestData receives the result of the hit // AwRenderViewHostExt::OnUpdateHitTestData receives the result of the hit
// test via AwViewHostMsg_UpdateHitTestData IPC message. // test via AwViewHostMsg_UpdateHitTestData IPC message.
// TODO(crbug.com/1146495): AwViewHostMsg_UpdateHitTestData IPC message should
// be converted to LocalMainFrameHost interface.
HitTest(gfx.mojom.PointF touch_center, gfx.mojom.SizeF touch_area); HitTest(gfx.mojom.PointF touch_center, gfx.mojom.SizeF touch_area);
// Requests for the renderer to determine if the document contains any image // Requests for the renderer to determine if the document contains any image
// elements. // elements.
DocumentHasImage() => (bool has_images); DocumentHasImage() => (bool has_images);
}; };
// Similar to blink::mojom::FrameHost. Implemented in Browser, this
// interface defines frame-specific methods that will be invoked from the
// renderer process (e.g. AwRenderFrameExt).
interface FrameHost {
// Response to AwViewMsg_DoHitTest.
UpdateHitTestData(HitTestData data);
};
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
// no-include-guard-because-multiply-included // no-include-guard-because-multiply-included
#include "android_webview/common/aw_hit_test_data.h"
#include "content/public/common/common_param_traits.h" #include "content/public/common/common_param_traits.h"
#include "ipc/ipc_channel_handle.h" #include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_macros.h"
...@@ -15,14 +14,6 @@ ...@@ -15,14 +14,6 @@
#include "ui/gfx/ipc/geometry/gfx_param_traits.h" #include "ui/gfx/ipc/geometry/gfx_param_traits.h"
#include "ui/gfx/ipc/skia/gfx_skia_param_traits.h" #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h"
IPC_STRUCT_TRAITS_BEGIN(android_webview::AwHitTestData)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(extra_data_for_type)
IPC_STRUCT_TRAITS_MEMBER(href)
IPC_STRUCT_TRAITS_MEMBER(anchor_text)
IPC_STRUCT_TRAITS_MEMBER(img_src)
IPC_STRUCT_TRAITS_END()
#define IPC_MESSAGE_START AndroidWebViewMsgStart #define IPC_MESSAGE_START AndroidWebViewMsgStart
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
...@@ -54,10 +45,6 @@ IPC_MESSAGE_ROUTED3(AwViewMsg_SmoothScroll, ...@@ -54,10 +45,6 @@ IPC_MESSAGE_ROUTED3(AwViewMsg_SmoothScroll,
// RenderView messages // RenderView messages
// These are messages sent from the renderer to the browser process. // These are messages sent from the renderer to the browser process.
// Response to AwViewMsg_DoHitTest.
IPC_MESSAGE_ROUTED1(AwViewHostMsg_UpdateHitTestData,
android_webview::AwHitTestData)
// Sent whenever the contents size (as seen by RenderView) is changed. // Sent whenever the contents size (as seen by RenderView) is changed.
IPC_MESSAGE_ROUTED1(AwViewHostMsg_OnContentsSizeChanged, IPC_MESSAGE_ROUTED1(AwViewHostMsg_OnContentsSizeChanged,
gfx::Size /* contents_size */) gfx::Size /* contents_size */)
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include "android_webview/common/aw_hit_test_data.h" #include "android_webview/common/mojom/frame.mojom.h"
#include "android_webview/common/render_view_messages.h" #include "android_webview/common/render_view_messages.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/content_capture/renderer/content_capture_sender.h" #include "components/content_capture/renderer/content_capture_sender.h"
#include "content/public/renderer/render_frame.h" #include "content/public/renderer/render_frame.h"
#include "content/public/renderer/render_view.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/platform/web_security_origin.h" #include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/platform/web_size.h" #include "third_party/blink/public/platform/web_size.h"
#include "third_party/blink/public/web/web_element.h" #include "third_party/blink/public/web/web_element.h"
...@@ -92,18 +93,19 @@ bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix, ...@@ -92,18 +93,19 @@ bool RemovePrefixAndAssignIfMatches(const base::StringPiece& prefix,
return false; return false;
} }
void DistinguishAndAssignSrcLinkType(const GURL& url, AwHitTestData* data) { void DistinguishAndAssignSrcLinkType(const GURL& url,
mojom::HitTestData* data) {
if (RemovePrefixAndAssignIfMatches(kAddressPrefix, url, if (RemovePrefixAndAssignIfMatches(kAddressPrefix, url,
&data->extra_data_for_type)) { &data->extra_data_for_type)) {
data->type = AwHitTestData::GEO_TYPE; data->type = mojom::HitTestDataType::kGeo;
} else if (RemovePrefixAndAssignIfMatches(kPhoneNumberPrefix, url, } else if (RemovePrefixAndAssignIfMatches(kPhoneNumberPrefix, url,
&data->extra_data_for_type)) { &data->extra_data_for_type)) {
data->type = AwHitTestData::PHONE_TYPE; data->type = mojom::HitTestDataType::kPhone;
} else if (RemovePrefixAndAssignIfMatches(kEmailPrefix, url, } else if (RemovePrefixAndAssignIfMatches(kEmailPrefix, url,
&data->extra_data_for_type)) { &data->extra_data_for_type)) {
data->type = AwHitTestData::EMAIL_TYPE; data->type = mojom::HitTestDataType::kEmail;
} else { } else {
data->type = AwHitTestData::SRC_LINK_TYPE; data->type = mojom::HitTestDataType::kSrcLink;
data->extra_data_for_type = url.possibly_invalid_spec(); data->extra_data_for_type = url.possibly_invalid_spec();
if (!data->extra_data_for_type.empty()) if (!data->extra_data_for_type.empty())
data->href = base::UTF8ToUTF16(data->extra_data_for_type); data->href = base::UTF8ToUTF16(data->extra_data_for_type);
...@@ -113,7 +115,7 @@ void DistinguishAndAssignSrcLinkType(const GURL& url, AwHitTestData* data) { ...@@ -113,7 +115,7 @@ void DistinguishAndAssignSrcLinkType(const GURL& url, AwHitTestData* data) {
void PopulateHitTestData(const GURL& absolute_link_url, void PopulateHitTestData(const GURL& absolute_link_url,
const GURL& absolute_image_url, const GURL& absolute_image_url,
bool is_editable, bool is_editable,
AwHitTestData* data) { mojom::HitTestData* data) {
// Note: Using GURL::is_empty instead of GURL:is_valid due to the // Note: Using GURL::is_empty instead of GURL:is_valid due to the
// WebViewClassic allowing any kind of protocol which GURL::is_valid // WebViewClassic allowing any kind of protocol which GURL::is_valid
// disallows. Similar reasons for using GURL::possibly_invalid_spec instead of // disallows. Similar reasons for using GURL::possibly_invalid_spec instead of
...@@ -129,15 +131,15 @@ void PopulateHitTestData(const GURL& absolute_link_url, ...@@ -129,15 +131,15 @@ void PopulateHitTestData(const GURL& absolute_link_url,
if (has_link_url && !has_image_url && !is_javascript_scheme) { if (has_link_url && !has_image_url && !is_javascript_scheme) {
DistinguishAndAssignSrcLinkType(absolute_link_url, data); DistinguishAndAssignSrcLinkType(absolute_link_url, data);
} else if (has_link_url && has_image_url && !is_javascript_scheme) { } else if (has_link_url && has_image_url && !is_javascript_scheme) {
data->type = AwHitTestData::SRC_IMAGE_LINK_TYPE; data->type = mojom::HitTestDataType::kSrcImageLink;
data->extra_data_for_type = data->img_src.possibly_invalid_spec(); data->extra_data_for_type = data->img_src.possibly_invalid_spec();
if (absolute_link_url.is_valid()) if (absolute_link_url.is_valid())
data->href = base::UTF8ToUTF16(absolute_link_url.possibly_invalid_spec()); data->href = base::UTF8ToUTF16(absolute_link_url.possibly_invalid_spec());
} else if (!has_link_url && has_image_url) { } else if (!has_link_url && has_image_url) {
data->type = AwHitTestData::IMAGE_TYPE; data->type = mojom::HitTestDataType::kImage;
data->extra_data_for_type = data->img_src.possibly_invalid_spec(); data->extra_data_for_type = data->img_src.possibly_invalid_spec();
} else if (is_editable) { } else if (is_editable) {
data->type = AwHitTestData::EDIT_TEXT_TYPE; data->type = mojom::HitTestDataType::kEditText;
DCHECK_EQ(0u, data->extra_data_for_type.length()); DCHECK_EQ(0u, data->extra_data_for_type.length());
} }
} }
...@@ -200,6 +202,16 @@ AwRenderFrameExt* AwRenderFrameExt::FromRenderFrame( ...@@ -200,6 +202,16 @@ AwRenderFrameExt* AwRenderFrameExt::FromRenderFrame(
return render_frame_ext; return render_frame_ext;
} }
const mojo::AssociatedRemote<mojom::FrameHost>&
AwRenderFrameExt::GetFrameHost() {
if (!frame_host_remote_) {
render_frame()->GetRemoteAssociatedInterfaces()->GetInterface(
&frame_host_remote_);
}
return frame_host_remote_;
}
bool AwRenderFrameExt::OnAssociatedInterfaceRequestForFrame( bool AwRenderFrameExt::OnAssociatedInterfaceRequestForFrame(
const std::string& interface_name, const std::string& interface_name,
mojo::ScopedInterfaceEndpointHandle* handle) { mojo::ScopedInterfaceEndpointHandle* handle) {
...@@ -242,20 +254,21 @@ void AwRenderFrameExt::FocusedElementChanged(const blink::WebElement& element) { ...@@ -242,20 +254,21 @@ void AwRenderFrameExt::FocusedElementChanged(const blink::WebElement& element) {
if (element.IsNull() || !render_frame() || !render_frame()->GetRenderView()) if (element.IsNull() || !render_frame() || !render_frame()->GetRenderView())
return; return;
AwHitTestData data; auto data = mojom::HitTestData::New();
data.href = GetHref(element); data->href = GetHref(element);
data.anchor_text = element.TextContent().Utf16(); data->anchor_text = element.TextContent().Utf16();
GURL absolute_link_url; GURL absolute_link_url;
if (element.IsLink()) if (element.IsLink())
absolute_link_url = GetAbsoluteUrl(element, data.href); absolute_link_url = GetAbsoluteUrl(element, data->href);
GURL absolute_image_url = GetChildImageUrlFromElement(element); GURL absolute_image_url = GetChildImageUrlFromElement(element);
PopulateHitTestData(absolute_link_url, absolute_image_url, PopulateHitTestData(absolute_link_url, absolute_image_url,
element.IsEditable(), &data); element.IsEditable(), data.get());
Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data));
GetFrameHost()->UpdateHitTestData(std::move(data));
} }
// Only main frame needs to *receive* the hit test request, because all we need // Only main frame needs to *receive* the hit test request, because all we need
...@@ -270,12 +283,12 @@ void AwRenderFrameExt::HitTest(const gfx::PointF& touch_center, ...@@ -270,12 +283,12 @@ void AwRenderFrameExt::HitTest(const gfx::PointF& touch_center,
const blink::WebHitTestResult result = webview->HitTestResultForTap( const blink::WebHitTestResult result = webview->HitTestResultForTap(
gfx::Point(touch_center.x(), touch_center.y()), gfx::Point(touch_center.x(), touch_center.y()),
blink::WebSize(touch_area.width(), touch_area.height())); blink::WebSize(touch_area.width(), touch_area.height()));
AwHitTestData data; auto data = mojom::HitTestData::New();
GURL absolute_image_url = result.AbsoluteImageURL(); GURL absolute_image_url = result.AbsoluteImageURL();
if (!result.UrlElement().IsNull()) { if (!result.UrlElement().IsNull()) {
data.anchor_text = result.UrlElement().TextContent().Utf16(); data->anchor_text = result.UrlElement().TextContent().Utf16();
data.href = GetHref(result.UrlElement()); data->href = GetHref(result.UrlElement());
// If we hit an image that failed to load, Blink won't give us its URL. // If we hit an image that failed to load, Blink won't give us its URL.
// Fall back to walking the DOM in this case. // Fall back to walking the DOM in this case.
if (absolute_image_url.is_empty()) if (absolute_image_url.is_empty())
...@@ -283,8 +296,9 @@ void AwRenderFrameExt::HitTest(const gfx::PointF& touch_center, ...@@ -283,8 +296,9 @@ void AwRenderFrameExt::HitTest(const gfx::PointF& touch_center,
} }
PopulateHitTestData(result.AbsoluteLinkURL(), absolute_image_url, PopulateHitTestData(result.AbsoluteLinkURL(), absolute_image_url,
result.IsContentEditable(), &data); result.IsContentEditable(), data.get());
Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data));
GetFrameHost()->UpdateHitTestData(std::move(data));
} }
void AwRenderFrameExt::OnSetTextZoomFactor(float zoom_factor) { void AwRenderFrameExt::OnSetTextZoomFactor(float zoom_factor) {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#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/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_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"
...@@ -64,6 +65,8 @@ class AwRenderFrameExt : public content::RenderFrameObserver, ...@@ -64,6 +65,8 @@ class AwRenderFrameExt : public content::RenderFrameObserver,
void BindLocalMainFrame( void BindLocalMainFrame(
mojo::PendingAssociatedReceiver<mojom::LocalMainFrame> pending_receiver); mojo::PendingAssociatedReceiver<mojom::LocalMainFrame> pending_receiver);
const mojo::AssociatedRemote<mojom::FrameHost>& GetFrameHost();
blink::WebView* GetWebView(); blink::WebView* GetWebView();
blink::WebFrameWidget* GetWebFrameWidget(); blink::WebFrameWidget* GetWebFrameWidget();
...@@ -73,6 +76,8 @@ class AwRenderFrameExt : public content::RenderFrameObserver, ...@@ -73,6 +76,8 @@ class AwRenderFrameExt : public content::RenderFrameObserver,
mojo::AssociatedReceiver<mojom::LocalMainFrame> local_main_frame_receiver_{ mojo::AssociatedReceiver<mojom::LocalMainFrame> local_main_frame_receiver_{
this}; this};
mojo::AssociatedRemote<mojom::FrameHost> frame_host_remote_;
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