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"
|
2018-04-24 13:50:35 +03:00
|
|
|
#include "mozilla/Unused.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"
|
2001-05-19 04:21:26 +04:00
|
|
|
|
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 {
|
2019-01-02 16:05:23 +03:00
|
|
|
class Document;
|
2013-12-02 14:26:12 +04:00
|
|
|
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
|
2018-02-02 16:21:32 +03:00
|
|
|
void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) override;
|
|
|
|
mozilla::StyleSheet* GetStyleSheet() override;
|
|
|
|
void InitStyleLinkElement(bool aDontLoadStyle) override;
|
2018-04-24 13:50:35 +03:00
|
|
|
|
|
|
|
mozilla::Result<Update, nsresult> UpdateStyleSheet(
|
2018-07-20 12:35:42 +03:00
|
|
|
nsICSSLoaderObserver*) override;
|
2018-04-24 13:50:35 +03:00
|
|
|
|
2018-02-02 16:21:32 +03:00
|
|
|
void SetEnableUpdates(bool aEnableUpdates) override;
|
2018-02-02 16:21:32 +03:00
|
|
|
void GetCharset(nsAString& aCharset) override;
|
2006-12-18 06:59:46 +03:00
|
|
|
|
2018-04-24 13:50:35 +03:00
|
|
|
void OverrideBaseURI(nsIURI* aNewBaseURI) override;
|
|
|
|
void SetLineNumber(uint32_t aLineNumber) override;
|
|
|
|
uint32_t GetLineNumber() override;
|
2018-07-05 09:21:04 +03:00
|
|
|
void SetColumnNumber(uint32_t aColumnNumber) override;
|
|
|
|
uint32_t GetColumnNumber() 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
|
|
|
|
|
|
|
void UpdateStyleSheetInternal() {
|
2018-04-24 13:50:35 +03:00
|
|
|
mozilla::Unused << UpdateStyleSheetInternal(nullptr, nullptr);
|
2013-12-02 14:26:12 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2001-05-19 04:21:26 +04:00
|
|
|
protected:
|
2007-04-21 02:59:18 +04:00
|
|
|
/**
|
2018-04-24 13:50:35 +03:00
|
|
|
* @param aOldDocument should be non-null only if we're updating because we
|
|
|
|
* removed the node from the document.
|
|
|
|
* @param aOldShadowRoot should be non-null only if we're updating because we
|
|
|
|
* removed the node from a shadow tree.
|
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.
|
2018-04-24 13:50:35 +03:00
|
|
|
*
|
|
|
|
* TODO(emilio): Should probably pass a single DocumentOrShadowRoot.
|
2007-04-21 02:59:18 +04:00
|
|
|
*/
|
2018-04-24 13:50:35 +03:00
|
|
|
mozilla::Result<Update, nsresult> UpdateStyleSheetInternal(
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* aOldDocument,
|
|
|
|
mozilla::dom::ShadowRoot* aOldShadowRoot, ForceUpdate = ForceUpdate::No);
|
2007-04-21 02:59:18 +04:00
|
|
|
|
2018-05-08 07:51:34 +03:00
|
|
|
// Gets a suitable title and media for SheetInfo out of an element, which
|
|
|
|
// needs to be `this`.
|
|
|
|
//
|
|
|
|
// NOTE(emilio): Needs nsString instead of nsAString because of
|
|
|
|
// CompressWhitespace.
|
|
|
|
static void GetTitleAndMediaForElement(const mozilla::dom::Element&,
|
|
|
|
nsString& aTitle, nsString& aMedia);
|
|
|
|
|
|
|
|
// Returns whether the type attribute specifies the text/css mime type.
|
|
|
|
static bool IsCSSMimeTypeAttribute(const mozilla::dom::Element&);
|
|
|
|
|
2018-05-08 07:11:56 +03:00
|
|
|
virtual mozilla::Maybe<SheetInfo> GetStyleSheetInfo() = 0;
|
2016-06-24 05:38:47 +03:00
|
|
|
|
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.
|
|
|
|
*/
|
2018-04-24 13:50:35 +03:00
|
|
|
mozilla::Result<Update, nsresult> DoUpdateStyleSheet(
|
2019-01-02 16:05:23 +03:00
|
|
|
mozilla::dom::Document* aOldDocument,
|
|
|
|
mozilla::dom::ShadowRoot* aOldShadowRoot, nsICSSLoaderObserver* aObserver,
|
|
|
|
ForceUpdate);
|
2001-05-19 04:21:26 +04:00
|
|
|
|
2016-09-26 15:03:25 +03:00
|
|
|
RefPtr<mozilla::StyleSheet> mStyleSheet;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
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;
|
2018-07-05 09:21:04 +03:00
|
|
|
uint32_t mColumnNumber;
|
2001-05-19 04:21:26 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsStyleLinkElement_h___ */
|