2015-05-03 22:32:37 +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: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2011-05-23 01:30:07 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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".
|
|
|
|
*/
|
|
|
|
|
2012-12-22 12:17:05 +04:00
|
|
|
#ifndef mozilla_dom_EventSource_h
|
|
|
|
#define mozilla_dom_EventSource_h
|
2011-05-23 01:30:07 +04:00
|
|
|
|
2021-02-03 18:03:54 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-04-01 10:13:50 +04:00
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
2011-05-23 01:30:07 +04:00
|
|
|
#include "nsDeque.h"
|
2020-10-19 15:18:01 +03:00
|
|
|
#include "nsICookieJarSettings.h"
|
2011-05-23 01:30:07 +04:00
|
|
|
|
2019-03-29 01:06:29 +03:00
|
|
|
class nsIGlobalObject;
|
2012-12-22 12:17:05 +04:00
|
|
|
|
2012-12-22 12:17:05 +04:00
|
|
|
namespace mozilla {
|
2012-12-22 12:17:05 +04:00
|
|
|
|
|
|
|
class ErrorResult;
|
|
|
|
|
2012-12-22 12:17:05 +04:00
|
|
|
namespace dom {
|
|
|
|
|
2012-12-22 12:17:05 +04:00
|
|
|
struct EventSourceInit;
|
2012-12-22 12:17:05 +04:00
|
|
|
|
2016-10-24 05:11:04 +03:00
|
|
|
class EventSourceImpl;
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class EventSource final : public DOMEventTargetHelper {
|
2016-10-24 05:11:04 +03:00
|
|
|
friend class EventSourceImpl;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-05-23 01:30:07 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2017-01-25 04:40:11 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(EventSource, DOMEventTargetHelper)
|
|
|
|
virtual bool IsCertainlyAliveForCC() const override;
|
2011-05-23 01:30:07 +04:00
|
|
|
|
2016-10-24 05:11:04 +03:00
|
|
|
// EventTarget
|
|
|
|
void DisconnectFromOwner() override {
|
|
|
|
DOMEventTargetHelper::DisconnectFromOwner();
|
|
|
|
Close();
|
|
|
|
}
|
2011-05-23 01:30:07 +04:00
|
|
|
|
2016-10-24 05:11:04 +03:00
|
|
|
JSObject* WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
2012-12-22 12:17:05 +04:00
|
|
|
|
|
|
|
// WebIDL
|
|
|
|
static already_AddRefed<EventSource> Constructor(
|
2012-12-03 20:07:49 +04:00
|
|
|
const GlobalObject& aGlobal, const nsAString& aURL,
|
2016-10-24 05:11:04 +03:00
|
|
|
const EventSourceInit& aEventSourceInitDict, ErrorResult& aRv);
|
2012-12-22 12:17:05 +04:00
|
|
|
|
|
|
|
void GetUrl(nsAString& aURL) const {
|
2016-10-24 05:11:04 +03:00
|
|
|
AssertIsOnTargetThread();
|
2012-12-22 12:17:05 +04:00
|
|
|
aURL = mOriginalURL;
|
|
|
|
}
|
2016-10-24 05:11:04 +03:00
|
|
|
|
2012-12-22 12:17:05 +04:00
|
|
|
bool WithCredentials() const {
|
2016-10-24 05:11:04 +03:00
|
|
|
AssertIsOnTargetThread();
|
2012-12-22 12:17:05 +04:00
|
|
|
return mWithCredentials;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t ReadyState() const {
|
2016-10-24 05:11:04 +03:00
|
|
|
AssertIsOnTargetThread();
|
2012-12-22 12:17:05 +04:00
|
|
|
return mReadyState;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_EVENT_HANDLER(open)
|
|
|
|
IMPL_EVENT_HANDLER(message)
|
|
|
|
IMPL_EVENT_HANDLER(error)
|
|
|
|
|
2016-10-24 05:11:04 +03:00
|
|
|
void Close();
|
2012-12-22 12:17:05 +04:00
|
|
|
|
2016-10-24 05:11:04 +03:00
|
|
|
private:
|
2020-03-04 11:59:08 +03:00
|
|
|
EventSource(nsIGlobalObject* aGlobal,
|
|
|
|
nsICookieJarSettings* aCookieJarSettings, bool aWithCredentials);
|
2014-07-09 01:23:16 +04:00
|
|
|
virtual ~EventSource();
|
2016-10-24 05:11:04 +03:00
|
|
|
// prevent bad usage
|
|
|
|
EventSource(const EventSource& x) = delete;
|
|
|
|
EventSource& operator=(const EventSource& x) = delete;
|
2014-07-09 01:23:16 +04:00
|
|
|
|
2016-10-24 05:11:04 +03:00
|
|
|
void AssertIsOnTargetThread() const {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread() == mIsMainThread);
|
|
|
|
}
|
2011-05-23 01:30:07 +04:00
|
|
|
|
2016-10-24 05:11:04 +03:00
|
|
|
nsresult CreateAndDispatchSimpleEvent(const nsAString& aName);
|
2011-05-23 01:30:07 +04:00
|
|
|
|
2021-02-03 18:03:47 +03:00
|
|
|
// This EventSourceImpl is created, managed and destroyed
|
2016-10-24 05:11:04 +03:00
|
|
|
// by EventSource.
|
2021-02-03 18:03:47 +03:00
|
|
|
RefPtr<EventSourceImpl> mESImpl;
|
2011-05-23 01:30:07 +04:00
|
|
|
nsString mOriginalURL;
|
2021-02-03 18:03:54 +03:00
|
|
|
Atomic<uint32_t> mReadyState;
|
|
|
|
const bool mWithCredentials;
|
|
|
|
const bool mIsMainThread;
|
2011-05-23 01:30:07 +04:00
|
|
|
};
|
|
|
|
|
2012-12-22 12:17:05 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_EventSource_h
|