forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TTS] reland mojo-ify ShowUnhandleTapUIIfNeeded.
Replaces the whole call chain for ShowUnhandledTapUIIfNeeded between Blink and Chrome/WebView with Mojo messaging. Removes the Blink WebTappedInfo class in favor of a new UnhandledTapInfo that sends a Mojo construct of the same name to the Browser which has a service installed via a RenderHostFrame observer. All functionality should remain unchanged. NEW CODE: The CSTabHelper now creates an UnhandledTapWebContentsObserver that connects the Mojo service via UnhandledTapNotifierImpl. That Impl calls back through Java to the CSTabHelper to the CSManager to notify that a Tap has occurred. The CSTabHelper ignores these notifications when CS is disabled. The mojo message is only sent to the browser if the tap is unhandled and the other required conditions are met. UPDATED TESTS: Test notification is now done through mojo messaging, so we now only know if the tap was unhandled, not whether the page changed or other details about why the tap was unhandled. Updated the test page by adding nodes that do not trigger, and removed the mousemove handler since it's unrelated to tap handling. BUG=754862 TBR=dcheng@chromium, yfriedman@chromium.org, kinuko@chromium.org Original CL: Reviewed-on: https://chromium-review.googlesource.com/841544 Reviewed-by: Yoichi Osato <yoichio@chromium.org> Reviewed-by: Theresa <twellington@chromium.org> Reviewed-by: Daniel Cheng <dcheng@chromium.org> Reviewed-by: Yaron Friedman <yfriedman@chromium.org> Reviewed-by: Kinuko Yasuda <kinuko@chromium.org> Change-Id: I824837419cd4116b26b32170009e7a7c3308d109 Reviewed-on: https://chromium-review.googlesource.com/952679 Commit-Queue: Donn Denman <donnd@chromium.org> Cr-Commit-Position: refs/heads/master@{#541569}
- Loading branch information
Donn Denman
authored and
Commit Bot
committed
Mar 7, 2018
1 parent
a7596aa
commit ba4d1c4
Showing
45 changed files
with
513 additions
and
369 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
chrome/browser/android/contextualsearch/unhandled_tap_notifier_impl.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2018 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 "chrome/browser/android/contextualsearch/unhandled_tap_notifier_impl.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/memory/ptr_util.h" | ||
#include "content/public/common/use_zoom_for_dsf_policy.h" | ||
#include "mojo/public/cpp/bindings/strong_binding.h" | ||
|
||
namespace contextual_search { | ||
|
||
UnhandledTapNotifierImpl::UnhandledTapNotifierImpl( | ||
float device_scale_factor, | ||
UnhandledTapCallback callback) | ||
: device_scale_factor_(device_scale_factor), | ||
unhandled_tap_callback_(std::move(callback)) {} | ||
|
||
UnhandledTapNotifierImpl::~UnhandledTapNotifierImpl() {} | ||
|
||
void UnhandledTapNotifierImpl::ShowUnhandledTapUIIfNeeded( | ||
blink::mojom::UnhandledTapInfoPtr unhandled_tap_info) { | ||
float x_px = unhandled_tap_info->tapped_position_in_viewport.x(); | ||
float y_px = unhandled_tap_info->tapped_position_in_viewport.y(); | ||
|
||
if (!content::IsUseZoomForDSFEnabled()) { | ||
x_px /= device_scale_factor_; | ||
y_px /= device_scale_factor_; | ||
} | ||
// Call back through the callback if possible. (The callback uses a weakptr | ||
// that might make this a NOP). | ||
unhandled_tap_callback_.Run(x_px, y_px); | ||
} | ||
|
||
// static | ||
void CreateUnhandledTapNotifierImpl( | ||
float device_scale_factor, | ||
UnhandledTapCallback callback, | ||
blink::mojom::UnhandledTapNotifierRequest request) { | ||
mojo::MakeStrongBinding(std::make_unique<UnhandledTapNotifierImpl>( | ||
device_scale_factor, std::move(callback)), | ||
std::move(request)); | ||
} | ||
|
||
} // namespace contextual_search |
49 changes: 49 additions & 0 deletions
49
chrome/browser/android/contextualsearch/unhandled_tap_notifier_impl.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2018 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 CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_UNHANDLED_TAP_NOTIFIER_IMPL_H_ | ||
#define CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_UNHANDLED_TAP_NOTIFIER_IMPL_H_ | ||
|
||
#include "base/macros.h" | ||
#include "chrome/browser/android/contextualsearch/unhandled_tap_web_contents_observer.h" | ||
#include "third_party/WebKit/public/platform/unhandled_tap_notifier.mojom.h" | ||
|
||
namespace contextual_search { | ||
|
||
// Implements a Mojo service endpoint for the mojo unhandled-tap notifier | ||
// message. | ||
class UnhandledTapNotifierImpl : public blink::mojom::UnhandledTapNotifier { | ||
public: | ||
// Creates an implementation that will scale tap locations by the given | ||
// |scale_factor| (when needed) and call the given |callback| when Mojo | ||
// ShowUnhandledTapUIIfNeeded messages are received for the | ||
// unhandled_tap_notifier service. | ||
UnhandledTapNotifierImpl(float device_scale_factor, | ||
UnhandledTapCallback callback); | ||
|
||
~UnhandledTapNotifierImpl() override; | ||
|
||
// Mojo UnhandledTapNotifier implementation. | ||
void ShowUnhandledTapUIIfNeeded( | ||
blink::mojom::UnhandledTapInfoPtr unhandled_tap_info) override; | ||
|
||
private: | ||
// Scale factor between pixels and DPs. | ||
float device_scale_factor_; | ||
|
||
// Callback to call when an unhandled tap notification takes place. | ||
UnhandledTapCallback unhandled_tap_callback_; | ||
|
||
DISALLOW_COPY_AND_ASSIGN(UnhandledTapNotifierImpl); | ||
}; | ||
|
||
// static | ||
void CreateUnhandledTapNotifierImpl( | ||
float device_scale_factor, | ||
UnhandledTapCallback callback, | ||
blink::mojom::UnhandledTapNotifierRequest request); | ||
|
||
} // namespace contextual_search | ||
|
||
#endif // CHROME_BROWSER_ANDROID_CONTEXTUALSEARCH_UNHANDLED_TAP_NOTIFIER_IMPL_H_ |
42 changes: 42 additions & 0 deletions
42
chrome/browser/android/contextualsearch/unhandled_tap_web_contents_observer.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2018 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 "chrome/browser/android/contextualsearch/unhandled_tap_web_contents_observer.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/memory/ptr_util.h" | ||
#include "build/build_config.h" | ||
#include "third_party/WebKit/public/public_features.h" | ||
|
||
#if BUILDFLAG(ENABLE_UNHANDLED_TAP) | ||
#include "chrome/browser/android/contextualsearch/unhandled_tap_notifier_impl.h" | ||
#endif // BUILDFLAG(ENABLE_UNHANDLED_TAP) | ||
|
||
namespace contextual_search { | ||
|
||
UnhandledTapWebContentsObserver::UnhandledTapWebContentsObserver( | ||
content::WebContents* web_contents, | ||
float device_scale_factor, | ||
UnhandledTapCallback callback) | ||
: content::WebContentsObserver(web_contents) { | ||
#if BUILDFLAG(ENABLE_UNHANDLED_TAP) | ||
registry_.AddInterface( | ||
base::BindRepeating(&contextual_search::CreateUnhandledTapNotifierImpl, | ||
device_scale_factor, std::move(callback))); | ||
#endif // BUILDFLAG(ENABLE_UNHANDLED_TAP) | ||
} | ||
|
||
UnhandledTapWebContentsObserver::~UnhandledTapWebContentsObserver() {} | ||
|
||
void UnhandledTapWebContentsObserver::OnInterfaceRequestFromFrame( | ||
content::RenderFrameHost* render_frame_host, | ||
const std::string& interface_name, | ||
mojo::ScopedMessagePipeHandle* interface_pipe) { | ||
#if BUILDFLAG(ENABLE_UNHANDLED_TAP) | ||
registry_.TryBindInterface(interface_name, interface_pipe); | ||
#endif // BUILDFLAG(ENABLE_UNHANDLED_TAP) | ||
} | ||
|
||
} // namespace contextual_search |
Oops, something went wrong.