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 @@
#include "components/remote_cocoa/common/native_widget_ns_window.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/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
......@@ -48,7 +49,8 @@ class REMOTE_COCOA_APP_SHIM_EXPORT ApplicationBridge
mojo::PendingRemote<mojom::ColorPanelHost> host) override;
void CreateNativeWidgetNSWindow(
uint64_t bridge_id,
mojom::NativeWidgetNSWindowAssociatedRequest bridge_request,
mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
bridge_receiver,
mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host,
mojom::TextInputHostAssociatedPtrInfo text_input_host) override;
void CreateRenderWidgetHostNSView(
......
......@@ -22,7 +22,8 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
public:
NativeWidgetBridgeOwner(
uint64_t bridge_id,
mojom::NativeWidgetNSWindowAssociatedRequest bridge_request,
mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
bridge_receiver,
mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host_ptr,
mojom::TextInputHostAssociatedPtrInfo text_input_host_ptr) {
host_ptr_.Bind(std::move(host_ptr),
......@@ -31,16 +32,16 @@ class NativeWidgetBridgeOwner : public NativeWidgetNSWindowHostHelper {
ui::WindowResizeHelperMac::Get()->task_runner());
bridge_ = std::make_unique<NativeWidgetNSWindowBridge>(
bridge_id, host_ptr_.get(), this, text_input_host_ptr_.get());
bridge_->BindRequest(
std::move(bridge_request),
base::BindOnce(&NativeWidgetBridgeOwner::OnConnectionError,
bridge_->BindReceiver(
std::move(bridge_receiver),
base::BindOnce(&NativeWidgetBridgeOwner::OnMojoDisconnect,
base::Unretained(this)));
}
private:
~NativeWidgetBridgeOwner() override {}
void OnConnectionError() { delete this; }
void OnMojoDisconnect() { delete this; }
// NativeWidgetNSWindowHostHelper:
id GetNativeViewAccessible() override {
......@@ -131,12 +132,13 @@ void ApplicationBridge::ShowColorPanel(
void ApplicationBridge::CreateNativeWidgetNSWindow(
uint64_t bridge_id,
mojom::NativeWidgetNSWindowAssociatedRequest bridge_request,
mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow>
bridge_receiver,
mojom::NativeWidgetNSWindowHostAssociatedPtrInfo host,
mojom::TextInputHostAssociatedPtrInfo text_input_host) {
// The resulting object will be destroyed when its message pipe is closed.
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)));
}
......
......@@ -17,7 +17,8 @@
#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/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 "ui/accelerated_widget_mac/ca_transaction_observer.h"
#include "ui/accelerated_widget_mac/display_ca_layer_tree.h"
......@@ -84,11 +85,11 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge
remote_cocoa::mojom::TextInputHost* text_input_host);
~NativeWidgetNSWindowBridge() override;
// Bind |bridge_mojo_binding_| to |request|, and set the connection error
// callback for |bridge_mojo_binding_| to |connection_closed_callback| (which
// Bind |bridge_mojo_receiver_| to |receiver|, and set the connection error
// callback for |bridge_mojo_receiver_| to |connection_closed_callback| (which
// will delete |this| when the connection is closed).
void BindRequest(
remote_cocoa::mojom::NativeWidgetNSWindowAssociatedRequest request,
void BindReceiver(mojo::PendingAssociatedReceiver<
remote_cocoa::mojom::NativeWidgetNSWindow> receiver,
base::OnceClosure connection_closed_callback);
// Initialize the NSWindow by taking ownership of the specified object.
......@@ -372,8 +373,8 @@ class REMOTE_COCOA_APP_SHIM_EXPORT NativeWidgetNSWindowBridge
// the first time it's shown.
std::vector<uint8_t> pending_restoration_data_;
mojo::AssociatedBinding<remote_cocoa::mojom::NativeWidgetNSWindow>
bridge_mojo_binding_;
mojo::AssociatedReceiver<remote_cocoa::mojom::NativeWidgetNSWindow>
bridge_mojo_receiver_{this};
DISALLOW_COPY_AND_ASSIGN(NativeWidgetNSWindowBridge);
};
......
......@@ -309,8 +309,7 @@ NativeWidgetNSWindowBridge::NativeWidgetNSWindowBridge(
: id_(bridged_native_widget_id),
host_(host),
host_helper_(host_helper),
text_input_host_(text_input_host),
bridge_mojo_binding_(this) {
text_input_host_(text_input_host) {
DCHECK(GetIdToWidgetImplMap().find(id_) == GetIdToWidgetImplMap().end());
GetIdToWidgetImplMap().insert(std::make_pair(id_, this));
}
......@@ -324,12 +323,12 @@ NativeWidgetNSWindowBridge::~NativeWidgetNSWindowBridge() {
DestroyContentView();
}
void NativeWidgetNSWindowBridge::BindRequest(
mojom::NativeWidgetNSWindowAssociatedRequest request,
void NativeWidgetNSWindowBridge::BindReceiver(
mojo::PendingAssociatedReceiver<mojom::NativeWidgetNSWindow> receiver,
base::OnceClosure connection_closed_callback) {
bridge_mojo_binding_.Bind(std::move(request),
bridge_mojo_receiver_.Bind(std::move(receiver),
ui::WindowResizeHelperMac::Get()->task_runner());
bridge_mojo_binding_.set_connection_error_handler(
bridge_mojo_receiver_.set_disconnect_handler(
std::move(connection_closed_callback));
}
......
......@@ -37,7 +37,7 @@ interface Application {
// the bridge.
CreateNativeWidgetNSWindow(
uint64 bridge_id,
associated NativeWidgetNSWindow& window_request,
pending_associated_receiver<NativeWidgetNSWindow> window_receiver,
associated NativeWidgetNSWindowHost host,
associated TextInputHost text_input_host);
......
......@@ -16,6 +16,7 @@
#include "components/remote_cocoa/common/native_widget_ns_window.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_remote.h"
#include "ui/accelerated_widget_mac/accelerated_widget_mac.h"
#include "ui/base/cocoa/accessibility_focus_overrider.h"
#include "ui/base/ime/input_method_delegate.h"
......@@ -106,7 +107,7 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
gfx::NativeViewAccessible GetNativeViewAccessibleForNSWindow() const;
// 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_|.
remote_cocoa::mojom::NativeWidgetNSWindow* GetNSWindowMojo() const;
......@@ -405,8 +406,8 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
NativeWidgetMacNSWindowHost* parent_ = nullptr;
std::vector<NativeWidgetMacNSWindowHost*> children_;
// The factory that was used to create |remote_ns_window_ptr_|. This must be
// the same as |parent_->application_host_|.
// The factory that was used to create |remote_ns_window_remote_|. This must
// be the same as |parent_->application_host_|.
remote_cocoa::ApplicationHost* application_host_ = nullptr;
Widget::InitParams::Type widget_type_ = Widget::InitParams::TYPE_WINDOW;
......@@ -419,9 +420,10 @@ class VIEWS_EXPORT NativeWidgetMacNSWindowHost
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.
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
// NSView.
......
......@@ -259,7 +259,7 @@ NativeWidgetMacNSWindowHost::~NativeWidgetMacNSWindowHost() {
DCHECK(children_.empty());
native_window_mapping_.reset();
if (application_host_) {
remote_ns_window_ptr_.reset();
remote_ns_window_remote_.reset();
application_host_->RemoveObserver(this);
application_host_ = nullptr;
}
......@@ -309,8 +309,8 @@ NativeWidgetMacNSWindowHost::GetNativeViewAccessibleForNSWindow() const {
remote_cocoa::mojom::NativeWidgetNSWindow*
NativeWidgetMacNSWindowHost::GetNSWindowMojo() const {
if (remote_ns_window_ptr_)
return remote_ns_window_ptr_.get();
if (remote_ns_window_remote_)
return remote_ns_window_remote_.get();
if (in_process_ns_window_bridge_)
return in_process_ns_window_bridge_.get();
return nullptr;
......@@ -348,7 +348,7 @@ void NativeWidgetMacNSWindowHost::CreateRemoteNSWindow(
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|.
remote_cocoa::mojom::NativeWidgetNSWindowHostAssociatedPtr host_ptr;
remote_ns_window_host_binding_.Bind(
......@@ -357,7 +357,7 @@ void NativeWidgetMacNSWindowHost::CreateRemoteNSWindow(
remote_cocoa::mojom::TextInputHostAssociatedPtr text_input_host_ptr;
text_input_host_->BindRequest(mojo::MakeRequest(&text_input_host_ptr));
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());
// Create the window in its process, and attach it to its parent window.
......@@ -464,7 +464,7 @@ void NativeWidgetMacNSWindowHost::SetBounds(const gfx::Rect& bounds) {
GetNSWindowMojo()->SetBounds(
bounds, native_widget_mac_->GetWidget()->GetMinimumSize());
if (remote_ns_window_ptr_) {
if (remote_ns_window_remote_) {
gfx::Rect window_in_screen =
gfx::ScreenRectFromNSRect([in_process_ns_window_ frame]);
gfx::Rect content_in_screen =
......@@ -734,7 +734,7 @@ void NativeWidgetMacNSWindowHost::GetAttachedNativeViewHostViewsRecursive(
void NativeWidgetMacNSWindowHost::UpdateLocalWindowFrame(
const gfx::Rect& frame) {
if (!remote_ns_window_ptr_)
if (!remote_ns_window_remote_)
return;
[in_process_ns_window_ setFrame:gfx::ScreenRectToNSRect(frame)
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