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/. */
|
|
|
|
|
2018-01-27 00:08:59 +03:00
|
|
|
#ifndef mozilla_dom_serviceworkerregistrationinfo_h
|
|
|
|
#define mozilla_dom_serviceworkerregistrationinfo_h
|
2016-04-09 03:28:25 +03:00
|
|
|
|
2018-01-27 00:08:59 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerInfo.h"
|
2017-08-16 09:18:52 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
|
2018-01-31 19:29:49 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
|
2018-01-27 00:08:58 +03:00
|
|
|
#include "nsProxyRelease.h"
|
2016-04-09 03:28:25 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class ServiceWorkerRegistrationInfo final
|
|
|
|
: public nsIServiceWorkerRegistrationInfo
|
|
|
|
{
|
2018-01-31 19:29:49 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2018-01-31 19:29:49 +03:00
|
|
|
ServiceWorkerRegistrationDescriptor mDescriptor;
|
2018-01-31 19:29:49 +03:00
|
|
|
nsTArray<nsCOMPtr<nsIServiceWorkerRegistrationInfoListener>> mListeners;
|
|
|
|
|
2018-01-05 20:10:21 +03:00
|
|
|
uint32_t mControlledClientsCounter;
|
2018-02-13 20:02:58 +03:00
|
|
|
uint32_t mDelayMultiplier;
|
2016-04-09 03:28:25 +03:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
NoUpdate,
|
|
|
|
NeedTimeCheckAndUpdate,
|
|
|
|
NeedUpdate
|
|
|
|
} mUpdateState;
|
|
|
|
|
2017-04-06 10:26:08 +03: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-28 02:09:15 +03:00
|
|
|
RefPtr<ServiceWorkerInfo> mEvaluatingWorker;
|
2016-04-17 14:29:53 +03:00
|
|
|
RefPtr<ServiceWorkerInfo> mActiveWorker;
|
|
|
|
RefPtr<ServiceWorkerInfo> mWaitingWorker;
|
|
|
|
RefPtr<ServiceWorkerInfo> mInstallingWorker;
|
|
|
|
|
2016-04-09 03:28:25 +03: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 17:50:22 +03:00
|
|
|
bool mCorrupt;
|
|
|
|
|
2018-01-31 19:29:49 +03:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISERVICEWORKERREGISTRATIONINFO
|
|
|
|
|
2016-04-09 03:28:25 +03:00
|
|
|
ServiceWorkerRegistrationInfo(const nsACString& aScope,
|
2017-01-04 12:08:43 +03:00
|
|
|
nsIPrincipal* aPrincipal,
|
2017-08-16 09:18:52 +03:00
|
|
|
ServiceWorkerUpdateViaCache aUpdateViaCache);
|
2016-04-09 03:28:25 +03:00
|
|
|
|
2018-01-31 19:29:49 +03:00
|
|
|
const nsCString&
|
|
|
|
Scope() const;
|
|
|
|
|
|
|
|
nsIPrincipal*
|
|
|
|
Principal() const;
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsPendingUninstall() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetPendingUninstall();
|
|
|
|
|
|
|
|
void
|
|
|
|
ClearPendingUninstall();
|
|
|
|
|
2016-04-09 03:28:25 +03: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 20:10:21 +03:00
|
|
|
StartControllingClient()
|
2016-04-09 03:28:25 +03:00
|
|
|
{
|
2018-01-05 20:10:21 +03:00
|
|
|
++mControlledClientsCounter;
|
2018-02-13 20:02:58 +03:00
|
|
|
mDelayMultiplier = 0;
|
2016-04-09 03:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-01-05 20:10:21 +03:00
|
|
|
StopControllingClient()
|
2016-04-09 03:28:25 +03:00
|
|
|
{
|
2018-01-05 20:10:21 +03:00
|
|
|
MOZ_ASSERT(mControlledClientsCounter);
|
|
|
|
--mControlledClientsCounter;
|
2016-04-09 03:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2018-01-05 20:10:21 +03:00
|
|
|
IsControllingClients() const
|
2016-04-09 03:28:25 +03:00
|
|
|
{
|
2018-01-05 20:10:21 +03:00
|
|
|
return mActiveWorker && mControlledClientsCounter;
|
2016-04-09 03:28:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Clear();
|
|
|
|
|
2018-04-02 17:50:22 +03:00
|
|
|
void
|
|
|
|
ClearAsCorrupt();
|
|
|
|
|
|
|
|
bool
|
|
|
|
IsCorrupt() const;
|
|
|
|
|
2016-04-09 03:28:25 +03: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 14:29:53 +03:00
|
|
|
|
2016-07-28 02:09:15 +03:00
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetEvaluating() const;
|
|
|
|
|
2016-04-17 14:29:53 +03:00
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetInstalling() const;
|
|
|
|
|
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetWaiting() const;
|
|
|
|
|
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetActive() const;
|
|
|
|
|
2018-02-19 23:06:19 +03:00
|
|
|
ServiceWorkerInfo*
|
|
|
|
GetByDescriptor(const ServiceWorkerDescriptor& aDescriptor) const;
|
|
|
|
|
2016-07-28 02:09:15 +03: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 14:29:53 +03:00
|
|
|
// Remove an existing installing worker, if present. The worker will
|
|
|
|
// be transitioned to the Redundant state.
|
|
|
|
void
|
|
|
|
ClearInstalling();
|
|
|
|
|
2016-07-28 02:09:15 +03:00
|
|
|
// Transition the current evaluating worker to be the installing worker. The
|
|
|
|
// worker's state is update to Installing.
|
2016-04-17 14:29:53 +03:00
|
|
|
void
|
2016-07-28 02:09:15 +03:00
|
|
|
TransitionEvaluatingToInstalling();
|
2016-04-17 14:29:53 +03:00
|
|
|
|
2016-04-17 14:29:53 +03:00
|
|
|
// Transition the current installing worker to be the waiting worker. The
|
2016-07-28 02:09:15 +03:00
|
|
|
// worker's state is updated to Installed.
|
2016-04-17 14:29:53 +03:00
|
|
|
void
|
2016-04-17 14:29:53 +03:00
|
|
|
TransitionInstallingToWaiting();
|
2016-04-17 14:29:53 +03:00
|
|
|
|
2016-04-17 14:29:53 +03: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 14:29:53 +03:00
|
|
|
void
|
|
|
|
SetActive(ServiceWorkerInfo* aServiceWorker);
|
2016-04-17 14:29:53 +03: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 17:12:08 +03:00
|
|
|
|
|
|
|
// Determine if the registration is actively performing work.
|
|
|
|
bool
|
|
|
|
IsIdle() const;
|
2016-11-21 05:14:54 +03:00
|
|
|
|
2017-08-16 09:18:52 +03:00
|
|
|
ServiceWorkerUpdateViaCache
|
|
|
|
GetUpdateViaCache() const;
|
2017-01-04 12:08:43 +03:00
|
|
|
|
2017-01-04 12:08:51 +03:00
|
|
|
void
|
2017-08-16 09:18:52 +03:00
|
|
|
SetUpdateViaCache(ServiceWorkerUpdateViaCache aUpdateViaCache);
|
2017-01-04 12:08:51 +03:00
|
|
|
|
2017-04-05 04:59:48 +03:00
|
|
|
int64_t
|
|
|
|
GetLastUpdateTime() const;
|
|
|
|
|
|
|
|
void
|
|
|
|
SetLastUpdateTime(const int64_t aTime);
|
|
|
|
|
2018-01-31 19:29:49 +03:00
|
|
|
const ServiceWorkerRegistrationDescriptor&
|
|
|
|
Descriptor() const;
|
|
|
|
|
2018-02-13 20:02:58 +03:00
|
|
|
uint32_t
|
|
|
|
GetUpdateDelay();
|
|
|
|
|
2016-11-21 05:14:54 +03: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 22:23:16 +03:00
|
|
|
UpdateRegistrationState();
|
2016-11-21 05:14:54 +03: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-03 00:02:50 +03:00
|
|
|
|
|
|
|
static uint64_t
|
|
|
|
GetNextId();
|
2016-04-09 03:28:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2018-01-27 00:08:59 +03:00
|
|
|
#endif // mozilla_dom_serviceworkerregistrationinfo_h
|