2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 15:12:37 +04:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2006-03-31 12:00:42 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A base class which implements nsIStyleSheetLinkingElement and can
|
|
|
|
* be subclassed by various content nodes that want to load
|
|
|
|
* stylesheets (<style>, <link>, processing instructions, etc).
|
|
|
|
*/
|
|
|
|
|
2001-05-19 04:21:26 +04:00
|
|
|
#ifndef nsStyleLinkElement_h___
|
|
|
|
#define nsStyleLinkElement_h___
|
|
|
|
|
2013-05-30 00:43:41 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-06-20 14:32:49 +04:00
|
|
|
#include "mozilla/CORSMode.h"
|
2016-09-26 15:03:25 +03:00
|
|
|
#include "mozilla/StyleSheetInlines.h"
|
2016-06-24 05:38:47 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2001-05-19 04:21:26 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsTArray.h"
|
2017-07-10 16:05:56 +03:00
|
|
|
#include "nsAttrValue.h"
|
2001-05-19 04:21:26 +04:00
|
|
|
|
|
|
|
class nsIDocument;
|
2013-03-18 19:38:19 +04:00
|
|
|
class nsIURI;
|
2001-05-19 04:21:26 +04:00
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
namespace mozilla {
|
2016-02-24 10:01:12 +03:00
|
|
|
class CSSStyleSheet;
|
2013-12-02 14:26:12 +04:00
|
|
|
namespace dom {
|
|
|
|
class ShadowRoot;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-08-10 05:17:52 +04:00
|
|
|
class nsStyleLinkElement : public nsIStyleSheetLinkingElement
|
2001-05-19 04:21:26 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsStyleLinkElement();
|
|
|
|
virtual ~nsStyleLinkElement();
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) override = 0;
|
2001-05-19 04:21:26 +04:00
|
|
|
|
2016-10-14 14:25:38 +03:00
|
|
|
mozilla::StyleSheet* GetSheet() const { return mStyleSheet; }
|
2013-02-03 21:42:40 +04:00
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
// nsIStyleSheetLinkingElement
|
2016-09-26 15:03:25 +03:00
|
|
|
NS_IMETHOD SetStyleSheet(mozilla::StyleSheet* aStyleSheet) override;
|
|
|
|
NS_IMETHOD_(mozilla::StyleSheet*) GetStyleSheet() override;
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) override;
|
2007-04-21 02:59:18 +04:00
|
|
|
NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aWillNotify,
|
2014-08-29 04:20:27 +04:00
|
|
|
bool* aIsAlternate,
|
2015-03-21 19:28:04 +03:00
|
|
|
bool aForceReload) override;
|
|
|
|
NS_IMETHOD SetEnableUpdates(bool aEnableUpdates) override;
|
|
|
|
NS_IMETHOD GetCharset(nsAString& aCharset) override;
|
2006-12-18 06:59:46 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void OverrideBaseURI(nsIURI* aNewBaseURI) override;
|
|
|
|
virtual void SetLineNumber(uint32_t aLineNumber) override;
|
2015-08-18 01:19:21 +03:00
|
|
|
virtual uint32_t GetLineNumber() override;
|
2001-05-19 04:21:26 +04:00
|
|
|
|
2014-02-27 17:44:52 +04:00
|
|
|
enum RelValue {
|
|
|
|
ePREFETCH = 0x00000001,
|
|
|
|
eDNS_PREFETCH = 0x00000002,
|
|
|
|
eSTYLESHEET = 0x00000004,
|
|
|
|
eNEXT = 0x00000008,
|
|
|
|
eALTERNATE = 0x00000010,
|
2017-06-12 17:36:02 +03:00
|
|
|
ePRECONNECT = 0x00000020,
|
2017-12-15 01:03:14 +03:00
|
|
|
// NOTE: 0x40 is unused
|
2017-07-10 16:05:56 +03:00
|
|
|
ePRELOAD = 0x00000080
|
2014-02-27 17:44:52 +04:00
|
|
|
};
|
|
|
|
|
2014-07-08 06:02:03 +04:00
|
|
|
// The return value is a bitwise or of 0 or more RelValues.
|
2017-06-12 17:36:02 +03:00
|
|
|
static uint32_t ParseLinkTypes(const nsAString& aTypes);
|
2013-12-02 14:26:12 +04:00
|
|
|
|
2017-07-10 16:05:56 +03:00
|
|
|
static bool CheckPreloadAttrs(const nsAttrValue& aAs, const nsAString& aType,
|
|
|
|
const nsAString& aMedia, nsIDocument* aDocument);
|
|
|
|
|
2013-12-02 14:26:12 +04:00
|
|
|
void UpdateStyleSheetInternal()
|
|
|
|
{
|
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr);
|
|
|
|
}
|
2001-05-19 04:21:26 +04:00
|
|
|
protected:
|
2007-04-21 02:59:18 +04:00
|
|
|
/**
|
|
|
|
* @param aOldDocument should be non-null only if we're updating because we
|
|
|
|
* removed the node from the document.
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param aForceUpdate true will force the update even if the URI has not
|
2007-04-21 02:59:18 +04:00
|
|
|
* changed. This should be used in cases when something
|
|
|
|
* about the content that affects the resulting sheet
|
|
|
|
* changed but the URI may not have changed.
|
|
|
|
*/
|
|
|
|
nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument,
|
2013-12-02 14:26:12 +04:00
|
|
|
mozilla::dom::ShadowRoot *aOldShadowRoot,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aForceUpdate = false);
|
2007-04-21 02:59:18 +04:00
|
|
|
|
2013-01-09 03:25:48 +04:00
|
|
|
void UpdateStyleSheetScopedness(bool aIsNowScoped);
|
|
|
|
|
2017-10-06 05:40:48 +03:00
|
|
|
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) = 0;
|
2002-04-05 15:29:40 +04:00
|
|
|
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
2002-03-24 02:54:46 +03:00
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
2013-01-09 03:25:47 +04:00
|
|
|
bool* aIsScoped,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aIsAlternate) = 0;
|
2001-05-19 04:21:26 +04:00
|
|
|
|
2012-08-28 21:10:07 +04:00
|
|
|
virtual mozilla::CORSMode GetCORSMode() const
|
|
|
|
{
|
|
|
|
// Default to no CORS
|
|
|
|
return mozilla::CORS_NONE;
|
|
|
|
}
|
|
|
|
|
2016-06-24 05:38:47 +03:00
|
|
|
virtual mozilla::net::ReferrerPolicy GetLinkReferrerPolicy()
|
|
|
|
{
|
|
|
|
return mozilla::net::RP_Unset;
|
|
|
|
}
|
|
|
|
|
2012-10-08 06:39:09 +04:00
|
|
|
// CC methods
|
|
|
|
void Unlink();
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
2007-04-21 02:59:18 +04:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* @param aOldDocument should be non-null only if we're updating because we
|
|
|
|
* removed the node from the document.
|
2013-12-02 14:26:12 +04:00
|
|
|
* @param aOldShadowRoot The ShadowRoot that used to contain the style.
|
|
|
|
* Passed as a parameter because on an update, the node
|
|
|
|
* is removed from the tree before the sheet is removed
|
|
|
|
* from the ShadowRoot.
|
2011-10-17 18:59:28 +04:00
|
|
|
* @param aForceUpdate true will force the update even if the URI has not
|
2007-04-21 02:59:18 +04:00
|
|
|
* changed. This should be used in cases when something
|
|
|
|
* about the content that affects the resulting sheet
|
|
|
|
* changed but the URI may not have changed.
|
|
|
|
*/
|
2013-12-02 14:26:12 +04:00
|
|
|
nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
|
|
|
mozilla::dom::ShadowRoot* aOldShadowRoot,
|
2007-04-21 02:59:18 +04:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aWillNotify,
|
|
|
|
bool* aIsAlternate,
|
|
|
|
bool aForceUpdate);
|
2001-05-19 04:21:26 +04:00
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<mozilla::StyleSheet> mStyleSheet;
|
2009-01-29 23:39:21 +03:00
|
|
|
protected:
|
2017-10-06 05:40:48 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mTriggeringPrincipal;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mDontLoadStyle;
|
|
|
|
bool mUpdatesEnabled;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mLineNumber;
|
2001-05-19 04:21:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsStyleLinkElement_h___ */
|
|
|
|
|