LCOV - code coverage report
Current view: top level - dom/base - nsStyleLinkElement.h (source / functions) Hit Total Coverage
Test: output.info Lines: 7 8 87.5 %
Date: 2017-07-14 16:53:18 Functions: 3 4 75.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             :  * A base class which implements nsIStyleSheetLinkingElement and can
       9             :  * be subclassed by various content nodes that want to load
      10             :  * stylesheets (<style>, <link>, processing instructions, etc).
      11             :  */
      12             : 
      13             : #ifndef nsStyleLinkElement_h___
      14             : #define nsStyleLinkElement_h___
      15             : 
      16             : #include "mozilla/Attributes.h"
      17             : #include "mozilla/CORSMode.h"
      18             : #include "mozilla/StyleSheetInlines.h"
      19             : #include "mozilla/net/ReferrerPolicy.h"
      20             : #include "nsCOMPtr.h"
      21             : #include "nsIStyleSheetLinkingElement.h"
      22             : #include "nsTArray.h"
      23             : #include "nsAttrValue.h"
      24             : 
      25             : class nsIDocument;
      26             : class nsIURI;
      27             : 
      28             : namespace mozilla {
      29             : class CSSStyleSheet;
      30             : namespace dom {
      31             : class ShadowRoot;
      32             : } // namespace dom
      33             : } // namespace mozilla
      34             : 
      35             : class nsStyleLinkElement : public nsIStyleSheetLinkingElement
      36             : {
      37             : public:
      38             :   nsStyleLinkElement();
      39             :   virtual ~nsStyleLinkElement();
      40             : 
      41             :   NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override = 0;
      42             : 
      43           0 :   mozilla::StyleSheet* GetSheet() const { return mStyleSheet; }
      44             : 
      45             :   // nsIStyleSheetLinkingElement
      46             :   NS_IMETHOD SetStyleSheet(mozilla::StyleSheet* aStyleSheet) override;
      47             :   NS_IMETHOD_(mozilla::StyleSheet*) GetStyleSheet() override;
      48             :   NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) override;
      49             :   NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
      50             :                               bool* aWillNotify,
      51             :                               bool* aIsAlternate,
      52             :                               bool aForceReload) override;
      53             :   NS_IMETHOD SetEnableUpdates(bool aEnableUpdates) override;
      54             :   NS_IMETHOD GetCharset(nsAString& aCharset) override;
      55             : 
      56             :   virtual void OverrideBaseURI(nsIURI* aNewBaseURI) override;
      57             :   virtual void SetLineNumber(uint32_t aLineNumber) override;
      58             :   virtual uint32_t GetLineNumber() override;
      59             : 
      60             :   enum RelValue {
      61             :     ePREFETCH =     0x00000001,
      62             :     eDNS_PREFETCH = 0x00000002,
      63             :     eSTYLESHEET =   0x00000004,
      64             :     eNEXT =         0x00000008,
      65             :     eALTERNATE =    0x00000010,
      66             :     ePRECONNECT =   0x00000020,
      67             :     ePRERENDER =    0x00000040,
      68             :     ePRELOAD =      0x00000080
      69             :   };
      70             : 
      71             :   // The return value is a bitwise or of 0 or more RelValues.
      72             :   static uint32_t ParseLinkTypes(const nsAString& aTypes);
      73             : 
      74             :   static bool CheckPreloadAttrs(const nsAttrValue& aAs, const nsAString& aType,
      75             :                                 const nsAString& aMedia, nsIDocument* aDocument);
      76             : 
      77          11 :   void UpdateStyleSheetInternal()
      78             :   {
      79          11 :     UpdateStyleSheetInternal(nullptr, nullptr);
      80          11 :   }
      81             : protected:
      82             :   /**
      83             :    * @param aOldDocument should be non-null only if we're updating because we
      84             :    *                     removed the node from the document.
      85             :    * @param aForceUpdate true will force the update even if the URI has not
      86             :    *                     changed.  This should be used in cases when something
      87             :    *                     about the content that affects the resulting sheet
      88             :    *                     changed but the URI may not have changed.
      89             :    */
      90             :   nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument,
      91             :                                     mozilla::dom::ShadowRoot *aOldShadowRoot,
      92             :                                     bool aForceUpdate = false);
      93             : 
      94             :   void UpdateStyleSheetScopedness(bool aIsNowScoped);
      95             : 
      96             :   virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0;
      97             :   virtual void GetStyleSheetInfo(nsAString& aTitle,
      98             :                                  nsAString& aType,
      99             :                                  nsAString& aMedia,
     100             :                                  bool* aIsScoped,
     101             :                                  bool* aIsAlternate) = 0;
     102             : 
     103           6 :   virtual mozilla::CORSMode GetCORSMode() const
     104             :   {
     105             :     // Default to no CORS
     106           6 :     return mozilla::CORS_NONE;
     107             :   }
     108             : 
     109           6 :   virtual mozilla::net::ReferrerPolicy GetLinkReferrerPolicy()
     110             :   {
     111           6 :     return mozilla::net::RP_Unset;
     112             :   }
     113             : 
     114             :   // CC methods
     115             :   void Unlink();
     116             :   void Traverse(nsCycleCollectionTraversalCallback &cb);
     117             : 
     118             : private:
     119             :   /**
     120             :    * @param aOldDocument should be non-null only if we're updating because we
     121             :    *                     removed the node from the document.
     122             :    * @param aOldShadowRoot The ShadowRoot that used to contain the style.
     123             :    *                     Passed as a parameter because on an update, the node
     124             :    *                     is removed from the tree before the sheet is removed
     125             :    *                     from the ShadowRoot.
     126             :    * @param aForceUpdate true will force the update even if the URI has not
     127             :    *                     changed.  This should be used in cases when something
     128             :    *                     about the content that affects the resulting sheet
     129             :    *                     changed but the URI may not have changed.
     130             :    */
     131             :   nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument,
     132             :                               mozilla::dom::ShadowRoot* aOldShadowRoot,
     133             :                               nsICSSLoaderObserver* aObserver,
     134             :                               bool* aWillNotify,
     135             :                               bool* aIsAlternate,
     136             :                               bool aForceUpdate);
     137             : 
     138             :   RefPtr<mozilla::StyleSheet> mStyleSheet;
     139             : protected:
     140             :   bool mDontLoadStyle;
     141             :   bool mUpdatesEnabled;
     142             :   uint32_t mLineNumber;
     143             : };
     144             : 
     145             : #endif /* nsStyleLinkElement_h___ */
     146             : 

Generated by: LCOV version 1.13