src/friendly-iframe-embed.js
/**
 * Creates the requested "friendly iframe" embed. Returns the promise that
 * will be resolved as soon as the embed is available. The actual
 * initialization of the embed will start as soon as the `iframe` is added
 * to the DOM.
 * @param {!HTMLIFrameElement} iframe
 * @param {!Element} container
 * @param {!FriendlyIframeSpec} spec
 * @param {function(!Window)=} opt_preinstallCallback
 * @return {!Promise<!FriendlyIframeEmbed>}
 */
Creates the requested "friendly iframe" embed. Returns the promise that
will be resolved as soon as the embed is available. The actual
initialization of the embed will start as soon as the `iframe` is added
to the DOM.
Creates the requested " friendly iframe " embed . Returns the promise that will be resolved as soon as the embed is available . The actual initialization of the embed will start as soon as the ` iframe ` is added to the DOM .
function installFriendlyIframeEmbed(iframe, container, spec,
    opt_preinstallCallback) {
  const win = getTopWindow(iframe.ownerDocument.defaultView);
  const extensions = Services.extensionsFor(win);
  setStyle(iframe, 'visibility', 'hidden');
  iframe.setAttribute('referrerpolicy', 'unsafe-url');
  if (spec.extensionIds) {
    spec.extensionIds.forEach(
        extensionId => extensions.preloadExtension(extensionId));
  }
  const html = mergeHtml(spec);
  iframe.onload = () => {
    iframe.readyState = 'complete';
  };
  let loadedPromise;
  if (isSrcdocSupported()) {
    iframe.srcdoc = html;
    loadedPromise = loadPromise(iframe);
    container.appendChild(iframe);
  } else {
    iframe.src = 'about:blank';
    container.appendChild(iframe);
    const childDoc = iframe.contentWindow.document;
    childDoc.open();
    childDoc.write(html);
    loadedPromise = loadPromise(iframe.contentWindow);
    childDoc.close();
  }
  let readyPromise;
  if (isIframeReady(iframe)) {
    readyPromise = Promise.resolve();
  } else {
    readyPromise = new Promise(resolve => {
      const interval = win.setInterval(() => {
        if (isIframeReady(iframe)) {
          resolve();
          win.clearInterval(interval);
        }
      },  5);
      loadedPromise.catch(error => {
        rethrowAsync(error);
      }).then(() => {
        resolve();
        win.clearInterval(interval);
      });
    });
  }
  return readyPromise.then(() => {
    const embed = new FriendlyIframeEmbed(iframe, spec, loadedPromise);
    iframe[EMBED_PROP] = embed;
    const childWin =  (iframe.contentWindow);
    extensions.installExtensionsInChildWindow(
        childWin, spec.extensionIds || [], opt_preinstallCallback);
    embed.startRender_();
    return embed;
  });
}
function installFriendlyIframeEmbed ( iframe , container , spec , opt_preinstallCallback ) { const win = getTopWindow ( iframe . ownerDocument . defaultView ) ; const extensions = Services . extensionsFor ( win ) ; setStyle ( iframe , 'visibility' , 'hidden' ) ; iframe . setAttribute ( 'referrerpolicy' , 'unsafe-url' ) ; if ( spec . extensionIds ) { spec . extensionIds . forEach ( extensionId => extensions . preloadExtension ( extensionId ) ) ; } const html = mergeHtml ( spec ) ; iframe . onload = ( ) => { iframe . readyState = 'complete' ; } ; let loadedPromise ; if ( isSrcdocSupported ( ) ) { iframe . srcdoc = html ; loadedPromise = loadPromise ( iframe ) ; container . appendChild ( iframe ) ; } else { iframe . src = 'about:blank' ; container . appendChild ( iframe ) ; const childDoc = iframe . contentWindow . document ; childDoc . open ( ) ; childDoc . write ( html ) ; loadedPromise = loadPromise ( iframe . contentWindow ) ; childDoc . close ( ) ; } let readyPromise ; if ( isIframeReady ( iframe ) ) { readyPromise = Promise . resolve ( ) ; } else { readyPromise = new Promise ( resolve => { const interval = win . setInterval ( ( ) => { if ( isIframeReady ( iframe ) ) { resolve ( ) ; win . clearInterval ( interval ) ; } } , 5 ) ; loadedPromise . catch ( error => { rethrowAsync ( error ) ; } ) . then ( ( ) => { resolve ( ) ; win . clearInterval ( interval ) ; } ) ; } ) ; } return readyPromise . then ( ( ) => { const embed = new FriendlyIframeEmbed ( iframe , spec , loadedPromise ) ; iframe [ EMBED_PROP ] = embed ; const childWin = ( iframe . contentWindow ) ; extensions . installExtensionsInChildWindow ( childWin , spec . extensionIds || [ ] , opt_preinstallCallback ) ; embed . startRender_ ( ) ; return embed ; } ) ; }
Creates the requested "friendly iframe" embed.
Creates the requested " friendly iframe " embed .
/** @const {!Window} */ /** @const {!./service/extensions-impl.Extensions} */ // Pre-load extensions. // Receive the signal when iframe is ready: it's document is formed. // Chrome does not reflect the iframe readystate. // With document.write, `iframe.onload` arrives almost immediately, thus // we need to wait for child's `window.onload`. // Wait for document ready signal. // This is complicated due to crbug.com/649201 on Chrome and a similar issue // on Safari where newly created document's `readyState` immediately equals // `complete`, even though the document itself is not yet available. There's // no other reliable signal for `readyState` in a child window and thus // we have to fallback to polling. /** @const {number} */ /* milliseconds */ // For safety, make sure we definitely stop polling when child doc is // loaded. /** @type {!Window} */ // Add extensions. // Ready to be shown.