Bug 1000199 - Enable web components for certified apps. r=gabor,smaug

This commit is contained in:
William Chen 2014-07-07 19:02:03 -07:00
parent 8d65effbf6
commit 4bebd4307b
12 changed files with 44 additions and 27 deletions

View File

@ -665,7 +665,8 @@ nsContentSink::ProcessLink(const nsSubstring& aAnchor, const nsSubstring& aHref,
const nsSubstring& aRel, const nsSubstring& aTitle,
const nsSubstring& aType, const nsSubstring& aMedia)
{
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aRel);
uint32_t linkTypes =
nsStyleLinkElement::ParseLinkTypes(aRel, mDocument->NodePrincipal());
// The link relation may apply to a different resource, specified
// in the anchor parameter. For the link relations supported so far,

View File

@ -5445,7 +5445,7 @@ nsDocument::CustomElementConstructor(JSContext* aCx, unsigned aArgc, JS::Value*
}
bool
nsDocument::IsRegisterElementEnabled(JSContext* aCx, JSObject* aObject)
nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject)
{
JS::Rooted<JSObject*> obj(aCx, aObject);
return Preferences::GetBool("dom.webcomponents.enabled") ||

View File

@ -1479,7 +1479,7 @@ public:
uint32_t aNamespaceID,
mozilla::ErrorResult& rv);
static bool IsRegisterElementEnabled(JSContext* aCx, JSObject* aObject);
static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject);
// The "registry" from the web components spec.
nsRefPtr<mozilla::dom::Registry> mRegistry;

View File

@ -120,21 +120,30 @@ nsStyleLinkElement::SetLineNumber(uint32_t aLineNumber)
}
/* static */ bool
nsStyleLinkElement::IsImportEnabled()
nsStyleLinkElement::IsImportEnabled(nsIPrincipal* aPrincipal)
{
static bool sAdded = false;
static bool sImportEnabled;
static bool sWebComponentsEnabled;
if (!sAdded) {
// This part runs only once because of the static flag.
Preferences::AddBoolVarCache(&sImportEnabled,
Preferences::AddBoolVarCache(&sWebComponentsEnabled,
"dom.webcomponents.enabled",
false);
sAdded = true;
}
return sImportEnabled;
if (sWebComponentsEnabled) {
return true;
}
// If the web components pref is not enabled, check
// if we are in a certified app because imports is enabled
// for certified apps.
return aPrincipal &&
aPrincipal->GetAppStatus() == nsIPrincipal::APP_STATUS_CERTIFIED;
}
static uint32_t ToLinkMask(const nsAString& aLink)
static uint32_t ToLinkMask(const nsAString& aLink, nsIPrincipal* aPrincipal)
{
if (aLink.EqualsLiteral("prefetch"))
return nsStyleLinkElement::ePREFETCH;
@ -146,13 +155,14 @@ static uint32_t ToLinkMask(const nsAString& aLink)
return nsStyleLinkElement::eNEXT;
else if (aLink.EqualsLiteral("alternate"))
return nsStyleLinkElement::eALTERNATE;
else if (aLink.EqualsLiteral("import") && nsStyleLinkElement::IsImportEnabled())
else if (aLink.EqualsLiteral("import") && aPrincipal &&
nsStyleLinkElement::IsImportEnabled(aPrincipal))
return nsStyleLinkElement::eHTMLIMPORT;
else
return 0;
}
uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes)
uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes, nsIPrincipal* aPrincipal)
{
uint32_t linkMask = 0;
nsAString::const_iterator start, done;
@ -169,7 +179,7 @@ uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes)
if (nsContentUtils::IsHTMLWhitespace(*current)) {
if (inString) {
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
linkMask |= ToLinkMask(subString);
linkMask |= ToLinkMask(subString, aPrincipal);
inString = false;
}
}
@ -183,7 +193,7 @@ uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes)
}
if (inString) {
nsContentUtils::ASCIIToLower(Substring(start, current), subString);
linkMask |= ToLinkMask(subString);
linkMask |= ToLinkMask(subString, aPrincipal);
}
return linkMask;
}

View File

@ -61,10 +61,13 @@ public:
eHTMLIMPORT = 0x00000020
};
// The return value is a bitwise or of 0 or more RelValues
static uint32_t ParseLinkTypes(const nsAString& aTypes);
// 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);
static bool IsImportEnabled();
static bool IsImportEnabled(nsIPrincipal* aPrincipal);
void UpdateStyleSheetInternal()
{

View File

@ -276,7 +276,7 @@ HTMLLinkElement::UpdateImport()
// 2. rel type should be import.
nsAutoString rel;
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel);
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
if (!(linkTypes & eHTMLIMPORT)) {
mImportLoader = nullptr;
return;
@ -288,7 +288,7 @@ HTMLLinkElement::UpdateImport()
return;
}
if (!nsStyleLinkElement::IsImportEnabled()) {
if (!nsStyleLinkElement::IsImportEnabled(NodePrincipal())) {
// For now imports are hidden behind a pref...
return;
}
@ -330,7 +330,8 @@ HTMLLinkElement::SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
aName == nsGkAtoms::type)) {
bool dropSheet = false;
if (aName == nsGkAtoms::rel) {
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue);
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(aValue,
NodePrincipal());
if (GetSheet()) {
dropSheet = !(linkTypes & nsStyleLinkElement::eSTYLESHEET);
} else if (linkTypes & eHTMLIMPORT) {
@ -456,7 +457,7 @@ HTMLLinkElement::GetStyleSheetInfo(nsAString& aTitle,
nsAutoString rel;
GetAttr(kNameSpaceID_None, nsGkAtoms::rel, rel);
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel);
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(rel, NodePrincipal());
// Is it a stylesheet link?
if (!(linkTypes & nsStyleLinkElement::eSTYLESHEET)) {
return;

View File

@ -607,7 +607,8 @@ nsXMLContentSink::CloseElement(nsIContent* aContent)
nsAutoString relVal;
aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal);
if (!relVal.IsEmpty()) {
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(relVal);
uint32_t linkTypes =
nsStyleLinkElement::ParseLinkTypes(relVal, aContent->NodePrincipal());
bool hasPrefetch = linkTypes & nsStyleLinkElement::ePREFETCH;
if (hasPrefetch || (linkTypes & nsStyleLinkElement::eNEXT)) {
nsAutoString hrefVal;

View File

@ -229,7 +229,7 @@ partial interface Document {
//http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/custom/index.html#dfn-document-register
partial interface Document {
[Throws, Func="nsDocument::IsRegisterElementEnabled"]
[Throws, Func="nsDocument::IsWebComponentsEnabled"]
object registerElement(DOMString name, optional ElementRegistrationOptions options);
};

View File

@ -201,11 +201,11 @@ partial interface Element {
// http://w3c.github.io/webcomponents/spec/shadow/#extensions-to-element-interface
partial interface Element {
[Throws,Pref="dom.webcomponents.enabled"]
[Throws,Func="nsDocument::IsWebComponentsEnabled"]
ShadowRoot createShadowRoot();
[Pref="dom.webcomponents.enabled"]
[Func="nsDocument::IsWebComponentsEnabled"]
NodeList getDestinationInsertionPoints();
[Pref="dom.webcomponents.enabled"]
[Func="nsDocument::IsWebComponentsEnabled"]
readonly attribute ShadowRoot? shadowRoot;
};

View File

@ -44,7 +44,7 @@ partial interface HTMLLinkElement {
// http://w3c.github.io/webcomponents/spec/imports/#interface-import
partial interface HTMLLinkElement {
[Pref="dom.webcomponents.enabled"]
[Func="nsDocument::IsWebComponentsEnabled"]
readonly attribute Document? import;
};

View File

@ -10,7 +10,7 @@
* liability, trademark and document use rules apply.
*/
[Pref="dom.webcomponents.enabled"]
[Func="nsDocument::IsWebComponentsEnabled"]
interface ShadowRoot : DocumentFragment
{
Element? getElementById(DOMString elementId);

View File

@ -86,7 +86,8 @@ nsHtml5DocumentBuilder::UpdateStyleSheet(nsIContent* aElement)
nsAutoString relVal;
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::rel, relVal);
if (!relVal.IsEmpty()) {
uint32_t linkTypes = nsStyleLinkElement::ParseLinkTypes(relVal);
uint32_t linkTypes =
nsStyleLinkElement::ParseLinkTypes(relVal, aElement->NodePrincipal());
bool hasPrefetch = linkTypes & nsStyleLinkElement::ePREFETCH;
if (hasPrefetch || (linkTypes & nsStyleLinkElement::eNEXT)) {
nsAutoString hrefVal;