0

Convert WebContentsNSView and WebContentsNSViewHost to new Mojo types

This CL converts WebContentsNSViewHost and WebContentsNSViewHost
from web_contents_ns_view_bridge.mojom to new Mojo types using
PendingAssociatedRemote, PendingAssociatedReceiver,
AssociatedReceiver,  and AssociatedRemote.

Bug: 955171
Change-Id: Ib6770e5030ee68c9882f7f5f2d3654e6cda79d1d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872215
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Ken Rockot <rockot@google.com>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#708876}
This commit is contained in:
Julie Jeongeun Kim
2019-10-24 01:31:34 +00:00
committed by Commit Bot
parent 4a20ea3df8
commit 98d7086a6a
5 changed files with 36 additions and 29 deletions

@ -17,9 +17,11 @@
#include "content/common/render_widget_host_ns_view.mojom.h"
#include "content/common/web_contents_ns_view_bridge.mojom.h"
#include "content/public/browser/native_web_keyboard_event.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_remote.h"
#include "mojo/public/cpp/bindings/strong_associated_binding.h"
#include "mojo/public/cpp/bindings/self_owned_associated_receiver.h"
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#include "ui/base/cocoa/remote_accessibility_api.h"
#include "ui/events/cocoa/cocoa_event_utils.h"
@ -153,17 +155,15 @@ void CreateWebContentsNSView(
uint64_t view_id,
mojo::ScopedInterfaceEndpointHandle host_handle,
mojo::ScopedInterfaceEndpointHandle view_request_handle) {
mojom::WebContentsNSViewHostAssociatedPtr host(
mojo::AssociatedInterfacePtrInfo<mojom::WebContentsNSViewHost>(
std::move(host_handle), 0));
mojom::WebContentsNSViewAssociatedRequest ns_view_request(
mojo::PendingAssociatedRemote<mojom::WebContentsNSViewHost> host(
std::move(host_handle), 0);
mojo::PendingAssociatedReceiver<mojom::WebContentsNSView> ns_view_receiver(
std::move(view_request_handle));
// Note that the resulting object will be destroyed when its underlying pipe
// is closed.
mojo::MakeStrongAssociatedBinding(
std::make_unique<WebContentsNSViewBridge>(
view_id, mojom::WebContentsNSViewHostAssociatedPtr(std::move(host))),
std::move(ns_view_request),
mojo::MakeSelfOwnedAssociatedReceiver(
std::make_unique<WebContentsNSViewBridge>(view_id, std::move(host)),
std::move(ns_view_receiver),
ui::WindowResizeHelperMac::Get()->task_runner());
}

@ -14,6 +14,8 @@
#include "components/remote_cocoa/app_shim/ns_view_ids.h"
#include "content/common/content_export.h"
#include "content/common/web_contents_ns_view_bridge.mojom.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
@class WebContentsViewCocoa;
@ -29,8 +31,9 @@ class CONTENT_EXPORT WebContentsNSViewBridge : public mojom::WebContentsNSView {
public:
// Create a bridge that will access its client in another process via a mojo
// interface.
WebContentsNSViewBridge(uint64_t view_id,
mojom::WebContentsNSViewHostAssociatedPtr client);
WebContentsNSViewBridge(
uint64_t view_id,
mojo::PendingAssociatedRemote<mojom::WebContentsNSViewHost> client);
// Create a bridge that will access its client directly in-process.
// TODO(ccameron): Change this to expose only the mojom::WebContentsNSView
// when all communication is through mojo.
@ -54,7 +57,7 @@ class CONTENT_EXPORT WebContentsNSViewBridge : public mojom::WebContentsNSView {
private:
base::scoped_nsobject<WebContentsViewCocoa> ns_view_;
mojom::WebContentsNSViewHostAssociatedPtr host_;
mojo::AssociatedRemote<mojom::WebContentsNSViewHost> host_;
std::unique_ptr<ScopedNSViewIdMapping> view_id_;

@ -13,7 +13,7 @@ namespace remote_cocoa {
WebContentsNSViewBridge::WebContentsNSViewBridge(
uint64_t view_id,
mojom::WebContentsNSViewHostAssociatedPtr client)
mojo::PendingAssociatedRemote<mojom::WebContentsNSViewHost> client)
: host_(std::move(client)) {
ns_view_.reset(
[[WebContentsViewCocoa alloc] initWithViewsHostableView:nullptr]);

@ -21,7 +21,8 @@
#include "content/common/drag_event_source_info.h"
#include "content/common/web_contents_ns_view_bridge.mojom.h"
#include "content/public/browser/visibility.h"
#include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#import "ui/base/cocoa/views_hostable.h"
#include "ui/gfx/geometry/size.h"
@ -216,9 +217,10 @@ class WebContentsViewMac : public WebContentsView,
in_process_ns_view_bridge_;
// Mojo bindings for an out of process instance of this NSView.
remote_cocoa::mojom::WebContentsNSViewAssociatedPtr remote_ns_view_;
mojo::AssociatedBinding<remote_cocoa::mojom::WebContentsNSViewHost>
remote_ns_view_host_binding_;
mojo::AssociatedRemote<remote_cocoa::mojom::WebContentsNSView>
remote_ns_view_;
mojo::AssociatedReceiver<remote_cocoa::mojom::WebContentsNSViewHost>
remote_ns_view_host_receiver_{this};
// Used by CloseTabAfterEventTrackingIfNeeded.
base::WeakPtrFactory<WebContentsViewMac> deferred_close_weak_ptr_factory_;

@ -31,7 +31,8 @@
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view_delegate.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_remote.h"
#include "ui/base/cocoa/cocoa_base_utils.h"
#include "ui/gfx/mac/coordinate_conversion.h"
@ -92,7 +93,6 @@ WebContentsViewMac::WebContentsViewMac(WebContentsImpl* web_contents,
: web_contents_(web_contents),
delegate_(delegate),
ns_view_id_(remote_cocoa::GetNewNSViewId()),
remote_ns_view_host_binding_(this),
deferred_close_weak_ptr_factory_(this) {}
WebContentsViewMac::~WebContentsViewMac() {
@ -631,20 +631,22 @@ void WebContentsViewMac::ViewsHostableAttach(
// Create an NSView in the target process, if one exists.
auto* remote_cocoa_application = views_host_->GetRemoteCocoaApplication();
if (remote_cocoa_application) {
remote_cocoa::mojom::WebContentsNSViewHostAssociatedPtr host;
remote_ns_view_host_binding_.Bind(mojo::MakeRequest(&host));
remote_cocoa::mojom::WebContentsNSViewAssociatedRequest ns_view_request =
mojo::MakeRequest(&remote_ns_view_);
mojo::PendingAssociatedRemote<remote_cocoa::mojom::WebContentsNSViewHost>
host;
remote_ns_view_host_receiver_.Bind(
host.InitWithNewEndpointAndPassReceiver());
mojo::PendingAssociatedReceiver<remote_cocoa::mojom::WebContentsNSView>
ns_view_receiver = remote_ns_view_.BindNewEndpointAndPassReceiver();
// Cast from mojom::WebContentsNSViewHostPtr and
// mojom::WebContentsNSViewBridgeRequest to the public interfaces
// accepted by the application.
// Cast from mojo::AssociatedRemote<mojom::WebContentsNSViewHost> and
// mojo::PendingAssociatedReceiver<remote_cocoa::mojom::WebContentsNSView>
// to the public interfaces accepted by the application.
// TODO(ccameron): Remove the need for this cast.
// https://crbug.com/888290
mojo::AssociatedInterfacePtrInfo<remote_cocoa::mojom::StubInterface>
stub_host(host.PassInterface().PassHandle(), 0);
stub_host(host.PassHandle(), 0);
remote_cocoa::mojom::StubInterfaceAssociatedRequest stub_ns_view_request(
ns_view_request.PassHandle());
ns_view_receiver.PassHandle());
remote_cocoa_application->CreateWebContentsNSView(
ns_view_id_, std::move(stub_host), std::move(stub_ns_view_request));
@ -675,7 +677,7 @@ void WebContentsViewMac::ViewsHostableDetach() {
if (remote_ns_view_) {
remote_ns_view_->SetVisible(false);
remote_ns_view_->ResetParentNSView();
remote_ns_view_host_binding_.Close();
remote_ns_view_host_receiver_.reset();
remote_ns_view_.reset();
// Permit the in-process NSView to call back into |this| again.
[GetInProcessNSView() setHost:this];