Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | /* |
michael@0 | 8 | * A base class which implements nsIStyleSheetLinkingElement and can |
michael@0 | 9 | * be subclassed by various content nodes that want to load |
michael@0 | 10 | * stylesheets (<style>, <link>, processing instructions, etc). |
michael@0 | 11 | */ |
michael@0 | 12 | |
michael@0 | 13 | #ifndef nsStyleLinkElement_h___ |
michael@0 | 14 | #define nsStyleLinkElement_h___ |
michael@0 | 15 | |
michael@0 | 16 | #include "mozilla/Attributes.h" |
michael@0 | 17 | #include "nsCOMPtr.h" |
michael@0 | 18 | #include "nsIStyleSheetLinkingElement.h" |
michael@0 | 19 | #include "nsCSSStyleSheet.h" |
michael@0 | 20 | #include "nsTArray.h" |
michael@0 | 21 | #include "mozilla/CORSMode.h" |
michael@0 | 22 | |
michael@0 | 23 | class nsIDocument; |
michael@0 | 24 | class nsIURI; |
michael@0 | 25 | |
michael@0 | 26 | namespace mozilla { |
michael@0 | 27 | namespace dom { |
michael@0 | 28 | class ShadowRoot; |
michael@0 | 29 | } // namespace dom |
michael@0 | 30 | } // namespace mozilla |
michael@0 | 31 | |
michael@0 | 32 | class nsStyleLinkElement : public nsIStyleSheetLinkingElement |
michael@0 | 33 | { |
michael@0 | 34 | public: |
michael@0 | 35 | nsStyleLinkElement(); |
michael@0 | 36 | virtual ~nsStyleLinkElement(); |
michael@0 | 37 | |
michael@0 | 38 | NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE = 0; |
michael@0 | 39 | |
michael@0 | 40 | nsCSSStyleSheet* GetSheet() const { return mStyleSheet; } |
michael@0 | 41 | |
michael@0 | 42 | // nsIStyleSheetLinkingElement |
michael@0 | 43 | NS_IMETHOD SetStyleSheet(nsCSSStyleSheet* aStyleSheet) MOZ_OVERRIDE; |
michael@0 | 44 | NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aStyleSheet) MOZ_OVERRIDE; |
michael@0 | 45 | NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) MOZ_OVERRIDE; |
michael@0 | 46 | NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver, |
michael@0 | 47 | bool* aWillNotify, |
michael@0 | 48 | bool* aIsAlternate) MOZ_OVERRIDE; |
michael@0 | 49 | NS_IMETHOD SetEnableUpdates(bool aEnableUpdates) MOZ_OVERRIDE; |
michael@0 | 50 | NS_IMETHOD GetCharset(nsAString& aCharset) MOZ_OVERRIDE; |
michael@0 | 51 | |
michael@0 | 52 | virtual void OverrideBaseURI(nsIURI* aNewBaseURI) MOZ_OVERRIDE; |
michael@0 | 53 | virtual void SetLineNumber(uint32_t aLineNumber) MOZ_OVERRIDE; |
michael@0 | 54 | |
michael@0 | 55 | enum RelValue { |
michael@0 | 56 | ePREFETCH = 0x00000001, |
michael@0 | 57 | eDNS_PREFETCH = 0x00000002, |
michael@0 | 58 | eSTYLESHEET = 0x00000004, |
michael@0 | 59 | eNEXT = 0x00000008, |
michael@0 | 60 | eALTERNATE = 0x00000010, |
michael@0 | 61 | }; |
michael@0 | 62 | |
michael@0 | 63 | // The return value is a bitwise or of 0 or more RelValues |
michael@0 | 64 | static uint32_t ParseLinkTypes(const nsAString& aTypes); |
michael@0 | 65 | |
michael@0 | 66 | void UpdateStyleSheetInternal() |
michael@0 | 67 | { |
michael@0 | 68 | UpdateStyleSheetInternal(nullptr, nullptr); |
michael@0 | 69 | } |
michael@0 | 70 | protected: |
michael@0 | 71 | /** |
michael@0 | 72 | * @param aOldDocument should be non-null only if we're updating because we |
michael@0 | 73 | * removed the node from the document. |
michael@0 | 74 | * @param aForceUpdate true will force the update even if the URI has not |
michael@0 | 75 | * changed. This should be used in cases when something |
michael@0 | 76 | * about the content that affects the resulting sheet |
michael@0 | 77 | * changed but the URI may not have changed. |
michael@0 | 78 | */ |
michael@0 | 79 | nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument, |
michael@0 | 80 | mozilla::dom::ShadowRoot *aOldShadowRoot, |
michael@0 | 81 | bool aForceUpdate = false); |
michael@0 | 82 | |
michael@0 | 83 | void UpdateStyleSheetScopedness(bool aIsNowScoped); |
michael@0 | 84 | |
michael@0 | 85 | virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0; |
michael@0 | 86 | virtual void GetStyleSheetInfo(nsAString& aTitle, |
michael@0 | 87 | nsAString& aType, |
michael@0 | 88 | nsAString& aMedia, |
michael@0 | 89 | bool* aIsScoped, |
michael@0 | 90 | bool* aIsAlternate) = 0; |
michael@0 | 91 | |
michael@0 | 92 | virtual mozilla::CORSMode GetCORSMode() const |
michael@0 | 93 | { |
michael@0 | 94 | // Default to no CORS |
michael@0 | 95 | return mozilla::CORS_NONE; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | // CC methods |
michael@0 | 99 | void Unlink(); |
michael@0 | 100 | void Traverse(nsCycleCollectionTraversalCallback &cb); |
michael@0 | 101 | |
michael@0 | 102 | private: |
michael@0 | 103 | /** |
michael@0 | 104 | * @param aOldDocument should be non-null only if we're updating because we |
michael@0 | 105 | * removed the node from the document. |
michael@0 | 106 | * @param aOldShadowRoot The ShadowRoot that used to contain the style. |
michael@0 | 107 | * Passed as a parameter because on an update, the node |
michael@0 | 108 | * is removed from the tree before the sheet is removed |
michael@0 | 109 | * from the ShadowRoot. |
michael@0 | 110 | * @param aForceUpdate true will force the update even if the URI has not |
michael@0 | 111 | * changed. This should be used in cases when something |
michael@0 | 112 | * about the content that affects the resulting sheet |
michael@0 | 113 | * changed but the URI may not have changed. |
michael@0 | 114 | */ |
michael@0 | 115 | nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument, |
michael@0 | 116 | mozilla::dom::ShadowRoot* aOldShadowRoot, |
michael@0 | 117 | nsICSSLoaderObserver* aObserver, |
michael@0 | 118 | bool* aWillNotify, |
michael@0 | 119 | bool* aIsAlternate, |
michael@0 | 120 | bool aForceUpdate); |
michael@0 | 121 | |
michael@0 | 122 | nsRefPtr<nsCSSStyleSheet> mStyleSheet; |
michael@0 | 123 | protected: |
michael@0 | 124 | bool mDontLoadStyle; |
michael@0 | 125 | bool mUpdatesEnabled; |
michael@0 | 126 | uint32_t mLineNumber; |
michael@0 | 127 | }; |
michael@0 | 128 | |
michael@0 | 129 | #endif /* nsStyleLinkElement_h___ */ |
michael@0 | 130 |