2001-05-19 00:21:26 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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 08:00:42 +00: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 00:21:26 +00:00
|
|
|
#ifndef nsStyleLinkElement_h___
|
|
|
|
#define nsStyleLinkElement_h___
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-06-20 10:32:49 +00:00
|
|
|
#include "mozilla/CORSMode.h"
|
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
2001-05-19 00:21:26 +00:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIStyleSheetLinkingElement.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2001-05-19 00:21:26 +00:00
|
|
|
|
|
|
|
class nsIDocument;
|
2013-03-18 15:38:19 +00:00
|
|
|
class nsIURI;
|
2001-05-19 00:21:26 +00:00
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class ShadowRoot;
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-08-10 01:17:52 +00:00
|
|
|
class nsStyleLinkElement : public nsIStyleSheetLinkingElement
|
2001-05-19 00:21:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsStyleLinkElement();
|
|
|
|
virtual ~nsStyleLinkElement();
|
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr) MOZ_OVERRIDE = 0;
|
2001-05-19 00:21:26 +00:00
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
mozilla::CSSStyleSheet* GetSheet() const { return mStyleSheet; }
|
2013-02-03 17:42:40 +00:00
|
|
|
|
2001-05-19 00:21:26 +00:00
|
|
|
// nsIStyleSheetLinkingElement
|
2014-06-20 10:32:49 +00:00
|
|
|
NS_IMETHOD SetStyleSheet(mozilla::CSSStyleSheet* aStyleSheet) MOZ_OVERRIDE;
|
2014-07-02 10:53:40 +00:00
|
|
|
NS_IMETHOD_(mozilla::CSSStyleSheet*) GetStyleSheet() MOZ_OVERRIDE;
|
2013-05-29 20:43:41 +00:00
|
|
|
NS_IMETHOD InitStyleLinkElement(bool aDontLoadStyle) MOZ_OVERRIDE;
|
2007-04-20 22:59:18 +00:00
|
|
|
NS_IMETHOD UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aWillNotify,
|
2014-08-29 00:20:27 +00:00
|
|
|
bool* aIsAlternate,
|
|
|
|
bool aForceReload) MOZ_OVERRIDE;
|
2013-05-29 20:43:41 +00:00
|
|
|
NS_IMETHOD SetEnableUpdates(bool aEnableUpdates) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD GetCharset(nsAString& aCharset) MOZ_OVERRIDE;
|
2006-12-18 03:59:46 +00:00
|
|
|
|
2013-05-29 20:43:41 +00:00
|
|
|
virtual void OverrideBaseURI(nsIURI* aNewBaseURI) MOZ_OVERRIDE;
|
|
|
|
virtual void SetLineNumber(uint32_t aLineNumber) MOZ_OVERRIDE;
|
2001-05-19 00:21:26 +00:00
|
|
|
|
2014-02-27 13:44:52 +00:00
|
|
|
enum RelValue {
|
|
|
|
ePREFETCH = 0x00000001,
|
|
|
|
eDNS_PREFETCH = 0x00000002,
|
|
|
|
eSTYLESHEET = 0x00000004,
|
|
|
|
eNEXT = 0x00000008,
|
|
|
|
eALTERNATE = 0x00000010,
|
2014-05-21 17:08:12 +00:00
|
|
|
eHTMLIMPORT = 0x00000020
|
2014-02-27 13:44:52 +00:00
|
|
|
};
|
|
|
|
|
2014-07-08 02:02:03 +00:00
|
|
|
// The return value is a bitwise or of 0 or more RelValues.
|
|
|
|
// aPrincipal is used to check if HTML imports is enabled for the
|
|
|
|
// provided principal.
|
|
|
|
static uint32_t ParseLinkTypes(const nsAString& aTypes,
|
|
|
|
nsIPrincipal* aPrincipal);
|
2013-12-02 10:26:12 +00:00
|
|
|
|
2014-07-08 02:02:03 +00:00
|
|
|
static bool IsImportEnabled(nsIPrincipal* aPrincipal);
|
2014-06-05 12:46:56 +00:00
|
|
|
|
2013-12-02 10:26:12 +00:00
|
|
|
void UpdateStyleSheetInternal()
|
|
|
|
{
|
|
|
|
UpdateStyleSheetInternal(nullptr, nullptr);
|
|
|
|
}
|
2001-05-19 00:21:26 +00:00
|
|
|
protected:
|
2007-04-20 22:59:18 +00:00
|
|
|
/**
|
|
|
|
* @param aOldDocument should be non-null only if we're updating because we
|
|
|
|
* removed the node from the document.
|
2011-10-17 14:59:28 +00:00
|
|
|
* @param aForceUpdate true will force the update even if the URI has not
|
2007-04-20 22:59:18 +00: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 10:26:12 +00:00
|
|
|
mozilla::dom::ShadowRoot *aOldShadowRoot,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aForceUpdate = false);
|
2007-04-20 22:59:18 +00:00
|
|
|
|
2013-01-08 23:25:48 +00:00
|
|
|
void UpdateStyleSheetScopedness(bool aIsNowScoped);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline) = 0;
|
2002-04-05 11:29:40 +00:00
|
|
|
virtual void GetStyleSheetInfo(nsAString& aTitle,
|
2002-03-23 23:54:46 +00:00
|
|
|
nsAString& aType,
|
|
|
|
nsAString& aMedia,
|
2013-01-08 23:25:47 +00:00
|
|
|
bool* aIsScoped,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aIsAlternate) = 0;
|
2001-05-19 00:21:26 +00:00
|
|
|
|
2012-08-28 17:10:07 +00:00
|
|
|
virtual mozilla::CORSMode GetCORSMode() const
|
|
|
|
{
|
|
|
|
// Default to no CORS
|
|
|
|
return mozilla::CORS_NONE;
|
|
|
|
}
|
|
|
|
|
2012-10-08 02:39:09 +00:00
|
|
|
// CC methods
|
|
|
|
void Unlink();
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback &cb);
|
|
|
|
|
2007-04-20 22:59:18 +00:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* @param aOldDocument should be non-null only if we're updating because we
|
|
|
|
* removed the node from the document.
|
2013-12-02 10:26:12 +00: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 14:59:28 +00:00
|
|
|
* @param aForceUpdate true will force the update even if the URI has not
|
2007-04-20 22:59:18 +00: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 10:26:12 +00:00
|
|
|
nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument,
|
|
|
|
mozilla::dom::ShadowRoot* aOldShadowRoot,
|
2007-04-20 22:59:18 +00:00
|
|
|
nsICSSLoaderObserver* aObserver,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool* aWillNotify,
|
|
|
|
bool* aIsAlternate,
|
|
|
|
bool aForceUpdate);
|
2001-05-19 00:21:26 +00:00
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
nsRefPtr<mozilla::CSSStyleSheet> mStyleSheet;
|
2009-01-29 20:39:21 +00:00
|
|
|
protected:
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mDontLoadStyle;
|
|
|
|
bool mUpdatesEnabled;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mLineNumber;
|
2001-05-19 00:21:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsStyleLinkElement_h___ */
|
|
|
|
|