author Mike Hommey <>
Thu, 26 Mar 2015 12:07:17 +0900
changeset 258314 fc1e894eec2fbd34b745cd94f505080427d24705
parent 258251 125623fcc804035f3fccd361f14d85c85d60b01e
permissions -rw-r--r--
Bug 1147207 - Add a ComposedFinder class that acts like a FileFinder proxy over multiple FileFinders. r=gps, a=sledru

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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 */

#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 {

namespace ipc {
class PrincipalInfo;

namespace dom {

namespace workers {
class WorkerFeature;

class BroadcastChannelChild;
class BroadcastChannelMessage;

class BroadcastChannel final
  : public DOMEventTargetHelper
  , public nsIIPCBackgroundChildCreateCallback
  , public nsIObserver

  typedef mozilla::ipc::PrincipalInfo PrincipalInfo;



  static bool IsEnabled(JSContext* aCx, JSObject* aGlobal);

  virtual JSObject*
  WrapObject(JSContext* aCx) override;

  static already_AddRefed<BroadcastChannel>
  Constructor(const GlobalObject& aGlobal, const nsAString& aChannel,
              ErrorResult& aRv);

  void GetName(nsAString& aName) const
    aName = mChannel;

  void PostMessage(JSContext* aCx, JS::Handle<JS::Value> aMessage,
                   ErrorResult& aRv);

  void Close();

  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,
                                ErrorResult& aRv) override;
  virtual void RemoveEventListener(const nsAString& aType,
                                   EventListener* aCallback,
                                   bool aCapture,
                                   ErrorResult& aRv) override;

  void Shutdown();

  bool IsClosed() const
    return mState != StateActive;

  BroadcastChannel(nsPIDOMWindow* aWindow,
                   const PrincipalInfo& aPrincipalInfo,
                   const nsAString& aOrigin,
                   const nsAString& aChannel,
                   bool aPrivateBrowsing);


  void PostMessageData(BroadcastChannelMessage* aData);

  void PostMessageInternal(JSContext* aCx, JS::Handle<JS::Value> aMessage,
                           ErrorResult& aRv);

  void UpdateMustKeepAlive();

  nsRefPtr<BroadcastChannelChild> mActor;
  nsTArray<nsRefPtr<BroadcastChannelMessage>> mPendingMessages;

  nsAutoPtr<workers::WorkerFeature> mWorkerFeature;

  nsAutoPtr<PrincipalInfo> mPrincipalInfo;

  nsString mOrigin;
  nsString mChannel;
  bool mPrivateBrowsing;

  bool mIsKeptAlive;

  uint64_t mInnerID;

  enum {
  } mState;

} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_BroadcastChannel_h