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"
|
|
|
|
#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
|
|
|
|
2014-07-03 04:48:35 +04:00
|
|
|
class nsIScriptError;
|
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
namespace mozilla {
|
2015-02-11 14:53:00 +03:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class BackgroundChild;
|
|
|
|
}
|
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
namespace dom {
|
2014-08-19 17:56:00 +04:00
|
|
|
|
|
|
|
class ServiceWorkerRegistration;
|
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
namespace workers {
|
|
|
|
|
|
|
|
class ServiceWorker;
|
2014-12-19 14:25:56 +03:00
|
|
|
class ServiceWorkerInfo;
|
2014-12-19 13:00:29 +03:00
|
|
|
|
|
|
|
class ServiceWorkerJobQueue;
|
|
|
|
|
|
|
|
class ServiceWorkerJob : public nsISupports
|
|
|
|
{
|
2015-02-11 01:33:23 +03:00
|
|
|
protected:
|
2014-12-19 13:00:29 +03:00
|
|
|
// The queue keeps the jobs alive, so they can hold a rawptr back to the
|
|
|
|
// queue.
|
|
|
|
ServiceWorkerJobQueue* mQueue;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
virtual void Start() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
explicit ServiceWorkerJob(ServiceWorkerJobQueue* aQueue)
|
|
|
|
: mQueue(aQueue)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~ServiceWorkerJob()
|
2013-11-20 03:15:02 +04:00
|
|
|
{ }
|
2014-12-19 13:00:29 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
Done(nsresult aStatus);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ServiceWorkerJobQueue MOZ_FINAL
|
|
|
|
{
|
|
|
|
friend class ServiceWorkerJob;
|
|
|
|
|
|
|
|
nsTArray<nsRefPtr<ServiceWorkerJob>> mJobs;
|
|
|
|
|
|
|
|
public:
|
|
|
|
~ServiceWorkerJobQueue()
|
|
|
|
{
|
2015-01-23 23:42:32 +03:00
|
|
|
if (!mJobs.IsEmpty()) {
|
|
|
|
NS_WARNING("Pending/running jobs still around on shutdown!");
|
|
|
|
}
|
2014-12-19 13:00:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Append(ServiceWorkerJob* aJob)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(aJob);
|
|
|
|
MOZ_ASSERT(!mJobs.Contains(aJob));
|
|
|
|
bool wasEmpty = mJobs.IsEmpty();
|
|
|
|
mJobs.AppendElement(aJob);
|
|
|
|
if (wasEmpty) {
|
|
|
|
aJob->Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-19 13:48:31 +03:00
|
|
|
// Only used by HandleError, keep it that way!
|
|
|
|
ServiceWorkerJob*
|
|
|
|
Peek()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mJobs.IsEmpty());
|
|
|
|
return mJobs[0];
|
|
|
|
}
|
|
|
|
|
2014-12-19 13:00:29 +03:00
|
|
|
private:
|
|
|
|
void
|
|
|
|
Pop()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mJobs.IsEmpty());
|
|
|
|
mJobs.RemoveElementAt(0);
|
|
|
|
if (!mJobs.IsEmpty()) {
|
|
|
|
mJobs[0]->Start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Done(ServiceWorkerJob* aJob)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mJobs.IsEmpty());
|
|
|
|
MOZ_ASSERT(mJobs[0] == aJob);
|
|
|
|
Pop();
|
|
|
|
}
|
2013-11-20 03:15:02 +04:00
|
|
|
};
|
|
|
|
|
2014-06-11 20:12:56 +04:00
|
|
|
// Needs to inherit from nsISupports because NS_ProxyRelease() does not support
|
|
|
|
// non-ISupports classes.
|
2014-08-19 17:56:00 +04:00
|
|
|
class ServiceWorkerRegistrationInfo MOZ_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-02-11 14:53:00 +03:00
|
|
|
explicit 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
|
|
|
|
|
|
|
void
|
|
|
|
TryToActivate();
|
|
|
|
|
|
|
|
void
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
void
|
|
|
|
FinishActivate(bool aSuccess);
|
2014-12-19 14:25:56 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
QueueStateChangeEvent(ServiceWorkerInfo* aInfo,
|
|
|
|
ServiceWorkerState aState) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
class ServiceWorkerInfo MOZ_FINAL
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
const ServiceWorkerRegistrationInfo* mRegistration;
|
|
|
|
nsCString mScriptSpec;
|
|
|
|
ServiceWorkerState mState;
|
|
|
|
|
|
|
|
~ServiceWorkerInfo()
|
|
|
|
{ }
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(ServiceWorkerInfo)
|
|
|
|
|
|
|
|
const nsCString&
|
|
|
|
ScriptSpec() const
|
|
|
|
{
|
|
|
|
return mScriptSpec;
|
|
|
|
}
|
|
|
|
|
2015-02-11 14:53:00 +03:00
|
|
|
void SetScriptSpec(const nsCString& aSpec)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!aSpec.IsEmpty());
|
|
|
|
mScriptSpec = aSpec;
|
|
|
|
}
|
|
|
|
|
2014-12-19 14:25:56 +03:00
|
|
|
explicit ServiceWorkerInfo(ServiceWorkerRegistrationInfo* aReg,
|
|
|
|
const nsACString& aScriptSpec)
|
|
|
|
: mRegistration(aReg)
|
|
|
|
, mScriptSpec(aScriptSpec)
|
|
|
|
, mState(ServiceWorkerState::EndGuard_)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mRegistration);
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceWorkerState
|
|
|
|
State() const
|
|
|
|
{
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateState(ServiceWorkerState aState)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Any state can directly transition to redundant, but everything else is
|
|
|
|
// ordered.
|
|
|
|
if (aState != ServiceWorkerState::Redundant) {
|
|
|
|
MOZ_ASSERT_IF(mState == ServiceWorkerState::EndGuard_, aState == ServiceWorkerState::Installing);
|
|
|
|
MOZ_ASSERT_IF(mState == ServiceWorkerState::Installing, aState == ServiceWorkerState::Installed);
|
|
|
|
MOZ_ASSERT_IF(mState == ServiceWorkerState::Installed, aState == ServiceWorkerState::Activating);
|
|
|
|
MOZ_ASSERT_IF(mState == ServiceWorkerState::Activating, aState == ServiceWorkerState::Activated);
|
|
|
|
}
|
|
|
|
// Activated can only go to redundant.
|
|
|
|
MOZ_ASSERT_IF(mState == ServiceWorkerState::Activated, aState == ServiceWorkerState::Redundant);
|
|
|
|
#endif
|
|
|
|
mState = aState;
|
|
|
|
mRegistration->QueueStateChangeEvent(this, mState);
|
|
|
|
}
|
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-02-11 14:53:00 +03:00
|
|
|
class ServiceWorkerManager MOZ_FINAL
|
|
|
|
: public nsIServiceWorkerManager
|
|
|
|
, public nsIIPCBackgroundChildCreateCallback
|
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;
|
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
|
2013-11-20 03:15:02 +04:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_SERVICEWORKERMANAGER_IMPL_IID)
|
|
|
|
|
|
|
|
static ServiceWorkerManager* FactoryCreate()
|
|
|
|
{
|
2014-07-21 10:25:44 +04:00
|
|
|
AssertIsOnMainThread();
|
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
ServiceWorkerManager* res = new ServiceWorkerManager;
|
|
|
|
NS_ADDREF(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
// Ordered list of scopes for glob matching.
|
|
|
|
// Each entry is an absolute URL representing the scope.
|
|
|
|
//
|
|
|
|
// An array is used for now since the number of controlled scopes per
|
|
|
|
// domain is expected to be relatively low. If that assumption was proved
|
|
|
|
// wrong this should be replaced with a better structure to avoid the
|
|
|
|
// memmoves associated with inserting stuff in the middle of the array.
|
|
|
|
nsTArray<nsCString> mOrderedScopes;
|
2014-07-15 01:15:23 +04:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
// Scope to registration.
|
|
|
|
// The scope should be a fully qualified valid URL.
|
|
|
|
nsRefPtrHashtable<nsCStringHashKey, ServiceWorkerRegistrationInfo> mServiceWorkerRegistrationInfos;
|
2014-07-21 10:25:44 +04:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
nsTObserverArray<ServiceWorkerRegistration*> mServiceWorkerRegistrations;
|
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-02-09 07:33:39 +03:00
|
|
|
// Maps scopes to job queues.
|
|
|
|
nsClassHashtable<nsCStringHashKey, ServiceWorkerJobQueue> mJobQueues;
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
nsDataHashtable<nsCStringHashKey, bool> mSetOfScopesBeingUpdated;
|
2014-07-15 01:15:23 +04:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
already_AddRefed<ServiceWorkerRegistrationInfo>
|
|
|
|
GetRegistration(const nsCString& aScope) const
|
|
|
|
{
|
|
|
|
nsRefPtr<ServiceWorkerRegistrationInfo> reg;
|
|
|
|
mServiceWorkerRegistrationInfos.Get(aScope, getter_AddRefs(reg));
|
|
|
|
return reg.forget();
|
|
|
|
}
|
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
|
|
|
|
RemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration)
|
|
|
|
{
|
2014-10-25 02:11:26 +04:00
|
|
|
MOZ_ASSERT(aRegistration);
|
|
|
|
MOZ_ASSERT(!aRegistration->IsControllingDocuments());
|
2015-02-09 07:33:39 +03:00
|
|
|
MOZ_ASSERT(mServiceWorkerRegistrationInfos.Contains(aRegistration->mScope));
|
|
|
|
ServiceWorkerManager::RemoveScope(mOrderedScopes, aRegistration->mScope);
|
|
|
|
mServiceWorkerRegistrationInfos.Remove(aRegistration->mScope);
|
|
|
|
}
|
2013-11-20 03:15:02 +04:00
|
|
|
|
2015-02-09 07:33:39 +03:00
|
|
|
ServiceWorkerJobQueue*
|
|
|
|
GetOrCreateJobQueue(const nsCString& aScope)
|
|
|
|
{
|
|
|
|
return mJobQueues.LookupOrAdd(aScope);
|
|
|
|
}
|
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,
|
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,
|
|
|
|
uint32_t aFlags);
|
|
|
|
|
2014-10-27 14:03:00 +03:00
|
|
|
void
|
2015-02-20 18:16:17 +03:00
|
|
|
GetAllClients(const nsCString& aScope,
|
|
|
|
nsTArray<uint64_t>* aControlledDocuments);
|
2014-10-27 14:03:00 +03:00
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
static already_AddRefed<ServiceWorkerManager>
|
|
|
|
GetInstance();
|
|
|
|
|
2015-02-11 14:53:00 +03:00
|
|
|
void LoadRegistrations(
|
|
|
|
const nsTArray<ServiceWorkerRegistrationData>& aRegistrations);
|
|
|
|
|
2013-11-20 03:15:02 +04:00
|
|
|
private:
|
|
|
|
ServiceWorkerManager();
|
|
|
|
~ServiceWorkerManager();
|
|
|
|
|
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,
|
|
|
|
const nsACString& aScriptSpec,
|
|
|
|
const nsACString& aScope,
|
|
|
|
ServiceWorker** aServiceWorker);
|
|
|
|
|
2014-07-03 04:48:50 +04:00
|
|
|
NS_IMETHOD
|
2015-02-17 15:36:09 +03:00
|
|
|
CreateServiceWorker(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aScriptSpec,
|
2014-07-03 04:48:50 +04:00
|
|
|
const nsACString& aScope,
|
|
|
|
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
|
|
|
|
|
|
|
void
|
2014-08-19 17:56:00 +04:00
|
|
|
InvalidateServiceWorkerRegistrationWorker(ServiceWorkerRegistrationInfo* aRegistration,
|
|
|
|
WhichServiceWorker aWhichOnes);
|
2014-07-24 01:05:08 +04:00
|
|
|
|
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>
|
|
|
|
GetServiceWorkerRegistrationInfo(nsIURI* aURI);
|
2014-07-11 22:52:19 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
AddScope(nsTArray<nsCString>& aList, const nsACString& aScope);
|
|
|
|
|
|
|
|
static nsCString
|
|
|
|
FindScopeForPath(nsTArray<nsCString>& aList, const nsACString& aPath);
|
|
|
|
|
|
|
|
static void
|
|
|
|
RemoveScope(nsTArray<nsCString>& aList, const nsACString& aScope);
|
|
|
|
|
2014-12-19 13:00:29 +03:00
|
|
|
void
|
|
|
|
QueueFireEventOnServiceWorkerRegistrations(ServiceWorkerRegistrationInfo* aRegistration,
|
|
|
|
const nsAString& aName);
|
|
|
|
|
2014-07-15 01:15:23 +04:00
|
|
|
void
|
2014-08-19 17:56:00 +04:00
|
|
|
FireEventOnServiceWorkerRegistrations(ServiceWorkerRegistrationInfo* aRegistration,
|
|
|
|
const nsAString& aName);
|
2014-07-15 01:15:23 +04:00
|
|
|
|
2014-12-19 16:01:53 +03:00
|
|
|
void
|
|
|
|
FireUpdateFound(ServiceWorkerRegistrationInfo* aRegistration)
|
|
|
|
{
|
|
|
|
FireEventOnServiceWorkerRegistrations(aRegistration,
|
|
|
|
NS_LITERAL_STRING("updatefound"));
|
|
|
|
}
|
|
|
|
|
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-02-11 01:33:23 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
MaybeRemoveRegistration(ServiceWorkerRegistrationInfo* aRegistration);
|
2015-02-11 14:53:00 +03:00
|
|
|
|
|
|
|
mozilla::ipc::PBackgroundChild* mActor;
|
|
|
|
|
|
|
|
struct PendingOperation;
|
|
|
|
nsTArray<PendingOperation> mPendingOperations;
|
2013-11-20 03:15:02 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(ServiceWorkerManager,
|
|
|
|
NS_SERVICEWORKERMANAGER_IMPL_IID);
|
|
|
|
|
|
|
|
} // namespace workers
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_serviceworkermanager_h
|