Commit 3d4b7cf0 authored by Gyuyoung Kim's avatar Gyuyoung Kim Committed by Commit Bot

Migrate webshare to the new Mojo types

This CL applies the new Mojo types into WebShare classes.

 - ShareServicePtr is converted to mojo::Remote<>.
 - mojo::Binding is converted to mojo::Receiver<>.

Bug: 955171
Change-Id: Ide5d49a710e57bfcb5d99e0b590381eaa6d8450a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1757961
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688239}
parent abca8a4a
......@@ -186,7 +186,7 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
return ScriptPromise::RejectWithDOMException(script_state, error);
}
if (!service_) {
if (!service_remote_) {
LocalFrame* frame = doc->GetFrame();
if (!frame) {
auto* error = MakeGarbageCollected<DOMException>(
......@@ -197,11 +197,12 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
}
// See https://bit.ly/2S0zRAS for task types.
frame->GetInterfaceProvider().GetInterface(mojo::MakeRequest(
&service_, frame->GetTaskRunner(TaskType::kMiscPlatformAPI)));
service_.set_connection_error_handler(WTF::Bind(
frame->GetInterfaceProvider().GetInterface(
service_remote_.BindNewPipeAndPassReceiver(
frame->GetTaskRunner(TaskType::kMiscPlatformAPI)));
service_remote_.set_disconnect_handler(WTF::Bind(
&NavigatorShare::OnConnectionError, WrapWeakPersistent(this)));
DCHECK(service_);
DCHECK(service_remote_);
}
bool has_files = HasFiles(*share_data);
......@@ -229,7 +230,7 @@ ScriptPromise NavigatorShare::share(ScriptState* script_state,
}
}
service_->Share(
service_remote_->Share(
share_data->hasTitle() ? share_data->title() : g_empty_string,
share_data->hasText() ? share_data->text() : g_empty_string, full_url,
std::move(files),
......@@ -249,7 +250,7 @@ void NavigatorShare::OnConnectionError() {
client->OnConnectionError();
}
clients_.clear();
service_.reset();
service_remote_.reset();
}
} // namespace blink
......@@ -5,6 +5,7 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSHARE_NAVIGATOR_SHARE_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBSHARE_NAVIGATOR_SHARE_H_
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/blink/public/mojom/webshare/webshare.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
......@@ -50,7 +51,7 @@ class MODULES_EXPORT NavigatorShare final
void OnConnectionError();
blink::mojom::blink::ShareServicePtr service_;
mojo::Remote<blink::mojom::blink::ShareService> service_remote_;
HeapHashSet<Member<ShareClientImpl>> clients_;
};
......
......@@ -29,11 +29,11 @@ using mojom::blink::ShareService;
// A mock ShareService used to intercept calls to the mojo methods.
class MockShareService : public ShareService {
public:
MockShareService() : binding_(this), error_(mojom::ShareError::OK) {}
MockShareService() : error_(mojom::ShareError::OK) {}
~MockShareService() override = default;
void Bind(mojo::ScopedMessagePipeHandle handle) {
binding_.Bind(mojom::blink::ShareServiceRequest(std::move(handle)));
receiver_.Bind(mojom::blink::ShareServiceRequest(std::move(handle)));
}
void set_error(mojom::ShareError value) { error_ = value; }
......@@ -63,7 +63,7 @@ class MockShareService : public ShareService {
std::move(callback).Run(error_);
}
mojo::Binding<ShareService> binding_;
mojo::Receiver<ShareService> receiver_{this};
WTF::String title_;
WTF::String text_;
KURL url_;
......
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