2016-04-09 03:28:25 +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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_workers_serviceworkerinfo_h
|
|
|
|
#define mozilla_dom_workers_serviceworkerinfo_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/ServiceWorkerBinding.h" // For ServiceWorkerState
|
2017-03-24 22:27:11 +03:00
|
|
|
#include "mozilla/dom/workers/Workers.h"
|
2016-04-09 03:28:25 +03:00
|
|
|
#include "nsIServiceWorkerManager.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
namespace workers {
|
|
|
|
|
|
|
|
class ServiceWorker;
|
|
|
|
class ServiceWorkerPrivate;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 final : public nsIServiceWorkerInfo
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
|
|
|
const nsCString mScope;
|
|
|
|
const nsCString mScriptSpec;
|
|
|
|
const nsString mCacheName;
|
|
|
|
ServiceWorkerState mState;
|
2017-01-12 19:38:48 +03:00
|
|
|
OriginAttributes mOriginAttributes;
|
2016-04-09 03:28:25 +03:00
|
|
|
|
2017-08-16 09:18:52 +03:00
|
|
|
// This LoadFlags is only applied to imported scripts, since the main script
|
|
|
|
// has already been downloaded when performing the bytecheck. This LoadFlag is
|
|
|
|
// composed of three parts:
|
|
|
|
// 1. nsIChannel::LOAD_BYPASS_SERVICE_WORKER
|
|
|
|
// 2. (Optional) nsIRequest::VALIDATE_ALWAYS
|
|
|
|
// depends on ServiceWorkerUpdateViaCache of its registration.
|
|
|
|
// 3. (optional) nsIRequest::LOAD_BYPASS_CACHE
|
|
|
|
// depends on whether the update timer is expired.
|
|
|
|
const nsLoadFlags mImportsLoadFlags;
|
|
|
|
|
2016-04-09 03:28:25 +03:00
|
|
|
// This id is shared with WorkerPrivate to match requests issued by service
|
|
|
|
// workers to their corresponding serviceWorkerInfo.
|
|
|
|
uint64_t mServiceWorkerID;
|
|
|
|
|
2017-04-06 10:26:08 +03:00
|
|
|
// Timestamp to track SW's state
|
|
|
|
PRTime mCreationTime;
|
|
|
|
TimeStamp mCreationTimeStamp;
|
|
|
|
|
|
|
|
// The time of states are 0, if SW has not reached that state yet. Besides, we
|
|
|
|
// update each of them after UpdateState() is called in SWRegistrationInfo.
|
|
|
|
PRTime mInstalledTime;
|
|
|
|
PRTime mActivatedTime;
|
|
|
|
PRTime mRedundantTime;
|
|
|
|
|
2016-04-09 03:28:25 +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.
|
|
|
|
AutoTArray<ServiceWorker*, 1> mInstances;
|
|
|
|
|
|
|
|
RefPtr<ServiceWorkerPrivate> mServiceWorkerPrivate;
|
|
|
|
bool mSkipWaitingFlag;
|
|
|
|
|
2016-12-19 05:38:53 +03:00
|
|
|
enum {
|
|
|
|
Unknown,
|
|
|
|
Enabled,
|
|
|
|
Disabled
|
|
|
|
} mHandlesFetch;
|
|
|
|
|
2016-04-09 03:28:25 +03:00
|
|
|
~ServiceWorkerInfo();
|
|
|
|
|
|
|
|
// Generates a unique id for the service worker, with zero being treated as
|
|
|
|
// invalid.
|
|
|
|
uint64_t
|
|
|
|
GetNextID() const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISERVICEWORKERINFO
|
|
|
|
|
|
|
|
class ServiceWorkerPrivate*
|
|
|
|
WorkerPrivate() const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mServiceWorkerPrivate);
|
|
|
|
return mServiceWorkerPrivate;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal*
|
2017-02-20 18:31:32 +03:00
|
|
|
Principal() const
|
2016-04-09 03:28:25 +03:00
|
|
|
{
|
|
|
|
return mPrincipal;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString&
|
|
|
|
ScriptSpec() const
|
|
|
|
{
|
|
|
|
return mScriptSpec;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCString&
|
|
|
|
Scope() const
|
|
|
|
{
|
|
|
|
return mScope;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SkipWaitingFlag() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
return mSkipWaitingFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSkipWaitingFlag()
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mSkipWaitingFlag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ServiceWorkerInfo(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aScope,
|
|
|
|
const nsACString& aScriptSpec,
|
2017-01-04 12:08:55 +03:00
|
|
|
const nsAString& aCacheName,
|
|
|
|
nsLoadFlags aLoadFlags);
|
2016-04-09 03:28:25 +03:00
|
|
|
|
|
|
|
ServiceWorkerState
|
|
|
|
State() const
|
|
|
|
{
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
2017-01-12 19:38:48 +03:00
|
|
|
const OriginAttributes&
|
2016-09-20 04:13:00 +03:00
|
|
|
GetOriginAttributes() const
|
|
|
|
{
|
|
|
|
return mOriginAttributes;
|
|
|
|
}
|
|
|
|
|
2016-04-09 03:28:25 +03:00
|
|
|
const nsString&
|
|
|
|
CacheName() const
|
|
|
|
{
|
|
|
|
return mCacheName;
|
|
|
|
}
|
|
|
|
|
2017-01-04 12:08:55 +03:00
|
|
|
nsLoadFlags
|
2017-08-16 09:18:52 +03:00
|
|
|
GetImportsLoadFlags() const
|
2017-01-04 12:08:55 +03:00
|
|
|
{
|
2017-08-16 09:18:52 +03:00
|
|
|
return mImportsLoadFlags;
|
2017-01-04 12:08:55 +03:00
|
|
|
}
|
|
|
|
|
2016-04-09 03:28:25 +03:00
|
|
|
uint64_t
|
|
|
|
ID() const
|
|
|
|
{
|
|
|
|
return mServiceWorkerID;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateState(ServiceWorkerState aState);
|
|
|
|
|
|
|
|
// Only used to set initial state when loading from disk!
|
|
|
|
void
|
|
|
|
SetActivateStateUncheckedWithoutEvent(ServiceWorkerState aState)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
mState = aState;
|
|
|
|
}
|
|
|
|
|
2016-12-19 05:38:53 +03:00
|
|
|
void
|
|
|
|
SetHandlesFetch(bool aHandlesFetch)
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mHandlesFetch == Unknown);
|
|
|
|
mHandlesFetch = aHandlesFetch ? Enabled : Disabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
HandlesFetch() const
|
|
|
|
{
|
|
|
|
AssertIsOnMainThread();
|
|
|
|
MOZ_DIAGNOSTIC_ASSERT(mHandlesFetch != Unknown);
|
|
|
|
return mHandlesFetch != Disabled;
|
|
|
|
}
|
|
|
|
|
2016-04-09 03:28:25 +03:00
|
|
|
void
|
|
|
|
AppendWorker(ServiceWorker* aWorker);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveWorker(ServiceWorker* aWorker);
|
|
|
|
|
|
|
|
already_AddRefed<ServiceWorker>
|
|
|
|
GetOrCreateInstance(nsPIDOMWindowInner* aWindow);
|
2017-04-06 10:26:08 +03:00
|
|
|
|
|
|
|
void
|
|
|
|
UpdateInstalledTime();
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateActivatedTime();
|
|
|
|
|
|
|
|
void
|
|
|
|
UpdateRedundantTime();
|
2017-04-05 04:59:48 +03:00
|
|
|
|
|
|
|
int64_t
|
|
|
|
GetInstalledTime() const
|
|
|
|
{
|
|
|
|
return mInstalledTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetInstalledTime(const int64_t aTime)
|
|
|
|
{
|
|
|
|
if (aTime == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInstalledTime = aTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
GetActivatedTime() const
|
|
|
|
{
|
|
|
|
return mActivatedTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SetActivatedTime(const int64_t aTime)
|
|
|
|
{
|
|
|
|
if (aTime == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mActivatedTime = aTime;
|
|
|
|
}
|
2016-04-09 03:28:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace workers
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_serviceworkerinfo_h
|