Skip to content

Commit

Permalink
Convert FrameMsg_ExtractSmartClipData to Mojo
Browse files Browse the repository at this point in the history
Convert and merge FrameHostMsg_SmartClipDataExtracted now using Mojo
callback directly.

Bug: 786836
Change-Id: If2925e9e019854558f8c97cf51e6b0d32b521345
Reviewed-on: https://chromium-review.googlesource.com/804804
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Reviewed-by: Will Harris <wfh@chromium.org>
Reviewed-by: Sam McNally <sammc@chromium.org>
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524017}
  • Loading branch information
Luciano Pacheco authored and Commit Bot committed Dec 14, 2017
1 parent 29334cc commit 8528c16
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 52 deletions.
49 changes: 26 additions & 23 deletions content/browser/frame_host/render_frame_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,6 @@ bool RenderFrameHostImpl::OnMessageReceived(const IPC::Message &msg) {
OnJavaScriptExecuteResponse)
IPC_MESSAGE_HANDLER(FrameHostMsg_VisualStateResponse,
OnVisualStateResponse)
IPC_MESSAGE_HANDLER(FrameHostMsg_SmartClipDataExtracted,
OnSmartClipDataExtracted)
IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunJavaScriptDialog,
OnRunJavaScriptDialog)
IPC_MESSAGE_HANDLER_DELAY_REPLY(FrameHostMsg_RunBeforeUnloadConfirm,
Expand Down Expand Up @@ -1935,11 +1933,17 @@ void RenderFrameHostImpl::OnRenderProcessGone(int status, int exit_code) {
for (const auto& iter : ax_tree_snapshot_callbacks_)
iter.second.Run(ui::AXTreeUpdate());

for (const auto& iter : smart_clip_callbacks_)
iter.second.Run(base::string16(), base::string16());
#if defined(OS_ANDROID)
// Execute any pending Samsung smart clip callbacks.
for (base::IDMap<std::unique_ptr<ExtractSmartClipDataCallback>>::iterator
iter(&smart_clip_callbacks_);
!iter.IsAtEnd(); iter.Advance()) {
std::move(*iter.GetCurrentValue()).Run(base::string16(), base::string16());
}
smart_clip_callbacks_.Clear();
#endif // defined(OS_ANDROID)

ax_tree_snapshot_callbacks_.clear();
smart_clip_callbacks_.clear();
javascript_callbacks_.clear();
visual_state_callbacks_.clear();

Expand Down Expand Up @@ -2046,25 +2050,24 @@ void RenderFrameHostImpl::OnJavaScriptExecuteResponse(
}
}

void RenderFrameHostImpl::RequestSmartClipExtract(SmartClipCallback callback,
gfx::Rect rect) {
static uint32_t next_id = 1;
uint32_t key = next_id++;
Send(new FrameMsg_ExtractSmartClipData(routing_id_, key, rect));
smart_clip_callbacks_.insert(std::make_pair(key, callback));
}

void RenderFrameHostImpl::OnSmartClipDataExtracted(uint32_t id,
base::string16 text,
base::string16 html) {
auto it = smart_clip_callbacks_.find(id);
if (it != smart_clip_callbacks_.end()) {
it->second.Run(text, html);
smart_clip_callbacks_.erase(it);
} else {
NOTREACHED() << "Received smartclip data response for unknown request";
}
#if defined(OS_ANDROID)
void RenderFrameHostImpl::RequestSmartClipExtract(
ExtractSmartClipDataCallback callback,
gfx::Rect rect) {
int32_t callback_id = smart_clip_callbacks_.Add(
std::make_unique<ExtractSmartClipDataCallback>(std::move(callback)));
frame_->ExtractSmartClipData(
rect, base::BindOnce(&RenderFrameHostImpl::OnSmartClipDataExtracted,
base::Unretained(this), callback_id));
}

void RenderFrameHostImpl::OnSmartClipDataExtracted(int32_t callback_id,
const base::string16& text,
const base::string16& html) {
std::move(*smart_clip_callbacks_.Lookup(callback_id)).Run(text, html);
smart_clip_callbacks_.Remove(callback_id);
}
#endif // defined(OS_ANDROID)

void RenderFrameHostImpl::OnVisualStateResponse(uint64_t id) {
auto it = visual_state_callbacks_.find(id);
Expand Down
23 changes: 16 additions & 7 deletions content/browser/frame_host/render_frame_host_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/containers/id_map.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
Expand Down Expand Up @@ -146,8 +147,6 @@ class CONTENT_EXPORT RenderFrameHostImpl
using AXTreeSnapshotCallback =
base::Callback<void(
const ui::AXTreeUpdate&)>;
using SmartClipCallback = base::Callback<void(const base::string16& text,
const base::string16& html)>;

// An accessibility reset is only allowed to prevent very rare corner cases
// or race conditions where the browser and renderer get out of sync. If
Expand Down Expand Up @@ -502,8 +501,18 @@ class CONTENT_EXPORT RenderFrameHostImpl
// renderer process to change the accessibility mode.
void UpdateAccessibilityMode();

#if defined(OS_ANDROID)
// Samsung Galaxy Note-specific "smart clip" stylus text getter.
void RequestSmartClipExtract(SmartClipCallback callback, gfx::Rect rect);
using ExtractSmartClipDataCallback =
base::OnceCallback<void(const base::string16&, const base::string16&)>;

void RequestSmartClipExtract(ExtractSmartClipDataCallback callback,
gfx::Rect rect);

void OnSmartClipDataExtracted(int32_t callback_id,
const base::string16& text,
const base::string16& html);
#endif // defined(OS_ANDROID)

// Request a one-time snapshot of the accessibility tree without changing
// the accessibility mode.
Expand Down Expand Up @@ -832,9 +841,6 @@ class CONTENT_EXPORT RenderFrameHostImpl
void OnAccessibilitySnapshotResponse(
int callback_id,
const AXContentTreeUpdate& snapshot);
void OnSmartClipDataExtracted(uint32_t id,
base::string16 text,
base::string16 html);
void OnToggleFullscreen(bool enter_fullscreen);
void OnSuddenTerminationDisablerChanged(
bool present,
Expand Down Expand Up @@ -1250,7 +1256,10 @@ class CONTENT_EXPORT RenderFrameHostImpl
std::map<int, AXTreeSnapshotCallback> ax_tree_snapshot_callbacks_;

// Samsung Galaxy Note-specific "smart clip" stylus text getter.
std::map<uint32_t, SmartClipCallback> smart_clip_callbacks_;
#if defined(OS_ANDROID)
base::IDMap<std::unique_ptr<ExtractSmartClipDataCallback>>
smart_clip_callbacks_;
#endif // defined(OS_ANDROID)

// Callback when an event is received, for testing.
base::Callback<void(RenderFrameHostImpl*, ui::AXEvent, int)>
Expand Down
9 changes: 5 additions & 4 deletions content/browser/web_contents/web_contents_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "content/browser/web_contents/web_contents_android.h"

#include <stdint.h>
#include <string>
#include <vector>

#include "base/android/jni_android.h"
#include "base/android/jni_array.h"
Expand All @@ -27,6 +29,7 @@
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/browser/web_contents/web_contents_view_android.h"
#include "content/common/devtools_messages.h"
#include "content/common/frame.mojom.h"
#include "content/common/frame_messages.h"
#include "content/common/input_messages.h"
#include "content/common/view_messages.h"
Expand Down Expand Up @@ -558,11 +561,9 @@ void WebContentsAndroid::RequestSmartClipExtract(
ScopedJavaGlobalRef<jobject> j_callback;
j_callback.Reset(env, callback);

RenderFrameHostImpl::SmartClipCallback smart_clip_callback =
base::Bind(&SmartClipCallback, j_callback);

web_contents_->GetMainFrame()->RequestSmartClipExtract(
smart_clip_callback, gfx::Rect(x, y, width, height));
base::BindOnce(&SmartClipCallback, j_callback),
gfx::Rect(x, y, width, height));
}

void WebContentsAndroid::RequestAccessibilitySnapshot(
Expand Down
8 changes: 8 additions & 0 deletions content/common/frame.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import "content/public/common/resource_type.mojom";
import "content/public/common/url_loader.mojom";
import "content/public/common/window_container_type.mojom";
import "mojo/common/unguessable_token.mojom";
import "mojo/common/string16.mojom";
import "services/service_manager/public/interfaces/interface_provider.mojom";
import "third_party/WebKit/common/feature_policy/feature_policy.mojom";
import "third_party/WebKit/public/platform/referrer.mojom";
import "third_party/WebKit/public/web/window_features.mojom";
import "ui/base/mojo/window_open_disposition.mojom";
import "url/mojo/url.mojom";
import "ui/gfx/geometry/mojo/geometry.mojom";

// The name of the InterfaceProviderSpec in service manifests used by the
// frame tree to expose frame-specific interfaces between renderer and browser.
Expand All @@ -25,6 +27,12 @@ const string kNavigation_FrameSpec = "navigation:frame";
interface Frame {
GetInterfaceProvider(service_manager.mojom.InterfaceProvider& interfaces);
GetCanonicalUrlForSharing() => (url.mojom.Url? canonical_url);

// Samsung Galaxy Note-specific "smart clip" stylus text getter.
// Extracts the data at the given rect.
// TODO(crbug.com/676224): Only enable for OS_ANDROID.
ExtractSmartClipData(gfx.mojom.Rect rect)
=> (mojo.common.mojom.String16 text, mojo.common.mojom.String16 html);
};

// See src/content/common/navigation_params.h
Expand Down
12 changes: 0 additions & 12 deletions content/common/frame_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,12 +834,6 @@ IPC_MESSAGE_ROUTED0(FrameMsg_DeleteProxy)
IPC_MESSAGE_ROUTED1(FrameMsg_TextSurroundingSelectionRequest,
uint32_t /* max_length */)

// Extracts the data at the given rect, returning it through the
// SmartClipDataExtracted IPC.
IPC_MESSAGE_ROUTED2(FrameMsg_ExtractSmartClipData,
uint32_t /* id */,
gfx::Rect /* rect */)

// Change the accessibility mode in the renderer process.
IPC_MESSAGE_ROUTED1(FrameMsg_SetAccessibilityMode, ui::AXMode)

Expand Down Expand Up @@ -1554,12 +1548,6 @@ IPC_MESSAGE_ROUTED0(FrameHostMsg_AbortNavigation)
// The message is delivered using RenderWidget::QueueMessage.
IPC_MESSAGE_ROUTED1(FrameHostMsg_VisualStateResponse, uint64_t /* id */)

// Reply to the ExtractSmartClipData message.
IPC_MESSAGE_ROUTED3(FrameHostMsg_SmartClipDataExtracted,
uint32_t /* id */,
base::string16 /* text */,
base::string16 /* html */)

// Puts the browser into "tab fullscreen" mode for the sending renderer.
// See the comment in chrome/browser/ui/browser.h for more details.
IPC_MESSAGE_ROUTED1(FrameHostMsg_ToggleFullscreen, bool /* enter_fullscreen */)
Expand Down
11 changes: 6 additions & 5 deletions content/renderer/render_frame_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,6 @@ bool RenderFrameImpl::OnMessageReceived(const IPC::Message& msg) {
OnSetAccessibilityMode)
IPC_MESSAGE_HANDLER(AccessibilityMsg_SnapshotTree,
OnSnapshotAccessibilityTree)
IPC_MESSAGE_HANDLER(FrameMsg_ExtractSmartClipData, OnExtractSmartClipData)
IPC_MESSAGE_HANDLER(FrameMsg_UpdateOpener, OnUpdateOpener)
IPC_MESSAGE_HANDLER(FrameMsg_DidUpdateFramePolicy, OnDidUpdateFramePolicy)
IPC_MESSAGE_HANDLER(FrameMsg_SetFrameOwnerProperties,
Expand Down Expand Up @@ -2407,13 +2406,15 @@ void RenderFrameImpl::OnSnapshotAccessibilityTree(int callback_id) {
routing_id_, callback_id, response));
}

void RenderFrameImpl::OnExtractSmartClipData(uint32_t id,
const gfx::Rect& rect) {
void RenderFrameImpl::ExtractSmartClipData(
const gfx::Rect& rect,
ExtractSmartClipDataCallback callback) {
#if defined(OS_ANDROID)
blink::WebString clip_text;
blink::WebString clip_html;
GetWebFrame()->ExtractSmartClipData(rect, clip_text, clip_html);
Send(new FrameHostMsg_SmartClipDataExtracted(
routing_id_, id, clip_text.Utf16(), clip_html.Utf16()));
std::move(callback).Run(clip_text.Utf16(), clip_html.Utf16());
#endif // defined(OS_ANDROID)
}

void RenderFrameImpl::OnUpdateOpener(int opener_routing_id) {
Expand Down
4 changes: 3 additions & 1 deletion content/renderer/render_frame_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@ class CONTENT_EXPORT RenderFrameImpl
service_manager::mojom::InterfaceProviderRequest request) override;
void GetCanonicalUrlForSharing(
GetCanonicalUrlForSharingCallback callback) override;
void ExtractSmartClipData(
const gfx::Rect& rect,
const ExtractSmartClipDataCallback callback) override;

// mojom::FrameBindingsControl implementation:
void AllowBindings(int32_t enabled_bindings_flags) override;
Expand Down Expand Up @@ -1028,7 +1031,6 @@ class CONTENT_EXPORT RenderFrameImpl
void OnTextSurroundingSelectionRequest(uint32_t max_length);
void OnSetAccessibilityMode(ui::AXMode new_mode);
void OnSnapshotAccessibilityTree(int callback_id);
void OnExtractSmartClipData(uint32_t callback_id, const gfx::Rect& rect);
void OnUpdateOpener(int opener_routing_id);
void OnDidUpdateFramePolicy(const blink::FramePolicy& frame_policy);
void OnSetFrameOwnerProperties(
Expand Down

0 comments on commit 8528c16

Please sign in to comment.