tor-browser

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

Link.h (4116B)


      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 /**
      8 * This is the base class for all link classes.
      9 */
     10 
     11 #ifndef mozilla_dom_Link_h__
     12 #define mozilla_dom_Link_h__
     13 
     14 #include "mozilla/dom/RustTypes.h"
     15 #include "nsCOMPtr.h"
     16 #include "nsWrapperCache.h"  // For nsWrapperCache::FlagsType
     17 
     18 class nsIURI;
     19 
     20 namespace mozilla {
     21 
     22 class SizeOfState;
     23 
     24 namespace dom {
     25 
     26 class Document;
     27 class Element;
     28 struct BindContext;
     29 
     30 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID \
     31  {0xb25edee6, 0xdd35, 0x4f8b, {0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5}}
     32 
     33 class Link : public nsISupports {
     34 public:
     35  NS_INLINE_DECL_STATIC_IID(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
     36 
     37  enum class State : uint8_t {
     38    Unvisited = 0,
     39    Visited,
     40    NotLink,
     41  };
     42 
     43  /**
     44   * aElement is the element pointer corresponding to this link.
     45   */
     46  explicit Link(Element* aElement);
     47 
     48  /**
     49   * This constructor is only used for testing.
     50   */
     51  explicit Link();
     52 
     53  virtual void VisitedQueryFinished(bool aVisited);
     54 
     55  /**
     56   * @return the URI this link is for, if available.
     57   */
     58  nsIURI* GetURI() const;
     59 
     60  /**
     61   * Helper methods for modifying and obtaining parts of the URI of the Link.
     62   */
     63  void SetProtocol(const nsACString& aProtocol);
     64  void SetUsername(const nsACString& aUsername);
     65  void SetPassword(const nsACString& aPassword);
     66  void SetHost(const nsACString& aHost);
     67  void SetHostname(const nsACString& aHostname);
     68  void SetPathname(const nsACString& aPathname);
     69  void SetSearch(const nsACString& aSearch);
     70  void SetPort(const nsACString& aPort);
     71  void SetHash(const nsACString& aHash);
     72  void GetOrigin(nsACString& aOrigin);
     73  void GetProtocol(nsACString& aProtocol);
     74  void GetUsername(nsACString& aUsername);
     75  void GetPassword(nsACString& aPassword);
     76  void GetHost(nsACString& aHost);
     77  void GetHostname(nsACString& aHostname);
     78  void GetPathname(nsACString& aPathname);
     79  void GetSearch(nsACString& aSearch);
     80  void GetPort(nsACString& aPort);
     81  void GetHash(nsACString& aHash);
     82 
     83  /**
     84   * Invalidates any link caching, and resets the state to the default.
     85   *
     86   * @param aNotify
     87   *        true if ResetLinkState should notify the owning document about style
     88   *        changes or false if it should not.
     89   */
     90  void ResetLinkState(bool aNotify, bool aHasHref);
     91  void ResetLinkState(bool aNotify) {
     92    ResetLinkState(aNotify, ElementHasHref());
     93  }
     94  void BindToTree(const BindContext&);
     95  void UnbindFromTree() { ResetLinkState(false); }
     96 
     97  // This method nevers returns a null element.
     98  Element* GetElement() const { return mElement; }
     99 
    100  virtual size_t SizeOfExcludingThis(mozilla::SizeOfState& aState) const;
    101 
    102  virtual bool ElementHasHref() const;
    103 
    104  bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate; }
    105  void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate = true; }
    106  void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate = false; }
    107  void TriggerLinkUpdate(bool aNotify);
    108 
    109  // To ensure correct mHasPendingLinkUpdate handling, we have this method
    110  // similar to the one in Element. Overriders must call
    111  // ClearHasPendingLinkUpdate().
    112  // If you change this, change also the method in nsINode.
    113  virtual void NodeInfoChanged(Document* aOldDoc) = 0;
    114 
    115 protected:
    116  virtual ~Link();
    117 
    118  nsIURI* GetCachedURI() const { return mCachedURI; }
    119  bool HasCachedURI() const { return !!mCachedURI; }
    120 
    121 private:
    122  /**
    123   * Unregisters from History and the document so this node no longer gets
    124   * notifications about changes to visitedness.
    125   */
    126  void Unregister();
    127  void SetLinkState(State, bool aNotify);
    128  void SetHrefAttribute(nsIURI* aURI);
    129 
    130  mutable nsCOMPtr<nsIURI> mCachedURI;
    131 
    132  Element* const mElement;
    133 
    134  bool mNeedsRegistration : 1;
    135  bool mRegistered : 1;
    136  bool mHasPendingLinkUpdate : 1;
    137  const bool mHistory : 1;
    138 };
    139 
    140 }  // namespace dom
    141 }  // namespace mozilla
    142 
    143 #endif  // mozilla_dom_Link_h__