tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ServiceWorkerContainerParent.cpp (3893B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "ServiceWorkerContainerParent.h"
      8 
      9 #include "ServiceWorkerContainerProxy.h"
     10 #include "mozilla/dom/ClientInfo.h"
     11 
     12 namespace mozilla::dom {
     13 
     14 using mozilla::ipc::IPCResult;
     15 
     16 void ServiceWorkerContainerParent::ActorDestroy(ActorDestroyReason aReason) {
     17  if (mProxy) {
     18    mProxy->RevokeActor(this);
     19    mProxy = nullptr;
     20  }
     21 }
     22 
     23 IPCResult ServiceWorkerContainerParent::RecvRegister(
     24    const IPCClientInfo& aClientInfo, const nsACString& aScopeURL,
     25    const WorkerType& aType, const nsACString& aScriptURL,
     26    const ServiceWorkerUpdateViaCache& aUpdateViaCache,
     27    RegisterResolver&& aResolver) {
     28  if (!mProxy) {
     29    aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
     30    return IPC_OK();
     31  }
     32 
     33  mProxy
     34      ->Register(ClientInfo(aClientInfo), aScopeURL, aType, aScriptURL,
     35                 aUpdateViaCache)
     36      ->Then(
     37          GetCurrentSerialEventTarget(), __func__,
     38          [aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
     39            aResolver(aDescriptor.ToIPC());
     40          },
     41          [aResolver](const CopyableErrorResult& aResult) {
     42            aResolver(aResult);
     43          });
     44 
     45  return IPC_OK();
     46 }
     47 
     48 IPCResult ServiceWorkerContainerParent::RecvGetRegistration(
     49    const IPCClientInfo& aClientInfo, const nsACString& aURL,
     50    GetRegistrationResolver&& aResolver) {
     51  if (!mProxy) {
     52    aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
     53    return IPC_OK();
     54  }
     55 
     56  mProxy->GetRegistration(ClientInfo(aClientInfo), aURL)
     57      ->Then(
     58          GetCurrentSerialEventTarget(), __func__,
     59          [aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
     60            aResolver(aDescriptor.ToIPC());
     61          },
     62          [aResolver](const CopyableErrorResult& aResult) {
     63            aResolver(aResult);
     64          });
     65 
     66  return IPC_OK();
     67 }
     68 
     69 IPCResult ServiceWorkerContainerParent::RecvGetRegistrations(
     70    const IPCClientInfo& aClientInfo, GetRegistrationsResolver&& aResolver) {
     71  if (!mProxy) {
     72    aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
     73    return IPC_OK();
     74  }
     75 
     76  mProxy->GetRegistrations(ClientInfo(aClientInfo))
     77      ->Then(
     78          GetCurrentSerialEventTarget(), __func__,
     79          [aResolver](
     80              const nsTArray<ServiceWorkerRegistrationDescriptor>& aList) {
     81            IPCServiceWorkerRegistrationDescriptorList ipcList;
     82            for (auto& desc : aList) {
     83              ipcList.values().AppendElement(desc.ToIPC());
     84            }
     85            aResolver(std::move(ipcList));
     86          },
     87          [aResolver](const CopyableErrorResult& aResult) {
     88            aResolver(aResult);
     89          });
     90 
     91  return IPC_OK();
     92 }
     93 
     94 IPCResult ServiceWorkerContainerParent::RecvGetReady(
     95    const IPCClientInfo& aClientInfo, GetReadyResolver&& aResolver) {
     96  if (!mProxy) {
     97    aResolver(CopyableErrorResult(NS_ERROR_DOM_INVALID_STATE_ERR));
     98    return IPC_OK();
     99  }
    100 
    101  mProxy->GetReady(ClientInfo(aClientInfo))
    102      ->Then(
    103          GetCurrentSerialEventTarget(), __func__,
    104          [aResolver](const ServiceWorkerRegistrationDescriptor& aDescriptor) {
    105            aResolver(aDescriptor.ToIPC());
    106          },
    107          [aResolver](const CopyableErrorResult& aResult) {
    108            aResolver(aResult);
    109          });
    110 
    111  return IPC_OK();
    112 }
    113 
    114 ServiceWorkerContainerParent::ServiceWorkerContainerParent() = default;
    115 
    116 ServiceWorkerContainerParent::~ServiceWorkerContainerParent() {
    117  MOZ_DIAGNOSTIC_ASSERT(!mProxy);
    118 }
    119 
    120 void ServiceWorkerContainerParent::Init() {
    121  mProxy = new ServiceWorkerContainerProxy(this);
    122 }
    123 
    124 }  // namespace mozilla::dom