content/base/src/Link.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
     2  * vim: sw=2 ts=2 et :
     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/. */
     7 /**
     8  * This is the base class for all link classes.
     9  */
    11 #ifndef mozilla_dom_Link_h__
    12 #define mozilla_dom_Link_h__
    14 #include "mozilla/IHistory.h"
    15 #include "mozilla/MemoryReporting.h"
    16 #include "mozilla/dom/URLSearchParams.h"
    17 #include "nsIContent.h"
    19 namespace mozilla {
    21 class EventStates;
    23 namespace dom {
    25 class Element;
    27 #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID               \
    28 { 0xb25edee6, 0xdd35, 0x4f8b,                             \
    29   { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
    31 class Link : public URLSearchParamsObserver
    32 {
    33 public:
    34   NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
    36   /**
    37    * aElement is the element pointer corresponding to this link.
    38    */
    39   Link(Element* aElement);
    40   virtual void SetLinkState(nsLinkState aState);
    42   /**
    43    * @return NS_EVENT_STATE_VISITED if this link is visited,
    44    *         NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
    45    *         link is not actually a link.
    46    */
    47   EventStates LinkState() const;
    49   /**
    50    * @return the URI this link is for, if available.
    51    */
    52   nsIURI* GetURI() const;
    53   virtual nsIURI* GetURIExternal() const {
    54     return GetURI();
    55   }
    57   /**
    58    * Helper methods for modifying and obtaining parts of the URI of the Link.
    59    */
    60   void SetProtocol(const nsAString &aProtocol);
    61   void SetUsername(const nsAString &aUsername);
    62   void SetPassword(const nsAString &aPassword);
    63   void SetHost(const nsAString &aHost);
    64   void SetHostname(const nsAString &aHostname);
    65   void SetPathname(const nsAString &aPathname);
    66   void SetSearch(const nsAString &aSearch);
    67   void SetSearchParams(mozilla::dom::URLSearchParams& aSearchParams);
    68   void SetPort(const nsAString &aPort);
    69   void SetHash(const nsAString &aHash);
    70   void GetOrigin(nsAString &aOrigin);
    71   void GetProtocol(nsAString &_protocol);
    72   void GetUsername(nsAString &aUsername);
    73   void GetPassword(nsAString &aPassword);
    74   void GetHost(nsAString &_host);
    75   void GetHostname(nsAString &_hostname);
    76   void GetPathname(nsAString &_pathname);
    77   void GetSearch(nsAString &_search);
    78   URLSearchParams* SearchParams();
    79   void GetPort(nsAString &_port);
    80   void GetHash(nsAString &_hash);
    82   /**
    83    * Invalidates any link caching, and resets the state to the default.
    84    *
    85    * @param aNotify
    86    *        true if ResetLinkState should notify the owning document about style
    87    *        changes or false if it should not.
    88    */
    89   void ResetLinkState(bool aNotify, bool aHasHref);
    91   // This method nevers returns a null element.
    92   Element* GetElement() const { return mElement; }
    94   /**
    95    * DNS prefetch has been deferred until later, e.g. page load complete.
    96    */
    97   virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
    99   /**
   100    * DNS prefetch has been submitted to Host Resolver.
   101    */
   102   virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
   104   /**
   105    * Checks if DNS Prefetching is ok
   106    * 
   107    * @returns boolean
   108    *          Defaults to true; should be overridden for specialised cases
   109    */
   110   virtual bool HasDeferredDNSPrefetchRequest() { return true; }
   112   virtual size_t
   113     SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
   115   bool ElementHasHref() const;
   117   // URLSearchParamsObserver
   118   void URLSearchParamsUpdated() MOZ_OVERRIDE;
   120 protected:
   121   virtual ~Link();
   123   /**
   124    * Return true if the link has associated URI.
   125    */
   126   bool HasURI() const
   127   {
   128     if (HasCachedURI()) {
   129       return true;
   130     }
   132     return !!GetURI();
   133   }
   135   nsIURI* GetCachedURI() const { return mCachedURI; }
   136   bool HasCachedURI() const { return !!mCachedURI; }
   138   void UpdateURLSearchParams();
   140   // CC methods
   141   void Unlink();
   142   void Traverse(nsCycleCollectionTraversalCallback &cb);
   144 private:
   145   /**
   146    * Unregisters from History so this node no longer gets notifications about
   147    * changes to visitedness.
   148    */
   149   void UnregisterFromHistory();
   151   already_AddRefed<nsIURI> GetURIToMutate();
   152   void SetHrefAttribute(nsIURI *aURI);
   154   void CreateSearchParamsIfNeeded();
   156   void SetSearchInternal(const nsAString& aSearch);
   158   mutable nsCOMPtr<nsIURI> mCachedURI;
   160   Element * const mElement;
   162   // Strong reference to History.  The link has to unregister before History
   163   // can disappear.
   164   nsCOMPtr<IHistory> mHistory;
   166   uint16_t mLinkState;
   168   bool mNeedsRegistration;
   170   bool mRegistered;
   172 protected:
   173   nsRefPtr<URLSearchParams> mSearchParams;
   174 };
   176 NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
   178 } // namespace dom
   179 } // namespace mozilla
   181 #endif // mozilla_dom_Link_h__

mercurial