summaryrefslogtreecommitdiff
path: root/dom/base
diff options
context:
space:
mode:
authorMatt A. Tobin <email@mattatobin.com>2020-04-17 07:43:40 -0400
committerMatt A. Tobin <email@mattatobin.com>2020-04-17 07:43:40 -0400
commit80c024779929d44397a8c03d2fa7808f97f2c21a (patch)
treee961240621bd07d87e8a45e3006da7c02c890306 /dom/base
parent6d76ab9b6c19d0829c343e1bc3cd7865221d64ba (diff)
downloaduxp-80c024779929d44397a8c03d2fa7808f97f2c21a.tar.gz
Issue #1375 - Fix IsWebComponentsEnabled checks
Diffstat (limited to 'dom/base')
-rw-r--r--dom/base/nsDocument.cpp76
-rw-r--r--dom/base/nsDocument.h16
2 files changed, 28 insertions, 64 deletions
diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp
index 745d170f18..7b280a188d 100644
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -2242,6 +2242,29 @@ WarnIfSandboxIneffective(nsIDocShell* aDocShell,
}
}
+bool
+nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject)
+{
+ if (!nsContentUtils::IsWebComponentsEnabled()) {
+ return false;
+ }
+
+ JS::Rooted<JSObject*> obj(aCx, aObject);
+
+ JSAutoCompartment ac(aCx, obj);
+ JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, obj));
+ nsCOMPtr<nsPIDOMWindowInner> window =
+ do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global));
+
+ nsIDocument* doc = window ? window->GetExtantDoc() : nullptr;
+ if (doc && doc->IsStyledByServo()) {
+ NS_WARNING("stylo: Web Components not supported yet");
+ return false;
+ }
+
+ return true;
+}
+
nsresult
nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
nsILoadGroup* aLoadGroup,
@@ -5582,64 +5605,11 @@ nsIDocument::CreateAttributeNS(const nsAString& aNamespaceURI,
}
bool
-nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject)
-{
- JS::Rooted<JSObject*> obj(aCx, aObject);
-
- if (nsContentUtils::IsWebComponentsEnabled()) {
- return true;
- }
-
- // Check for the webcomponents permission. See Bug 1181555.
- JSAutoCompartment ac(aCx, obj);
- JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, obj));
- nsCOMPtr<nsPIDOMWindowInner> window =
- do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global));
-
- return IsWebComponentsEnabled(window);
-}
-
-bool
nsDocument::IsWebComponentsEnabled(const nsINode* aNode)
{
return aNode->OwnerDoc()->IsWebComponentsEnabled();
}
-bool
-nsDocument::IsWebComponentsEnabled(dom::NodeInfo* aNodeInfo)
-{
- if (nsContentUtils::IsWebComponentsEnabled()) {
- return true;
- }
-
- nsIDocument* doc = aNodeInfo->GetDocument();
- // Use GetScopeObject() here so that data documents work the same way as the
- // main document they're associated with.
- nsCOMPtr<nsPIDOMWindowInner> window =
- do_QueryInterface(doc->GetScopeObject());
- return IsWebComponentsEnabled(window);
-}
-
-bool
-nsDocument::IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow)
-{
- if (aWindow) {
- nsresult rv;
- nsCOMPtr<nsIPermissionManager> permMgr =
- do_GetService(NS_PERMISSIONMANAGER_CONTRACTID, &rv);
- NS_ENSURE_SUCCESS(rv, false);
-
- uint32_t perm;
- rv = permMgr->TestPermissionFromWindow(
- aWindow, "moz-extremely-unstable-and-will-change-webcomponents", &perm);
- NS_ENSURE_SUCCESS(rv, false);
-
- return perm == nsIPermissionManager::ALLOW_ACTION;
- }
-
- return false;
-}
-
NS_IMETHODIMP
nsDocument::GetElementsByTagName(const nsAString& aTagname,
nsIDOMNodeList** aReturn)
diff --git a/dom/base/nsDocument.h b/dom/base/nsDocument.h
index 4ab2858408..6520d905d1 100644
--- a/dom/base/nsDocument.h
+++ b/dom/base/nsDocument.h
@@ -755,6 +755,11 @@ public:
virtual void NotifyLayerManagerRecreated() override;
+ // Check whether web components are enabled for the global of aObject.
+ static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject);
+ // Check whether web components are enabled for the document this node belongs
+ // to.
+ static bool IsWebComponentsEnabled(const nsINode* aNode);
private:
void AddOnDemandBuiltInUASheet(mozilla::StyleSheet* aSheet);
nsRadioGroupStruct* GetRadioGroupInternal(const nsAString& aName) const;
@@ -1341,17 +1346,6 @@ protected:
nsWeakPtr mFullscreenRoot;
public:
- // Check whether web components are enabled for the global of aObject.
- static bool IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject);
- // Check whether web components are enabled for the document this node belongs
- // to.
- static bool IsWebComponentsEnabled(const nsINode* aNode);
- // Check whether web components are enabled for the global of the document
- // this nodeinfo comes from.
- static bool IsWebComponentsEnabled(mozilla::dom::NodeInfo* aNodeInfo);
- // Check whether web components are enabled for the given window.
- static bool IsWebComponentsEnabled(nsPIDOMWindowInner* aWindow);
-
RefPtr<mozilla::EventListenerManager> mListenerManager;
RefPtr<nsDOMStyleSheetSetList> mStyleSheetSetList;
RefPtr<nsScriptLoader> mScriptLoader;