Commit 98d7086a authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

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/+/1872215Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#708876}
parent 4a20ea3d
...@@ -17,9 +17,11 @@ ...@@ -17,9 +17,11 @@
#include "content/common/render_widget_host_ns_view.mojom.h" #include "content/common/render_widget_host_ns_view.mojom.h"
#include "content/common/web_contents_ns_view_bridge.mojom.h" #include "content/common/web_contents_ns_view_bridge.mojom.h"
#include "content/public/browser/native_web_keyboard_event.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/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/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/accelerated_widget_mac/window_resize_helper_mac.h"
#include "ui/base/cocoa/remote_accessibility_api.h" #include "ui/base/cocoa/remote_accessibility_api.h"
#include "ui/events/cocoa/cocoa_event_utils.h" #include "ui/events/cocoa/cocoa_event_utils.h"
...@@ -153,17 +155,15 @@ void CreateWebContentsNSView( ...@@ -153,17 +155,15 @@ void CreateWebContentsNSView(
uint64_t view_id, uint64_t view_id,
mojo::ScopedInterfaceEndpointHandle host_handle, mojo::ScopedInterfaceEndpointHandle host_handle,
mojo::ScopedInterfaceEndpointHandle view_request_handle) { mojo::ScopedInterfaceEndpointHandle view_request_handle) {
mojom::WebContentsNSViewHostAssociatedPtr host( mojo::PendingAssociatedRemote<mojom::WebContentsNSViewHost> host(
mojo::AssociatedInterfacePtrInfo<mojom::WebContentsNSViewHost>( std::move(host_handle), 0);
std::move(host_handle), 0)); mojo::PendingAssociatedReceiver<mojom::WebContentsNSView> ns_view_receiver(
mojom::WebContentsNSViewAssociatedRequest ns_view_request(
std::move(view_request_handle)); std::move(view_request_handle));
// Note that the resulting object will be destroyed when its underlying pipe // Note that the resulting object will be destroyed when its underlying pipe
// is closed. // is closed.
mojo::MakeStrongAssociatedBinding( mojo::MakeSelfOwnedAssociatedReceiver(
std::make_unique<WebContentsNSViewBridge>( std::make_unique<WebContentsNSViewBridge>(view_id, std::move(host)),
view_id, mojom::WebContentsNSViewHostAssociatedPtr(std::move(host))), std::move(ns_view_receiver),
std::move(ns_view_request),
ui::WindowResizeHelperMac::Get()->task_runner()); ui::WindowResizeHelperMac::Get()->task_runner());
} }
......
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include "components/remote_cocoa/app_shim/ns_view_ids.h" #include "components/remote_cocoa/app_shim/ns_view_ids.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/common/web_contents_ns_view_bridge.mojom.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; @class WebContentsViewCocoa;
...@@ -29,8 +31,9 @@ class CONTENT_EXPORT WebContentsNSViewBridge : public mojom::WebContentsNSView { ...@@ -29,8 +31,9 @@ class CONTENT_EXPORT WebContentsNSViewBridge : public mojom::WebContentsNSView {
public: public:
// Create a bridge that will access its client in another process via a mojo // Create a bridge that will access its client in another process via a mojo
// interface. // interface.
WebContentsNSViewBridge(uint64_t view_id, WebContentsNSViewBridge(
mojom::WebContentsNSViewHostAssociatedPtr client); uint64_t view_id,
mojo::PendingAssociatedRemote<mojom::WebContentsNSViewHost> client);
// Create a bridge that will access its client directly in-process. // Create a bridge that will access its client directly in-process.
// TODO(ccameron): Change this to expose only the mojom::WebContentsNSView // TODO(ccameron): Change this to expose only the mojom::WebContentsNSView
// when all communication is through mojo. // when all communication is through mojo.
...@@ -54,7 +57,7 @@ class CONTENT_EXPORT WebContentsNSViewBridge : public mojom::WebContentsNSView { ...@@ -54,7 +57,7 @@ class CONTENT_EXPORT WebContentsNSViewBridge : public mojom::WebContentsNSView {
private: private:
base::scoped_nsobject<WebContentsViewCocoa> ns_view_; base::scoped_nsobject<WebContentsViewCocoa> ns_view_;
mojom::WebContentsNSViewHostAssociatedPtr host_; mojo::AssociatedRemote<mojom::WebContentsNSViewHost> host_;
std::unique_ptr<ScopedNSViewIdMapping> view_id_; std::unique_ptr<ScopedNSViewIdMapping> view_id_;
......
...@@ -13,7 +13,7 @@ namespace remote_cocoa { ...@@ -13,7 +13,7 @@ namespace remote_cocoa {
WebContentsNSViewBridge::WebContentsNSViewBridge( WebContentsNSViewBridge::WebContentsNSViewBridge(
uint64_t view_id, uint64_t view_id,
mojom::WebContentsNSViewHostAssociatedPtr client) mojo::PendingAssociatedRemote<mojom::WebContentsNSViewHost> client)
: host_(std::move(client)) { : host_(std::move(client)) {
ns_view_.reset( ns_view_.reset(
[[WebContentsViewCocoa alloc] initWithViewsHostableView:nullptr]); [[WebContentsViewCocoa alloc] initWithViewsHostableView:nullptr]);
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
#include "content/common/drag_event_source_info.h" #include "content/common/drag_event_source_info.h"
#include "content/common/web_contents_ns_view_bridge.mojom.h" #include "content/common/web_contents_ns_view_bridge.mojom.h"
#include "content/public/browser/visibility.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" #import "ui/base/cocoa/views_hostable.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
...@@ -216,9 +217,10 @@ class WebContentsViewMac : public WebContentsView, ...@@ -216,9 +217,10 @@ class WebContentsViewMac : public WebContentsView,
in_process_ns_view_bridge_; in_process_ns_view_bridge_;
// Mojo bindings for an out of process instance of this NSView. // Mojo bindings for an out of process instance of this NSView.
remote_cocoa::mojom::WebContentsNSViewAssociatedPtr remote_ns_view_; mojo::AssociatedRemote<remote_cocoa::mojom::WebContentsNSView>
mojo::AssociatedBinding<remote_cocoa::mojom::WebContentsNSViewHost> remote_ns_view_;
remote_ns_view_host_binding_; mojo::AssociatedReceiver<remote_cocoa::mojom::WebContentsNSViewHost>
remote_ns_view_host_receiver_{this};
// Used by CloseTabAfterEventTrackingIfNeeded. // Used by CloseTabAfterEventTrackingIfNeeded.
base::WeakPtrFactory<WebContentsViewMac> deferred_close_weak_ptr_factory_; base::WeakPtrFactory<WebContentsViewMac> deferred_close_weak_ptr_factory_;
......
...@@ -31,7 +31,8 @@ ...@@ -31,7 +31,8 @@
#include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view_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/base/cocoa/cocoa_base_utils.h"
#include "ui/gfx/mac/coordinate_conversion.h" #include "ui/gfx/mac/coordinate_conversion.h"
...@@ -92,7 +93,6 @@ WebContentsViewMac::WebContentsViewMac(WebContentsImpl* web_contents, ...@@ -92,7 +93,6 @@ WebContentsViewMac::WebContentsViewMac(WebContentsImpl* web_contents,
: web_contents_(web_contents), : web_contents_(web_contents),
delegate_(delegate), delegate_(delegate),
ns_view_id_(remote_cocoa::GetNewNSViewId()), ns_view_id_(remote_cocoa::GetNewNSViewId()),
remote_ns_view_host_binding_(this),
deferred_close_weak_ptr_factory_(this) {} deferred_close_weak_ptr_factory_(this) {}
WebContentsViewMac::~WebContentsViewMac() { WebContentsViewMac::~WebContentsViewMac() {
...@@ -631,20 +631,22 @@ void WebContentsViewMac::ViewsHostableAttach( ...@@ -631,20 +631,22 @@ void WebContentsViewMac::ViewsHostableAttach(
// Create an NSView in the target process, if one exists. // Create an NSView in the target process, if one exists.
auto* remote_cocoa_application = views_host_->GetRemoteCocoaApplication(); auto* remote_cocoa_application = views_host_->GetRemoteCocoaApplication();
if (remote_cocoa_application) { if (remote_cocoa_application) {
remote_cocoa::mojom::WebContentsNSViewHostAssociatedPtr host; mojo::PendingAssociatedRemote<remote_cocoa::mojom::WebContentsNSViewHost>
remote_ns_view_host_binding_.Bind(mojo::MakeRequest(&host)); host;
remote_cocoa::mojom::WebContentsNSViewAssociatedRequest ns_view_request = remote_ns_view_host_receiver_.Bind(
mojo::MakeRequest(&remote_ns_view_); host.InitWithNewEndpointAndPassReceiver());
mojo::PendingAssociatedReceiver<remote_cocoa::mojom::WebContentsNSView>
// Cast from mojom::WebContentsNSViewHostPtr and ns_view_receiver = remote_ns_view_.BindNewEndpointAndPassReceiver();
// 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. // TODO(ccameron): Remove the need for this cast.
// https://crbug.com/888290 // https://crbug.com/888290
mojo::AssociatedInterfacePtrInfo<remote_cocoa::mojom::StubInterface> 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( remote_cocoa::mojom::StubInterfaceAssociatedRequest stub_ns_view_request(
ns_view_request.PassHandle()); ns_view_receiver.PassHandle());
remote_cocoa_application->CreateWebContentsNSView( remote_cocoa_application->CreateWebContentsNSView(
ns_view_id_, std::move(stub_host), std::move(stub_ns_view_request)); ns_view_id_, std::move(stub_host), std::move(stub_ns_view_request));
...@@ -675,7 +677,7 @@ void WebContentsViewMac::ViewsHostableDetach() { ...@@ -675,7 +677,7 @@ void WebContentsViewMac::ViewsHostableDetach() {
if (remote_ns_view_) { if (remote_ns_view_) {
remote_ns_view_->SetVisible(false); remote_ns_view_->SetVisible(false);
remote_ns_view_->ResetParentNSView(); remote_ns_view_->ResetParentNSView();
remote_ns_view_host_binding_.Close(); remote_ns_view_host_receiver_.reset();
remote_ns_view_.reset(); remote_ns_view_.reset();
// Permit the in-process NSView to call back into |this| again. // Permit the in-process NSView to call back into |this| again.
[GetInProcessNSView() setHost:this]; [GetInProcessNSView() setHost:this];
......
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