/* -*- 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/. */
namespace ipc { class PrincipalInfo;
} // namespace ipc
namespace dom {
class ContentParent; class ServiceWorkerInfo; class ServiceWorkerJobQueue; class ServiceWorkerManagerChild; class ServiceWorkerPrivate; class ServiceWorkerRegistrar; class ServiceWorkerShutdownBlocker;
class ServiceWorkerUpdateFinishCallback { protected: virtual ~ServiceWorkerUpdateFinishCallback() = default;
/* * The ServiceWorkerManager is a per-process global that deals with the * installation, querying and event dispatch of ServiceWorkers for all the * origins in the process. * * NOTE: the following documentation is a WIP: * * The ServiceWorkerManager (SWM) is a main-thread, parent-process singleton * that encapsulates the browser-global state of service workers. This state * includes, but is not limited to, all service worker registrations and all * controlled service worker clients. The SWM also provides methods to read and * mutate this state and to dispatch operations (e.g. DOM events such as a * FetchEvent) to service workers. * * Example usage: * * MOZ_ASSERT(NS_IsMainThread(), "SWM is main-thread only"); * * RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance(); * * // Nullness must be checked by code that possibly executes during browser * // shutdown, which is when the SWM is destroyed. * if (swm) { * // Do something with the SWM. * }
*/ class ServiceWorkerManager final : public nsIServiceWorkerManager, public nsIObserver { friendclass GetRegistrationsRunnable; friendclass GetRegistrationRunnable; friendclass ServiceWorkerInfo; friendclass ServiceWorkerJob; friendclass ServiceWorkerRegistrationInfo; friendclass ServiceWorkerShutdownBlocker; friendclass ServiceWorkerUnregisterJob; friendclass ServiceWorkerUpdateJob; friendclass UpdateTimerCallback;
// Determine the correct lifetime extension to use for a given client. This // will work for ServiceWorker clients, but ideally you should have a // ServiceWorkerDescriptor in that case.
ServiceWorkerLifetimeExtension DetermineLifetimeForClient( const ClientInfo& aClientInfo);
// Determine the correct lifetime extension to use for a given client. This // will work for ServiceWorker clients, but ideally you should have a // ServiceWorkerDescriptor in that case.
ServiceWorkerLifetimeExtension DetermineLifetimeForServiceWorker( const ServiceWorkerDescriptor& aServiceWorker);
// Return true if the given principal and URI matches a registered service // worker which handles fetch event. // If there is a matched service worker but doesn't handle fetch events, this // method will try to set the matched service worker as the controller of the // passed in channel. Then also schedule a soft-update job for the service // worker. bool IsAvailable(nsIPrincipal* aPrincipal, nsIURI* aURI,
nsIChannel* aChannel);
/** * Report an error for the given scope to any window we think might be * interested, failing over to the Browser Console if we couldn't find any. * * Error messages should be localized, so you probably want to call * LocalizeAndReportToAllClients instead, which in turn calls us after * localizing the error.
*/ void ReportToAllClients(const nsCString& aScope, const nsString& aMessage, const nsCString& aFilename, const nsString& aLine,
uint32_t aLineNumber, uint32_t aColumnNumber,
uint32_t aFlags);
/** * Report a localized error for the given scope to any window we think might * be interested. * * Note that this method takes an nsTArray<nsString> for the parameters, not * bare chart16_t*[]. You can use a std::initializer_list constructor inline * so that argument might look like: nsTArray<nsString> { some_nsString, * PromiseFlatString(some_nsSubString_aka_nsAString), * NS_ConvertUTF8toUTF16(some_nsCString_or_nsCSubString), * u"some literal"_ns }. If you have anything else, like a * number, you can use an nsAutoString with AppendInt/friends. * * @param [aFlags] * The nsIScriptError flag, one of errorFlag (0x0), warningFlag (0x1), * infoFlag (0x8). We default to error if omitted because usually we're * logging exceptional and/or obvious breakage.
*/ staticvoid LocalizeAndReportToAllClients( const nsCString& aScope, constchar* aStringKey, const nsTArray<nsString>& aParamArray, uint32_t aFlags = 0x0, const nsCString& aFilename = ""_ns, const nsString& aLine = u""_ns,
uint32_t aLineNumber = 0, uint32_t aColumnNumber = 0);
// Always consumes the error by reporting to consoles of all controlled // documents. void HandleError(JSContext* aCx, nsIPrincipal* aPrincipal, const nsCString& aScope, const nsCString& aWorkerURL, const nsString& aMessage, const nsCString& aFilename, const nsString& aLine, uint32_t aLineNumber,
uint32_t aColumnNumber, uint32_t aFlags, JSExnType aExnType);
// Returns the shutdown state ID (may be an invalid ID if an // nsIAsyncShutdownBlocker is not used).
uint32_t MaybeInitServiceWorkerShutdownProgress() const;
// Record periodic telemetry on number of running ServiceWorkers. When // the number of running ServiceWorkers changes (or on shutdown), // ServiceWorkerPrivateImpl will call RecordTelemetry with the number of // running serviceworkers and those supporting Fetch. We use // mTelemetryLastChange to determine how many datapoints to inject into // Telemetry, and dispatch a background runnable to call // RecordTelemetryGap() and Accumulate them. void RecordTelemetry(uint32_t aNumber, uint32_t aFetch);
// Given the ClientInfo for a ServiceWorker global, return the corresponding // ServiceWorkerInfo, nullptr otherwise. Do not use this for clients for // globals that are not ServiceWorkers (and ideally you should be using // GetServiceWorkerByDescriptor instead).
ServiceWorkerInfo* GetServiceWorkerByClientInfo( const ClientInfo& aClientInfo) const;
// Given the ServiceWorkerDescriptor for a ServiceWorker, return the // corresponding nullptr otherwise.
ServiceWorkerInfo* GetServiceWorkerByDescriptor( const ServiceWorkerDescriptor& aServiceWorker) const;
// Find the ServiceWorkerRegistration whose scope best matches the URL of the // given window or worker client (for the origin of the client based on its // principal). This cannot be used with ServiceWorker ClientInfos.
already_AddRefed<ServiceWorkerRegistrationInfo>
GetServiceWorkerRegistrationInfo(const ClientInfo& aClientInfo) const;
// Find the ServiceWorkerRegistration whose scope best matches the provided // URL (for the origin of the given principal). // // Note that `GetRegistration` should be used in cases where you already have // an exact scope.
already_AddRefed<ServiceWorkerRegistrationInfo>
GetServiceWorkerRegistrationInfo(nsIPrincipal* aPrincipal,
nsIURI* aURI) const;
// Find the ServiceWorkerRegistration whose scope best matches the provided // URL for the origin encoded as a scope key that has been obtained from // PrincipToScopeKey.
already_AddRefed<ServiceWorkerRegistrationInfo>
GetServiceWorkerRegistrationInfo(const nsACString& aScopeKey,
nsIURI* aURI) const;
// Used by remove() and removeAll() when clearing history. // MUST ONLY BE CALLED FROM UnregisterIfMatchesHost! void ForceUnregister(RegistrationDataPerPrincipal* aRegistrationData,
ServiceWorkerRegistrationInfo* aRegistration);
// An "orphaned" registration is one that is unregistered and not controlling // clients. The ServiceWorkerManager must know about all orphaned // registrations to forcefully shutdown all Service Workers during browser // shutdown. void AddOrphanedRegistration(ServiceWorkerRegistrationInfo* aRegistration);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.