2015-05-03 22:32:37 +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: */
|
2013-11-20 03:15:02 +04:00
|
|
|
/* 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_workers_serviceworkermanager_h
|
|
|
|
#define mozilla_dom_workers_serviceworkermanager_h
|
|
|
|
|
|
|
|
#include "nsIServiceWorkerManager.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
2015-02-11 14:53:00 +03:00
|
|
|
#include "ipc/IPCMessageUtils.h"
|
2013-11-20 03:15:02 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-03-06 04:37:49 +03:00
|
|
|
#include "mozilla/AutoRestore.h"
|
2013-11-20 03:15:02 +04:00
|
|
|
#include "mozilla/LinkedList.h"
|
2014-07-21 10:25:44 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2014-07-24 01:05:08 +04:00
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2014-08-01 20:42:19 +04:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2013-11-20 03:15:02 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
|
|
|
#include "mozilla/dom/Promise.h"
|
2014-10-17 22:43:14 +04:00
|
|
|
#include "mozilla/dom/ServiceWorkerBinding.h" // For ServiceWorkerState
|
2014-08-19 17:56:00 +04:00
|
|
|
#include "mozilla/dom/ServiceWorkerCommon.h"
|
2015-02-11 14:53:00 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrar.h"
|
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrarTypes.h"
|
|
|
|
#include "mozilla/ipc/BackgroundUtils.h"
|
|
|
|
#include "nsIIPCBackgroundChildCreateCallback.h"
|
2014-12-19 13:48:31 +03:00
|
|
|
#include "nsClassHashtable.h"
|
|
|
|
#include "nsDataHashtable.h"
|
2013-11-20 03:15:02 +04:00
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2014-07-15 01:15:23 +04:00
|
|
|
#include "nsTObserverArray.h"
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2015-08-03 23:51:07 +03:00
|
|
|
class mozIApplicationClearPrivateDataParams;
|
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
namespace mozilla {
|
2015-02-11 14:53:00 +03:00
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
class OriginAttributes;
|
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
namespace dom {
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2015-04-08 23:13:32 +03:00
|
|
|
class ServiceWorkerRegistrationListener;
|
2014-08-19 17:56:00 +04:00
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
namespace workers {
|
|
|
|
|
|
|
|
class ServiceWorker;
|
2015-03-06 16:04:49 +03:00
|
|
|
class ServiceWorkerClientInfo;
|
2014-12-19 14:25:56 +03:00
|
|
|
class ServiceWorkerInfo;
|
2015-06-03 11:43:43 +03:00
|
|
|
class ServiceWorkerJob;
|
2014-12-19 13:00:29 +03:00
|
|
|
class ServiceWorkerJobQueue;
|
2015-06-04 21:51:57 +03:00
|
|
|
class ServiceWorkerManagerChild;
|
2014-12-19 13:00:29 +03:00
|
|
|
|
2014-06-11 20:12:56 +04:00
|
|
|
// Needs to inherit from nsISupports because NS_ProxyRelease() does not support
|
|
|
|
// non-ISupports classes.
|
2015-03-21 19:28:04 +03:00
|
|
|
class ServiceWorkerRegistrationInfo final : public nsISupports
|
2013-11-20 03:15:02 +04:00
|
|
|
{
|
2014-07-21 10:25:44 +04:00
|
|
|
uint32_t mControlledDocumentsCounter;
|
|
|
|
|
2014-08-19 17:56:00 +04:00
|
|
|
virtual ~ServiceWorkerRegistrationInfo();
|
2014-06-11 20:12:56 +04:00
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
public:
|
2014-06-11 20:12:56 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-11-20 03:15:02 +04:00
|
|
|
|
|
|
|
nsCString mScope;
|
|
|
|
// The scriptURL for the registration. This may be completely different from
|
|
|
|
// the URLs of the following three workers.
|
|
|
|
nsCString mScriptSpec;
|
|
|
|
|
2015-02-11 14:53:00 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
|
2014-12-19 13:00:29 +03:00
|
|
|
nsRefPtr<ServiceWorkerInfo> mActiveWorker;
|
2014-07-21 10:25:44 +04:00
|
|
|
nsRefPtr<ServiceWorkerInfo> mWaitingWorker;
|
|
|
|
nsRefPtr<ServiceWorkerInfo> mInstallingWorker;
|
2013-11-20 03:15:02 +04:00
|
|
|
|
|
|
|
// When unregister() is called on a registration, it is not immediately
|
|
|
|
// removed since documents may be controlled. It is marked as
|
|
|
|
// pendingUninstall and when all controlling documents go away, removed.
|
|
|
|
bool mPendingUninstall;
|
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
ServiceWorkerRegistrationInfo(const nsACString& aScope,
|
|
|
|
nsIPrincipal* aPrincipal);
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2014-07-21 10:25:44 +04:00
|
|
|
already_AddRefed<ServiceWorkerInfo>
|
|
|
|
Newest()
|
2013-11-20 03:15:02 +04:00
|
|
|
{
|
2014-07-21 10:25:44 +04:00
|
|
|
nsRefPtr<ServiceWorkerInfo> newest;
|
|
|
|
if (mInstallingWorker) {
|
|
|
|
newest = mInstallingWorker;
|
|
|
|
} else if (mWaitingWorker) {
|
|
|
|
newest = mWaitingWorker;
|
2013-11-20 03:15:02 +04:00
|
|
|
} else {
|
2014-12-19 13:00:29 +03:00
|
|
|
newest = mActiveWorker;
|
2013-11-20 03:15:02 +04:00
|
|
|
}
|
2014-07-21 10:25:44 +04:00
|
|
|
|
|
|
|
return newest.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StartControllingADocument()
|
|
|
|
{
|
|
|
|
++mControlledDocumentsCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
StopControllingADocument()
|
|
|
|
{
|
|
|
|
--mControlledDocumentsCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsControllingDocuments() const
|
|
|
|
{
|
2014-12-19 13:00:29 +03:00
|
|
|
return mActiveWorker && mControlledDocumentsCounter > 0;
|
2013-11-20 03:15:02 +04:00
|
|
|
}
|
2014-07-14 21:33:44 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
Clear();
|
2014-12-19 13:00:29 +03:00
|
|
|
|
2015-06-02 14:12:00 +03:00
|
|
|
void
|
|
|
|
PurgeActiveWorker();
|
|
|
|
|
2014-12-19 13:00:29 +03:00
|
|
|
void
|
|
|
|
TryToActivate();
|
|
|
|
|
|
|
|
void
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
void
|
|
|
|
FinishActivate(bool aSuccess);
|
2014-12-19 14:25:56 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2015-08-15 01:06:00 +03:00
|
|
|
class ServiceWorkerUpdateFinishCallback
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual ~ServiceWorkerUpdateFinishCallback()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerUpdateFinishCallback)
|
|
|
|
|
|
|
|
virtual
|
|
|
|
void UpdateSucceeded(ServiceWorkerRegistrationInfo* aInfo)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual
|
|
|
|
void UpdateFailed(nsresult aStatus)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual
|
2015-08-20 02:21:25 +03:00
|
|
|
void UpdateFailed(JSExnType aExnType, const ErrorEventInit& aDesc)
|
2015-08-15 01:06:00 +03:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
2014-12-19 14:25:56 +03:00
|
|
|
/*
|
|
|
|
* Wherever the spec treats a worker instance and a description of said worker
|
|
|
|
* as the same thing; i.e. "Resolve foo with
|
|
|
|
* _GetNewestWorker(serviceWorkerRegistration)", we represent the description
|
|
|
|
* by this class and spawn a ServiceWorker in the right global when required.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class ServiceWorkerInfo final
|
2014-12-19 14:25:56 +03:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
const ServiceWorkerRegistrationInfo* mRegistration;
|
|
|
|
nsCString mScriptSpec;
|
2015-03-19 21:41:42 +03:00
|
|
|
nsString mCacheName;
|
2014-12-19 14:25:56 +03:00
|
|
|
ServiceWorkerState mState;
|
2015-05-14 22:41:42 +03:00
|
|
|
|
|
|
|
// This id is shared with WorkerPrivate to match requests issued by service
|
|
|
|
// workers to their corresponding serviceWorkerInfo.
|
|
|
|
uint64_t mServiceWorkerID;
|
|
|
|
|
2015-02-19 19:40:21 +03:00
|
|
|
// We hold rawptrs since the ServiceWorker constructor and destructor ensure
|
|
|
|
// addition and removal.
|
|
|
|
// There is a high chance of there being at least one ServiceWorker
|
|
|
|
// associated with this all the time.
|
|
|
|
nsAutoTArray<ServiceWorker*, 1> mInstances;
|
2015-06-02 14:12:00 +03:00
|
|
|
bool mSkipWaitingFlag;
|
2014-12-19 14:25:56 +03:00
|
|
|
|
|
|
|
~ServiceWorkerInfo()
|
|
|
|
{ }
|
|
|
|
|
2015-05-14 22:41:42 +03:00
|
|
|
// Generates a unique id for the service worker, with zero being treated as
|
|
|
|
// invalid.
|
|
|
|
uint64_t
|
|
|
|
GetNextID() const;
|
|
|
|
|
2014-12-19 14:25:56 +03:00
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerInfo)
|
|
|
|
|
|
|
|
const nsCString&
|
|
|
|
ScriptSpec() const
|
|
|
|
{
|
|
|
|
return mScriptSpec;
|
|
|
|
}
|
|
|
|
|
2015-02-19 19:40:21 +03:00
|
|
|
const nsCString&
|
|
|
|
Scope() const
|
|
|
|
{
|
|
|
|
return mRegistration->mScope;
|
|
|
|
}
|
|
|
|
|
2015-02-11 14:53:00 +03:00
|
|
|
void SetScriptSpec(const nsCString& aSpec)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aSpec.IsEmpty());
|
|
|
|
mScriptSpec = aSpec;
|
|
|
|
}
|
|
|
|
|
2015-06-02 14:12:00 +03:00
|
|
|
bool SkipWaitingFlag() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mSkipWaitingFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSkipWaitingFlag()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mSkipWaitingFlag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceWorkerInfo(ServiceWorkerRegistrationInfo* aReg,
|
|
|
|
const nsACString& aScriptSpec,
|
|
|
|
const nsAString& aCacheName)
|
2014-12-19 14:25:56 +03:00
|
|
|
: mRegistration(aReg)
|
|
|
|
, mScriptSpec(aScriptSpec)
|
2015-03-19 21:41:42 +03:00
|
|
|
, mCacheName(aCacheName)
|
2014-12-19 14:25:56 +03:00
|
|
|
, mState(ServiceWorkerState::EndGuard_)
|
2015-05-14 22:41:42 +03:00
|
|
|
, mServiceWorkerID(GetNextID())
|
2015-06-02 14:12:00 +03:00
|
|
|
, mSkipWaitingFlag(false)
|
2014-12-19 14:25:56 +03:00
|
|
|
{
|
|
|
|
MOZ_ASSERT(mRegistration);
|
2015-03-18 19:46:38 +03:00
|
|
|
MOZ_ASSERT(!aCacheName.IsEmpty());
|
2014-12-19 14:25:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ServiceWorkerState
|
|
|
|
State() const
|
|
|
|
{
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
2015-03-19 21:41:42 +03:00
|
|
|
const nsString&
|
|
|
|
CacheName() const
|
|
|
|
{
|
|
|
|
return mCacheName;
|
|
|
|
}
|
|
|
|
|
2015-05-14 22:41:42 +03:00
|
|
|
uint64_t
|
|
|
|
ID() const
|
|
|
|
{
|
|
|
|
return mServiceWorkerID;
|
|
|
|
}
|
|
|
|
|
2014-12-19 14:25:56 +03:00
|
|
|
void
|
2015-02-19 19:40:21 +03:00
|
|
|
UpdateState(ServiceWorkerState aState);
|
2015-02-11 05:08:58 +03:00
|
|
|
|
|
|
|
// Only used to set initial state when loading from disk!
|
|
|
|
void
|
|
|
|
SetActivateStateUncheckedWithoutEvent(ServiceWorkerState aState)
|
|
|
|
{
|
|
|
|
mState = aState;
|
|
|
|
}
|
2015-02-19 19:40:21 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
AppendWorker(ServiceWorker* aWorker);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveWorker(ServiceWorker* aWorker);
|
2013-11-20 03:15:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define NS_SERVICEWORKERMANAGER_IMPL_IID \
|
|
|
|
{ /* f4f8755a-69ca-46e8-a65d-775745535990 */ \
|
|
|
|
0xf4f8755a, \
|
|
|
|
0x69ca, \
|
|
|
|
0x46e8, \
|
|
|
|
{ 0xa6, 0x5d, 0x77, 0x57, 0x45, 0x53, 0x59, 0x90 } \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class ServiceWorkerManager final
|
2015-02-11 14:53:00 +03:00
|
|
|
: public nsIServiceWorkerManager
|
|
|
|
, public nsIIPCBackgroundChildCreateCallback
|
2015-03-06 04:37:49 +03:00
|
|
|
, public nsIObserver
|
2013-11-20 03:15:02 +04:00
|
|
|
{
|
2014-08-26 12:16:03 +04:00
|
|
|
friend class GetReadyPromiseRunnable;
|
2014-08-20 19:40:00 +04:00
|
|
|
friend class GetRegistrationsRunnable;
|
|
|
|
friend class GetRegistrationRunnable;
|
2015-06-03 11:43:43 +03:00
|
|
|
friend class ServiceWorkerJobQueue;
|
2014-10-25 02:11:26 +04:00
|
|
|
friend class ServiceWorkerRegisterJob;
|
|
|
|
friend class ServiceWorkerRegistrationInfo;
|
2015-01-23 01:10:38 +03:00
|
|
|
friend class ServiceWorkerUnregisterJob;
|
2013-11-20 03:15:02 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISERVICEWORKERMANAGER
|
2015-02-11 14:53:00 +03:00
|
|
|
NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
|
2015-03-06 04:37:49 +03:00
|
|
|
NS_DECL_NSIOBSERVER
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
struct RegistrationDataPerPrincipal;
|
|
|
|
nsClassHashtable<nsCStringHashKey, RegistrationDataPerPrincipal> mRegistrationInfos;
|
2014-07-21 10:25:44 +04:00
|
|
|
|
2015-04-08 23:13:32 +03:00
|
|
|
nsTObserverArray<ServiceWorkerRegistrationListener*> mServiceWorkerRegistrationListeners;
|
2014-12-19 13:00:29 +03:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
nsRefPtrHashtable<nsISupportsHashKey, ServiceWorkerRegistrationInfo> mControlledDocuments;
|
2014-12-19 13:48:31 +03:00
|
|
|
|
2015-05-14 22:41:42 +03:00
|
|
|
// Set of all documents that may be controlled by a service worker.
|
|
|
|
nsTHashtable<nsISupportsHashKey> mAllDocuments;
|
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
bool
|
|
|
|
IsAvailable(const OriginAttributes& aOriginAttributes, nsIURI* aURI);
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
bool
|
|
|
|
IsControlled(nsIDocument* aDocument, ErrorResult& aRv);
|
|
|
|
|
2015-09-22 00:10:37 +03:00
|
|
|
already_AddRefed<nsIRunnable>
|
|
|
|
PrepareFetchEvent(const OriginAttributes& aOriginAttributes,
|
|
|
|
nsIDocument* aDoc,
|
|
|
|
nsIInterceptedChannel* aChannel,
|
|
|
|
bool aIsReload,
|
2015-09-17 21:56:41 +03:00
|
|
|
bool aIsSubresourceLoad,
|
2015-09-22 00:10:37 +03:00
|
|
|
ErrorResult& aRv);
|
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
void
|
2015-09-22 00:10:37 +03:00
|
|
|
DispatchPreparedFetchEvent(nsIInterceptedChannel* aChannel,
|
|
|
|
nsIRunnable* aPreparedRunnable,
|
|
|
|
ErrorResult& aRv);
|
2015-06-03 11:43:43 +03:00
|
|
|
|
|
|
|
void
|
2015-08-15 01:06:00 +03:00
|
|
|
SoftUpdate(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aScope,
|
|
|
|
ServiceWorkerUpdateFinishCallback* aCallback = nullptr);
|
2014-07-15 01:15:23 +04:00
|
|
|
|
2015-06-04 21:51:57 +03:00
|
|
|
void
|
2015-08-15 01:06:00 +03:00
|
|
|
SoftUpdate(const OriginAttributes& aOriginAttributes,
|
|
|
|
const nsACString& aScope,
|
|
|
|
ServiceWorkerUpdateFinishCallback* aCallback = nullptr);
|
2015-06-04 21:51:57 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
PropagateSoftUpdate(const OriginAttributes& aOriginAttributes,
|
|
|
|
const nsAString& aScope);
|
|
|
|
|
2015-06-21 14:19:07 +03:00
|
|
|
void
|
|
|
|
PropagateRemove(const nsACString& aHost);
|
|
|
|
|
|
|
|
void
|
|
|
|
Remove(const nsACString& aHost);
|
|
|
|
|
2015-06-21 14:17:58 +03:00
|
|
|
void
|
|
|
|
PropagateRemoveAll();
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveAll();
|
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
2015-06-03 11:43:43 +03:00
|
|
|
GetRegistration(nsIPrincipal* aPrincipal, const nsACString& aScope) const;
|
2014-12-19 13:00:29 +03:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
ServiceWorkerRegistrationInfo*
|
2015-02-11 14:53:00 +03:00
|
|
|
CreateNewRegistration(const nsCString& aScope, nsIPrincipal* aPrincipal);
|
2014-07-15 01:15:23 +04:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
void
|
2015-02-11 21:51:32 +03:00
|
|
|
RemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration);
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2015-02-11 14:53:00 +03:00
|
|
|
void StoreRegistration(nsIPrincipal* aPrincipal,
|
|
|
|
ServiceWorkerRegistrationInfo* aRegistration);
|
|
|
|
|
2014-06-11 20:12:56 +04:00
|
|
|
void
|
2014-10-06 19:45:14 +04:00
|
|
|
FinishFetch(ServiceWorkerRegistrationInfo* aRegistration);
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2014-12-19 13:48:31 +03:00
|
|
|
// Returns true if the error was handled, false if normal worker error
|
|
|
|
// handling should continue.
|
|
|
|
bool
|
2014-07-03 04:48:35 +04:00
|
|
|
HandleError(JSContext* aCx,
|
2015-06-03 11:43:43 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
2014-12-19 13:48:31 +03:00
|
|
|
const nsCString& aScope,
|
|
|
|
const nsString& aWorkerURL,
|
2014-07-03 04:48:35 +04:00
|
|
|
nsString aMessage,
|
|
|
|
nsString aFilename,
|
|
|
|
nsString aLine,
|
|
|
|
uint32_t aLineNumber,
|
|
|
|
uint32_t aColumnNumber,
|
2015-08-20 02:21:25 +03:00
|
|
|
uint32_t aFlags,
|
|
|
|
JSExnType aExnType);
|
2014-07-03 04:48:35 +04:00
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
void
|
2015-06-03 11:43:43 +03:00
|
|
|
GetAllClients(nsIPrincipal* aPrincipal,
|
|
|
|
const nsCString& aScope,
|
2015-03-06 16:04:49 +03:00
|
|
|
nsTArray<ServiceWorkerClientInfo>& aControlledDocuments);
|
2014-10-27 14:03:00 +03:00
|
|
|
|
2015-05-14 22:41:42 +03:00
|
|
|
void
|
|
|
|
MaybeClaimClient(nsIDocument* aDocument,
|
|
|
|
ServiceWorkerRegistrationInfo* aWorkerRegistration);
|
|
|
|
|
|
|
|
nsresult
|
2015-06-03 11:43:43 +03:00
|
|
|
ClaimClients(nsIPrincipal* aPrincipal, const nsCString& aScope, uint64_t aId);
|
2015-05-14 22:41:42 +03:00
|
|
|
|
2015-06-02 14:12:00 +03:00
|
|
|
nsresult
|
2015-06-03 17:20:52 +03:00
|
|
|
SetSkipWaitingFlag(nsIPrincipal* aPrincipal, const nsCString& aScope,
|
|
|
|
uint64_t aServiceWorkerID);
|
2015-06-02 14:12:00 +03:00
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
static already_AddRefed<ServiceWorkerManager>
|
|
|
|
GetInstance();
|
|
|
|
|
2015-06-04 21:51:57 +03:00
|
|
|
void
|
|
|
|
LoadRegistration(const ServiceWorkerRegistrationData& aRegistration);
|
|
|
|
|
2015-06-02 14:12:00 +03:00
|
|
|
void
|
|
|
|
LoadRegistrations(const nsTArray<ServiceWorkerRegistrationData>& aRegistrations);
|
2015-02-11 14:53:00 +03:00
|
|
|
|
2015-03-06 04:37:49 +03:00
|
|
|
// Used by remove() and removeAll() when clearing history.
|
|
|
|
// MUST ONLY BE CALLED FROM UnregisterIfMatchesHost!
|
|
|
|
void
|
2015-06-03 11:43:43 +03:00
|
|
|
ForceUnregister(RegistrationDataPerPrincipal* aRegistrationData,
|
|
|
|
ServiceWorkerRegistrationInfo* aRegistration);
|
2015-03-06 04:37:49 +03:00
|
|
|
|
2015-04-08 23:13:32 +03:00
|
|
|
NS_IMETHOD
|
|
|
|
AddRegistrationEventListener(const nsAString& aScope,
|
|
|
|
ServiceWorkerRegistrationListener* aListener);
|
|
|
|
|
|
|
|
NS_IMETHOD
|
|
|
|
RemoveRegistrationEventListener(const nsAString& aScope,
|
|
|
|
ServiceWorkerRegistrationListener* aListener);
|
2013-11-20 03:15:02 +04:00
|
|
|
private:
|
|
|
|
ServiceWorkerManager();
|
|
|
|
~ServiceWorkerManager();
|
|
|
|
|
2015-06-04 20:21:52 +03:00
|
|
|
void
|
|
|
|
Init();
|
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
ServiceWorkerJobQueue*
|
|
|
|
GetOrCreateJobQueue(const nsACString& aOriginSuffix,
|
|
|
|
const nsACString& aScope);
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeRemoveRegistrationInfo(const nsACString& aScopeKey);
|
|
|
|
|
|
|
|
void
|
2015-08-15 01:06:00 +03:00
|
|
|
SoftUpdate(const nsACString& aScopeKey,
|
|
|
|
const nsACString& aScope,
|
|
|
|
ServiceWorkerUpdateFinishCallback* aCallback = nullptr);
|
2015-06-03 11:43:43 +03:00
|
|
|
|
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
|
|
|
GetRegistration(const nsACString& aScopeKey,
|
|
|
|
const nsACString& aScope) const;
|
|
|
|
|
2014-07-14 21:33:44 +04:00
|
|
|
void
|
|
|
|
AbortCurrentUpdate(ServiceWorkerRegistrationInfo* aRegistration);
|
|
|
|
|
2014-10-06 19:45:14 +04:00
|
|
|
nsresult
|
|
|
|
Update(ServiceWorkerRegistrationInfo* aRegistration);
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2015-02-19 04:34:29 +03:00
|
|
|
nsresult
|
|
|
|
GetDocumentRegistration(nsIDocument* aDoc, ServiceWorkerRegistrationInfo** aRegistrationInfo);
|
|
|
|
|
2014-07-03 04:48:50 +04:00
|
|
|
NS_IMETHOD
|
2013-11-20 03:15:02 +04:00
|
|
|
CreateServiceWorkerForWindow(nsPIDOMWindow* aWindow,
|
2015-02-19 19:40:21 +03:00
|
|
|
ServiceWorkerInfo* aInfo,
|
2015-07-15 22:21:40 +03:00
|
|
|
nsIRunnable* aLoadFailedRunnable,
|
2013-11-20 03:15:02 +04:00
|
|
|
ServiceWorker** aServiceWorker);
|
|
|
|
|
2014-07-03 04:48:50 +04:00
|
|
|
NS_IMETHOD
|
2015-02-17 15:36:09 +03:00
|
|
|
CreateServiceWorker(nsIPrincipal* aPrincipal,
|
2015-02-19 19:40:21 +03:00
|
|
|
ServiceWorkerInfo* aInfo,
|
2015-07-15 22:21:40 +03:00
|
|
|
nsIRunnable* aLoadFailedRunnable,
|
2014-07-03 04:48:50 +04:00
|
|
|
ServiceWorker** aServiceWorker);
|
|
|
|
|
2014-07-24 01:05:08 +04:00
|
|
|
NS_IMETHODIMP
|
2014-08-25 09:35:03 +04:00
|
|
|
GetServiceWorkerForScope(nsIDOMWindow* aWindow,
|
|
|
|
const nsAString& aScope,
|
|
|
|
WhichServiceWorker aWhichWorker,
|
|
|
|
nsISupports** aServiceWorker);
|
2014-07-24 01:05:08 +04:00
|
|
|
|
2015-04-11 06:19:28 +03:00
|
|
|
already_AddRefed<ServiceWorker>
|
2015-06-03 11:43:43 +03:00
|
|
|
CreateServiceWorkerForScope(const OriginAttributes& aOriginAttributes,
|
2015-07-15 22:21:40 +03:00
|
|
|
const nsACString& aScope,
|
|
|
|
nsIRunnable* aLoadFailedRunnable);
|
2015-04-11 06:19:28 +03:00
|
|
|
|
2014-07-24 01:05:08 +04:00
|
|
|
void
|
2014-08-19 17:56:00 +04:00
|
|
|
InvalidateServiceWorkerRegistrationWorker(ServiceWorkerRegistrationInfo* aRegistration,
|
|
|
|
WhichServiceWorker aWhichOnes);
|
2014-07-24 01:05:08 +04:00
|
|
|
|
2015-05-14 22:41:42 +03:00
|
|
|
void
|
|
|
|
StartControllingADocument(ServiceWorkerRegistrationInfo* aRegistration,
|
|
|
|
nsIDocument* aDoc);
|
|
|
|
|
|
|
|
void
|
|
|
|
StopControllingADocument(ServiceWorkerRegistrationInfo* aRegistration);
|
|
|
|
|
2014-08-19 17:56:00 +04:00
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
|
|
|
GetServiceWorkerRegistrationInfo(nsPIDOMWindow* aWindow);
|
2014-07-11 22:52:19 +04:00
|
|
|
|
2014-08-19 17:56:00 +04:00
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
|
|
|
GetServiceWorkerRegistrationInfo(nsIDocument* aDoc);
|
2014-07-11 22:52:19 +04:00
|
|
|
|
2014-08-19 17:56:00 +04:00
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
2015-06-03 11:43:43 +03:00
|
|
|
GetServiceWorkerRegistrationInfo(nsIPrincipal* aPrincipal, nsIURI* aURI);
|
|
|
|
|
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
|
|
|
GetServiceWorkerRegistrationInfo(const OriginAttributes& aOriginAttributes,
|
|
|
|
nsIURI* aURI);
|
|
|
|
|
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
|
|
|
GetServiceWorkerRegistrationInfo(const nsACString& aScopeKey,
|
|
|
|
nsIURI* aURI);
|
|
|
|
|
|
|
|
// This method generates a key using appId and isInElementBrowser from the
|
|
|
|
// principal. We don't use the origin because it can change during the
|
|
|
|
// loading.
|
|
|
|
static nsresult
|
|
|
|
PrincipalToScopeKey(nsIPrincipal* aPrincipal, nsACString& aKey);
|
2014-07-11 22:52:19 +04:00
|
|
|
|
|
|
|
static void
|
2015-06-03 11:43:43 +03:00
|
|
|
AddScopeAndRegistration(const nsACString& aScope,
|
|
|
|
ServiceWorkerRegistrationInfo* aRegistation);
|
|
|
|
|
|
|
|
static bool
|
|
|
|
FindScopeForPath(const nsACString& aScopeKey,
|
|
|
|
const nsACString& aPath,
|
|
|
|
RegistrationDataPerPrincipal** aData, nsACString& aMatch);
|
2014-07-11 22:52:19 +04:00
|
|
|
|
2015-06-03 11:43:43 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
static bool
|
|
|
|
HasScope(nsIPrincipal* aPrincipal, const nsACString& aScope);
|
|
|
|
#endif
|
2014-07-11 22:52:19 +04:00
|
|
|
|
|
|
|
static void
|
2015-06-03 11:43:43 +03:00
|
|
|
RemoveScopeAndRegistration(ServiceWorkerRegistrationInfo* aRegistration);
|
2014-07-11 22:52:19 +04:00
|
|
|
|
2014-12-19 13:00:29 +03:00
|
|
|
void
|
|
|
|
QueueFireEventOnServiceWorkerRegistrations(ServiceWorkerRegistrationInfo* aRegistration,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
2014-07-15 01:15:23 +04:00
|
|
|
void
|
2015-04-08 23:13:32 +03:00
|
|
|
FireUpdateFoundOnServiceWorkerRegistrations(ServiceWorkerRegistrationInfo* aRegistration);
|
2014-12-19 16:01:53 +03:00
|
|
|
|
2014-12-19 13:00:29 +03:00
|
|
|
void
|
|
|
|
FireControllerChange(ServiceWorkerRegistrationInfo* aRegistration);
|
|
|
|
|
2014-08-26 12:16:03 +04:00
|
|
|
void
|
|
|
|
StorePendingReadyPromise(nsPIDOMWindow* aWindow, nsIURI* aURI, Promise* aPromise);
|
|
|
|
|
|
|
|
void
|
|
|
|
CheckPendingReadyPromises();
|
|
|
|
|
|
|
|
bool
|
|
|
|
CheckReadyPromise(nsPIDOMWindow* aWindow, nsIURI* aURI, Promise* aPromise);
|
|
|
|
|
|
|
|
struct PendingReadyPromise
|
|
|
|
{
|
|
|
|
PendingReadyPromise(nsIURI* aURI, Promise* aPromise)
|
|
|
|
: mURI(aURI), mPromise(aPromise)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
|
|
|
nsRefPtr<Promise> mPromise;
|
|
|
|
};
|
|
|
|
|
2015-02-11 14:53:00 +03:00
|
|
|
void AppendPendingOperation(nsIRunnable* aRunnable);
|
|
|
|
void AppendPendingOperation(ServiceWorkerJobQueue* aQueue,
|
|
|
|
ServiceWorkerJob* aJob);
|
|
|
|
|
|
|
|
bool HasBackgroundActor() const
|
|
|
|
{
|
|
|
|
return !!mActor;
|
|
|
|
}
|
|
|
|
|
2014-08-26 12:16:03 +04:00
|
|
|
static PLDHashOperator
|
|
|
|
CheckPendingReadyPromisesEnumerator(nsISupports* aSupports,
|
|
|
|
nsAutoPtr<PendingReadyPromise>& aData,
|
|
|
|
void* aUnused);
|
|
|
|
|
|
|
|
nsClassHashtable<nsISupportsHashKey, PendingReadyPromise> mPendingReadyPromises;
|
2015-03-06 04:37:49 +03:00
|
|
|
|
2015-02-11 01:33:23 +03:00
|
|
|
void
|
|
|
|
MaybeRemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration);
|
2015-02-11 14:53:00 +03:00
|
|
|
|
2015-03-06 04:37:49 +03:00
|
|
|
// Does all cleanup except removing the registration from
|
|
|
|
// mServiceWorkerRegistrationInfos. This is useful when we clear
|
|
|
|
// registrations via remove()/removeAll() since we are iterating over the
|
|
|
|
// hashtable and can cleanly remove within the hashtable enumeration
|
|
|
|
// function.
|
|
|
|
void
|
|
|
|
RemoveRegistrationInternal(ServiceWorkerRegistrationInfo* aRegistration);
|
|
|
|
|
2015-08-03 23:51:07 +03:00
|
|
|
// Removes all service worker registrations that matches the given
|
|
|
|
// mozIApplicationClearPrivateDataParams.
|
2015-06-11 20:42:38 +03:00
|
|
|
void
|
2015-08-19 09:46:53 +03:00
|
|
|
RemoveAllRegistrations(OriginAttributes* aParams);
|
2015-06-11 20:42:38 +03:00
|
|
|
|
2015-06-04 21:51:57 +03:00
|
|
|
nsRefPtr<ServiceWorkerManagerChild> mActor;
|
2015-02-11 14:53:00 +03:00
|
|
|
|
|
|
|
struct PendingOperation;
|
|
|
|
nsTArray<PendingOperation> mPendingOperations;
|
2015-06-23 15:56:29 +03:00
|
|
|
|
|
|
|
bool mShuttingDown;
|
2013-11-20 03:15:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace workers
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_serviceworkermanager_h
|