diff --git a/dom/base/CustomElementRegistry.cpp b/dom/base/CustomElementRegistry.cpp index af04f3b31831..69311a72a2cd 100644 --- a/dom/base/CustomElementRegistry.cpp +++ b/dom/base/CustomElementRegistry.cpp @@ -1253,37 +1253,51 @@ CustomElementRegistry::CallGetCustomInterface(Element* aElement, { MOZ_ASSERT(aElement); - if (nsContentUtils::IsChromeDoc(aElement->OwnerDoc())) { - CustomElementDefinition* definition = aElement->GetCustomElementDefinition(); - if (definition && definition->mCallbacks && - definition->mCallbacks->mGetCustomInterfaceCallback.WasPassed() && - definition->mLocalName == aElement->NodeInfo()->NameAtom()) { - - LifecycleGetCustomInterfaceCallback* func = - definition->mCallbacks->mGetCustomInterfaceCallback.Value(); - JS::Rooted customInterface(RootingCx()); - - nsCOMPtr iid = nsJSID::NewID(aIID); - func->Call(aElement, iid, &customInterface); - JS::Rooted funcGlobal(RootingCx(), func->CallbackGlobalOrNull()); - if (customInterface && funcGlobal) { - AutoJSAPI jsapi; - if (jsapi.Init(funcGlobal)) { - nsIXPConnect *xpConnect = nsContentUtils::XPConnect(); - JSContext* cx = jsapi.cx(); - - nsCOMPtr wrapper; - nsresult rv = xpConnect->WrapJSAggregatedToNative(aElement, cx, customInterface, - aIID, getter_AddRefs(wrapper)); - if (NS_SUCCEEDED(rv)) { - return wrapper.forget(); - } - } - } - } + if (!nsContentUtils::IsChromeDoc(aElement->OwnerDoc())) { + return nullptr; } - return nullptr; + // Try to get our GetCustomInterfaceCallback callback. + CustomElementDefinition* definition = aElement->GetCustomElementDefinition(); + if (!definition || !definition->mCallbacks || + !definition->mCallbacks->mGetCustomInterfaceCallback.WasPassed() || + (definition->mLocalName != aElement->NodeInfo()->NameAtom())) { + return nullptr; + } + LifecycleGetCustomInterfaceCallback* func = + definition->mCallbacks->mGetCustomInterfaceCallback.Value(); + + // Initialize a AutoJSAPI to enter the compartment of the callback. + AutoJSAPI jsapi; + JS::RootedObject funcGlobal(RootingCx(), func->CallbackGlobalOrNull()); + if (!funcGlobal || !jsapi.Init(funcGlobal)) { + return nullptr; + } + + // Grab our JSContext. + JSContext* cx = jsapi.cx(); + + // Convert our IID to a JSValue to call our callback. + JS::RootedValue jsiid(cx); + if (!xpc::ID2JSValue(cx, aIID, &jsiid)) { + return nullptr; + } + + JS::RootedObject customInterface(cx); + func->Call(aElement, jsiid, &customInterface); + if (!customInterface) { + return nullptr; + } + + // Wrap our JSObject into a nsISupports through XPConnect + nsCOMPtr wrapper; + nsresult rv = nsContentUtils::XPConnect()->WrapJSAggregatedToNative( + aElement, cx, customInterface, aIID, getter_AddRefs(wrapper)); + if (NS_WARN_IF(NS_FAILED(rv))) { + return nullptr; + } + + return wrapper.forget(); } //----------------------------------------------------- diff --git a/dom/webidl/WebComponents.webidl b/dom/webidl/WebComponents.webidl index 23343fd8d932..cc254c41d14c 100644 --- a/dom/webidl/WebComponents.webidl +++ b/dom/webidl/WebComponents.webidl @@ -10,8 +10,6 @@ * liability, trademark and document use rules apply. */ -interface IID; - callback LifecycleConnectedCallback = void(); callback LifecycleDisconnectedCallback = void(); callback LifecycleAdoptedCallback = void(Document? oldDocument, @@ -20,7 +18,7 @@ callback LifecycleAttributeChangedCallback = void(DOMString attrName, DOMString? oldValue, DOMString? newValue, DOMString? namespaceURI); -callback LifecycleGetCustomInterfaceCallback = object?(IID iid); +callback LifecycleGetCustomInterfaceCallback = object?(any iid); dictionary LifecycleCallbacks { LifecycleConnectedCallback connectedCallback;