2016-04-09 00:28:25 +00: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/. */
|
|
|
|
|
2018-01-26 21:08:59 +00:00
|
|
|
#ifndef mozilla_dom_serviceworkerregistrationinfo_h
|
|
|
|
#define mozilla_dom_serviceworkerregistrationinfo_h
|
2016-04-09 00:28:25 +00:00
|
|
|
|
2018-01-26 21:08:59 +00:00
|
|
|
#include "mozilla/dom/ServiceWorkerInfo.h"
|
2017-08-16 06:18:52 +00:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
|
2018-01-31 16:29:49 +00:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
|
2018-01-26 21:08:58 +00:00
|
|
|
#include "nsProxyRelease.h"
|
2018-07-02 14:44:19 +00:00
|
|
|
#include "nsTObserverArray.h"
|
2016-04-09 00:28:25 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-07-02 14:44:19 +00:00
|
|
|
class ServiceWorkerRegistrationListener;
|
|
|
|
|
2016-04-09 00:28:25 +00:00
|
|
|
class ServiceWorkerRegistrationInfo final
|
|
|
|
: public nsIServiceWorkerRegistrationInfo
|
|
|
|
{
|
2018-01-31 16:29:49 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2018-01-31 16:29:49 +00:00
|
|
|
ServiceWorkerRegistrationDescriptor mDescriptor;
|
2018-01-31 16:29:49 +00:00
|
|
|
nsTArray<nsCOMPtr<nsIServiceWorkerRegistrationInfoListener>> mListeners;
|
2018-07-02 14:44:19 +00:00
|
|
|
nsTObserverArray<ServiceWorkerRegistrationListener*> mInstanceList;
|
2018-01-31 16:29:49 +00:00
|
|
|
|
2018-01-05 17:10:21 +00:00
|
|
|
uint32_t mControlledClientsCounter;
|
2018-02-13 17:02:58 +00:00
|
|
|
uint32_t mDelayMultiplier;
|
2016-04-09 00:28:25 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NoUpdate,
|
|
|
|
NeedTimeCheckAndUpdate,
|
|
|
|
NeedUpdate
|
|
|
|
} mUpdateState;
|
|
|
|
|
2017-04-06 07:26:08 +00:00
|
|
|
// Timestamp to track SWR's last update time
|
|
|
|
PRTime mCreationTime;
|
|
|
|
TimeStamp mCreationTimeStamp;
|
|
|
|
// The time of update is 0, if SWR've never been updated yet.
|
|
|
|
PRTime mLastUpdateTime;
|
|
|
|
|
2016-07-27 23:09:15 +00:00
|
|
|
RefPtr<ServiceWorkerInfo> mEvaluatingWorker;
|
2016-04-17 11:29:53 +00:00
|
|
|
RefPtr<ServiceWorkerInfo> mActiveWorker;
|
|
|
|
RefPtr<ServiceWorkerInfo> mWaitingWorker;
|
|
|
|
RefPtr<ServiceWorkerInfo> mInstallingWorker;
|
|
|
|
|
2016-04-09 00:28:25 +00:00
|
|
|
virtual ~ServiceWorkerRegistrationInfo();
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2018-04-02 14:50:22 +00:00
|
|
|
bool mCorrupt;
|
|
|
|
|
2018-01-31 16:29:49 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISERVICEWORKERREGISTRATIONINFO
|
|
|
|
|
2016-04-09 00:28:25 +00:00
|
|
|
ServiceWorkerRegistrationInfo(const nsACString& aScope,
|
2017-01-04 09:08:43 +00:00
|
|
|
nsIPrincipal* aPrincipal,
|
2017-08-16 06:18:52 +00:00
|
|
|
ServiceWorkerUpdateViaCache aUpdateViaCache);
|
2016-04-09 00:28:25 +00:00
|
|
|
|
2018-07-02 14:44:19 +00:00
|
|
|
void
|
|
|
|
AddInstance(ServiceWorkerRegistrationListener* aInstance);
|
|
|
|
|
|
|
|
void
|
|
|
|
RemoveInstance(ServiceWorkerRegistrationListener* aInstance);
|
|
|
|
|
2018-01-31 16:29:49 +00:00
|
|
|
const nsCString&
|
|
|
|
Scope() const;
|
|
|
|
|
|
|
|
nsIPrincipal*
|
|
|
|
Principal() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsPendingUninstall() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetPendingUninstall();
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearPendingUninstall();
|
|
|
|
|
2016-04-09 00:28:25 +00:00
|
|
|
already_AddRefed<ServiceWorkerInfo>
|
|
|
|
Newest() const
|
|
|
|
{
|
|
|
|
RefPtr<ServiceWorkerInfo> newest;
|
|
|
|
if (mInstallingWorker) {
|
|
|
|
newest = mInstallingWorker;
|
|
|
|
} else if (mWaitingWorker) {
|
|
|
|
newest = mWaitingWorker;
|
|
|
|
} else {
|
|
|
|
newest = mActiveWorker;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newest.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<ServiceWorkerInfo>
|
|
|
|
GetServiceWorkerInfoById(uint64_t aId);
|
|
|
|
|
|
|
|
void
|
2018-01-05 17:10:21 +00:00
|
|
|
StartControllingClient()
|
2016-04-09 00:28:25 +00:00
|
|
|
{
|
2018-01-05 17:10:21 +00:00
|
|
|
++mControlledClientsCounter;
|
2018-02-13 17:02:58 +00:00
|
|
|
mDelayMultiplier = 0;
|
2016-04-09 00:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-05 17:10:21 +00:00
|
|
|
StopControllingClient()
|
2016-04-09 00:28:25 +00:00
|
|
|
{
|
2018-01-05 17:10:21 +00:00
|
|
|
MOZ_ASSERT(mControlledClientsCounter);
|
|
|
|
--mControlledClientsCounter;
|
2016-04-09 00:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-01-05 17:10:21 +00:00
|
|
|
IsControllingClients() const
|
2016-04-09 00:28:25 +00:00
|
|
|
{
|
2018-01-05 17:10:21 +00:00
|
|
|
return mActiveWorker && mControlledClientsCounter;
|
2016-04-09 00:28:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Clear();
|
|
|
|
|
2018-04-02 14:50:22 +00:00
|
|
|
void
|
|
|
|
ClearAsCorrupt();
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsCorrupt() const;
|
|
|
|
|
2016-04-09 00:28:25 +00:00
|
|
|
void
|
|
|
|
TryToActivateAsync();
|
|
|
|
|
|
|
|
void
|
|
|
|
TryToActivate();
|
|
|
|
|
|
|
|
void
|
|
|
|
Activate();
|
|
|
|
|
|
|
|
void
|
|
|
|
FinishActivate(bool aSuccess);
|
|
|
|
|
|
|
|
void
|
|
|
|
RefreshLastUpdateCheckTime();
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsLastUpdateCheckTimeOverOneDay() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeScheduleTimeCheckAndUpdate();
|
|
|
|
|
|
|
|
void
|
|
|
|
MaybeScheduleUpdate();
|
|
|
|
|
|
|
|
bool
|
|
|
|
CheckAndClearIfUpdateNeeded();
|
2016-04-17 11:29:53 +00:00
|
|
|
|
2016-07-27 23:09:15 +00:00
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetEvaluating() const;
|
|
|
|
|
2016-04-17 11:29:53 +00:00
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetInstalling() const;
|
|
|
|
|
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetWaiting() const;
|
|
|
|
|
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetActive() const;
|
|
|
|
|
2018-02-19 20:06:19 +00:00
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetByDescriptor(const ServiceWorkerDescriptor& aDescriptor) const;
|
|
|
|
|
2016-07-27 23:09:15 +00:00
|
|
|
// Set the given worker as the evaluating service worker. The worker
|
|
|
|
// state is not changed.
|
|
|
|
void
|
|
|
|
SetEvaluating(ServiceWorkerInfo* aServiceWorker);
|
|
|
|
|
|
|
|
// Remove an existing evaluating worker, if present. The worker will
|
|
|
|
// be transitioned to the Redundant state.
|
|
|
|
void
|
|
|
|
ClearEvaluating();
|
|
|
|
|
2016-04-17 11:29:53 +00:00
|
|
|
// Remove an existing installing worker, if present. The worker will
|
|
|
|
// be transitioned to the Redundant state.
|
|
|
|
void
|
|
|
|
ClearInstalling();
|
|
|
|
|
2016-07-27 23:09:15 +00:00
|
|
|
// Transition the current evaluating worker to be the installing worker. The
|
|
|
|
// worker's state is update to Installing.
|
2016-04-17 11:29:53 +00:00
|
|
|
void
|
2016-07-27 23:09:15 +00:00
|
|
|
TransitionEvaluatingToInstalling();
|
2016-04-17 11:29:53 +00:00
|
|
|
|
2016-04-17 11:29:53 +00:00
|
|
|
// Transition the current installing worker to be the waiting worker. The
|
2016-07-27 23:09:15 +00:00
|
|
|
// worker's state is updated to Installed.
|
2016-04-17 11:29:53 +00:00
|
|
|
void
|
2016-04-17 11:29:53 +00:00
|
|
|
TransitionInstallingToWaiting();
|
2016-04-17 11:29:53 +00:00
|
|
|
|
2016-04-17 11:29:53 +00:00
|
|
|
// Override the current active worker. This is used during browser
|
|
|
|
// initialization to load persisted workers. Its also used to propagate
|
|
|
|
// active workers across child processes in e10s. This second use will
|
|
|
|
// go away once the ServiceWorkerManager moves to the parent process.
|
|
|
|
// The worker is transitioned to the Activated state.
|
2016-04-17 11:29:53 +00:00
|
|
|
void
|
|
|
|
SetActive(ServiceWorkerInfo* aServiceWorker);
|
2016-04-17 11:29:53 +00:00
|
|
|
|
|
|
|
// Transition the current waiting worker to be the new active worker. The
|
|
|
|
// worker is updated to the Activating state.
|
|
|
|
void
|
|
|
|
TransitionWaitingToActive();
|
2016-08-18 14:12:08 +00:00
|
|
|
|
|
|
|
// Determine if the registration is actively performing work.
|
|
|
|
bool
|
|
|
|
IsIdle() const;
|
2016-11-21 02:14:54 +00:00
|
|
|
|
2017-08-16 06:18:52 +00:00
|
|
|
ServiceWorkerUpdateViaCache
|
|
|
|
GetUpdateViaCache() const;
|
2017-01-04 09:08:43 +00:00
|
|
|
|
2017-01-04 09:08:51 +00:00
|
|
|
void
|
2017-08-16 06:18:52 +00:00
|
|
|
SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache);
|
2017-01-04 09:08:51 +00:00
|
|
|
|
2017-04-05 01:59:48 +00:00
|
|
|
int64_t
|
|
|
|
GetLastUpdateTime() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetLastUpdateTime(const int64_t aTime);
|
|
|
|
|
2018-01-31 16:29:49 +00:00
|
|
|
const ServiceWorkerRegistrationDescriptor&
|
|
|
|
Descriptor() const;
|
|
|
|
|
2018-07-02 14:44:18 +00:00
|
|
|
uint64_t
|
|
|
|
Id() const;
|
|
|
|
|
2018-02-13 17:02:58 +00:00
|
|
|
uint32_t
|
|
|
|
GetUpdateDelay();
|
|
|
|
|
2018-07-02 14:44:19 +00:00
|
|
|
void
|
|
|
|
FireUpdateFound();
|
|
|
|
|
|
|
|
void
|
|
|
|
NotifyRemoved();
|
|
|
|
|
2016-11-21 02:14:54 +00:00
|
|
|
private:
|
|
|
|
// Roughly equivalent to [[Update Registration State algorithm]]. Make sure
|
|
|
|
// this is called *before* updating SW instances' state, otherwise they
|
|
|
|
// may get CC-ed.
|
|
|
|
void
|
2018-02-14 19:23:16 +00:00
|
|
|
UpdateRegistrationState();
|
2016-11-21 02:14:54 +00:00
|
|
|
|
|
|
|
// Used by devtools to track changes to the properties of *nsIServiceWorkerRegistrationInfo*.
|
|
|
|
// Note, this doesn't necessarily need to be in sync with the DOM registration objects, but
|
|
|
|
// it does need to be called in the same task that changed |mInstallingWorker|,
|
|
|
|
// |mWaitingWorker| or |mActiveWorker|.
|
|
|
|
void
|
|
|
|
NotifyChromeRegistrationListeners();
|
2018-03-02 21:02:50 +00:00
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
GetNextId();
|
2016-04-09 00:28:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-01-26 21:08:59 +00:00
|
|
|
#endif // mozilla_dom_serviceworkerregistrationinfo_h
|