Bug 1443923 - part5: Emit chrome-only event customelementdefined for DevTools;r=masayuki
MozReview-Commit-ID: GCFhhpVj5VS
--- a/dom/base/CustomElementRegistry.cpp
+++ b/dom/base/CustomElementRegistry.cpp
@@ -1,22 +1,24 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/CustomElementRegistry.h"
+#include "mozilla/AsyncEventDispatcher.h"
#include "mozilla/CycleCollectedJSContext.h"
#include "mozilla/dom/CustomElementRegistryBinding.h"
#include "mozilla/dom/HTMLElementBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/WebComponentsBinding.h"
#include "mozilla/dom/DocGroup.h"
+#include "mozilla/dom/CustomEvent.h"
#include "nsHTMLTags.h"
#include "jsapi.h"
#include "xpcprivate.h"
#include "nsGlobalWindow.h"
namespace mozilla {
namespace dom {
@@ -961,16 +963,37 @@ CustomElementRegistry::Define(JSContext*
* when-defined promise map.
*/
RefPtr<Promise> promise;
mWhenDefinedPromiseMap.Remove(nameAtom, getter_AddRefs(promise));
if (promise) {
promise->MaybeResolveWithUndefined();
}
+ // Dispatch a "customelementdefined" event for DevTools.
+ {
+ JSString* nameJsStr = JS_NewUCStringCopyN(aCx,
+ aName.BeginReading(),
+ aName.Length());
+
+ JS::Rooted<JS::Value> detail(aCx, JS::StringValue(nameJsStr));
+ RefPtr<CustomEvent> event = NS_NewDOMCustomEvent(doc, nullptr, nullptr);
+ event->InitCustomEvent(aCx,
+ NS_LITERAL_STRING("customelementdefined"),
+ /* CanBubble */ true,
+ /* Cancelable */ true,
+ detail);
+ event->SetTrusted(true);
+
+ AsyncEventDispatcher* dispatcher = new AsyncEventDispatcher(doc, event);
+ dispatcher->mOnlyChromeDispatch = ChromeOnlyDispatch::eYes;
+
+ dispatcher->PostDOMEvent();
+ }
+
/**
* Clean-up mElementCreationCallbacks (if it exists)
*/
mElementCreationCallbacks.Remove(nameAtom);
}
void