2018-01-24 17:47:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#ifndef _mozilla_dom_ServiceWorkerUtils_h
|
|
|
|
#define _mozilla_dom_ServiceWorkerUtils_h
|
|
|
|
|
2018-03-22 20:03:22 +00:00
|
|
|
#include "mozilla/MozPromise.h"
|
2021-06-10 06:01:27 +00:00
|
|
|
#include "mozilla/dom/IPCNavigationPreloadState.h"
|
2018-03-22 20:03:22 +00:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
|
2018-04-17 14:46:14 +00:00
|
|
|
#include "nsTArray.h"
|
2018-03-22 20:03:22 +00:00
|
|
|
|
2024-10-24 03:02:40 +00:00
|
|
|
class nsIGlobalObject;
|
2018-07-09 23:02:39 +00:00
|
|
|
class nsIURI;
|
|
|
|
|
2018-01-24 17:47:16 +00:00
|
|
|
namespace mozilla {
|
2018-04-23 16:46:53 +00:00
|
|
|
|
2018-07-09 23:02:39 +00:00
|
|
|
class CopyableErrorResult;
|
2020-11-23 16:21:38 +00:00
|
|
|
class ErrorResult;
|
2018-04-23 16:46:53 +00:00
|
|
|
|
2018-01-24 17:47:16 +00:00
|
|
|
namespace dom {
|
|
|
|
|
2018-07-09 23:02:39 +00:00
|
|
|
class ClientInfo;
|
2018-04-09 17:54:23 +00:00
|
|
|
class ServiceWorkerRegistrationData;
|
2018-03-22 20:03:22 +00:00
|
|
|
class ServiceWorkerRegistrationDescriptor;
|
2021-06-10 06:01:27 +00:00
|
|
|
struct NavigationPreloadState;
|
2018-03-22 20:03:22 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using ServiceWorkerRegistrationPromise =
|
|
|
|
MozPromise<ServiceWorkerRegistrationDescriptor, CopyableErrorResult, false>;
|
2018-03-22 20:03:22 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using ServiceWorkerRegistrationListPromise =
|
|
|
|
MozPromise<CopyableTArray<ServiceWorkerRegistrationDescriptor>,
|
|
|
|
CopyableErrorResult, false>;
|
2018-04-17 14:46:14 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using NavigationPreloadStatePromise =
|
|
|
|
MozPromise<IPCNavigationPreloadState, CopyableErrorResult, false>;
|
2021-06-10 06:01:27 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using ServiceWorkerRegistrationCallback =
|
|
|
|
std::function<void(const ServiceWorkerRegistrationDescriptor&)>;
|
2018-06-15 19:21:32 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using ServiceWorkerRegistrationListCallback =
|
|
|
|
std::function<void(const nsTArray<ServiceWorkerRegistrationDescriptor>&)>;
|
2018-06-15 19:21:33 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using ServiceWorkerBoolCallback = std::function<void(bool)>;
|
2018-06-15 19:21:33 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using ServiceWorkerFailureCallback = std::function<void(ErrorResult&&)>;
|
2018-06-15 19:21:32 +00:00
|
|
|
|
2021-08-11 14:41:34 +00:00
|
|
|
using NavigationPreloadGetStateCallback =
|
|
|
|
std::function<void(NavigationPreloadState&&)>;
|
2021-06-10 06:01:27 +00:00
|
|
|
|
2018-04-09 17:54:23 +00:00
|
|
|
bool ServiceWorkerRegistrationDataIsValid(
|
|
|
|
const ServiceWorkerRegistrationData& aData);
|
|
|
|
|
2024-10-24 03:02:40 +00:00
|
|
|
// Performs key spec validation steps of
|
|
|
|
// https://w3c.github.io/ServiceWorker/#start-register-algorithm and
|
|
|
|
// https://w3c.github.io/ServiceWorker/#register-algorithm as well as CSP
|
|
|
|
// validation corresponding to
|
|
|
|
// https://w3c.github.io/webappsec-csp/#directive-worker-src.
|
|
|
|
//
|
|
|
|
// This is extracted out of ServiceWorkerContainer::Register because we validate
|
|
|
|
// both in the content process as the site of the call, as well as in the parent
|
|
|
|
// process in the ServiceWorkerManager.
|
|
|
|
//
|
|
|
|
// On worker threads, this will involve use of a syncloop until Bug 1901387 is
|
|
|
|
// addressed, allowing us to call CheckMayLoad off main-thread (OMT).
|
|
|
|
//
|
|
|
|
// A global may be optionally provided for reporting purposes; this is desired
|
|
|
|
// when this is used by ServiceWorkerContainer::Register but not necessary in
|
|
|
|
// the parent process.
|
|
|
|
void ServiceWorkerScopeAndScriptAreValid(
|
|
|
|
const ClientInfo& aClientInfo, nsIURI* aScopeURI, nsIURI* aScriptURI,
|
|
|
|
ErrorResult& aRv, nsIGlobalObject* aGlobalForReporting = nullptr);
|
2018-04-23 16:46:55 +00:00
|
|
|
|
2023-02-01 19:36:09 +00:00
|
|
|
bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
|
2018-01-24 17:47:16 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // _mozilla_dom_ServiceWorkerUtils_h
|