Commit 4636233c authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert color_panel.mojom to new Mojo types

This CL converts ColorPanel and ColorPanelHost to
new Mojo types using PendingReceiver, Receiver,
PendingRemote, Remote and SelfOwnedReceiver.

Bug: 955171
Change-Id: Ie147c1bde436e427ca086a21a5ba7dd16e33b26a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1847491Reviewed-by: default avatarccameron <ccameron@chromium.org>
Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarOksana Zhuravlova <oksamyt@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#704438}
parent d9240193
......@@ -11,7 +11,8 @@
#include "components/remote_cocoa/common/color_panel.mojom.h"
#include "content/public/browser/color_chooser.h"
#include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
class ColorChooserMac : public content::ColorChooser,
public remote_cocoa::mojom::ColorPanelHost {
......@@ -40,8 +41,8 @@ class ColorChooserMac : public content::ColorChooser,
// outlive this class.
content::WebContents* web_contents_;
remote_cocoa::mojom::ColorPanelPtr mojo_panel_ptr_;
mojo::Binding<remote_cocoa::mojom::ColorPanelHost> mojo_host_binding_;
mojo::Remote<remote_cocoa::mojom::ColorPanel> mojo_panel_remote_;
mojo::Receiver<remote_cocoa::mojom::ColorPanelHost> mojo_host_receiver_{this};
DISALLOW_COPY_AND_ASSIGN(ColorChooserMac);
};
......
......@@ -9,8 +9,7 @@
#include "components/remote_cocoa/app_shim/color_panel_bridge.h"
#include "components/remote_cocoa/browser/application_host.h"
#include "components/remote_cocoa/browser/window.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "skia/ext/skia_utils_mac.h"
namespace {
......@@ -32,20 +31,20 @@ ColorChooserMac* ColorChooserMac::Open(content::WebContents* web_contents,
ColorChooserMac::ColorChooserMac(content::WebContents* web_contents,
SkColor initial_color)
: web_contents_(web_contents), mojo_host_binding_(this) {
remote_cocoa::mojom::ColorPanelHostPtr mojo_host_ptr;
mojo_host_binding_.Bind(mojo::MakeRequest(&mojo_host_ptr));
: web_contents_(web_contents) {
auto* application_host = remote_cocoa::ApplicationHost::GetForNativeView(
web_contents ? web_contents->GetNativeView() : gfx::NativeView());
if (application_host) {
application_host->GetApplication()->ShowColorPanel(
mojo::MakeRequest(&mojo_panel_ptr_), std::move(mojo_host_ptr));
mojo_panel_remote_.BindNewPipeAndPassReceiver(),
mojo_host_receiver_.BindNewPipeAndPassRemote());
} else {
mojo::MakeStrongBinding(std::make_unique<remote_cocoa::ColorPanelBridge>(
std::move(mojo_host_ptr)),
mojo::MakeRequest(&mojo_panel_ptr_));
mojo::MakeSelfOwnedReceiver(
std::make_unique<remote_cocoa::ColorPanelBridge>(
mojo_host_receiver_.BindNewPipeAndPassRemote()),
mojo_panel_remote_.BindNewPipeAndPassReceiver());
}
mojo_panel_ptr_->Show(initial_color);
mojo_panel_remote_->Show(initial_color);
}
ColorChooserMac::~ColorChooserMac() {
......@@ -73,7 +72,7 @@ void ColorChooserMac::End() {
}
void ColorChooserMac::SetSelectedColor(SkColor color) {
mojo_panel_ptr_->SetSelectedColor(color);
mojo_panel_remote_->SetSelectedColor(color);
}
namespace chrome {
......
......@@ -11,6 +11,8 @@
#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_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
namespace remote_cocoa {
......@@ -41,8 +43,8 @@ class REMOTE_COCOA_APP_SHIM_EXPORT ApplicationBridge
// mojom::Application:
void CreateAlert(mojom::AlertBridgeRequest bridge_request) override;
void ShowColorPanel(mojom::ColorPanelRequest request,
mojom::ColorPanelHostPtr host) override;
void ShowColorPanel(mojo::PendingReceiver<mojom::ColorPanel> receiver,
mojo::PendingRemote<mojom::ColorPanelHost> host) override;
void CreateNativeWidgetNSWindow(
uint64_t bridge_id,
mojom::NativeWidgetNSWindowAssociatedRequest bridge_request,
......
......@@ -10,7 +10,7 @@
#include "components/remote_cocoa/app_shim/color_panel_bridge.h"
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
#include "components/remote_cocoa/app_shim/native_widget_ns_window_host_helper.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#include "ui/accelerated_widget_mac/window_resize_helper_mac.h"
#include "ui/base/cocoa/remote_accessibility_api.h"
......@@ -121,10 +121,11 @@ void ApplicationBridge::CreateAlert(mojom::AlertBridgeRequest bridge_request) {
ignore_result(new AlertBridge(std::move(bridge_request)));
}
void ApplicationBridge::ShowColorPanel(mojom::ColorPanelRequest request,
mojom::ColorPanelHostPtr host) {
mojo::MakeStrongBinding(std::make_unique<ColorPanelBridge>(std::move(host)),
std::move(request));
void ApplicationBridge::ShowColorPanel(
mojo::PendingReceiver<mojom::ColorPanel> receiver,
mojo::PendingRemote<mojom::ColorPanelHost> host) {
mojo::MakeSelfOwnedReceiver(
std::make_unique<ColorPanelBridge>(std::move(host)), std::move(receiver));
}
void ApplicationBridge::CreateNativeWidgetNSWindow(
......
......@@ -7,6 +7,8 @@
#include "components/remote_cocoa/app_shim/remote_cocoa_app_shim_export.h"
#include "components/remote_cocoa/common/color_panel.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
namespace remote_cocoa {
......@@ -15,7 +17,7 @@ namespace remote_cocoa {
class REMOTE_COCOA_APP_SHIM_EXPORT ColorPanelBridge
: public remote_cocoa::mojom::ColorPanel {
public:
ColorPanelBridge(mojom::ColorPanelHostPtr host);
ColorPanelBridge(mojo::PendingRemote<mojom::ColorPanelHost> host);
~ColorPanelBridge() override;
mojom::ColorPanelHost* host() { return host_.get(); }
......@@ -24,7 +26,7 @@ class REMOTE_COCOA_APP_SHIM_EXPORT ColorPanelBridge
void SetSelectedColor(uint32_t color) override;
private:
mojom::ColorPanelHostPtr host_;
mojo::Remote<mojom::ColorPanelHost> host_;
};
} // namespace remote_cocoa
......
......@@ -116,7 +116,8 @@ remote_cocoa::ColorPanelBridge* g_current_panel_bridge = nullptr;
namespace remote_cocoa {
ColorPanelBridge::ColorPanelBridge(mojom::ColorPanelHostPtr host)
ColorPanelBridge::ColorPanelBridge(
mojo::PendingRemote<mojom::ColorPanelHost> host)
: host_(std::move(host)) {
g_current_panel_bridge = this;
}
......
......@@ -29,7 +29,8 @@ interface Application {
CreateAlert(AlertBridge& alert_bridge_request);
// Show the NSColorPanel in this application.
ShowColorPanel(ColorPanel& request, ColorPanelHost host);
ShowColorPanel(pending_receiver<ColorPanel> receiver,
pending_remote<ColorPanelHost> host);
// Create a window for a native widget. The resulting object will be owned by
// the connection for |host|. Closing that connection will result in deleting
......
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