Commit 2d56bd10 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert mojom::NativeWidgetNSWindow to new Mojo types

It converts NativeWidgetNSWindow to new Mojo types using
PendingAssociatedReceiver, AssociatedReceiver, and
AssociatedRemote.

Bug: 955171
Change-Id: I1da0bd8961616cb6f819a0cef44c9bcb03f0215b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895092
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712048}
parent b6d25327
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/remote_cocoa/common/native_widget_ns_window.mojom.h" #include "components/remote_cocoa/common/native_widget_ns_window.mojom.h"
#include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h" #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
...@@ -48,7 +49,8 @@ class REMOTE_COCOA_APP_SHIM_EXPORT ApplicationBridge ...@@ -48,7 +49,8 @@ class REMOTE_COCOA_APP_SHIM_EXPORT ApplicationBridge
mojo::PendingRemote<mojom::ColorPanelHost> host) override; mojo::PendingRemote<mojom::ColorPanelHost> host) override;
void CreateNativeWidgetNSWindow( void CreateNativeWidgetNSWindow(
uint64_t bridge_id, uint64_t bridge_id,
mojom::NativeWidgetNSWindowAssociatedRequest bridge_request, mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
bridge_receiver,
mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host, mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host,
mojom::TextInputHostAssociatedPtrInfo text_input_host) override; mojom::TextInputHostAssociatedPtrInfo text_input_host) override;
void CreateRenderWidgetHostNSView( void CreateRenderWidgetHostNSView(
......
...@@ -22,7 +22,8 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper { ...@@ -22,7 +22,8 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
public: public:
NativeWidgetBridgeOwner( NativeWidgetBridgeOwner(
uint64_t bridge_id, uint64_t bridge_id,
mojom::NativeWidgetNSWindowAssociatedRequest bridge_request, mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
bridge_receiver,
mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host_ptr, mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host_ptr,
mojom::TextInputHostAssociatedPtrInfo text_input_host_ptr) { mojom::TextInputHostAssociatedPtrInfo text_input_host_ptr) {
host_ptr_.Bind(std::move(host_ptr), host_ptr_.Bind(std::move(host_ptr),
...@@ -31,16 +32,16 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper { ...@@ -31,16 +32,16 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
ui::WindowResizeHelperMac::Get()->task_runner()); ui::WindowResizeHelperMac::Get()->task_runner());
bridge_ = std::make_unique<NativeWidgetNSWindowBridge>( bridge_ = std::make_unique<NativeWidgetNSWindowBridge>(
bridge_id, host_ptr_.get(), this, text_input_host_ptr_.get()); bridge_id, host_ptr_.get(), this, text_input_host_ptr_.get());
bridge_->BindRequest( bridge_->BindReceiver(
std::move(bridge_request), std::move(bridge_receiver),
base::BindOnce(&NativeWidgetBridgeOwner::OnConnectionError, base::BindOnce(&NativeWidgetBridgeOwner::OnMojoDisconnect,
base::Unretained(this))); base::Unretained(this)));
} }
private: private:
~NativeWidgetBridgeOwner() override {} ~NativeWidgetBridgeOwner() override {}
void OnConnectionError() { delete this; } void OnMojoDisconnect() { delete this; }
// NativeWidgetNSWindowHostHelper: // NativeWidgetNSWindowHostHelper:
id GetNativeViewAccessible() override { id GetNativeViewAccessible() override {
...@@ -131,12 +132,13 @@ void ApplicationBridge::ShowColorPanel( ...@@ -131,12 +132,13 @@ void ApplicationBridge::ShowColorPanel(
void ApplicationBridge::CreateNativeWidgetNSWindow( void ApplicationBridge::CreateNativeWidgetNSWindow(
uint64_t bridge_id, uint64_t bridge_id,
mojom::NativeWidgetNSWindowAssociatedRequest bridge_request, mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
bridge_receiver,
mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host, mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host,
mojom::TextInputHostAssociatedPtrInfo text_input_host) { mojom::TextInputHostAssociatedPtrInfo text_input_host) {
// The resulting object will be destroyed when its message pipe is closed. // The resulting object will be destroyed when its message pipe is closed.
ignore_result( ignore_result(
new NativeWidgetBridgeOwner(bridge_id, std::move(bridge_request), new NativeWidgetBridgeOwner(bridge_id, std::move(bridge_receiver),
std::move(host), std::move(text_input_host))); std::move(host), std::move(text_input_host)));
} }
......
...@@ -17,7 +17,8 @@ ...@@ -17,7 +17,8 @@
#include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h" #include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h"
#include "components/remote_cocoa/common/native_widget_ns_window.mojom.h" #include "components/remote_cocoa/common/native_widget_ns_window.mojom.h"
#include "components/remote_cocoa/common/text_input_host.mojom.h" #include "components/remote_cocoa/common/text_input_host.mojom.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "ui/accelerated_widget_mac/ca_transaction_observer.h" #include "ui/accelerated_widget_mac/ca_transaction_observer.h"
#include "ui/accelerated_widget_mac/display_ca_layer_tree.h" #include "ui/accelerated_widget_mac/display_ca_layer_tree.h"
...@@ -84,12 +85,12 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge ...@@ -84,12 +85,12 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge
remote_cocoa::mojom::TextInputHost* text_input_host); remote_cocoa::mojom::TextInputHost* text_input_host);
~NativeWidgetNSWindowBridge() override; ~NativeWidgetNSWindowBridge() override;
// Bind |bridge_mojo_binding_| to |request|, and set the connection error // Bind |bridge_mojo_receiver_| to |receiver|, and set the connection error
// callback for |bridge_mojo_binding_| to |connection_closed_callback| (which // callback for |bridge_mojo_receiver_| to |connection_closed_callback| (which
// will delete |this| when the connection is closed). // will delete |this| when the connection is closed).
void BindRequest( void BindReceiver(mojo::PendingAssociatedReceiver<
remote_cocoa::mojom::NativeWidgetNSWindowAssociatedRequest request, remote_cocoa::mojom::NativeWidgetNSWindow> receiver,
base::OnceClosure connection_closed_callback); base::OnceClosure connection_closed_callback);
// Initialize the NSWindow by taking ownership of the specified object. // Initialize the NSWindow by taking ownership of the specified object.
// TODO(ccameron): When a NativeWidgetNSWindowBridge is allocated across a // TODO(ccameron): When a NativeWidgetNSWindowBridge is allocated across a
...@@ -372,8 +373,8 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge ...@@ -372,8 +373,8 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge
// the first time it's shown. // the first time it's shown.
std::vector<uint8_t> pending_restoration_data_; std::vector<uint8_t> pending_restoration_data_;
mojo::AssociatedBinding<remote_cocoa::mojom::NativeWidgetNSWindow> mojo::AssociatedReceiver<remote_cocoa::mojom::NativeWidgetNSWindow>
bridge_mojo_binding_; bridge_mojo_receiver_{this};
DISALLOW_COPY_AND_ASSIGN(NativeWidgetNSWindowBridge); DISALLOW_COPY_AND_ASSIGN(NativeWidgetNSWindowBridge);
}; };
......
...@@ -309,8 +309,7 @@ NativeWidgetNSWindowBridge::NativeWidgetNSWindowBridge( ...@@ -309,8 +309,7 @@ NativeWidgetNSWindowBridge::NativeWidgetNSWindowBridge(
: id_(bridged_native_widget_id), : id_(bridged_native_widget_id),
host_(host), host_(host),
host_helper_(host_helper), host_helper_(host_helper),
text_input_host_(text_input_host), text_input_host_(text_input_host) {
bridge_mojo_binding_(this) {
DCHECK(GetIdToWidgetImplMap().find(id_) == GetIdToWidgetImplMap().end()); DCHECK(GetIdToWidgetImplMap().find(id_) == GetIdToWidgetImplMap().end());
GetIdToWidgetImplMap().insert(std::make_pair(id_, this)); GetIdToWidgetImplMap().insert(std::make_pair(id_, this));
} }
...@@ -324,12 +323,12 @@ NativeWidgetNSWindowBridge::~NativeWidgetNSWindowBridge() { ...@@ -324,12 +323,12 @@ NativeWidgetNSWindowBridge::~NativeWidgetNSWindowBridge() {
DestroyContentView(); DestroyContentView();
} }
void NativeWidgetNSWindowBridge::BindRequest( void NativeWidgetNSWindowBridge::BindReceiver(
mojom::NativeWidgetNSWindowAssociatedRequest request, mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow> receiver,
base::OnceClosure connection_closed_callback) { base::OnceClosure connection_closed_callback) {
bridge_mojo_binding_.Bind(std::move(request), bridge_mojo_receiver_.Bind(std::move(receiver),
ui::WindowResizeHelperMac::Get()->task_runner()); ui::WindowResizeHelperMac::Get()->task_runner());
bridge_mojo_binding_.set_connection_error_handler( bridge_mojo_receiver_.set_disconnect_handler(
std::move(connection_closed_callback)); std::move(connection_closed_callback));
} }
......
...@@ -37,7 +37,7 @@ interface Application { ...@@ -37,7 +37,7 @@ interface Application {
// the bridge. // the bridge.
CreateNativeWidgetNSWindow( CreateNativeWidgetNSWindow(
uint64 bridge_id, uint64 bridge_id,
associated NativeWidgetNSWindow& window_request, pending_associated_receiver<NativeWidgetNSWindow> window_receiver,
associated NativeWidgetNSWindowHost host, associated NativeWidgetNSWindowHost host,
associated TextInputHost text_input_host); associated TextInputHost text_input_host);
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/remote_cocoa/common/native_widget_ns_window.mojom.h" #include "components/remote_cocoa/common/native_widget_ns_window.mojom.h"
#include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h" #include "components/remote_cocoa/common/native_widget_ns_window_host.mojom.h"
#include "mojo/public/cpp/bindings/associated_binding.h" #include "mojo/public/cpp/bindings/associated_binding.h"
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h" #include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
#include "ui/base/cocoa/accessibility_focus_overrider.h" #include "ui/base/cocoa/accessibility_focus_overrider.h"
#include "ui/base/ime/input_method_delegate.h" #include "ui/base/ime/input_method_delegate.h"
...@@ -106,7 +107,7 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost ...@@ -106,7 +107,7 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
gfx::NativeViewAccessible GetNativeViewAccessibleForNSWindow() const; gfx::NativeViewAccessible GetNativeViewAccessibleForNSWindow() const;
// The mojo interface through which to communicate with the underlying // The mojo interface through which to communicate with the underlying
// NSWindow and NSView. This points to either |remote_ns_window_ptr_| or // NSWindow and NSView. This points to either |remote_ns_window_remote_| or
// |in_process_ns_window_bridge_|. // |in_process_ns_window_bridge_|.
remote_cocoa::mojom::NativeWidgetNSWindow* GetNSWindowMojo() const; remote_cocoa::mojom::NativeWidgetNSWindow* GetNSWindowMojo() const;
...@@ -405,8 +406,8 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost ...@@ -405,8 +406,8 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
NativeWidgetMacNSWindowHost* parent_ = nullptr; NativeWidgetMacNSWindowHost* parent_ = nullptr;
std::vector<NativeWidgetMacNSWindowHost*> children_; std::vector<NativeWidgetMacNSWindowHost*> children_;
// The factory that was used to create |remote_ns_window_ptr_|. This must be // The factory that was used to create |remote_ns_window_remote_|. This must
// the same as |parent_->application_host_|. // be the same as |parent_->application_host_|.
remote_cocoa::ApplicationHost* application_host_ = nullptr; remote_cocoa::ApplicationHost* application_host_ = nullptr;
Widget::InitParams::Type widget_type_ = Widget::InitParams::TYPE_WINDOW; Widget::InitParams::Type widget_type_ = Widget::InitParams::TYPE_WINDOW;
...@@ -419,9 +420,10 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost ...@@ -419,9 +420,10 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
std::unique_ptr<DragDropClientMac> drag_drop_client_; std::unique_ptr<DragDropClientMac> drag_drop_client_;
// The mojo pointer to a BridgedNativeWidget, which may exist in another // The mojo remote for a BridgedNativeWidget, which may exist in another
// process. // process.
remote_cocoa::mojom::NativeWidgetNSWindowAssociatedPtr remote_ns_window_ptr_; mojo::AssociatedRemote<remote_cocoa::mojom::NativeWidgetNSWindow>
remote_ns_window_remote_;
// Remote accessibility objects corresponding to the NSWindow and its root // Remote accessibility objects corresponding to the NSWindow and its root
// NSView. // NSView.
......
...@@ -259,7 +259,7 @@ NativeWidgetMacNSWindowHost::~NativeWidgetMacNSWindowHost() { ...@@ -259,7 +259,7 @@ NativeWidgetMacNSWindowHost::~NativeWidgetMacNSWindowHost() {
DCHECK(children_.empty()); DCHECK(children_.empty());
native_window_mapping_.reset(); native_window_mapping_.reset();
if (application_host_) { if (application_host_) {
remote_ns_window_ptr_.reset(); remote_ns_window_remote_.reset();
application_host_->RemoveObserver(this); application_host_->RemoveObserver(this);
application_host_ = nullptr; application_host_ = nullptr;
} }
...@@ -309,8 +309,8 @@ NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const { ...@@ -309,8 +309,8 @@ NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const {
remote_cocoa::mojom::NativeWidgetNSWindow* remote_cocoa::mojom::NativeWidgetNSWindow*
NativeWidgetMacNSWindowHost::GetNSWindowMojo() const { NativeWidgetMacNSWindowHost::GetNSWindowMojo() const {
if (remote_ns_window_ptr_) if (remote_ns_window_remote_)
return remote_ns_window_ptr_.get(); return remote_ns_window_remote_.get();
if (in_process_ns_window_bridge_) if (in_process_ns_window_bridge_)
return in_process_ns_window_bridge_.get(); return in_process_ns_window_bridge_.get();
return nullptr; return nullptr;
...@@ -348,7 +348,7 @@ void NativeWidgetMacNSWindowHost::CreateRemoteNSWindow( ...@@ -348,7 +348,7 @@ void NativeWidgetMacNSWindowHost::CreateRemoteNSWindow(
root_view_id_, [in_process_ns_window_ contentView]); root_view_id_, [in_process_ns_window_ contentView]);
} }
// Initialize |remote_ns_window_ptr_| to point to a bridge created by // Initialize |remote_ns_window_remote_| to point to a bridge created by
// |factory|. // |factory|.
remote_cocoa::mojom::NativeWidgetNSWindowHostAssociatedPtr host_ptr; remote_cocoa::mojom::NativeWidgetNSWindowHostAssociatedPtr host_ptr;
remote_ns_window_host_binding_.Bind( remote_ns_window_host_binding_.Bind(
...@@ -357,7 +357,7 @@ void NativeWidgetMacNSWindowHost::CreateRemoteNSWindow( ...@@ -357,7 +357,7 @@ void NativeWidgetMacNSWindowHost::CreateRemoteNSWindow(
remote_cocoa::mojom::TextInputHostAssociatedPtr text_input_host_ptr; remote_cocoa::mojom::TextInputHostAssociatedPtr text_input_host_ptr;
text_input_host_->BindRequest(mojo::MakeRequest(&text_input_host_ptr)); text_input_host_->BindRequest(mojo::MakeRequest(&text_input_host_ptr));
application_host_->GetApplication()->CreateNativeWidgetNSWindow( application_host_->GetApplication()->CreateNativeWidgetNSWindow(
widget_id_, mojo::MakeRequest(&remote_ns_window_ptr_), widget_id_, remote_ns_window_remote_.BindNewEndpointAndPassReceiver(),
host_ptr.PassInterface(), text_input_host_ptr.PassInterface()); host_ptr.PassInterface(), text_input_host_ptr.PassInterface());
// Create the window in its process, and attach it to its parent window. // Create the window in its process, and attach it to its parent window.
...@@ -464,7 +464,7 @@ void NativeWidgetMacNSWindowHost::SetBounds(const gfx::Rect& bounds) { ...@@ -464,7 +464,7 @@ void NativeWidgetMacNSWindowHost::SetBounds(const gfx::Rect& bounds) {
GetNSWindowMojo()->SetBounds( GetNSWindowMojo()->SetBounds(
bounds, native_widget_mac_->GetWidget()->GetMinimumSize()); bounds, native_widget_mac_->GetWidget()->GetMinimumSize());
if (remote_ns_window_ptr_) { if (remote_ns_window_remote_) {
gfx::Rect window_in_screen = gfx::Rect window_in_screen =
gfx::ScreenRectFromNSRect([in_process_ns_window_ frame]); gfx::ScreenRectFromNSRect([in_process_ns_window_ frame]);
gfx::Rect content_in_screen = gfx::Rect content_in_screen =
...@@ -734,7 +734,7 @@ void NativeWidgetMacNSWindowHost::GetAttachedNativeViewHostViewsRecursive( ...@@ -734,7 +734,7 @@ void NativeWidgetMacNSWindowHost::GetAttachedNativeViewHostViewsRecursive(
void NativeWidgetMacNSWindowHost::UpdateLocalWindowFrame( void NativeWidgetMacNSWindowHost::UpdateLocalWindowFrame(
const gfx::Rect& frame) { const gfx::Rect& frame) {
if (!remote_ns_window_ptr_) if (!remote_ns_window_remote_)
return; return;
[in_process_ns_window_ setFrame:gfx::ScreenRectToNSRect(frame) [in_process_ns_window_ setFrame:gfx::ScreenRectToNSRect(frame)
display:NO display:NO
......
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