From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- dom/base/EventSource.h | 104 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 dom/base/EventSource.h (limited to 'dom/base/EventSource.h') diff --git a/dom/base/EventSource.h b/dom/base/EventSource.h new file mode 100644 index 0000000000..22c3f78a37 --- /dev/null +++ b/dom/base/EventSource.h @@ -0,0 +1,104 @@ +/* -*- 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/. */ + +/* + * 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/Atomics.h" +#include "mozilla/Attributes.h" +#include "mozilla/DOMEventTargetHelper.h" +#include "nsDeque.h" +#include "nsICookieJarSettings.h" + +class nsIGlobalObject; + +namespace mozilla { + +class ErrorResult; + +namespace dom { + +struct EventSourceInit; + +class EventSourceImpl; + +class EventSource final : public DOMEventTargetHelper { + friend class EventSourceImpl; + + public: + NS_DECL_ISUPPORTS_INHERITED + NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(EventSource, DOMEventTargetHelper) + virtual bool IsCertainlyAliveForCC() const override; + + // EventTarget + void DisconnectFromOwner() override { + DOMEventTargetHelper::DisconnectFromOwner(); + Close(); + } + + JSObject* WrapObject(JSContext* aCx, + JS::Handle aGivenProto) override; + + // WebIDL + static already_AddRefed Constructor( + const GlobalObject& aGlobal, const nsAString& aURL, + const EventSourceInit& aEventSourceInitDict, ErrorResult& aRv); + + void GetUrl(nsAString& aURL) const { + AssertIsOnTargetThread(); + aURL = mOriginalURL; + } + + bool WithCredentials() const { + AssertIsOnTargetThread(); + return mWithCredentials; + } + + uint16_t ReadyState() const { + AssertIsOnTargetThread(); + return mReadyState; + } + + IMPL_EVENT_HANDLER(open) + IMPL_EVENT_HANDLER(message) + IMPL_EVENT_HANDLER(error) + + void Close(); + + private: + EventSource(nsIGlobalObject* aGlobal, + nsICookieJarSettings* aCookieJarSettings, 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); + + // This EventSourceImpl is created, managed and destroyed + // by EventSource. + RefPtr mESImpl; + nsString mOriginalURL; + Atomic mReadyState; + const bool mWithCredentials; + const bool mIsMainThread; +}; + +} // namespace dom +} // namespace mozilla + +#endif // mozilla_dom_EventSource_h -- cgit v1.2.3