tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

XULBroadcastManager.h (3249B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef mozilla_dom_XULBroadcastManager_h
      8 #define mozilla_dom_XULBroadcastManager_h
      9 
     10 #include "nsAtom.h"
     11 #include "nsTArray.h"
     12 
     13 class PLDHashTable;
     14 class nsXULElement;
     15 
     16 namespace mozilla {
     17 
     18 class ErrorResult;
     19 
     20 namespace dom {
     21 
     22 class Document;
     23 class Element;
     24 
     25 class XULBroadcastManager final {
     26 public:
     27  explicit XULBroadcastManager(Document* aDocument);
     28 
     29  NS_INLINE_DECL_THREADSAFE_REFCOUNTING(XULBroadcastManager)
     30 
     31  /**
     32   * Checks whether an element uses any of the special broadcaster attributes
     33   * or is an observes element. This mimics the logic in FindBroadcaster, but
     34   * is intended to be a lighter weight check and doesn't actually guarantee
     35   * that the element will need a listener.
     36   */
     37  static bool MayNeedListener(const Element& aElement);
     38 
     39  nsresult AddListener(Element* aElement);
     40  nsresult RemoveListener(Element* aElement);
     41  void AttributeChanged(Element* aElement, int32_t aNameSpaceID,
     42                        nsAtom* aAttribute);
     43  // TODO: Convert this to MOZ_CAN_RUN_SCRIPT (bug 1415230)
     44  MOZ_CAN_RUN_SCRIPT_BOUNDARY void MaybeBroadcast();
     45  void DropDocumentReference();  // notification that doc is going away
     46 protected:
     47  enum HookupAction { eHookupAdd = 0, eHookupRemove };
     48 
     49  nsresult UpdateListenerHookup(Element* aElement, HookupAction aAction);
     50 
     51  void RemoveListenerFor(Element& aBroadcaster, Element& aListener,
     52                         const nsAString& aAttr);
     53  void AddListenerFor(Element& aBroadcaster, Element& aListener,
     54                      const nsAString& aAttr, ErrorResult& aRv);
     55 
     56  MOZ_CAN_RUN_SCRIPT nsresult ExecuteOnBroadcastHandlerFor(
     57      Element* aBroadcaster, Element* aListener, nsAtom* aAttr);
     58  // The out params of FindBroadcaster only have values that make sense when
     59  // the method returns NS_FINDBROADCASTER_FOUND.  In all other cases, the
     60  // values of the out params should not be relied on (though *aListener and
     61  // *aBroadcaster do need to be released if non-null, of course).
     62  nsresult FindBroadcaster(Element* aElement, Element** aListener,
     63                           nsString& aBroadcasterID, nsString& aAttribute,
     64                           Element** aBroadcaster);
     65 
     66  void SynchronizeBroadcastListener(Element* aBroadcaster, Element* aListener,
     67                                    const nsAString& aAttr);
     68 
     69  // This reference is nulled by the Document in it's destructor through
     70  // DropDocumentReference().
     71  Document* MOZ_NON_OWNING_REF mDocument;
     72 
     73  /**
     74   * A map from a broadcaster element to a list of listener elements.
     75   */
     76  PLDHashTable* mBroadcasterMap;
     77 
     78  class nsDelayedBroadcastUpdate;
     79  nsTArray<nsDelayedBroadcastUpdate> mDelayedBroadcasters;
     80  nsTArray<nsDelayedBroadcastUpdate> mDelayedAttrChangeBroadcasts;
     81  bool mHandlingDelayedAttrChange;
     82  bool mHandlingDelayedBroadcasters;
     83 
     84 private:
     85  ~XULBroadcastManager();
     86 };
     87 
     88 }  // namespace dom
     89 }  // namespace mozilla
     90 
     91 #endif  // mozilla_dom_XULBroadcastManager_h