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"
|
2016-06-07 23:10:18 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2015-01-15 19:58:40 +03:00
|
|
|
#include "nsIIPCBackgroundChildCreateCallback.h"
|
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsTArray.h"
|
2015-10-18 08:24:48 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2015-01-15 19:58:40 +03:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
class nsPIDOMWindowInner;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2015-01-15 19:58:42 +03:00
|
|
|
|
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace ipc
|
2015-01-15 19:58:42 +03:00
|
|
|
|
2015-01-15 19:58:40 +03:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
namespace workers {
|
2016-06-23 11:53:14 +03:00
|
|
|
class WorkerHolder;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace workers
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2015-10-13 14:04:17 +03:00
|
|
|
friend class BroadcastChannelChild;
|
|
|
|
|
2015-01-15 19:58:40 +03:00
|
|
|
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 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
|
|
|
|
2017-04-18 14:51:59 +03:00
|
|
|
IMPL_EVENT_HANDLER(message)
|
2015-01-15 19:58:40 +03:00
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
|
|
|
private:
|
2016-01-30 20:05:36 +03:00
|
|
|
BroadcastChannel(nsPIDOMWindowInner* aWindow,
|
2015-01-15 19:58:40 +03:00
|
|
|
const PrincipalInfo& aPrincipalInfo,
|
2015-07-06 21:28:41 +03:00
|
|
|
const nsACString& aOrigin,
|
2016-06-07 14:50:00 +03:00
|
|
|
const nsAString& aChannel);
|
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-10-13 14:04:17 +03:00
|
|
|
void RemoveDocFromBFCache();
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<BroadcastChannelChild> mActor;
|
|
|
|
nsTArray<RefPtr<BroadcastChannelMessage>> mPendingMessages;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
2016-06-23 11:53:14 +03:00
|
|
|
nsAutoPtr<workers::WorkerHolder> mWorkerHolder;
|
2015-01-15 19:58:40 +03:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
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
|