зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1477432 - Part 11: Update CustomElementRegistry to not use nsIJSID, r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D9733
This commit is contained in:
Родитель
589d2a7b6f
Коммит
2f7bbe21e3
|
@ -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<JSObject*> customInterface(RootingCx());
|
||||
|
||||
nsCOMPtr<nsIJSID> iid = nsJSID::NewID(aIID);
|
||||
func->Call(aElement, iid, &customInterface);
|
||||
JS::Rooted<JSObject*> funcGlobal(RootingCx(), func->CallbackGlobalOrNull());
|
||||
if (customInterface && funcGlobal) {
|
||||
AutoJSAPI jsapi;
|
||||
if (jsapi.Init(funcGlobal)) {
|
||||
nsIXPConnect *xpConnect = nsContentUtils::XPConnect();
|
||||
JSContext* cx = jsapi.cx();
|
||||
|
||||
nsCOMPtr<nsISupports> 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<nsISupports> 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();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------
|
||||
|
|
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче