Commit 43b9c27d authored by Han Leon's avatar Han Leon Committed by Commit Bot

[OnionSoup] Remove WebServiceWorkerClientCallbacks - part 2

After https://chromium-review.googlesource.com/c/chromium/src/+/1214709,
now we send {FocusClient, NavigateClient, OpenPaymentHandlerWindow,
OpenWindowForClients} Mojo messages from within Blink, no longer need
blink::NavigateClientCallback (subclass of
WebServiceWorkerClientCallbacks) to help cross the boundary of Content
and Blink.

This CL removes blink::NavigateClientCallback then removes
the parent class WebServiceWorkerClientCallbacks completely.

BUG=879019

Change-Id: I0643b7439d1a07ca2a3296f3327440d306cf0c2f
Reviewed-on: https://chromium-review.googlesource.com/1227619Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Leon Han <leon.han@intel.com>
Cr-Commit-Position: refs/heads/master@{#593054}
parent d5227511
...@@ -8,16 +8,16 @@ ...@@ -8,16 +8,16 @@
#include "services/network/public/mojom/request_context_frame_type.mojom-shared.h" #include "services/network/public/mojom/request_context_frame_type.mojom-shared.h"
#include "third_party/blink/public/mojom/page/page_visibility_state.mojom-shared.h" #include "third_party/blink/public/mojom/page/page_visibility_state.mojom-shared.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_client.mojom-shared.h" #include "third_party/blink/public/mojom/service_worker/service_worker_client.mojom-shared.h"
#include "third_party/blink/public/platform/web_callbacks.h" #include "third_party/blink/public/platform/web_string.h"
#include "third_party/blink/public/platform/web_url.h" #include "third_party/blink/public/platform/web_url.h"
#include "third_party/blink/public/platform/web_url_request.h"
#include <memory>
namespace blink { namespace blink {
struct WebServiceWorkerError; // The only usage of this class is to carry the source of an extendable message
// dispatched via content.mojom.ServiceWorker across the boundary of Content and
// Blink.
// TODO(crbug.com/879019): Remove this class once we move
// content.mojom.ServiceWorker impl into Blink.
struct WebServiceWorkerClientInfo { struct WebServiceWorkerClientInfo {
WebServiceWorkerClientInfo() WebServiceWorkerClientInfo()
: page_visibility_state(mojom::PageVisibilityState::kMaxValue), : page_visibility_state(mojom::PageVisibilityState::kMaxValue),
...@@ -34,10 +34,6 @@ struct WebServiceWorkerClientInfo { ...@@ -34,10 +34,6 @@ struct WebServiceWorkerClientInfo {
mojom::ServiceWorkerClientType client_type; mojom::ServiceWorkerClientType client_type;
}; };
using WebServiceWorkerClientCallbacks =
WebCallbacks<std::unique_ptr<WebServiceWorkerClientInfo>,
const WebServiceWorkerError&>;
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_SERVICE_WORKER_WEB_SERVICE_WORKER_CLIENTS_INFO_H_ #endif // THIRD_PARTY_BLINK_PUBLIC_PLATFORM_MODULES_SERVICE_WORKER_WEB_SERVICE_WORKER_CLIENTS_INFO_H_
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "third_party/blink/renderer/core/workers/worker_location.h" #include "third_party/blink/renderer/core/workers/worker_location.h"
#include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h" #include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client_callback.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "third_party/blink/renderer/core/workers/worker_location.h" #include "third_party/blink/renderer/core/workers/worker_location.h"
#include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h" #include "third_party/blink/renderer/modules/service_worker/respond_with_observer.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client_callback.h"
#include "third_party/blink/renderer/platform/bindings/script_state.h" #include "third_party/blink/renderer/platform/bindings/script_state.h"
#include "third_party/blink/renderer/platform/wtf/text/atomic_string.h" #include "third_party/blink/renderer/platform/wtf/text/atomic_string.h"
...@@ -104,7 +103,7 @@ ScriptPromise PaymentRequestEvent::openWindow(ScriptState* script_state, ...@@ -104,7 +103,7 @@ ScriptPromise PaymentRequestEvent::openWindow(ScriptState* script_state,
context->ConsumeWindowInteraction(); context->ConsumeWindowInteraction();
ServiceWorkerGlobalScopeClient::From(context)->OpenWindowForPaymentHandler( ServiceWorkerGlobalScopeClient::From(context)->OpenWindowForPaymentHandler(
parsed_url_to_open, std::make_unique<NavigateClientCallback>(resolver)); parsed_url_to_open, resolver);
return promise; return promise;
} }
......
...@@ -54,8 +54,6 @@ blink_modules_sources("service_worker") { ...@@ -54,8 +54,6 @@ blink_modules_sources("service_worker") {
"service_worker_thread.h", "service_worker_thread.h",
"service_worker_window_client.cc", "service_worker_window_client.cc",
"service_worker_window_client.h", "service_worker_window_client.h",
"service_worker_window_client_callback.cc",
"service_worker_window_client_callback.h",
"thread_safe_script_container.cc", "thread_safe_script_container.cc",
"thread_safe_script_container.h", "thread_safe_script_container.h",
"wait_until_observer.cc", "wait_until_observer.cc",
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "third_party/blink/renderer/modules/service_worker/service_worker_error.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_error.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_window_client.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client_callback.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h" #include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/wtf/vector.h" #include "third_party/blink/renderer/platform/wtf/vector.h"
...@@ -52,7 +51,7 @@ void DidGetClient(ScriptPromiseResolver* resolver, ...@@ -52,7 +51,7 @@ void DidGetClient(ScriptPromiseResolver* resolver,
resolver->Resolve(); resolver->Resolve();
return; return;
} }
ServiceWorkerClient* client; ServiceWorkerClient* client = nullptr;
switch (info->client_type) { switch (info->client_type) {
case mojom::ServiceWorkerClientType::kWindow: case mojom::ServiceWorkerClientType::kWindow:
client = ServiceWorkerWindowClient::Create(*info); client = ServiceWorkerWindowClient::Create(*info);
...@@ -182,7 +181,7 @@ ScriptPromise ServiceWorkerClients::openWindow(ScriptState* script_state, ...@@ -182,7 +181,7 @@ ScriptPromise ServiceWorkerClients::openWindow(ScriptState* script_state,
context->ConsumeWindowInteraction(); context->ConsumeWindowInteraction();
ServiceWorkerGlobalScopeClient::From(context)->OpenWindowForClients( ServiceWorkerGlobalScopeClient::From(context)->OpenWindowForClients(
parsed_url, std::make_unique<NavigateClientCallback>(resolver)); parsed_url, resolver);
return promise; return promise;
} }
......
...@@ -36,87 +36,44 @@ ...@@ -36,87 +36,44 @@
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_error.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_response.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_response.h"
#include "third_party/blink/public/web/modules/service_worker/web_service_worker_context_client.h" #include "third_party/blink/public/web/modules/service_worker/web_service_worker_context_client.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/fetch/response.h" #include "third_party/blink/renderer/core/fetch/response.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
#include "third_party/blink/renderer/platform/wtf/vector.h" #include "third_party/blink/renderer/platform/wtf/vector.h"
namespace blink { namespace blink {
namespace { namespace {
// TODO(leonhsl): Remove this function, pass ServiceWorkerClientInfoPtr through void DidNavigateOrOpenWindow(ScriptPromiseResolver* resolver,
// to replace WebServiceWorkerClientInfo. bool success,
blink::WebServiceWorkerClientInfo ToWebServiceWorkerClientInfo( mojom::blink::ServiceWorkerClientInfoPtr info,
mojom::blink::ServiceWorkerClientInfoPtr client_info) { const String& error_msg) {
DCHECK(!client_info->client_uuid.IsEmpty()); if (!resolver->GetExecutionContext() ||
resolver->GetExecutionContext()->IsContextDestroyed()) {
blink::WebServiceWorkerClientInfo web_client_info;
web_client_info.uuid = client_info->client_uuid;
web_client_info.page_visibility_state = client_info->page_visibility_state;
web_client_info.is_focused = client_info->is_focused;
web_client_info.url = client_info->url;
web_client_info.frame_type = client_info->frame_type;
web_client_info.client_type = client_info->client_type;
return web_client_info;
}
void DidOpenWindow(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
bool success,
mojom::blink::ServiceWorkerClientInfoPtr client,
const String& error_msg) {
if (!success) {
DCHECK(!client);
DCHECK(!error_msg.IsNull());
callbacks->OnError(blink::WebServiceWorkerError(
mojom::blink::ServiceWorkerErrorType::kNavigation, error_msg));
return; return;
} }
std::unique_ptr<blink::WebServiceWorkerClientInfo> web_client;
if (client) {
web_client = std::make_unique<blink::WebServiceWorkerClientInfo>(
ToWebServiceWorkerClientInfo(std::move(client)));
}
callbacks->OnSuccess(std::move(web_client));
}
void DidFocusClient(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
mojom::blink::ServiceWorkerClientInfoPtr client) {
if (!client) {
callbacks->OnError(blink::WebServiceWorkerError(
mojom::blink::ServiceWorkerErrorType::kNotFound,
"The client was not found."));
return;
}
auto web_client = std::make_unique<blink::WebServiceWorkerClientInfo>(
ToWebServiceWorkerClientInfo(std::move(client)));
callbacks->OnSuccess(std::move(web_client));
}
void DidNavigateClient(
std::unique_ptr<blink::WebServiceWorkerClientCallbacks> callbacks,
bool success,
mojom::blink::ServiceWorkerClientInfoPtr client,
const String& error_msg) {
if (!success) { if (!success) {
DCHECK(!client); DCHECK(!info);
DCHECK(!error_msg.IsNull()); DCHECK(!error_msg.IsNull());
callbacks->OnError(blink::WebServiceWorkerError( ScriptState::Scope scope(resolver->GetScriptState());
mojom::blink::ServiceWorkerErrorType::kNavigation, error_msg)); resolver->Reject(V8ThrowException::CreateTypeError(
resolver->GetScriptState()->GetIsolate(), error_msg));
return; return;
} }
ServiceWorkerWindowClient* window_client = nullptr;
std::unique_ptr<blink::WebServiceWorkerClientInfo> web_client; // Even if the open/navigation succeeded, |info| may be null if information of
if (client) { // the opened/navigated window could not be obtained (this can happen for a
web_client = std::make_unique<blink::WebServiceWorkerClientInfo>( // cross-origin window, or if the browser process could not get the
ToWebServiceWorkerClientInfo(std::move(client))); // information in time before the window was closed).
} if (info)
callbacks->OnSuccess(std::move(web_client)); window_client = ServiceWorkerWindowClient::Create(*info);
resolver->Resolve(window_client);
} }
} // namespace } // namespace
...@@ -138,18 +95,16 @@ void ServiceWorkerGlobalScopeClient::GetClients( ...@@ -138,18 +95,16 @@ void ServiceWorkerGlobalScopeClient::GetClients(
void ServiceWorkerGlobalScopeClient::OpenWindowForClients( void ServiceWorkerGlobalScopeClient::OpenWindowForClients(
const KURL& url, const KURL& url,
std::unique_ptr<WebServiceWorkerClientCallbacks> callbacks) { ScriptPromiseResolver* resolver) {
DCHECK(callbacks);
service_worker_host_->OpenNewTab( service_worker_host_->OpenNewTab(
url, WTF::Bind(&DidOpenWindow, std::move(callbacks))); url, WTF::Bind(&DidNavigateOrOpenWindow, WrapPersistent(resolver)));
} }
void ServiceWorkerGlobalScopeClient::OpenWindowForPaymentHandler( void ServiceWorkerGlobalScopeClient::OpenWindowForPaymentHandler(
const KURL& url, const KURL& url,
std::unique_ptr<WebServiceWorkerClientCallbacks> callbacks) { ScriptPromiseResolver* resolver) {
DCHECK(callbacks);
service_worker_host_->OpenPaymentHandlerWindow( service_worker_host_->OpenPaymentHandlerWindow(
url, WTF::Bind(&DidOpenWindow, std::move(callbacks))); url, WTF::Bind(&DidNavigateOrOpenWindow, WrapPersistent(resolver)));
} }
void ServiceWorkerGlobalScopeClient::SetCachedMetadata(const KURL& url, void ServiceWorkerGlobalScopeClient::SetCachedMetadata(const KURL& url,
...@@ -178,21 +133,17 @@ void ServiceWorkerGlobalScopeClient::Claim(ClaimCallback callback) { ...@@ -178,21 +133,17 @@ void ServiceWorkerGlobalScopeClient::Claim(ClaimCallback callback) {
service_worker_host_->ClaimClients(std::move(callback)); service_worker_host_->ClaimClients(std::move(callback));
} }
void ServiceWorkerGlobalScopeClient::Focus( void ServiceWorkerGlobalScopeClient::Focus(const String& client_uuid,
const String& client_uuid, FocusCallback callback) {
std::unique_ptr<WebServiceWorkerClientCallbacks> callbacks) { service_worker_host_->FocusClient(client_uuid, std::move(callback));
DCHECK(callbacks);
service_worker_host_->FocusClient(
client_uuid, WTF::Bind(&DidFocusClient, std::move(callbacks)));
} }
void ServiceWorkerGlobalScopeClient::Navigate( void ServiceWorkerGlobalScopeClient::Navigate(const String& client_uuid,
const String& client_uuid, const KURL& url,
const KURL& url, ScriptPromiseResolver* resolver) {
std::unique_ptr<WebServiceWorkerClientCallbacks> callbacks) {
DCHECK(callbacks);
service_worker_host_->NavigateClient( service_worker_host_->NavigateClient(
client_uuid, url, WTF::Bind(&DidNavigateClient, std::move(callbacks))); client_uuid, url,
WTF::Bind(&DidNavigateOrOpenWindow, WrapPersistent(resolver)));
} }
void ServiceWorkerGlobalScopeClient::DidHandleActivateEvent( void ServiceWorkerGlobalScopeClient::DidHandleActivateEvent(
......
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include "third_party/blink/public/common/messaging/transferable_message.h" #include "third_party/blink/public/common/messaging/transferable_message.h"
#include "third_party/blink/public/mojom/service_worker/service_worker.mojom-blink.h" #include "third_party/blink/public/mojom/service_worker/service_worker.mojom-blink.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom-blink.h" #include "third_party/blink/public/mojom/service_worker/service_worker_event_status.mojom-blink.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_info.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_stream_handle.h" #include "third_party/blink/public/platform/modules/service_worker/web_service_worker_stream_handle.h"
#include "third_party/blink/renderer/core/messaging/message_port.h" #include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h" #include "third_party/blink/renderer/core/workers/worker_clients.h"
...@@ -48,9 +47,10 @@ namespace blink { ...@@ -48,9 +47,10 @@ namespace blink {
struct WebPaymentHandlerResponse; struct WebPaymentHandlerResponse;
class ExecutionContext; class ExecutionContext;
class KURL;
class ScriptPromiseResolver;
class WebServiceWorkerContextClient; class WebServiceWorkerContextClient;
class WebServiceWorkerResponse; class WebServiceWorkerResponse;
class KURL;
class WorkerClients; class WorkerClients;
// See WebServiceWorkerContextClient for documentation for the methods in this // See WebServiceWorkerContextClient for documentation for the methods in this
...@@ -67,6 +67,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final ...@@ -67,6 +67,7 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final
using GetClientCallback = mojom::blink::ServiceWorkerHost::GetClientCallback; using GetClientCallback = mojom::blink::ServiceWorkerHost::GetClientCallback;
using GetClientsCallback = using GetClientsCallback =
mojom::blink::ServiceWorkerHost::GetClientsCallback; mojom::blink::ServiceWorkerHost::GetClientsCallback;
using FocusCallback = mojom::blink::ServiceWorkerHost::FocusClientCallback;
static const char kSupplementName[]; static const char kSupplementName[];
...@@ -76,21 +77,15 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final ...@@ -76,21 +77,15 @@ class MODULES_EXPORT ServiceWorkerGlobalScopeClient final
void GetClient(const String&, GetClientCallback); void GetClient(const String&, GetClientCallback);
void GetClients(mojom::blink::ServiceWorkerClientQueryOptionsPtr, void GetClients(mojom::blink::ServiceWorkerClientQueryOptionsPtr,
GetClientsCallback); GetClientsCallback);
void OpenWindowForClients(const KURL&, void OpenWindowForClients(const KURL&, ScriptPromiseResolver*);
std::unique_ptr<WebServiceWorkerClientCallbacks>); void OpenWindowForPaymentHandler(const KURL&, ScriptPromiseResolver*);
void OpenWindowForPaymentHandler(
const KURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>);
void SetCachedMetadata(const KURL&, const char*, size_t); void SetCachedMetadata(const KURL&, const char*, size_t);
void ClearCachedMetadata(const KURL&); void ClearCachedMetadata(const KURL&);
void PostMessageToClient(const String& client_uuid, BlinkTransferableMessage); void PostMessageToClient(const String& client_uuid, BlinkTransferableMessage);
void SkipWaiting(SkipWaitingCallback); void SkipWaiting(SkipWaitingCallback);
void Claim(ClaimCallback); void Claim(ClaimCallback);
void Focus(const String& client_uuid, void Focus(const String& client_uuid, FocusCallback);
std::unique_ptr<WebServiceWorkerClientCallbacks>); void Navigate(const String& client_uuid, const KURL&, ScriptPromiseResolver*);
void Navigate(const String& client_uuid,
const KURL&,
std::unique_ptr<WebServiceWorkerClientCallbacks>);
void DidHandleActivateEvent(int event_id, void DidHandleActivateEvent(int event_id,
mojom::ServiceWorkerEventStatus, mojom::ServiceWorkerEventStatus,
......
...@@ -16,24 +16,39 @@ ...@@ -16,24 +16,39 @@
#include "third_party/blink/renderer/core/workers/worker_location.h" #include "third_party/blink/renderer/core/workers/worker_location.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_error.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_error.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h" #include "third_party/blink/renderer/modules/service_worker/service_worker_global_scope_client.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client_callback.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h" #include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
namespace blink { namespace blink {
ServiceWorkerWindowClient* ServiceWorkerWindowClient::Take( namespace {
ScriptPromiseResolver*,
std::unique_ptr<WebServiceWorkerClientInfo> web_client) { void DidFocus(ScriptPromiseResolver* resolver,
return web_client ? ServiceWorkerWindowClient::Create(*web_client) : nullptr; mojom::blink::ServiceWorkerClientInfoPtr client) {
if (!resolver->GetExecutionContext() ||
resolver->GetExecutionContext()->IsContextDestroyed()) {
return;
}
if (!client) {
resolver->Reject(ServiceWorkerError::GetException(
resolver, mojom::blink::ServiceWorkerErrorType::kNotFound,
"The client was not found."));
return;
}
resolver->Resolve(ServiceWorkerWindowClient::Create(*client));
} }
} // namespace
ServiceWorkerWindowClient* ServiceWorkerWindowClient::Create( ServiceWorkerWindowClient* ServiceWorkerWindowClient::Create(
const WebServiceWorkerClientInfo& info) { const WebServiceWorkerClientInfo& info) {
DCHECK_EQ(mojom::blink::ServiceWorkerClientType::kWindow, info.client_type);
return new ServiceWorkerWindowClient(info); return new ServiceWorkerWindowClient(info);
} }
ServiceWorkerWindowClient* ServiceWorkerWindowClient::Create( ServiceWorkerWindowClient* ServiceWorkerWindowClient::Create(
const mojom::blink::ServiceWorkerClientInfo& info) { const mojom::blink::ServiceWorkerClientInfo& info) {
DCHECK_EQ(mojom::blink::ServiceWorkerClientType::kWindow, info.client_type);
return new ServiceWorkerWindowClient(info); return new ServiceWorkerWindowClient(info);
} }
...@@ -67,10 +82,7 @@ ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* script_state) { ...@@ -67,10 +82,7 @@ ScriptPromise ServiceWorkerWindowClient::focus(ScriptState* script_state) {
ExecutionContext::From(script_state)->ConsumeWindowInteraction(); ExecutionContext::From(script_state)->ConsumeWindowInteraction();
ServiceWorkerGlobalScopeClient::From(ExecutionContext::From(script_state)) ServiceWorkerGlobalScopeClient::From(ExecutionContext::From(script_state))
->Focus(Uuid(), ->Focus(Uuid(), WTF::Bind(&DidFocus, WrapPersistent(resolver)));
std::make_unique<CallbackPromiseAdapter<ServiceWorkerWindowClient,
ServiceWorkerError>>(
resolver));
return promise; return promise;
} }
...@@ -93,8 +105,8 @@ ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* script_state, ...@@ -93,8 +105,8 @@ ScriptPromise ServiceWorkerWindowClient::navigate(ScriptState* script_state,
return promise; return promise;
} }
ServiceWorkerGlobalScopeClient::From(context)->Navigate( ServiceWorkerGlobalScopeClient::From(context)->Navigate(Uuid(), parsed_url,
Uuid(), parsed_url, std::make_unique<NavigateClientCallback>(resolver)); resolver);
return promise; return promise;
} }
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
namespace blink { namespace blink {
class ScriptPromiseResolver;
class ScriptState; class ScriptState;
class MODULES_EXPORT ServiceWorkerWindowClient final class MODULES_EXPORT ServiceWorkerWindowClient final
...@@ -22,13 +21,6 @@ class MODULES_EXPORT ServiceWorkerWindowClient final ...@@ -22,13 +21,6 @@ class MODULES_EXPORT ServiceWorkerWindowClient final
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
// To be used by CallbackPromiseAdapter.
using WebType = std::unique_ptr<WebServiceWorkerClientInfo>;
static ServiceWorkerWindowClient* Take(
ScriptPromiseResolver*,
std::unique_ptr<WebServiceWorkerClientInfo>);
static ServiceWorkerWindowClient* Create(const WebServiceWorkerClientInfo&); static ServiceWorkerWindowClient* Create(const WebServiceWorkerClientInfo&);
static ServiceWorkerWindowClient* Create( static ServiceWorkerWindowClient* Create(
const mojom::blink::ServiceWorkerClientInfo&); const mojom::blink::ServiceWorkerClientInfo&);
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client_callback.h"
#include <memory>
#include "base/memory/ptr_util.h"
#include "third_party/blink/public/mojom/service_worker/service_worker_error_type.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_error.h"
#include "third_party/blink/renderer/modules/service_worker/service_worker_window_client.h"
#include "third_party/blink/renderer/platform/bindings/v8_throw_exception.h"
namespace blink {
void NavigateClientCallback::OnSuccess(
std::unique_ptr<WebServiceWorkerClientInfo> client_info) {
if (!resolver_->GetExecutionContext() ||
resolver_->GetExecutionContext()->IsContextDestroyed())
return;
resolver_->Resolve(ServiceWorkerWindowClient::Take(
resolver_.Get(), base::WrapUnique(client_info.release())));
}
void NavigateClientCallback::OnError(const WebServiceWorkerError& error) {
if (!resolver_->GetExecutionContext() ||
resolver_->GetExecutionContext()->IsContextDestroyed())
return;
if (error.error_type == mojom::blink::ServiceWorkerErrorType::kNavigation) {
ScriptState::Scope scope(resolver_->GetScriptState());
resolver_->Reject(V8ThrowException::CreateTypeError(
resolver_->GetScriptState()->GetIsolate(), error.message));
return;
}
resolver_->Reject(ServiceWorkerError::Take(resolver_.Get(), error));
}
} // namespace blink
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_WINDOW_CLIENT_CALLBACK_H_
#define THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_WINDOW_CLIENT_CALLBACK_H_
#include "base/macros.h"
#include "third_party/blink/public/platform/modules/service_worker/web_service_worker_clients_info.h"
#include "third_party/blink/renderer/platform/heap/persistent.h"
namespace blink {
class ScriptPromiseResolver;
class NavigateClientCallback : public WebServiceWorkerClientCallbacks {
public:
explicit NavigateClientCallback(ScriptPromiseResolver* resolver)
: resolver_(resolver) {}
void OnSuccess(std::unique_ptr<WebServiceWorkerClientInfo>) override;
void OnError(const WebServiceWorkerError&) override;
private:
Persistent<ScriptPromiseResolver> resolver_;
DISALLOW_COPY_AND_ASSIGN(NavigateClientCallback);
};
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SERVICE_WORKER_SERVICE_WORKER_WINDOW_CLIENT_CALLBACK_H_
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