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: */
|
2015-01-15 19:58:40 +03: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"
|
|
|
|
#include "nsRefPtr.h"
|
|
|
|
|
|
|
|
class nsPIDOMWindow;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2015-01-15 19:58:42 +03:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
|
|
|
}
|
|
|
|
|
2015-01-15 19:58:40 +03:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace workers {
|
|
|
|
class WorkerFeature;
|
|
|
|
}
|
|
|
|
|
|
|
|
class BroadcastChannelChild;
|
2015-01-15 19:58:41 +03:00
|
|
|
class BroadcastChannelMessage;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class BroadcastChannel final
|
2015-01-15 19:58:40 +03: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)
|
|
|
|
|
2015-01-15 19:58:41 +03:00
|
|
|
static bool IsEnabled(JSContext* aCx, JSObject* aGlobal);
|
|
|
|
|
2015-01-15 19:58:40 +03:00
|
|
|
virtual JSObject*
|
2015-03-21 19:28:04 +03:00
|
|
|
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
static already_AddRefed<BroadcastChannel>
|
|
|
|
Constructor(const GlobalObject& aGlobal, const nsAString& aChannel,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
|
|
|
|
void GetName(nsAString& aName) const
|
|
|
|
{
|
|
|
|
aName = mChannel;
|
|
|
|
}
|
|
|
|
|
2015-01-15 19:58:41 +03:00
|
|
|
void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
|
ErrorResult& aRv);
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
void Close();
|
2015-01-15 19:58:40 +03: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 19:28:04 +03:00
|
|
|
ErrorResult& aRv) override;
|
2015-01-15 19:58:40 +03:00
|
|
|
virtual void RemoveEventListener(const nsAString& aType,
|
|
|
|
EventListener* aCallback,
|
|
|
|
bool aCapture,
|
2015-03-21 19:28:04 +03:00
|
|
|
ErrorResult& aRv) override;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
2015-01-15 19:58:42 +03:00
|
|
|
bool IsClosed() const
|
|
|
|
{
|
|
|
|
return mState != StateActive;
|
|
|
|
}
|
|
|
|
|
2015-01-15 19:58:40 +03:00
|
|
|
private:
|
|
|
|
BroadcastChannel(nsPIDOMWindow* aWindow,
|
|
|
|
const PrincipalInfo& aPrincipalInfo,
|
2015-07-06 21:28:41 +03:00
|
|
|
const nsACString& aOrigin,
|
2015-04-01 14:41:29 +03:00
|
|
|
const nsAString& aChannel,
|
|
|
|
bool aPrivateBrowsing);
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
~BroadcastChannel();
|
|
|
|
|
2015-01-15 19:58:41 +03:00
|
|
|
void PostMessageData(BroadcastChannelMessage* aData);
|
|
|
|
|
|
|
|
void PostMessageInternal(JSContext* aCx, JS::Handle<JS::Value> aMessage,
|
|
|
|
ErrorResult& aRv);
|
2015-01-15 19:58:40 +03:00
|
|
|
|
2015-01-15 19:58:40 +03:00
|
|
|
void UpdateMustKeepAlive();
|
|
|
|
|
2015-06-29 19:42:41 +03:00
|
|
|
bool IsCertainlyAliveForCC() const override
|
|
|
|
{
|
|
|
|
return mIsKeptAlive;
|
|
|
|
}
|
|
|
|
|
2015-01-15 19:58:40 +03:00
|
|
|
nsRefPtr<BroadcastChannelChild> mActor;
|
2015-01-15 19:58:41 +03:00
|
|
|
nsTArray<nsRefPtr<BroadcastChannelMessage>> mPendingMessages;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
nsAutoPtr<workers::WorkerFeature> mWorkerFeature;
|
|
|
|
|
2015-01-15 19:58:42 +03:00
|
|
|
nsAutoPtr<PrincipalInfo> mPrincipalInfo;
|
|
|
|
|
2015-07-06 21:28:41 +03:00
|
|
|
nsCString mOrigin;
|
2015-01-15 19:58:40 +03:00
|
|
|
nsString mChannel;
|
2015-04-01 14:41:29 +03:00
|
|
|
bool mPrivateBrowsing;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
bool mIsKeptAlive;
|
|
|
|
|
|
|
|
uint64_t mInnerID;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
enum {
|
|
|
|
StateActive,
|
|
|
|
StateClosing,
|
|
|
|
StateClosed
|
|
|
|
} mState;
|
2015-01-15 19:58:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_dom_BroadcastChannel_h
|