Bug 1019319 - part 2: Import as link type should be prefed. r=mrbkap
--- a/content/base/src/nsStyleLinkElement.cpp
+++ b/content/base/src/nsStyleLinkElement.cpp
@@ -10,16 +10,17 @@
* stylesheets (<style>, <link>, processing instructions, etc).
*/
#include "nsStyleLinkElement.h"
#include "mozilla/css/Loader.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/ShadowRoot.h"
+#include "mozilla/Preferences.h"
#include "nsCSSStyleSheet.h"
#include "nsIContent.h"
#include "nsIDocument.h"
#include "nsIDOMComment.h"
#include "nsIDOMNode.h"
#include "nsIDOMStyleSheet.h"
#include "nsNetUtil.h"
#include "nsUnicharUtils.h"
@@ -115,29 +116,44 @@ nsStyleLinkElement::OverrideBaseURI(nsIU
}
/* virtual */ void
nsStyleLinkElement::SetLineNumber(uint32_t aLineNumber)
{
mLineNumber = aLineNumber;
}
+/* static */ bool
+nsStyleLinkElement::IsImportEnabled()
+{
+ static bool sAdded = false;
+ static bool sImportEnabled;
+ if (!sAdded) {
+ // This part runs only once because of the static flag.
+ Preferences::AddBoolVarCache(&sImportEnabled,
+ "dom.webcomponents.enabled",
+ false);
+ sAdded = true;
+ }
+ return sImportEnabled;
+}
+
static uint32_t ToLinkMask(const nsAString& aLink)
{
if (aLink.EqualsLiteral("prefetch"))
return nsStyleLinkElement::ePREFETCH;
else if (aLink.EqualsLiteral("dns-prefetch"))
return nsStyleLinkElement::eDNS_PREFETCH;
else if (aLink.EqualsLiteral("stylesheet"))
return nsStyleLinkElement::eSTYLESHEET;
else if (aLink.EqualsLiteral("next"))
return nsStyleLinkElement::eNEXT;
else if (aLink.EqualsLiteral("alternate"))
return nsStyleLinkElement::eALTERNATE;
- else if (aLink.EqualsLiteral("import"))
+ else if (aLink.EqualsLiteral("import") && nsStyleLinkElement::IsImportEnabled())
return nsStyleLinkElement::eHTMLIMPORT;
else
return 0;
}
uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes)
{
uint32_t linkMask = 0;
--- a/content/base/src/nsStyleLinkElement.h
+++ b/content/base/src/nsStyleLinkElement.h
@@ -59,16 +59,18 @@ public:
eNEXT = 0x00000008,
eALTERNATE = 0x00000010,
eHTMLIMPORT = 0x00000020
};
// The return value is a bitwise or of 0 or more RelValues
static uint32_t ParseLinkTypes(const nsAString& aTypes);
+ static bool IsImportEnabled();
+
void UpdateStyleSheetInternal()
{
UpdateStyleSheetInternal(nullptr, nullptr);
}
protected:
/**
* @param aOldDocument should be non-null only if we're updating because we
* removed the node from the document.
--- a/content/html/content/src/HTMLLinkElement.cpp
+++ b/content/html/content/src/HTMLLinkElement.cpp
@@ -284,17 +284,17 @@ HTMLLinkElement::UpdateImport()
}
nsCOMPtr<nsIURI> uri = GetHrefURI();
if (!uri) {
mImportLoader = nullptr;
return;
}
- if (!Preferences::GetBool("dom.webcomponents.enabled")) {
+ if (!nsStyleLinkElement::IsImportEnabled()) {
// For now imports are hidden behind a pref...
return;
}
nsRefPtr<ImportManager> manager = doc->ImportManager();
MOZ_ASSERT(manager, "ImportManager should be created lazily when needed");
{