2015-05-03 12:32:37 -07: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: */
|
2015-01-15 08:58:40 -08: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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_BroadcastChannel_h
|
|
|
|
#define mozilla_dom_BroadcastChannel_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/DOMEventTargetHelper.h"
|
|
|
|
#include "nsIIPCBackgroundChildCreateCallback.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsTArray.h"
|
2015-07-28 17:52:52 -07:00
|
|
|
#include "mozilla/nsRefPtr.h"
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2015-01-15 08:58:42 -08:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace ipc
|
2015-01-15 08:58:42 -08:00
|
|
|
|
2015-01-15 08:58:40 -08:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace workers {
|
|
|
|
class WorkerFeature;
|
2015-07-13 08:25:42 -07:00
|
|
|
} // namespace workers
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
class BroadcastChannelChild;
|
2015-01-15 08:58:41 -08:00
|
|
|
class BroadcastChannelMessage;
|
2015-01-15 08:58:40 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class BroadcastChannel final
|
2015-01-15 08:58:40 -08:00
|
|
|
: public DOMEventTargetHelper
|
|
|
|
, public nsIIPCBackgroundChildCreateCallback
|
|
|
|
, public nsIObserver
|
|
|
|
{
|
|
|
|
NS_DECL_NSIIPCBACKGROUNDCHILDCREATECALLBACK
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
|
|
|
|
typedef mozilla::ipc::PrincipalInfo PrincipalInfo;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(BroadcastChannel,
|
|
|
|
DOMEventTargetHelper)
|
|
|
|
|
|
|
|
virtual JSObject*
|
2015-03-21 09:28:04 -07:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
static already_AddRefed<BroadcastChannel>
|
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& aChannel,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
void GetName(nsAString& aName) const
|
|
|
|
{
|
|
|
|
aName = mChannel;
|
|
|
|
}
|
|
|
|
|
2015-01-15 08:58:41 -08:00
|
|
|
void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
|
ErrorResult& aRv);
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
void Close();
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
EventHandlerNonNull* GetOnmessage();
|
|
|
|
void SetOnmessage(EventHandlerNonNull* aCallback);
|
|
|
|
|
|
|
|
using nsIDOMEventTarget::AddEventListener;
|
|
|
|
using nsIDOMEventTarget::RemoveEventListener;
|
|
|
|
|
|
|
|
virtual void AddEventListener(const nsAString& aType,
|
|
|
|
EventListener* aCallback,
|
|
|
|
bool aCapture,
|
|
|
|
const Nullable<bool>& aWantsUntrusted,
|
2015-03-21 09:28:04 -07:00
|
|
|
ErrorResult& aRv) override;
|
2015-01-15 08:58:40 -08:00
|
|
|
virtual void RemoveEventListener(const nsAString& aType,
|
|
|
|
EventListener* aCallback,
|
|
|
|
bool aCapture,
|
2015-03-21 09:28:04 -07:00
|
|
|
ErrorResult& aRv) override;
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
2015-01-15 08:58:42 -08:00
|
|
|
bool IsClosed() const
|
|
|
|
{
|
|
|
|
return mState != StateActive;
|
|
|
|
}
|
|
|
|
|
2015-01-15 08:58:40 -08:00
|
|
|
private:
|
|
|
|
BroadcastChannel(nsPIDOMWindow* aWindow,
|
|
|
|
const PrincipalInfo& aPrincipalInfo,
|
2015-07-06 11:28:41 -07:00
|
|
|
const nsACString& aOrigin,
|
2015-04-01 04:41:29 -07:00
|
|
|
const nsAString& aChannel,
|
|
|
|
bool aPrivateBrowsing);
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
~BroadcastChannel();
|
|
|
|
|
2015-01-15 08:58:41 -08:00
|
|
|
void PostMessageData(BroadcastChannelMessage* aData);
|
|
|
|
|
|
|
|
void PostMessageInternal(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
|
ErrorResult& aRv);
|
2015-01-15 08:58:40 -08:00
|
|
|
|
2015-01-15 08:58:40 -08:00
|
|
|
void UpdateMustKeepAlive();
|
|
|
|
|
2015-06-29 09:42:41 -07:00
|
|
|
bool IsCertainlyAliveForCC() const override
|
|
|
|
{
|
|
|
|
return mIsKeptAlive;
|
|
|
|
}
|
|
|
|
|
2015-01-15 08:58:40 -08:00
|
|
|
nsRefPtr<BroadcastChannelChild> mActor;
|
2015-01-15 08:58:41 -08:00
|
|
|
nsTArray<nsRefPtr<BroadcastChannelMessage>> mPendingMessages;
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
|
|
|
|
|
2015-01-15 08:58:42 -08:00
|
|
|
nsAutoPtr<PrincipalInfo> mPrincipalInfo;
|
|
|
|
|
2015-07-06 11:28:41 -07:00
|
|
|
nsCString mOrigin;
|
2015-01-15 08:58:40 -08:00
|
|
|
nsString mChannel;
|
2015-04-01 04:41:29 -07:00
|
|
|
bool mPrivateBrowsing;
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
bool mIsKeptAlive;
|
|
|
|
|
|
|
|
uint64_t mInnerID;
|
2015-01-15 08:58:40 -08:00
|
|
|
|
|
|
|
enum {
|
|
|
|
StateActive,
|
|
|
|
StateClosing,
|
|
|
|
StateClosed
|
|
|
|
} mState;
|
2015-01-15 08:58:40 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_BroadcastChannel_h
|