2017-11-09 08:19:59 +03: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/. */
|
|
|
|
|
|
|
|
#include "ClientSource.h"
|
|
|
|
|
|
|
|
#include "ClientManager.h"
|
|
|
|
#include "ClientManagerChild.h"
|
2018-02-28 21:32:50 +03:00
|
|
|
#include "ClientPrincipalUtils.h"
|
2017-11-09 08:19:59 +03:00
|
|
|
#include "ClientSourceChild.h"
|
2017-12-06 04:45:23 +03:00
|
|
|
#include "ClientState.h"
|
2017-11-14 22:36:45 +03:00
|
|
|
#include "ClientValidation.h"
|
2019-07-26 21:39:58 +03:00
|
|
|
#include "mozilla/dom/BlobURLProtocolHandler.h"
|
2017-11-09 08:19:59 +03:00
|
|
|
#include "mozilla/dom/ClientIPCTypes.h"
|
2018-05-02 16:29:27 +03:00
|
|
|
#include "mozilla/dom/DOMMozPromiseRequestHolder.h"
|
2017-12-08 22:46:43 +03:00
|
|
|
#include "mozilla/dom/ipc/StructuredCloneData.h"
|
|
|
|
#include "mozilla/dom/MessageEvent.h"
|
|
|
|
#include "mozilla/dom/MessageEventBinding.h"
|
|
|
|
#include "mozilla/dom/Navigator.h"
|
2017-11-14 22:36:45 +03:00
|
|
|
#include "mozilla/dom/WorkerPrivate.h"
|
2017-12-08 22:46:43 +03:00
|
|
|
#include "mozilla/dom/WorkerScope.h"
|
2019-07-26 21:39:58 +03:00
|
|
|
#include "mozilla/dom/WorkerRef.h"
|
2018-01-27 00:08:59 +03:00
|
|
|
#include "mozilla/dom/ServiceWorker.h"
|
2017-12-08 22:46:43 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerContainer.h"
|
2018-01-27 00:08:59 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerManager.h"
|
2019-05-27 17:06:49 +03:00
|
|
|
#include "mozilla/StorageAccess.h"
|
2019-05-22 02:14:27 +03:00
|
|
|
#include "nsIContentSecurityPolicy.h"
|
2017-12-08 22:46:43 +03:00
|
|
|
#include "nsContentUtils.h"
|
2019-06-03 22:42:28 +03:00
|
|
|
#include "nsFocusManager.h"
|
2017-11-14 22:36:45 +03:00
|
|
|
#include "nsIDocShell.h"
|
|
|
|
#include "nsPIDOMWindow.h"
|
2017-11-09 08:19:59 +03:00
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2017-12-08 22:46:43 +03:00
|
|
|
using mozilla::dom::ipc::StructuredCloneData;
|
2019-05-22 02:14:27 +03:00
|
|
|
using mozilla::ipc::CSPInfo;
|
|
|
|
using mozilla::ipc::CSPToCSPInfo;
|
2017-11-09 08:19:59 +03:00
|
|
|
using mozilla::ipc::PrincipalInfo;
|
2017-12-08 22:46:43 +03:00
|
|
|
using mozilla::ipc::PrincipalInfoToPrincipal;
|
2017-11-09 08:19:59 +03:00
|
|
|
|
|
|
|
void ClientSource::Shutdown() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
if (IsShutdown()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ShutdownThing();
|
|
|
|
|
|
|
|
mManager = nullptr;
|
|
|
|
}
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
void ClientSource::ExecutionReady(const ClientSourceExecutionReadyArgs& aArgs) {
|
|
|
|
// Fast fail if we don't understand this particular principal/URL combination.
|
|
|
|
// This can happen since we use MozURL for validation which does not handle
|
|
|
|
// some of the more obscure internal principal/url combinations. Normal
|
|
|
|
// content pages will pass this check.
|
|
|
|
if (NS_WARN_IF(!ClientIsValidCreationURL(mClientInfo.PrincipalInfo(),
|
|
|
|
aArgs.url()))) {
|
|
|
|
Shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mClientInfo.SetURL(aArgs.url());
|
|
|
|
mClientInfo.SetFrameType(aArgs.frameType());
|
|
|
|
MaybeExecute([aArgs](PClientSourceChild* aActor) {
|
|
|
|
aActor->SendExecutionReady(aArgs);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
Result<ClientState, ErrorResult> ClientSource::SnapshotWindowState() {
|
2017-12-06 04:45:23 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsPIDOMWindowInner* window = GetInnerWindow();
|
|
|
|
if (!window || !window->IsCurrentInnerWindow() ||
|
|
|
|
!window->HasActiveDocument()) {
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientState(ClientWindowState(VisibilityState::Hidden, TimeStamp(),
|
|
|
|
StorageAccess::eDeny, false));
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = window->GetExtantDoc();
|
2020-01-30 12:01:26 +03:00
|
|
|
ErrorResult rv;
|
2017-12-06 04:45:23 +03:00
|
|
|
if (NS_WARN_IF(!doc)) {
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowInvalidStateError("Document not active");
|
2020-01-30 12:01:26 +03:00
|
|
|
return Err(std::move(rv));
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool focused = doc->HasFocus(rv);
|
|
|
|
if (NS_WARN_IF(rv.Failed())) {
|
2020-01-30 12:01:26 +03:00
|
|
|
return Err(std::move(rv));
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
2019-05-27 17:06:49 +03:00
|
|
|
StorageAccess storage = StorageAllowedForDocument(doc);
|
2017-12-12 23:44:46 +03:00
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientState(ClientWindowState(doc->VisibilityState(),
|
|
|
|
doc->LastFocusTime(), storage, focused));
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
WorkerPrivate* ClientSource::GetWorkerPrivate() const {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
if (!mOwner.is<WorkerPrivate*>()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mOwner.as<WorkerPrivate*>();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocShell* ClientSource::GetDocShell() const {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
if (!mOwner.is<nsCOMPtr<nsIDocShell>>()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mOwner.as<nsCOMPtr<nsIDocShell>>();
|
|
|
|
}
|
|
|
|
|
2018-06-28 22:58:23 +03:00
|
|
|
nsIGlobalObject* ClientSource::GetGlobal() const {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
nsPIDOMWindowInner* win = GetInnerWindow();
|
|
|
|
if (win) {
|
|
|
|
return win->AsGlobal();
|
|
|
|
}
|
|
|
|
|
|
|
|
WorkerPrivate* wp = GetWorkerPrivate();
|
|
|
|
if (wp) {
|
|
|
|
return wp->GlobalScope();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note, ClientSource objects attached to docshell for conceptual
|
|
|
|
// initial about:blank will get nullptr here. The caller should
|
|
|
|
// use MaybeCreateIntitialDocument() to create the window before
|
|
|
|
// GetGlobal() if it wants this before.
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-06 04:45:23 +03:00
|
|
|
void ClientSource::MaybeCreateInitialDocument() {
|
|
|
|
nsIDocShell* docshell = GetDocShell();
|
|
|
|
if (docshell) {
|
|
|
|
// Force the create of the initial document if it does not exist yet.
|
|
|
|
Unused << docshell->GetDocument();
|
|
|
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(GetInnerWindow());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
ClientSource::ClientSource(ClientManager* aManager,
|
2017-11-16 21:15:10 +03:00
|
|
|
nsISerialEventTarget* aEventTarget,
|
2017-11-09 08:19:59 +03:00
|
|
|
const ClientSourceConstructorArgs& aArgs)
|
|
|
|
: mManager(aManager),
|
2017-11-16 21:15:10 +03:00
|
|
|
mEventTarget(aEventTarget),
|
2017-11-14 22:36:45 +03:00
|
|
|
mOwner(AsVariant(Nothing())),
|
2017-11-09 08:19:59 +03:00
|
|
|
mClientInfo(aArgs.id(), aArgs.type(), aArgs.principalInfo(),
|
|
|
|
aArgs.creationTime()) {
|
|
|
|
MOZ_ASSERT(mManager);
|
2017-11-16 21:15:10 +03:00
|
|
|
MOZ_ASSERT(mEventTarget);
|
2017-11-09 08:19:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClientSource::Activate(PClientManagerChild* aActor) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
MOZ_ASSERT(!GetActor());
|
|
|
|
|
|
|
|
if (IsShutdown()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
// Fast fail if we don't understand this particular kind of PrincipalInfo.
|
|
|
|
// This can happen since we use MozURL for validation which does not handle
|
|
|
|
// some of the more obscure internal principal/url combinations. Normal
|
|
|
|
// content pages will pass this check.
|
|
|
|
if (NS_WARN_IF(!ClientIsValidPrincipalInfo(mClientInfo.PrincipalInfo()))) {
|
|
|
|
Shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
ClientSourceConstructorArgs args(mClientInfo.Id(), mClientInfo.Type(),
|
|
|
|
mClientInfo.PrincipalInfo(),
|
|
|
|
mClientInfo.CreationTime());
|
|
|
|
PClientSourceChild* actor = aActor->SendPClientSourceConstructor(args);
|
|
|
|
if (!actor) {
|
|
|
|
Shutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ActivateThing(static_cast<ClientSourceChild*>(actor));
|
|
|
|
}
|
|
|
|
|
|
|
|
ClientSource::~ClientSource() { Shutdown(); }
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
nsPIDOMWindowInner* ClientSource::GetInnerWindow() const {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
if (!mOwner.is<RefPtr<nsPIDOMWindowInner>>()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mOwner.as<RefPtr<nsPIDOMWindowInner>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientSource::WorkerExecutionReady(WorkerPrivate* aWorkerPrivate) {
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate);
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
|
2017-12-08 19:52:06 +03:00
|
|
|
if (IsShutdown()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-05 20:10:22 +03:00
|
|
|
// A client without access to storage should never be controlled by
|
|
|
|
// a service worker. Check this here in case we were controlled before
|
|
|
|
// execution ready. We can't reliably determine what our storage policy
|
|
|
|
// is before execution ready, unfortunately.
|
|
|
|
if (mController.isSome()) {
|
2019-04-12 08:31:40 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate->StorageAccess() >
|
2019-05-27 17:06:49 +03:00
|
|
|
StorageAccess::ePrivateBrowsing ||
|
2018-03-01 19:13:56 +03:00
|
|
|
StringBeginsWith(aWorkerPrivate->ScriptURL(),
|
|
|
|
NS_LITERAL_STRING("blob:")));
|
2018-01-05 20:10:22 +03:00
|
|
|
}
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
// Its safe to store the WorkerPrivate* here because the ClientSource
|
|
|
|
// is explicitly destroyed by WorkerPrivate before exiting its run loop.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mOwner.is<Nothing>());
|
|
|
|
mOwner = AsVariant(aWorkerPrivate);
|
|
|
|
|
|
|
|
ClientSourceExecutionReadyArgs args(aWorkerPrivate->GetLocationInfo().mHref,
|
|
|
|
FrameType::None);
|
|
|
|
|
|
|
|
ExecutionReady(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult ClientSource::WindowExecutionReady(nsPIDOMWindowInner* aInnerWindow) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aInnerWindow);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aInnerWindow->IsCurrentInnerWindow());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aInnerWindow->HasActiveDocument());
|
|
|
|
|
2017-12-08 19:52:06 +03:00
|
|
|
if (IsShutdown()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* doc = aInnerWindow->GetExtantDoc();
|
2018-03-01 19:13:56 +03:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
nsIURI* uri = doc->GetOriginalURI();
|
|
|
|
NS_ENSURE_TRUE(uri, NS_ERROR_UNEXPECTED);
|
|
|
|
|
|
|
|
// Don't use nsAutoCString here since IPC requires a full nsCString anyway.
|
|
|
|
nsCString spec;
|
|
|
|
nsresult rv = uri->GetSpec(spec);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-11-14 22:36:45 +03:00
|
|
|
|
2018-01-05 20:10:22 +03:00
|
|
|
// A client without access to storage should never be controlled by
|
|
|
|
// a service worker. Check this here in case we were controlled before
|
|
|
|
// execution ready. We can't reliably determine what our storage policy
|
|
|
|
// is before execution ready, unfortunately.
|
2018-03-01 19:13:56 +03:00
|
|
|
//
|
|
|
|
// Note, explicitly avoid checking storage policy for windows that inherit
|
|
|
|
// service workers from their parent. If a user opens a controlled window
|
|
|
|
// and then blocks storage, that window will continue to be controlled by
|
|
|
|
// the SW until the window is closed. Any about:blank or blob URL should
|
|
|
|
// continue to inherit the SW as well. We need to avoid triggering the
|
|
|
|
// assertion in this corner case.
|
2018-01-05 20:10:22 +03:00
|
|
|
if (mController.isSome()) {
|
2019-05-27 17:06:49 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(spec.LowerCaseEqualsLiteral("about:blank") ||
|
|
|
|
StringBeginsWith(spec, NS_LITERAL_CSTRING("blob:")) ||
|
|
|
|
StorageAllowedForWindow(aInnerWindow) ==
|
|
|
|
StorageAccess::eAllow);
|
2018-01-05 20:10:22 +03:00
|
|
|
}
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
nsPIDOMWindowOuter* outer = aInnerWindow->GetOuterWindow();
|
2018-03-01 19:13:56 +03:00
|
|
|
NS_ENSURE_TRUE(outer, NS_ERROR_UNEXPECTED);
|
2017-11-14 22:36:45 +03:00
|
|
|
|
|
|
|
FrameType frameType = FrameType::Top_level;
|
|
|
|
if (!outer->IsTopLevelWindow()) {
|
|
|
|
frameType = FrameType::Nested;
|
|
|
|
} else if (outer->HadOriginalOpener()) {
|
|
|
|
frameType = FrameType::Auxiliary;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We should either be setting a window execution ready for the
|
|
|
|
// first time or setting the same window execution ready again.
|
|
|
|
// The secondary calls are due to initial about:blank replacement.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mOwner.is<Nothing>() ||
|
|
|
|
mOwner.is<nsCOMPtr<nsIDocShell>>() ||
|
|
|
|
GetInnerWindow() == aInnerWindow);
|
|
|
|
|
|
|
|
// This creates a cycle with the window. It is broken when
|
|
|
|
// nsGlobalWindow::FreeInnerObjects() deletes the ClientSource.
|
|
|
|
mOwner = AsVariant(RefPtr<nsPIDOMWindowInner>(aInnerWindow));
|
|
|
|
|
|
|
|
ClientSourceExecutionReadyArgs args(spec, frameType);
|
|
|
|
ExecutionReady(args);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult ClientSource::DocShellExecutionReady(nsIDocShell* aDocShell) {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aDocShell);
|
|
|
|
|
2017-12-08 19:52:06 +03:00
|
|
|
if (IsShutdown()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
nsPIDOMWindowOuter* outer = aDocShell->GetWindow();
|
|
|
|
if (NS_WARN_IF(!outer)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2018-01-05 20:10:22 +03:00
|
|
|
// Note: We don't assert storage access for a controlled client. If
|
|
|
|
// the about:blank actually gets used then WindowExecutionReady() will
|
|
|
|
// get called which asserts storage access.
|
|
|
|
|
2017-11-14 22:36:45 +03:00
|
|
|
// TODO: dedupe this with WindowExecutionReady
|
|
|
|
FrameType frameType = FrameType::Top_level;
|
|
|
|
if (!outer->IsTopLevelWindow()) {
|
|
|
|
frameType = FrameType::Nested;
|
|
|
|
} else if (outer->HadOriginalOpener()) {
|
|
|
|
frameType = FrameType::Auxiliary;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mOwner.is<Nothing>());
|
|
|
|
|
|
|
|
// This creates a cycle with the docshell. It is broken when
|
|
|
|
// nsDocShell::Destroy() deletes the ClientSource.
|
|
|
|
mOwner = AsVariant(nsCOMPtr<nsIDocShell>(aDocShell));
|
|
|
|
|
|
|
|
ClientSourceExecutionReadyArgs args(NS_LITERAL_CSTRING("about:blank"),
|
|
|
|
frameType);
|
|
|
|
ExecutionReady(args);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-11-21 23:13:05 +03:00
|
|
|
void ClientSource::Freeze() {
|
|
|
|
MaybeExecute([](PClientSourceChild* aActor) { aActor->SendFreeze(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientSource::Thaw() {
|
|
|
|
MaybeExecute([](PClientSourceChild* aActor) { aActor->SendThaw(); });
|
|
|
|
}
|
|
|
|
|
2017-11-16 21:15:09 +03:00
|
|
|
const ClientInfo& ClientSource::Info() const { return mClientInfo; }
|
|
|
|
|
2017-12-06 04:45:22 +03:00
|
|
|
void ClientSource::WorkerSyncPing(WorkerPrivate* aWorkerPrivate) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate);
|
2017-12-08 19:52:06 +03:00
|
|
|
|
|
|
|
if (IsShutdown()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-06 04:45:22 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(aWorkerPrivate == mManager->GetWorkerPrivate());
|
|
|
|
aWorkerPrivate->AssertIsOnWorkerThread();
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(GetActor());
|
2017-12-08 19:52:06 +03:00
|
|
|
|
2017-12-06 04:45:22 +03:00
|
|
|
GetActor()->SendWorkerSyncPing();
|
|
|
|
}
|
|
|
|
|
2017-12-05 22:54:10 +03:00
|
|
|
void ClientSource::SetController(
|
|
|
|
const ServiceWorkerDescriptor& aServiceWorker) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
|
2018-02-28 21:32:50 +03:00
|
|
|
// We should never have a cross-origin controller. Since this would be
|
|
|
|
// same-origin policy violation we do a full release assertion here.
|
|
|
|
MOZ_RELEASE_ASSERT(ClientMatchPrincipalInfo(mClientInfo.PrincipalInfo(),
|
|
|
|
aServiceWorker.PrincipalInfo()));
|
|
|
|
|
2017-12-20 18:53:19 +03:00
|
|
|
// A client in private browsing mode should never be controlled by
|
|
|
|
// a service worker. The principal origin attributes should guarantee
|
|
|
|
// this invariant.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!mClientInfo.IsPrivateBrowsing());
|
|
|
|
|
2018-01-05 20:10:22 +03:00
|
|
|
// A client without access to storage should never be controlled a
|
|
|
|
// a service worker. If we are already execution ready with a real
|
|
|
|
// window or worker, then verify assert the storage policy is correct.
|
2018-03-01 19:13:56 +03:00
|
|
|
//
|
|
|
|
// Note, explicitly avoid checking storage policy for clients that inherit
|
|
|
|
// service workers from their parent. This basically means blob: URLs
|
|
|
|
// and about:blank windows.
|
2018-01-05 20:10:22 +03:00
|
|
|
if (GetInnerWindow()) {
|
2018-03-01 19:13:56 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(
|
|
|
|
Info().URL().LowerCaseEqualsLiteral("about:blank") ||
|
|
|
|
StringBeginsWith(Info().URL(), NS_LITERAL_CSTRING("blob:")) ||
|
2019-05-27 17:06:49 +03:00
|
|
|
StorageAllowedForWindow(GetInnerWindow()) == StorageAccess::eAllow);
|
2018-03-01 12:55:28 +03:00
|
|
|
} else if (GetWorkerPrivate()) {
|
2019-04-12 08:31:40 +03:00
|
|
|
MOZ_DIAGNOSTIC_ASSERT(GetWorkerPrivate()->StorageAccess() >
|
2019-05-27 17:06:49 +03:00
|
|
|
StorageAccess::ePrivateBrowsing ||
|
2018-03-01 19:13:56 +03:00
|
|
|
StringBeginsWith(GetWorkerPrivate()->ScriptURL(),
|
|
|
|
NS_LITERAL_STRING("blob:")));
|
2018-01-05 20:10:22 +03:00
|
|
|
}
|
|
|
|
|
2017-12-05 22:54:10 +03:00
|
|
|
if (mController.isSome() && mController.ref() == aServiceWorker) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mController.reset();
|
|
|
|
mController.emplace(aServiceWorker);
|
2017-12-12 23:44:48 +03:00
|
|
|
|
|
|
|
RefPtr<ServiceWorkerContainer> swc;
|
|
|
|
nsPIDOMWindowInner* window = GetInnerWindow();
|
|
|
|
if (window) {
|
2018-01-22 20:59:15 +03:00
|
|
|
swc = window->Navigator()->ServiceWorker();
|
2017-12-12 23:44:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Also self.navigator.serviceWorker on workers when its exposed there
|
|
|
|
|
|
|
|
if (swc && nsContentUtils::IsSafeToRunScript()) {
|
2018-02-01 22:21:14 +03:00
|
|
|
swc->ControllerChanged(IgnoreErrors());
|
2017-12-12 23:44:48 +03:00
|
|
|
}
|
2017-12-05 22:54:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ClientOpPromise> ClientSource::Control(
|
|
|
|
const ClientControlledArgs& aArgs) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
|
2018-06-28 22:58:23 +03:00
|
|
|
// Determine if the client is allowed to be controlled. Currently we
|
|
|
|
// prevent service workers from controlling clients that cannot access
|
|
|
|
// storage. We exempt this restriction for local URL clients, like
|
|
|
|
// about:blank and blob:, since access to service workers is dictated by their
|
|
|
|
// parent.
|
|
|
|
//
|
|
|
|
// Note, we default to allowing the client to be controlled in the case
|
|
|
|
// where we are not execution ready yet. This can only happen if the
|
|
|
|
// the non-subresource load is intercepted by a service worker. Since
|
|
|
|
// ServiceWorkerInterceptController() uses StorageAllowedForChannel()
|
|
|
|
// it should be fine to accept these control messages.
|
|
|
|
//
|
|
|
|
// Its also fine to default to allowing ClientSource attached to a docshell
|
|
|
|
// to be controlled. These clients represent inital about:blank windows
|
|
|
|
// that do not have an inner window created yet. We explicitly allow initial
|
|
|
|
// about:blank.
|
|
|
|
bool controlAllowed = true;
|
|
|
|
if (GetInnerWindow()) {
|
|
|
|
// Local URL windows and windows with access to storage can be controlled.
|
|
|
|
controlAllowed =
|
|
|
|
Info().URL().LowerCaseEqualsLiteral("about:blank") ||
|
|
|
|
StringBeginsWith(Info().URL(), NS_LITERAL_CSTRING("blob:")) ||
|
2019-05-27 17:06:49 +03:00
|
|
|
StorageAllowedForWindow(GetInnerWindow()) == StorageAccess::eAllow;
|
2018-06-28 22:58:23 +03:00
|
|
|
} else if (GetWorkerPrivate()) {
|
|
|
|
// Local URL workers and workers with access to storage cna be controlled.
|
2019-05-27 17:06:49 +03:00
|
|
|
controlAllowed =
|
|
|
|
GetWorkerPrivate()->StorageAccess() > StorageAccess::ePrivateBrowsing ||
|
|
|
|
StringBeginsWith(GetWorkerPrivate()->ScriptURL(),
|
|
|
|
NS_LITERAL_STRING("blob:"));
|
2018-06-28 22:58:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_WARN_IF(!controlAllowed)) {
|
2020-01-30 12:01:26 +03:00
|
|
|
CopyableErrorResult rv;
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowInvalidStateError("Client cannot be controlled");
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndReject(rv, __func__);
|
2018-06-28 22:58:23 +03:00
|
|
|
}
|
|
|
|
|
2017-12-05 22:54:10 +03:00
|
|
|
SetController(ServiceWorkerDescriptor(aArgs.serviceWorker()));
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndResolve(CopyableErrorResult(), __func__);
|
2017-12-05 22:54:10 +03:00
|
|
|
}
|
|
|
|
|
2018-06-22 17:22:59 +03:00
|
|
|
void ClientSource::InheritController(
|
|
|
|
const ServiceWorkerDescriptor& aServiceWorker) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
|
|
|
|
// If we are in legacy child-side intercept mode then we must tell the current
|
|
|
|
// process SWM that this client inherited a controller. This will only update
|
|
|
|
// the local SWM data and not send any messages to the ClientManagerService.
|
2019-07-26 21:39:58 +03:00
|
|
|
if (!ServiceWorkerParentInterceptEnabled()) {
|
|
|
|
if (GetDocShell()) {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (swm) {
|
|
|
|
swm->NoteInheritedController(mClientInfo, aServiceWorker);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate();
|
|
|
|
MOZ_ASSERT(workerPrivate);
|
|
|
|
|
|
|
|
RefPtr<StrongWorkerRef> strongWorkerRef = StrongWorkerRef::Create(
|
|
|
|
workerPrivate,
|
|
|
|
NS_ConvertUTF16toUTF8(workerPrivate->WorkerName()).get());
|
|
|
|
auto threadSafeWorkerRef =
|
|
|
|
MakeRefPtr<ThreadSafeWorkerRef>(strongWorkerRef);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
|
|
|
|
__func__, [workerRef = threadSafeWorkerRef, clientInfo = mClientInfo,
|
|
|
|
serviceWorker = aServiceWorker]() {
|
|
|
|
MOZ_ASSERT(IsBlobURI(workerRef->Private()->GetBaseURI()));
|
|
|
|
|
|
|
|
RefPtr<ServiceWorkerManager> swm =
|
|
|
|
ServiceWorkerManager::GetInstance();
|
|
|
|
|
|
|
|
if (swm) {
|
|
|
|
swm->NoteInheritedController(clientInfo, serviceWorker);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(workerPrivate->DispatchToMainThread(r.forget())));
|
2018-06-22 17:22:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also tell the parent-side ClientManagerService that the controller was
|
|
|
|
// inherited. This is necessary for clients.matchAll() to work properly.
|
|
|
|
// In parent-side intercept mode this will also note the inheritance in
|
|
|
|
// the parent-side SWM.
|
|
|
|
MaybeExecute([aServiceWorker](PClientSourceChild* aActor) {
|
|
|
|
aActor->SendInheritController(ClientControlledArgs(aServiceWorker.ToIPC()));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Finally, record the new controller in our local ClientSource for any
|
|
|
|
// immediate synchronous access.
|
|
|
|
SetController(aServiceWorker);
|
|
|
|
}
|
|
|
|
|
2017-12-05 22:54:10 +03:00
|
|
|
const Maybe<ServiceWorkerDescriptor>& ClientSource::GetController() const {
|
|
|
|
return mController;
|
|
|
|
}
|
|
|
|
|
2018-06-23 20:11:47 +03:00
|
|
|
void ClientSource::NoteDOMContentLoaded() {
|
|
|
|
if (mController.isSome() && !ServiceWorkerParentInterceptEnabled()) {
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (swm) {
|
|
|
|
swm->MaybeCheckNavigationUpdate(mClientInfo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MaybeExecute(
|
|
|
|
[](PClientSourceChild* aActor) { aActor->SendNoteDOMContentLoaded(); });
|
|
|
|
}
|
|
|
|
|
2017-12-08 22:46:43 +03:00
|
|
|
RefPtr<ClientOpPromise> ClientSource::Focus(const ClientFocusArgs& aArgs) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
|
|
|
|
if (mClientInfo.Type() != ClientType::Window) {
|
2020-01-30 12:01:26 +03:00
|
|
|
CopyableErrorResult rv;
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowNotSupportedError("Not a Window client");
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndReject(rv, __func__);
|
2017-12-08 22:46:43 +03:00
|
|
|
}
|
|
|
|
nsPIDOMWindowOuter* outer = nullptr;
|
|
|
|
|
|
|
|
nsPIDOMWindowInner* inner = GetInnerWindow();
|
|
|
|
if (inner) {
|
|
|
|
outer = inner->GetOuterWindow();
|
|
|
|
} else {
|
|
|
|
nsIDocShell* docshell = GetDocShell();
|
|
|
|
if (docshell) {
|
|
|
|
outer = docshell->GetWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!outer) {
|
2020-01-30 12:01:26 +03:00
|
|
|
CopyableErrorResult rv;
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowInvalidStateError("Browsing context discarded");
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndReject(rv, __func__);
|
2017-12-08 22:46:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2020-01-16 17:38:40 +03:00
|
|
|
nsFocusManager::FocusWindow(outer, aArgs.callerType());
|
2017-12-08 22:46:43 +03:00
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
Result<ClientState, ErrorResult> state = SnapshotState();
|
|
|
|
if (state.isErr()) {
|
|
|
|
return ClientOpPromise::CreateAndReject(
|
|
|
|
CopyableErrorResult(state.unwrapErr()), __func__);
|
2017-12-08 22:46:43 +03:00
|
|
|
}
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndResolve(state.inspect().ToIPC(), __func__);
|
2017-12-08 22:46:43 +03:00
|
|
|
}
|
|
|
|
|
2017-12-08 22:46:43 +03:00
|
|
|
RefPtr<ClientOpPromise> ClientSource::PostMessage(
|
|
|
|
const ClientPostMessageArgs& aArgs) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
|
2018-10-11 15:37:37 +03:00
|
|
|
// TODO: Currently this function only supports clients whose global
|
|
|
|
// object is a Window; it should also support those whose global
|
|
|
|
// object is a WorkerGlobalScope.
|
|
|
|
if (nsPIDOMWindowInner* const window = GetInnerWindow()) {
|
|
|
|
const RefPtr<ServiceWorkerContainer> container =
|
|
|
|
window->Navigator()->ServiceWorker();
|
|
|
|
container->ReceiveMessage(aArgs);
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndResolve(CopyableErrorResult(), __func__);
|
2017-12-08 22:46:43 +03:00
|
|
|
}
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
CopyableErrorResult rv;
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowNotSupportedError(
|
2020-02-03 23:09:15 +03:00
|
|
|
"postMessage to non-Window clients is not supported yet");
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndReject(rv, __func__);
|
2017-12-08 22:46:43 +03:00
|
|
|
}
|
|
|
|
|
2017-12-08 22:46:42 +03:00
|
|
|
RefPtr<ClientOpPromise> ClientSource::Claim(const ClientClaimArgs& aArgs) {
|
2018-06-28 22:58:23 +03:00
|
|
|
// The ClientSource::Claim method is only needed in the legacy
|
|
|
|
// mode where the ServiceWorkerManager is run in each child-process.
|
|
|
|
// In parent-process mode this method should not be called.
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(!ServiceWorkerParentInterceptEnabled());
|
|
|
|
|
|
|
|
nsIGlobalObject* global = GetGlobal();
|
|
|
|
if (NS_WARN_IF(!global)) {
|
2020-01-30 12:01:26 +03:00
|
|
|
CopyableErrorResult rv;
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowInvalidStateError("Browsing context torn down");
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientOpPromise::CreateAndReject(rv, __func__);
|
2018-06-28 22:58:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Note, we cannot just mark the ClientSource controlled. We must go through
|
|
|
|
// the SWM so that it can keep track of which clients are controlled by each
|
|
|
|
// registration. We must tell the child-process SWM in legacy child-process
|
|
|
|
// mode. In parent-process service worker mode the SWM is notified in the
|
|
|
|
// parent-process in ClientManagerService::Claim().
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
RefPtr<GenericErrorResultPromise::Private> innerPromise =
|
|
|
|
new GenericErrorResultPromise::Private(__func__);
|
2017-12-12 23:44:48 +03:00
|
|
|
ServiceWorkerDescriptor swd(aArgs.serviceWorker());
|
|
|
|
|
2018-06-28 22:58:23 +03:00
|
|
|
nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction(
|
|
|
|
"ClientSource::Claim",
|
|
|
|
[innerPromise, clientInfo = mClientInfo, swd]() mutable {
|
|
|
|
RefPtr<ServiceWorkerManager> swm = ServiceWorkerManager::GetInstance();
|
|
|
|
if (NS_WARN_IF(!swm)) {
|
2020-02-03 23:09:15 +03:00
|
|
|
CopyableErrorResult rv;
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowInvalidStateError("Browser shutting down");
|
2020-02-03 23:09:15 +03:00
|
|
|
innerPromise->Reject(rv, __func__);
|
2018-06-28 22:58:23 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
RefPtr<GenericErrorResultPromise> p =
|
|
|
|
swm->MaybeClaimClient(clientInfo, swd);
|
2018-06-28 22:58:23 +03:00
|
|
|
p->ChainTo(innerPromise.forget(), __func__);
|
|
|
|
});
|
|
|
|
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
r->Run();
|
|
|
|
} else {
|
|
|
|
MOZ_ALWAYS_SUCCEEDS(SystemGroup::Dispatch(TaskCategory::Other, r.forget()));
|
2017-12-12 23:44:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ClientOpPromise::Private> outerPromise =
|
|
|
|
new ClientOpPromise::Private(__func__);
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
auto holder =
|
|
|
|
MakeRefPtr<DOMMozPromiseRequestHolder<GenericErrorResultPromise>>(global);
|
2018-05-02 16:29:27 +03:00
|
|
|
|
2018-06-28 22:58:23 +03:00
|
|
|
innerPromise
|
|
|
|
->Then(
|
|
|
|
mEventTarget, __func__,
|
2018-05-02 16:29:27 +03:00
|
|
|
[outerPromise, holder](bool aResult) {
|
|
|
|
holder->Complete();
|
2020-01-30 12:01:26 +03:00
|
|
|
outerPromise->Resolve(CopyableErrorResult(), __func__);
|
2018-05-02 16:29:27 +03:00
|
|
|
},
|
2020-01-30 12:01:26 +03:00
|
|
|
[outerPromise, holder](const CopyableErrorResult& aResult) {
|
2018-05-02 16:29:27 +03:00
|
|
|
holder->Complete();
|
2017-12-12 23:44:48 +03:00
|
|
|
outerPromise->Reject(aResult, __func__);
|
2018-05-02 16:29:27 +03:00
|
|
|
})
|
|
|
|
->Track(*holder);
|
2017-12-08 22:46:42 +03:00
|
|
|
|
2020-02-13 17:38:48 +03:00
|
|
|
return outerPromise;
|
2017-12-08 22:46:42 +03:00
|
|
|
}
|
|
|
|
|
2017-12-06 04:45:23 +03:00
|
|
|
RefPtr<ClientOpPromise> ClientSource::GetInfoAndState(
|
|
|
|
const ClientGetInfoAndStateArgs& aArgs) {
|
2020-01-30 12:01:26 +03:00
|
|
|
Result<ClientState, ErrorResult> state = SnapshotState();
|
|
|
|
if (state.isErr()) {
|
|
|
|
return ClientOpPromise::CreateAndReject(
|
|
|
|
CopyableErrorResult(state.unwrapErr()), __func__);
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
2018-12-11 13:46:21 +03:00
|
|
|
return ClientOpPromise::CreateAndResolve(
|
2020-01-30 12:01:26 +03:00
|
|
|
ClientInfoAndState(mClientInfo.ToIPC(), state.inspect().ToIPC()),
|
|
|
|
__func__);
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
Result<ClientState, ErrorResult> ClientSource::SnapshotState() {
|
2017-12-06 04:45:23 +03:00
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
|
|
|
|
if (mClientInfo.Type() == ClientType::Window) {
|
|
|
|
MaybeCreateInitialDocument();
|
2020-01-30 12:01:26 +03:00
|
|
|
return SnapshotWindowState();
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
2017-12-12 23:44:46 +03:00
|
|
|
WorkerPrivate* workerPrivate = GetWorkerPrivate();
|
|
|
|
if (!workerPrivate) {
|
2020-01-30 12:01:26 +03:00
|
|
|
ErrorResult rv;
|
2020-02-03 23:19:11 +03:00
|
|
|
rv.ThrowInvalidStateError("Worker terminated");
|
2020-01-30 12:01:26 +03:00
|
|
|
return Err(std::move(rv));
|
2017-12-12 23:44:46 +03:00
|
|
|
}
|
|
|
|
|
2020-01-30 12:01:26 +03:00
|
|
|
return ClientState(ClientWorkerState(workerPrivate->StorageAccess()));
|
2017-12-06 04:45:23 +03:00
|
|
|
}
|
|
|
|
|
2017-11-16 21:15:10 +03:00
|
|
|
nsISerialEventTarget* ClientSource::EventTarget() const { return mEventTarget; }
|
|
|
|
|
2019-05-22 02:14:27 +03:00
|
|
|
void ClientSource::SetCsp(nsIContentSecurityPolicy* aCsp) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
if (!aCsp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSPInfo cspInfo;
|
|
|
|
nsresult rv = CSPToCSPInfo(aCsp, &cspInfo);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mClientInfo.SetCspInfo(cspInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientSource::SetPreloadCsp(nsIContentSecurityPolicy* aPreloadCsp) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
if (!aPreloadCsp) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSPInfo cspPreloadInfo;
|
|
|
|
nsresult rv = CSPToCSPInfo(aPreloadCsp, &cspPreloadInfo);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mClientInfo.SetPreloadCspInfo(cspPreloadInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClientSource::SetCspInfo(const CSPInfo& aCSPInfo) {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
mClientInfo.SetCspInfo(aCSPInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Maybe<mozilla::ipc::CSPInfo>& ClientSource::GetCspInfo() {
|
|
|
|
NS_ASSERT_OWNINGTHREAD(ClientSource);
|
|
|
|
return mClientInfo.GetCspInfo();
|
|
|
|
}
|
|
|
|
|
2017-12-05 06:13:33 +03:00
|
|
|
void ClientSource::Traverse(nsCycleCollectionTraversalCallback& aCallback,
|
|
|
|
const char* aName, uint32_t aFlags) {
|
|
|
|
if (mOwner.is<RefPtr<nsPIDOMWindowInner>>()) {
|
|
|
|
ImplCycleCollectionTraverse(
|
|
|
|
aCallback, mOwner.as<RefPtr<nsPIDOMWindowInner>>(), aName, aFlags);
|
|
|
|
} else if (mOwner.is<nsCOMPtr<nsIDocShell>>()) {
|
|
|
|
ImplCycleCollectionTraverse(aCallback, mOwner.as<nsCOMPtr<nsIDocShell>>(),
|
|
|
|
aName, aFlags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 18:04:48 +03:00
|
|
|
void ClientSource::NoteCalledRegisterForServiceWorkerScope(
|
|
|
|
const nsACString& aScope) {
|
|
|
|
if (mRegisteringScopeList.Contains(aScope)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRegisteringScopeList.AppendElement(aScope);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClientSource::CalledRegisterForServiceWorkerScope(
|
|
|
|
const nsACString& aScope) {
|
|
|
|
return mRegisteringScopeList.Contains(aScope);
|
|
|
|
}
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|