LCOV - code coverage report
Current view: top level - dom/base - Link.h (source / functions) Hit Total Coverage
Test: output.info Lines: 0 18 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/IHistory.h"
      15             : #include "mozilla/MemoryReporting.h"
      16             : #include "nsIContent.h" // for nsLinkState
      17             : #include "nsIContentPolicyBase.h"
      18             : 
      19             : namespace mozilla {
      20             : 
      21             : class EventStates;
      22             : 
      23             : namespace dom {
      24             : 
      25             : class Element;
      26             : 
      27             : #define MOZILLA_DOM_LINK_IMPLEMENTATION_IID               \
      28             : { 0xb25edee6, 0xdd35, 0x4f8b,                             \
      29             :   { 0xab, 0x90, 0x66, 0xd0, 0xbd, 0x3c, 0x22, 0xd5 } }
      30             : 
      31             : class Link : public nsISupports
      32             : {
      33             : public:
      34             :   NS_DECLARE_STATIC_IID_ACCESSOR(MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
      35             : 
      36             :   /**
      37             :    * aElement is the element pointer corresponding to this link.
      38             :    */
      39             :   explicit Link(Element* aElement);
      40             : 
      41             :   /**
      42             :    * This constructor is only used for testing.
      43             :    */
      44             :   explicit Link();
      45             : 
      46             :   virtual void SetLinkState(nsLinkState aState);
      47             : 
      48             :   /**
      49             :    * @return NS_EVENT_STATE_VISITED if this link is visited,
      50             :    *         NS_EVENT_STATE_UNVISTED if this link is not visited, or 0 if this
      51             :    *         link is not actually a link.
      52             :    */
      53             :   EventStates LinkState() const;
      54             : 
      55             :   /**
      56             :    * @return the URI this link is for, if available.
      57             :    */
      58             :   nsIURI* GetURI() const;
      59           0 :   virtual nsIURI* GetURIExternal() const {
      60           0 :     return GetURI();
      61             :   }
      62             : 
      63             :   /**
      64             :    * Helper methods for modifying and obtaining parts of the URI of the Link.
      65             :    */
      66             :   void SetProtocol(const nsAString &aProtocol);
      67             :   void SetUsername(const nsAString &aUsername);
      68             :   void SetPassword(const nsAString &aPassword);
      69             :   void SetHost(const nsAString &aHost);
      70             :   void SetHostname(const nsAString &aHostname);
      71             :   void SetPathname(const nsAString &aPathname);
      72             :   void SetSearch(const nsAString &aSearch);
      73             :   void SetPort(const nsAString &aPort);
      74             :   void SetHash(const nsAString &aHash);
      75             :   void GetOrigin(nsAString &aOrigin);
      76             :   void GetProtocol(nsAString &_protocol);
      77             :   void GetUsername(nsAString &aUsername);
      78             :   void GetPassword(nsAString &aPassword);
      79             :   void GetHost(nsAString &_host);
      80             :   void GetHostname(nsAString &_hostname);
      81             :   void GetPathname(nsAString &_pathname);
      82             :   void GetSearch(nsAString &_search);
      83             :   void GetPort(nsAString &_port);
      84             :   void GetHash(nsAString &_hash);
      85             : 
      86             :   /**
      87             :    * Invalidates any link caching, and resets the state to the default.
      88             :    *
      89             :    * @param aNotify
      90             :    *        true if ResetLinkState should notify the owning document about style
      91             :    *        changes or false if it should not.
      92             :    */
      93             :   void ResetLinkState(bool aNotify, bool aHasHref);
      94             : 
      95             :   // This method nevers returns a null element.
      96           0 :   Element* GetElement() const { return mElement; }
      97             : 
      98             :   /**
      99             :    * DNS prefetch has been deferred until later, e.g. page load complete.
     100             :    */
     101           0 :   virtual void OnDNSPrefetchDeferred() { /*do nothing*/ }
     102             : 
     103             :   /**
     104             :    * DNS prefetch has been submitted to Host Resolver.
     105             :    */
     106           0 :   virtual void OnDNSPrefetchRequested() { /*do nothing*/ }
     107             : 
     108             :   /**
     109             :    * Checks if DNS Prefetching is ok
     110             :    *
     111             :    * @returns boolean
     112             :    *          Defaults to true; should be overridden for specialised cases
     113             :    */
     114           0 :   virtual bool HasDeferredDNSPrefetchRequest() { return true; }
     115             : 
     116             :   virtual size_t
     117             :     SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
     118             : 
     119             :   virtual bool ElementHasHref() const;
     120             : 
     121             :   // This is called by HTMLAnchorElement.
     122             :   void TryDNSPrefetch();
     123             :   void CancelDNSPrefetch(nsWrapperCache::FlagsType aDeferredFlag,
     124             :                          nsWrapperCache::FlagsType aRequestedFlag);
     125             : 
     126             :   // This is called by HTMLLinkElement.
     127             :   void TryDNSPrefetchOrPreconnectOrPrefetchOrPreloadOrPrerender();
     128             :   void UpdatePreload(nsIAtom* aName, const nsAttrValue* aValue,
     129             :                      const nsAttrValue* aOldValue);
     130             :   void CancelPrefetchOrPreload();
     131             : 
     132           0 :   bool HasPendingLinkUpdate() const { return mHasPendingLinkUpdate; }
     133           0 :   void SetHasPendingLinkUpdate() { mHasPendingLinkUpdate = true; }
     134           0 :   void ClearHasPendingLinkUpdate() { mHasPendingLinkUpdate = false; }
     135             : 
     136             :   // To ensure correct mHasPendingLinkUpdate handling, we have this method
     137             :   // similar to the one in Element. Overriders must call
     138             :   // ClearHasPendingLinkUpdate().
     139             :   // If you change this, change also the method in Element.
     140             :   virtual void NodeInfoChanged(nsIDocument* aOldDoc) = 0;
     141             : 
     142           0 :   bool IsInDNSPrefetch() { return mInDNSPrefetch; }
     143           0 :   void SetIsInDNSPrefetch() { mInDNSPrefetch = true; }
     144           0 :   void ClearIsInDNSPrefetch() { mInDNSPrefetch = false; }
     145             : 
     146             :   static void ParseAsValue(const nsAString& aValue, nsAttrValue& aResult);
     147             :   static nsContentPolicyType AsValueToContentPolicy(const nsAttrValue& aValue);
     148             : protected:
     149             :   virtual ~Link();
     150             : 
     151             :   /**
     152             :    * Return true if the link has associated URI.
     153             :    */
     154           0 :   bool HasURI() const
     155             :   {
     156           0 :     if (HasCachedURI()) {
     157           0 :       return true;
     158             :     }
     159             : 
     160           0 :     return !!GetURI();
     161             :   }
     162             : 
     163           0 :   nsIURI* GetCachedURI() const { return mCachedURI; }
     164           0 :   bool HasCachedURI() const { return !!mCachedURI; }
     165             : 
     166             : private:
     167             :   /**
     168             :    * Unregisters from History so this node no longer gets notifications about
     169             :    * changes to visitedness.
     170             :    */
     171             :   void UnregisterFromHistory();
     172             : 
     173             :   already_AddRefed<nsIURI> GetURIToMutate();
     174             :   void SetHrefAttribute(nsIURI *aURI);
     175             : 
     176             :   void GetContentPolicyMimeTypeMedia(nsAttrValue& aAsAttr,
     177             :                                      nsContentPolicyType& aPolicyType,
     178             :                                      nsString& aMimeType,
     179             :                                      nsAString& aMedia);
     180             : 
     181             :   mutable nsCOMPtr<nsIURI> mCachedURI;
     182             : 
     183             :   Element * const mElement;
     184             : 
     185             :   // Strong reference to History.  The link has to unregister before History
     186             :   // can disappear.
     187             :   nsCOMPtr<IHistory> mHistory;
     188             : 
     189             :   uint16_t mLinkState;
     190             : 
     191             :   bool mNeedsRegistration : 1;
     192             : 
     193             :   bool mRegistered : 1;
     194             : 
     195             :   bool mHasPendingLinkUpdate : 1;
     196             : 
     197             :   bool mInDNSPrefetch : 1;
     198             : };
     199             : 
     200             : NS_DEFINE_STATIC_IID_ACCESSOR(Link, MOZILLA_DOM_LINK_IMPLEMENTATION_IID)
     201             : 
     202             : enum ASDestination : uint8_t {
     203             :   DESTINATION_INVALID,
     204             :   DESTINATION_AUDIO,
     205             :   DESTINATION_DOCUMENT,
     206             :   DESTINATION_EMBED,
     207             :   DESTINATION_FONT,
     208             :   DESTINATION_IMAGE,
     209             :   DESTINATION_MANIFEST,
     210             :   DESTINATION_OBJECT,
     211             :   DESTINATION_REPORT,
     212             :   DESTINATION_SCRIPT,
     213             :   DESTINATION_SERVICEWORKER,
     214             :   DESTINATION_SHAREDWORKER,
     215             :   DESTINATION_STYLE,
     216             :   DESTINATION_TRACK,
     217             :   DESTINATION_VIDEO,
     218             :   DESTINATION_WORKER,
     219             :   DESTINATION_XSLT,
     220             :   DESTINATION_FETCH
     221             : };
     222             : 
     223             : } // namespace dom
     224             : } // namespace mozilla
     225             : 
     226             : #endif // mozilla_dom_Link_h__

Generated by: LCOV version 1.13