author James Teh <>
Thu, 07 Mar 2019 18:10:13 +0000
changeset 520910 c26d4a8d43c4d0d6f6e13135b8f35924123fe99e
parent 505383 6f3709b3878117466168c40affa7bca0b60cf75b
permissions -rw-r--r--
Bug 1527922: Ensure the Reload button is disabled when testing against blank tabs in the browser toolbar key nav tests. r=Gijs For a blank tab, the Reload button should be disabled. These tests depend on this. This seems to be true when setting the new tab page to blank in Firefox Options. However, when we open about:blank with BrowserTestUtils.withNewTab, this is unreliable. That is, sometimes the Reload button is enabled, sometimes it isn't. I don't understand why this happens. For the purposes of these tests, just force the Reload button to be disabled for new, blank tabs so we get consistent results. Differential Revision:

/* -*- 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 */

#ifndef mozilla_dom_serviceworkerinfo_h
#define mozilla_dom_serviceworkerinfo_h

#include "MainThreadUtils.h"
#include "mozilla/dom/ServiceWorkerBinding.h"  // For ServiceWorkerState
#include "mozilla/dom/WorkerCommon.h"
#include "mozilla/OriginAttributes.h"
#include "nsIServiceWorkerManager.h"

namespace mozilla {
namespace dom {

class ClientInfoAndState;
class ClientState;
class ServiceWorkerCloneData;
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 {
  nsCOMPtr<nsIPrincipal> mPrincipal;
  ServiceWorkerDescriptor mDescriptor;
  const nsString mCacheName;
  OriginAttributes mOriginAttributes;

  // 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:
  //   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;

  // 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;

  RefPtr<ServiceWorkerPrivate> mServiceWorkerPrivate;
  bool mSkipWaitingFlag;

  enum { Unknown, Enabled, Disabled } mHandlesFetch;


  // Generates a unique id for the service worker, with zero being treated as
  // invalid.
  uint64_t GetNextID() const;


  void PostMessage(RefPtr<ServiceWorkerCloneData>&& aData,
                   const ClientInfo& aClientInfo,
                   const ClientState& aClientState);

  class ServiceWorkerPrivate* WorkerPrivate() const {
    return mServiceWorkerPrivate;

  nsIPrincipal* Principal() const { return mPrincipal; }

  const nsCString& ScriptSpec() const { return mDescriptor.ScriptURL(); }

  const nsCString& Scope() const { return mDescriptor.Scope(); }

  bool SkipWaitingFlag() const {
    return mSkipWaitingFlag;

  void SetSkipWaitingFlag() {
    mSkipWaitingFlag = true;

  ServiceWorkerInfo(nsIPrincipal* aPrincipal, const nsACString& aScope,
                    uint64_t aRegistrationId, uint64_t aRegistrationVersion,
                    const nsACString& aScriptSpec, const nsAString& aCacheName,
                    nsLoadFlags aLoadFlags);

  ServiceWorkerState State() const { return mDescriptor.State(); }

  const OriginAttributes& GetOriginAttributes() const {
    return mOriginAttributes;

  const nsString& CacheName() const { return mCacheName; }

  nsLoadFlags GetImportsLoadFlags() const { return mImportsLoadFlags; }

  uint64_t ID() const { return mDescriptor.Id(); }

  const ServiceWorkerDescriptor& Descriptor() const { return mDescriptor; }

  void UpdateState(ServiceWorkerState aState);

  // Only used to set initial state when loading from disk!
  void SetActivateStateUncheckedWithoutEvent(ServiceWorkerState aState) {

  void SetHandlesFetch(bool aHandlesFetch) {
    MOZ_DIAGNOSTIC_ASSERT(mHandlesFetch == Unknown);
    mHandlesFetch = aHandlesFetch ? Enabled : Disabled;

  void SetRegistrationVersion(uint64_t aVersion);

  bool HandlesFetch() const {
    MOZ_DIAGNOSTIC_ASSERT(mHandlesFetch != Unknown);
    return mHandlesFetch != Disabled;

  void UpdateInstalledTime();

  void UpdateActivatedTime();

  void UpdateRedundantTime();

  int64_t GetInstalledTime() const { return mInstalledTime; }

  void SetInstalledTime(const int64_t aTime) {
    if (aTime == 0) {

    mInstalledTime = aTime;

  int64_t GetActivatedTime() const { return mActivatedTime; }

  void SetActivatedTime(const int64_t aTime) {
    if (aTime == 0) {

    mActivatedTime = aTime;

}  // namespace dom
}  // namespace mozilla

#endif  // mozilla_dom_serviceworkerinfo_h