dom/base/Timeout.h
author Andreas Farre <farre@mozilla.com>
Wed, 05 Oct 2016 14:26:08 +0200
changeset 320171 030e1cc3b1c1feede3182d67adc12a1d6f80c746
parent 319194 24839edcf0efc585c655760128b202df88041933
child 319195 ffaf3d371130200ed62ffb462386a191901d1421
permissions -rw-r--r--
Bug 1198381 - Extract nsITimeoutHandler from nsIScriptTimeoutHandler. r=smaug MozReview-Commit-ID: HJHrbodWYVf

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* 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_timeout_h
#define mozilla_dom_timeout_h

#include "mozilla/LinkedList.h"
#include "mozilla/TimeStamp.h"
#include "nsCOMPtr.h"
#include "nsCycleCollectionParticipant.h"

class nsGlobalWindow;
class nsIPrincipal;
class nsITimeoutHandler;
class nsITimer;

namespace mozilla {
namespace dom {

/*
 * Timeout struct that holds information about each script
 * timeout.  Holds a strong reference to an nsITimeoutHandler, which
 * abstracts the language specific cruft.
 */
class Timeout final
  : public LinkedListElement<Timeout>
{
public:
  Timeout();

  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(Timeout)
  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(Timeout)

  nsresult InitTimer(uint32_t aDelay);

  static void TimerNameCallback(nsITimer* aTimer, void* aClosure, char* aBuf,
                                size_t aLen);

#ifdef DEBUG
  bool HasRefCntOne() const;
#endif // DEBUG

  // Window for which this timeout fires
  RefPtr<nsGlobalWindow> mWindow;

  // The actual timer object
  nsCOMPtr<nsITimer> mTimer;

  // True if the timeout was cleared
  bool mCleared;

  // True if this is one of the timeouts that are currently running
  bool mRunning;

  // True if this is a repeating/interval timer
  bool mIsInterval;

  // Returned as value of setTimeout()
  uint32_t mPublicId;

  // Interval in milliseconds
  uint32_t mInterval;

  // mWhen and mTimeRemaining can't be in a union, sadly, because they
  // have constructors.
  // Nominal time to run this timeout.  Use only when timeouts are not
  // suspended.
  TimeStamp mWhen;
  // Remaining time to wait.  Used only when timeouts are suspended.
  TimeDuration mTimeRemaining;

  // Principal with which to execute
  nsCOMPtr<nsIPrincipal> mPrincipal;

  // stack depth at which timeout is firing
  uint32_t mFiringDepth;

  uint32_t mNestingLevel;

  // The popup state at timeout creation time if not created from
  // another timeout
  PopupControlState mPopupState;

  // The language-specific information about the callback.
  nsCOMPtr<nsITimeoutHandler> mScriptHandler;

private:
  ~Timeout();
};

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_timeout_h