mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:18:48 +00:00
3b1d2cdd8a
- Bug 1171486 - Part 2: Make it OK to call ServiceWorkerManager::GetInstance() during its Init() function; r=baku (c3c7bd78c) - Bug 1115820 - Add telemetry to ServiceWorkers. r=nsm, r=vladan (9a86f7466) - Bug 1172717 - Fail on UNKNOWN_APP_ID instead of crashing. r=bholley a=RyanVM (f950a7c59) - Bug 1154068 - rename relaxed to insecure scheme and add more runtime checks r=hurley (76e8ce41a) - Bug 1154061 - clear cached alt svc mappings on a variety of state changes r=hurley (9855ee544) - Bug 1153437 - rename proxyFlags to controlFlags with nsISocketProvider interfaces r=hurley (043a531c8) - bug 1153212 - 2/2 Necko explicitly track origin vs routed host and give psm only origin r=dkeeler r=hurley IGNORE IDL (d44c3d0e6) - part of Bug 935838 - Add per app network traffic statistics (d1861cb3d) - Bug 1109338: Part 1: Separate UDPSocket logging from network logging r=dragana (c2c887b0f) - Bug 1109338: Part 2: Sharing UDPSocket between PNecko and PBackground r=bent (90b2a09d2) - Bug 1133189 - Extend PrincipalInfo to handle expanded principals. r=bent, r=sicking (d3269d57e) - Bug 1155153 - about:serviceworkers should work in e10s mode, r=nsm, r=bholley (90dd0bb4b) - Bug 1061116 - Make the comparison query/hash insensitive for validity widget. r=fabrice (0969e8404) - Bug 1167603 - use string to replace nsIURI in aApps.widgetPages. r=fabrice (c528e2615) - Bug 1087469 - Add support for a start_url property in app manifests r=fabrice (0053f26d6) - Bug 1168783 - Expose principal in mozIApplication. r=fabrice (2fee4ed8e) - Bug 1169249 - Unregister service worker registration when uninstalling a service-worker-enabled application. r=baku (c881ee50b) - Bug 1174381 - ServiceWorkerManager::TeardownRunnable should be called when xpcom-shutdown notification is received, r=nsm (f47d59f19) - Bug 1167296 - patch 1 - ServiceWorkerManager::RemoveAll should use PBackground, r=nsm (8f8feda13) - Bug 1167296 - patch 2 - ServiceWorkerManager::Remove should use PBackground, r=nsm (fc931fffc)
316 lines
7.6 KiB
C++
316 lines
7.6 KiB
C++
/* -*- 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 "ServiceWorkerManagerParent.h"
|
|
#include "ServiceWorkerManagerService.h"
|
|
#include "mozilla/AppProcessChecker.h"
|
|
#include "mozilla/ipc/BackgroundParent.h"
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
#include "mozilla/unused.h"
|
|
|
|
namespace mozilla {
|
|
|
|
using namespace ipc;
|
|
|
|
namespace dom {
|
|
namespace workers {
|
|
|
|
namespace {
|
|
|
|
uint64_t sServiceWorkerManagerParentID = 0;
|
|
|
|
void
|
|
AssertIsInMainProcess()
|
|
{
|
|
MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
|
|
}
|
|
|
|
class RegisterServiceWorkerCallback final : public nsRunnable
|
|
{
|
|
public:
|
|
RegisterServiceWorkerCallback(const ServiceWorkerRegistrationData& aData,
|
|
uint64_t aParentID)
|
|
: mData(aData)
|
|
, mParentID(aParentID)
|
|
{
|
|
AssertIsInMainProcess();
|
|
AssertIsOnBackgroundThread();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
Run()
|
|
{
|
|
AssertIsInMainProcess();
|
|
AssertIsOnBackgroundThread();
|
|
|
|
nsRefPtr<dom::ServiceWorkerRegistrar> service =
|
|
dom::ServiceWorkerRegistrar::Get();
|
|
MOZ_ASSERT(service);
|
|
|
|
service->RegisterServiceWorker(mData);
|
|
|
|
nsRefPtr<ServiceWorkerManagerService> managerService =
|
|
ServiceWorkerManagerService::Get();
|
|
if (managerService) {
|
|
managerService->PropagateRegistration(mParentID, mData);
|
|
}
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
ServiceWorkerRegistrationData mData;
|
|
const uint64_t mParentID;
|
|
};
|
|
|
|
class UnregisterServiceWorkerCallback final : public nsRunnable
|
|
{
|
|
public:
|
|
UnregisterServiceWorkerCallback(const PrincipalInfo& aPrincipalInfo,
|
|
const nsString& aScope)
|
|
: mPrincipalInfo(aPrincipalInfo)
|
|
, mScope(aScope)
|
|
{
|
|
AssertIsInMainProcess();
|
|
AssertIsOnBackgroundThread();
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
Run()
|
|
{
|
|
AssertIsInMainProcess();
|
|
AssertIsOnBackgroundThread();
|
|
|
|
nsRefPtr<dom::ServiceWorkerRegistrar> service =
|
|
dom::ServiceWorkerRegistrar::Get();
|
|
MOZ_ASSERT(service);
|
|
|
|
service->UnregisterServiceWorker(mPrincipalInfo,
|
|
NS_ConvertUTF16toUTF8(mScope));
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
const PrincipalInfo mPrincipalInfo;
|
|
nsString mScope;
|
|
};
|
|
|
|
class CheckPrincipalWithCallbackRunnable final : public nsRunnable
|
|
{
|
|
public:
|
|
CheckPrincipalWithCallbackRunnable(already_AddRefed<ContentParent> aParent,
|
|
const PrincipalInfo& aPrincipalInfo,
|
|
nsRunnable* aCallback)
|
|
: mContentParent(aParent)
|
|
, mPrincipalInfo(aPrincipalInfo)
|
|
, mCallback(aCallback)
|
|
, mBackgroundThread(NS_GetCurrentThread())
|
|
{
|
|
AssertIsInMainProcess();
|
|
AssertIsOnBackgroundThread();
|
|
|
|
MOZ_ASSERT(mContentParent);
|
|
MOZ_ASSERT(mCallback);
|
|
MOZ_ASSERT(mBackgroundThread);
|
|
}
|
|
|
|
NS_IMETHODIMP Run()
|
|
{
|
|
if (NS_IsMainThread()) {
|
|
nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(mPrincipalInfo);
|
|
AssertAppPrincipal(mContentParent, principal);
|
|
mContentParent = nullptr;
|
|
|
|
mBackgroundThread->Dispatch(this, NS_DISPATCH_NORMAL);
|
|
return NS_OK;
|
|
}
|
|
|
|
AssertIsOnBackgroundThread();
|
|
mCallback->Run();
|
|
mCallback = nullptr;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
private:
|
|
nsRefPtr<ContentParent> mContentParent;
|
|
PrincipalInfo mPrincipalInfo;
|
|
nsRefPtr<nsRunnable> mCallback;
|
|
nsCOMPtr<nsIThread> mBackgroundThread;
|
|
};
|
|
|
|
} // anonymous namespace
|
|
|
|
ServiceWorkerManagerParent::ServiceWorkerManagerParent()
|
|
: mService(ServiceWorkerManagerService::GetOrCreate())
|
|
, mID(++sServiceWorkerManagerParentID)
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
mService->RegisterActor(this);
|
|
}
|
|
|
|
ServiceWorkerManagerParent::~ServiceWorkerManagerParent()
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
}
|
|
|
|
bool
|
|
ServiceWorkerManagerParent::RecvRegister(
|
|
const ServiceWorkerRegistrationData& aData)
|
|
{
|
|
AssertIsInMainProcess();
|
|
AssertIsOnBackgroundThread();
|
|
|
|
// Basic validation.
|
|
if (aData.scope().IsEmpty() ||
|
|
aData.scriptSpec().IsEmpty() ||
|
|
aData.principal().type() == PrincipalInfo::TNullPrincipalInfo ||
|
|
aData.principal().type() == PrincipalInfo::TSystemPrincipalInfo) {
|
|
return false;
|
|
}
|
|
|
|
nsRefPtr<RegisterServiceWorkerCallback> callback =
|
|
new RegisterServiceWorkerCallback(aData, mID);
|
|
|
|
nsRefPtr<ContentParent> parent =
|
|
BackgroundParent::GetContentParent(Manager());
|
|
|
|
// If the ContentParent is null we are dealing with a same-process actor.
|
|
if (!parent) {
|
|
callback->Run();
|
|
return true;
|
|
}
|
|
|
|
nsRefPtr<CheckPrincipalWithCallbackRunnable> runnable =
|
|
new CheckPrincipalWithCallbackRunnable(parent.forget(), aData.principal(),
|
|
callback);
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ServiceWorkerManagerParent::RecvUnregister(const PrincipalInfo& aPrincipalInfo,
|
|
const nsString& aScope)
|
|
{
|
|
AssertIsInMainProcess();
|
|
AssertIsOnBackgroundThread();
|
|
|
|
// Basic validation.
|
|
if (aScope.IsEmpty() ||
|
|
aPrincipalInfo.type() == PrincipalInfo::TNullPrincipalInfo ||
|
|
aPrincipalInfo.type() == PrincipalInfo::TSystemPrincipalInfo) {
|
|
return false;
|
|
}
|
|
|
|
nsRefPtr<UnregisterServiceWorkerCallback> callback =
|
|
new UnregisterServiceWorkerCallback(aPrincipalInfo, aScope);
|
|
|
|
nsRefPtr<ContentParent> parent =
|
|
BackgroundParent::GetContentParent(Manager());
|
|
|
|
// If the ContentParent is null we are dealing with a same-process actor.
|
|
if (!parent) {
|
|
callback->Run();
|
|
return true;
|
|
}
|
|
|
|
nsRefPtr<CheckPrincipalWithCallbackRunnable> runnable =
|
|
new CheckPrincipalWithCallbackRunnable(parent.forget(), aPrincipalInfo,
|
|
callback);
|
|
nsresult rv = NS_DispatchToMainThread(runnable);
|
|
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(rv));
|
|
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ServiceWorkerManagerParent::RecvPropagateSoftUpdate(const OriginAttributes& aOriginAttributes,
|
|
const nsString& aScope)
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
return false;
|
|
}
|
|
|
|
mService->PropagateSoftUpdate(mID, aOriginAttributes, aScope);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ServiceWorkerManagerParent::RecvPropagateUnregister(const PrincipalInfo& aPrincipalInfo,
|
|
const nsString& aScope)
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
return false;
|
|
}
|
|
|
|
mService->PropagateUnregister(mID, aPrincipalInfo, aScope);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ServiceWorkerManagerParent::RecvPropagateRemove(const nsCString& aHost)
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
return false;
|
|
}
|
|
|
|
mService->PropagateRemove(mID, aHost);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ServiceWorkerManagerParent::RecvPropagateRemoveAll()
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
return false;
|
|
}
|
|
|
|
mService->PropagateRemoveAll(mID);
|
|
return true;
|
|
}
|
|
|
|
bool
|
|
ServiceWorkerManagerParent::RecvShutdown()
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
|
|
if (NS_WARN_IF(!mService)) {
|
|
return false;
|
|
}
|
|
|
|
mService->UnregisterActor(this);
|
|
mService = nullptr;
|
|
|
|
unused << Send__delete__(this);
|
|
return true;
|
|
}
|
|
|
|
void
|
|
ServiceWorkerManagerParent::ActorDestroy(ActorDestroyReason aWhy)
|
|
{
|
|
AssertIsOnBackgroundThread();
|
|
|
|
if (mService) {
|
|
// This object is about to be released and with it, also mService will be
|
|
// released too.
|
|
mService->UnregisterActor(this);
|
|
}
|
|
}
|
|
|
|
} // workers namespace
|
|
} // dom namespace
|
|
} // mozilla namespace
|