| Index: third_party/WebKit/Source/web/ServiceWorkerGlobalScopeClientImpl.cpp
|
| diff --git a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeClientImpl.cpp b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeClientImpl.cpp
|
| index 17ed8e58f48fac253bfbb83480cfb8dfeb8bb339..a96544cf3b0a8b997b09b675e515f720c044d1dd 100644
|
| --- a/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeClientImpl.cpp
|
| +++ b/third_party/WebKit/Source/web/ServiceWorkerGlobalScopeClientImpl.cpp
|
| @@ -31,20 +31,45 @@
|
| #include "web/ServiceWorkerGlobalScopeClientImpl.h"
|
|
|
| #include "modules/fetch/Response.h"
|
| +#include "modules/serviceworkers/FetchEvent.h"
|
| +#include "modules/serviceworkers/ForeignFetchEvent.h"
|
| +#include "modules/serviceworkers/WaitUntilObserver.h"
|
| +#include "platform/heap/ThreadState.h"
|
| +#include "public/platform/ServiceRegistry.h"
|
| #include "public/platform/WebURL.h"
|
| +#include "public/platform/modules/serviceworker/WebServiceWorkerRequest.h"
|
| #include "public/platform/modules/serviceworker/WebServiceWorkerResponse.h"
|
| #include "public/web/modules/serviceworker/WebServiceWorkerContextClient.h"
|
| #include <memory>
|
|
|
| +namespace {
|
| +void printIsMainThread_internal(const char* pretty_function, int line) {
|
| + LOG(ERROR) << "[" << pretty_function << ":" << line << "] "
|
| + << ((blink::ThreadState::current()->isMainThread()) ? "true" : "false");
|
| +}
|
| +}
|
| +#define printIsMainThread() printIsMainThread_internal(__PRETTY_FUNCTION__, __LINE__)
|
| +#define cerrWithHeader() LOG(ERROR) << "[" << __PRETTY_FUNCTION__ << ":" << __LINE__ << "] "
|
| +
|
| +
|
| namespace blink {
|
|
|
| ServiceWorkerGlobalScopeClient* ServiceWorkerGlobalScopeClientImpl::create(WebServiceWorkerContextClient& client)
|
| {
|
| + printIsMainThread();
|
| return new ServiceWorkerGlobalScopeClientImpl(client);
|
| }
|
|
|
| ServiceWorkerGlobalScopeClientImpl::~ServiceWorkerGlobalScopeClientImpl()
|
| {
|
| + printIsMainThread();
|
| +}
|
| +
|
| +void ServiceWorkerGlobalScopeClientImpl::dispose()
|
| +{
|
| + printIsMainThread();
|
| + m_clientBinding->Close();
|
| + m_hostProcess.reset();
|
| }
|
|
|
| void ServiceWorkerGlobalScopeClientImpl::getClient(const WebString& id, WebServiceWorkerClientCallbacks* callbacks)
|
| @@ -77,6 +102,16 @@ WebURL ServiceWorkerGlobalScopeClientImpl::scope() const
|
| return m_client.scope();
|
| }
|
|
|
| +void ServiceWorkerGlobalScopeClientImpl::didInitializeContext(ServiceWorkerGlobalScope* parent) {
|
| + // This should be reclaimed on the worker thread
|
| + ThreadState::current()->registerPreFinalizer(this);
|
| + printIsMainThread();
|
| + m_parent = parent;
|
| + m_clientBinding.reset(new mojo::Binding<mojom::blink::ServiceWorkerGlobalScopeClient>(this));
|
| + m_client.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_hostProcess));
|
| + m_hostProcess->SetClient(m_clientBinding->CreateInterfacePtrAndBind());
|
| +}
|
| +
|
| void ServiceWorkerGlobalScopeClientImpl::didHandleActivateEvent(int eventID, WebServiceWorkerEventResult result)
|
| {
|
| m_client.didHandleActivateEvent(eventID, result);
|
| @@ -89,17 +124,39 @@ void ServiceWorkerGlobalScopeClientImpl::didHandleExtendableMessageEvent(int eve
|
|
|
| void ServiceWorkerGlobalScopeClientImpl::respondToFetchEvent(int responseID)
|
| {
|
| + if (m_fetchCallbacks.contains(responseID)) {
|
| + LOG(ERROR) << "MOJOMOJOMOJO respond: fallback";
|
| + auto callback = m_fetchCallbacks.take(responseID);
|
| + callback.Run(false, nullptr);
|
| + return;
|
| + }
|
| +
|
| m_client.respondToFetchEvent(responseID);
|
| }
|
|
|
| void ServiceWorkerGlobalScopeClientImpl::respondToFetchEvent(int responseID, const WebServiceWorkerResponse& response)
|
| {
|
| - m_client.respondToFetchEvent(responseID, response);
|
| + if (m_fetchCallbacks.contains(responseID)) {
|
| + LOG(ERROR) << "MOJOMOJOMOJO respond: response";
|
| + auto callback = m_fetchCallbacks.take(responseID);
|
| + auto mojoResponse = mojom::blink::ServiceWorkerResponse::New();
|
| + mojoResponse->url = response.url().string();
|
| + mojoResponse->status_code = response.status();
|
| + mojoResponse->status_text = response.statusText();
|
| + mojoResponse->blob_uuid = response.blobUUID();
|
| + mojoResponse->blob_size = response.blobSize();
|
| + mojoResponse->stream_url = response.streamURL().string();
|
| + callback.Run(true, std::move(mojoResponse));
|
| + return;
|
| + }
|
| +
|
| + m_client.respondToFetchEvent(responseID, response);
|
| }
|
|
|
| void ServiceWorkerGlobalScopeClientImpl::didHandleFetchEvent(int eventFinishID, WebServiceWorkerEventResult result)
|
| {
|
| - m_client.didHandleFetchEvent(eventFinishID, result);
|
| + m_hostProcess->DidHandleSimpleEvent(eventFinishID, result);
|
| + // m_client.didHandleFetchEvent(eventFinishID, result);
|
| }
|
|
|
| void ServiceWorkerGlobalScopeClientImpl::didHandleInstallEvent(int installEventID, WebServiceWorkerEventResult result)
|
| @@ -162,9 +219,55 @@ void ServiceWorkerGlobalScopeClientImpl::registerForeignFetchScopes(const WebVec
|
| m_client.registerForeignFetchScopes(subScopes, origins);
|
| }
|
|
|
| +void ServiceWorkerGlobalScopeClientImpl::DispatchPingEvent(const WTF::String& message)
|
| +{
|
| + LOG(ERROR) << __PRETTY_FUNCTION__;
|
| + return;
|
| +}
|
| +
|
| +void ServiceWorkerGlobalScopeClientImpl::DispatchFetchEvent(int responseID, int eventFinishID, mojom::blink::ServiceWorkerFetchRequestPtr mojoRequest, const DispatchFetchEventCallback& callback) {
|
| + LOG(ERROR) << "(request: " << mojoRequest->url.getString().ascii().data() << ")";
|
| +
|
| + m_fetchCallbacks.set(responseID, callback);
|
| +
|
| + WebServiceWorkerRequest webRequest;
|
| + ScriptState::Scope scope(workerGlobalScope()->scriptController()->getScriptState());
|
| + WaitUntilObserver* waitUntilObserver = WaitUntilObserver::create(workerGlobalScope(), WaitUntilObserver::Fetch, eventFinishID);
|
| + RespondWithObserver* respondWithObserver = RespondWithObserver::create(workerGlobalScope(), responseID, webRequest.url(), webRequest.mode(), webRequest.frameType(), webRequest.requestContext(), waitUntilObserver);
|
| + Request* request = Request::create(workerGlobalScope()->scriptController()->getScriptState(), webRequest);
|
| + request->getHeaders()->setGuard(Headers::ImmutableGuard);
|
| + FetchEventInit eventInit;
|
| + eventInit.setCancelable(true);
|
| + eventInit.setRequest(request);
|
| + eventInit.setClientId(webRequest.isMainResourceLoad() ? WebString() : webRequest.clientId());
|
| + eventInit.setIsReload(webRequest.isReload());
|
| + FetchEvent* fetchEvent = FetchEvent::create(workerGlobalScope()->scriptController()->getScriptState(), EventTypeNames::fetch, eventInit, respondWithObserver, waitUntilObserver);
|
| + waitUntilObserver->willDispatchEvent();
|
| + DispatchEventResult dispatchResult = workerGlobalScope()->dispatchEvent(fetchEvent);
|
| + respondWithObserver->didDispatchEvent(dispatchResult);
|
| + // false is okay because waitUntil for fetch event doesn't care about the
|
| + // promise rejection or an uncaught runtime script error.
|
| + waitUntilObserver->didDispatchEvent(false /* errorOccurred */);
|
| +}
|
| +
|
| +
|
| ServiceWorkerGlobalScopeClientImpl::ServiceWorkerGlobalScopeClientImpl(WebServiceWorkerContextClient& client)
|
| : m_client(client)
|
| {
|
| }
|
|
|
| +mojom::blink::ServiceWorkerGlobalScopeHostPtr& ServiceWorkerGlobalScopeClientImpl::hostProcess()
|
| +{
|
| + if (!m_hostProcess) {
|
| + m_client.serviceRegistry()->connectToRemoteService(mojo::GetProxy(&m_hostProcess));
|
| + m_hostProcess->SetClient(m_clientBinding->CreateInterfacePtrAndBind());
|
| + }
|
| + return m_hostProcess;
|
| +}
|
| +
|
| +ServiceWorkerGlobalScope* ServiceWorkerGlobalScopeClientImpl::workerGlobalScope()
|
| +{
|
| + return m_parent.get();
|
| +}
|
| +
|
| } // namespace blink
|
|
|