Commit 5d01e87e authored by Kevin McNee's avatar Kevin McNee Committed by Commit Bot

Define guest view custom elements synchronously

Previously, we've had to wait for readystatechange before defining
the guest view custom elements because
1) there were circular dependencies that would cause errors if we
tried to perform the definition immediately, and
2) the Custom Elements V0 registration context was scoped to the
document rather than the window, so if we defined the elements
while the document was still on about:blank, the definition would
be available on about:blank, but not for the extension.

Now that the circular dependencies are fixed and guest view is
migrated to Custom Elements V1 (whose registration context is
scoped to the window), it is no longer necessary to wait for
readystatechange.

We now perform the definition immediately.

Bug: 810012
Change-Id: Ib5e8ba6f4e302eaae56c5566765521d64b1a0e15
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1278287
Commit-Queue: Kevin McNee <mcnee@chromium.org>
Reviewed-by: default avatarJames MacLean <wjmaclean@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700425}
parent 2aca508a
...@@ -15,20 +15,11 @@ var GuestViewInternalNatives = requireNative('guest_view_internal'); ...@@ -15,20 +15,11 @@ var GuestViewInternalNatives = requireNative('guest_view_internal');
var IdGenerator = requireNative('id_generator'); var IdGenerator = requireNative('id_generator');
var logging = requireNative('logging'); var logging = requireNative('logging');
// Registers the browserplugin and guestview as custom elements once the // Registers the browserplugin and guestview as custom elements.
// document has loaded.
// |containerElementType| is a GuestViewContainerElement (e.g. WebViewElement) // |containerElementType| is a GuestViewContainerElement (e.g. WebViewElement)
function registerElement(elementName, containerElementType) { function registerElement(elementName, containerElementType) {
var useCapture = true; registerInternalElement($String.toLowerCase(elementName));
window.addEventListener('readystatechange', function listener(event) { registerGuestViewElement(elementName, containerElementType);
if (document.readyState == 'loading')
return;
registerInternalElement($String.toLowerCase(elementName));
registerGuestViewElement(elementName, containerElementType);
$EventTarget.removeEventListener(window, event.type, listener, useCapture);
}, useCapture);
} }
// Registers the browser plugin <object> custom element. |viewType| is the // Registers the browser plugin <object> custom element. |viewType| is the
......
...@@ -40,19 +40,11 @@ function registerGuestViewElement(viewType) { ...@@ -40,19 +40,11 @@ function registerGuestViewElement(viewType) {
}); });
} }
var useCapture = true; for (var viewType of VIEW_TYPES) {
window.addEventListener('readystatechange', function listener(event) { // Register the error-providing custom element only for those view types
if (document.readyState == 'loading') // that have not already been registered. Since this module is always loaded
return; // last, all the view types that are available (i.e. have the proper
// permissions) will have already been registered on |window|.
for (var viewType of VIEW_TYPES) { if (!$Object.hasOwnProperty(window, viewType))
// Register the error-providing custom element only for those view types registerGuestViewElement(viewType);
// that have not already been registered. Since this module is always loaded }
// last, all the view types that are available (i.e. have the proper
// permissions) will have already been registered on |window|.
if (!$Object.hasOwnProperty(window, viewType))
registerGuestViewElement(viewType);
}
$EventTarget.removeEventListener(window, event.type, listener, useCapture);
}, useCapture);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment