author Simon Whitehead <>
Sat, 13 May 2017 15:12:15 -0500
changeset 358329 633151f5d481d49bd39900d43e6a75d77459a7bb
parent 330922 8fd0b1d9a60a42a5f680514403e5571ab8f52cd3
child 363659 e155fa765af299f0e8cfb42e0a1709e5b04928b9
permissions -rw-r--r--
servo: Merge #16829 - Disallow negative duration for animation and transition (from hiikezoe:disallow-negative-duration); r=emilio <!-- Please describe your changes on the following line: --> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #15343 <!-- Either: --> - [X] There are tests for these changes written by @simon-whitehead . Thank you! <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: Source-Revision: 4613c0382ab76263fb8202ccf52f4c0520e44809

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

 * This implementation has support only for http requests. It is because the
 * spec has defined event streams only for http. HTTP is required because
 * this implementation uses some http headers: "Last-Event-ID", "Cache-Control"
 * and "Accept".

#ifndef mozilla_dom_EventSource_h
#define mozilla_dom_EventSource_h

#include "mozilla/Attributes.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "nsIObserver.h"
#include "nsIStreamListener.h"
#include "nsIChannelEventSink.h"
#include "nsIInterfaceRequestor.h"
#include "nsITimer.h"
#include "nsIHttpChannel.h"
#include "nsWeakReference.h"
#include "nsDeque.h"
#include "nsIUnicodeDecoder.h"

class nsPIDOMWindowInner;

namespace mozilla {

class ErrorResult;

namespace dom {

struct EventSourceInit;

class EventSourceImpl;

class EventSource final : public DOMEventTargetHelper
  friend class EventSourceImpl;
  virtual bool IsCertainlyAliveForCC() const override;

  // EventTarget
  void DisconnectFromOwner() override

  JSObject* WrapObject(JSContext* aCx,
                       JS::Handle<JSObject*> aGivenProto) override;

  // WebIDL
  static already_AddRefed<EventSource>
  Constructor(const GlobalObject& aGlobal, const nsAString& aURL,
              const EventSourceInit& aEventSourceInitDict, ErrorResult& aRv);

  void GetUrl(nsAString& aURL) const
    aURL = mOriginalURL;

  bool WithCredentials() const
    return mWithCredentials;

  uint16_t ReadyState() const
    return mReadyState;


  void Close();

  EventSource(nsPIDOMWindowInner* aOwnerWindow, bool aWithCredentials);
  virtual ~EventSource();
  // prevent bad usage
  EventSource(const EventSource& x) = delete;
  EventSource& operator=(const EventSource& x) = delete;

  void AssertIsOnTargetThread() const
    MOZ_ASSERT(NS_IsMainThread() == mIsMainThread);

  nsresult CreateAndDispatchSimpleEvent(const nsAString& aName);

  // Raw pointer because this EventSourceImpl is created, managed and destroyed
  // by EventSource.
  EventSourceImpl* mImpl;
  nsString mOriginalURL;
  uint16_t mReadyState;
  bool mWithCredentials;
  bool mIsMainThread;
  // This is used to keep EventSourceImpl instance when there is a connection.
  bool mKeepingAlive;

  void UpdateMustKeepAlive();
  void UpdateDontKeepAlive();

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_EventSource_h