{"action":"created","comment":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/79069022","id":79069022,"diff_hunk":"@@ -0,0 +1,171 @@\n+/**\n+ * Copyright 2016 The AMP HTML Authors. All Rights Reserved.\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *      http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS-IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+import {createElementWithAttributes} from './dom';\n+import {extensionsFor} from './extensions';\n+import {getTopWindow} from './service';\n+import {loadPromise} from './event-helper';\n+import {resourcesForDoc} from './resources';\n+\n+\n+/**\n+ * Parameters used to create the new \"friendly iframe\" embed.\n+ * - html: The complete content of an AMP embed, which is itself an AMP\n+ *   document. Can include whatever is normally allowed in an AMP document,\n+ *   except for AMP `<script>` declarations. Those should be passed as an\n+ *   array of `extensionIds`.\n+ * - extensionsIds: An optional array of AMP extension IDs used in this embed.\n+ * - fonts: An optional array of fonts used in this embed.\n+ *\n+ * @typedef {{\n+ *   url: string,\n+ *   html: string,\n+ *   extensionIds: (?Array<string>|undefined),\n+ *   fonts: (?Array<string>|undefined),\n+ * }}\n+ */\n+export let FriendlyIframeSpec;\n+\n+\n+/**\n+ * @type {boolean|undefined}\n+ * @visiblefortesting\n+ */\n+let srcdocSupported;\n+\n+/**\n+ * @param {boolean|undefined} val\n+ * @visiblefortesting\n+ */\n+export function setSrcdocSupportedForTesting(val) {\n+  srcdocSupported = val;\n+}\n+\n+/**\n+ * Returns `true` if the Friendly Iframes are supported.\n+ * @return {boolean}\n+ */\n+function isSrcdocSupported() {\n+  if (srcdocSupported === undefined) {\n+    srcdocSupported = 'srcdoc' in HTMLIFrameElement.prototype;\n+  }\n+  return srcdocSupported;\n+}\n+\n+\n+/**\n+ * Creates the requested \"friendly iframe\" embed. Returns the promise that\n+ * will be resolved as soon as the embed is available. The actual\n+ * initialization of the embed will start as soon as the `iframe` is added\n+ * to the DOM.\n+ * @param {!HTMLIFrameElement} iframe\n+ * @param {!Element} container\n+ * @param {!FriendlyIframeSpec} spec\n+ * @return {!Promise<FriendlyIframeEmbed>}\n+ */\n+export function installFriendlyIframeEmbed(iframe, container, spec) {\n+  const win = getTopWindow(iframe.ownerDocument.defaultView);\n+  const extensions = extensionsFor(win);\n+\n+  iframe.style.visibility = 'hidden';\n+  iframe.setAttribute('referrerpolicy', 'unsafe-url');\n+\n+  // Pre-load extensions.\n+  if (spec.extensionIds) {\n+    spec.extensionIds.forEach(\n+        extensionId => extensions.loadExtension(extensionId));\n+  }\n+\n+  // Receive the signal when iframe is ready: it's document is formed.\n+  iframe.onload = () => {\n+    // Chrome does not reflect the iframe readystate.\n+    iframe.readyState = 'complete';\n+  };\n+  let readyPromise;\n+  if (isSrcdocSupported()) {\n+    iframe.srcdoc = spec.html;\n+    // TODO(dvoytenko): Look for a way to get a faster call from here.\n+    // Experiments show that the iframe's \"load\" event is consistently 50-100ms\n+    // later than the contentWindow actually available.\n+    readyPromise = loadPromise(iframe);\n+    container.appendChild(iframe);\n+  } else {\n+    iframe.src = 'about:blank';\n+    container.appendChild(iframe);\n+    const childDoc = iframe.contentWindow.document;\n+    childDoc.open();\n+    childDoc.write(spec.html);\n+    childDoc.close();\n+    readyPromise = Promise.resolve();\n+  }\n+  return readyPromise.then(() => {\n+    const childWin = iframe.contentWindow;\n+    const childDoc = childWin.document;\n+\n+    // Add <BASE> tag.\n+    childDoc.head.appendChild(createElementWithAttributes(\n+        childDoc,\n+        'base',\n+        {'href': spec.url}));\n+\n+    // Load fonts.\n+    if (spec.fonts) {\n+      spec.fonts.forEach(font => {\n+        childDoc.head.appendChild(createElementWithAttributes(\n+            childDoc,\n+            'link', {\n+              'href': font,\n+              'rel': 'stylesheet',\n+              'type': 'text/css',\n+            }));\n+      });\n+    }\n+\n+    // Add extensions.\n+    extensionsFor(win).installExtensionsInChildWindow(\n+        childWin, spec.extensionIds || []);\n+    iframe.style.visibility = '';\n+    return new FriendlyIframeEmbed(iframe, spec);\n+  });\n+}\n+\n+\n+/**","path":"src/friendly-iframe-embed.js","position":146,"original_position":146,"commit_id":"026567d2ae6a6038ff84acc44bbf72184d13139c","original_commit_id":"026567d2ae6a6038ff84acc44bbf72184d13139c","user":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"body":"Done","created_at":"2016-09-15T21:45:45Z","updated_at":"2016-09-15T21:45:45Z","html_url":"https://github.com/ampproject/amphtml/pull/4916#discussion_r79069022","pull_request_url":"https://api.github.com/repos/ampproject/amphtml/pulls/4916","_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments/79069022"},"html":{"href":"https://github.com/ampproject/amphtml/pull/4916#discussion_r79069022"},"pull_request":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4916"}}},"pull_request":{"url":"https://api.github.com/repos/ampproject/amphtml/pulls/4916","id":84736429,"html_url":"https://github.com/ampproject/amphtml/pull/4916","diff_url":"https://github.com/ampproject/amphtml/pull/4916.diff","patch_url":"https://github.com/ampproject/amphtml/pull/4916.patch","issue_url":"https://api.github.com/repos/ampproject/amphtml/issues/4916","number":4916,"state":"open","locked":false,"title":"Friendly frames embeds","user":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"body":"Partial for #4915.\r\n\r\nThis outlines major changes for \"friendly frames\" support. It also contains a manual test setup to demonstrate the use of the API. Let's discuss before tests. Some important points:\r\n\r\n1. Boundary traversal rules: who and when is allowed traversal\r\n2. Analytics will have to have some major changes to support friendly frames (although it'd have to have the same for shadow DOM as well)\r\n3. Things like UrlReplacements are still very unclear. Specifically we probably shouldn't allow a blanket access to parent document's URL vars - some scoping is necessary. Likewise, shadow DOM has the same issues most likely.\r\n","created_at":"2016-09-10T00:03:04Z","updated_at":"2016-09-15T21:45:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"077990a2e5e268d9f3ed1a4ae0cc34f260978e28","assignee":{"login":"cramforce","id":89679,"avatar_url":"https://avatars.githubusercontent.com/u/89679?v=3","gravatar_id":"","url":"https://api.github.com/users/cramforce","html_url":"https://github.com/cramforce","followers_url":"https://api.github.com/users/cramforce/followers","following_url":"https://api.github.com/users/cramforce/following{/other_user}","gists_url":"https://api.github.com/users/cramforce/gists{/gist_id}","starred_url":"https://api.github.com/users/cramforce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramforce/subscriptions","organizations_url":"https://api.github.com/users/cramforce/orgs","repos_url":"https://api.github.com/users/cramforce/repos","events_url":"https://api.github.com/users/cramforce/events{/privacy}","received_events_url":"https://api.github.com/users/cramforce/received_events","type":"User","site_admin":false},"assignees":[{"login":"cramforce","id":89679,"avatar_url":"https://avatars.githubusercontent.com/u/89679?v=3","gravatar_id":"","url":"https://api.github.com/users/cramforce","html_url":"https://github.com/cramforce","followers_url":"https://api.github.com/users/cramforce/followers","following_url":"https://api.github.com/users/cramforce/following{/other_user}","gists_url":"https://api.github.com/users/cramforce/gists{/gist_id}","starred_url":"https://api.github.com/users/cramforce/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cramforce/subscriptions","organizations_url":"https://api.github.com/users/cramforce/orgs","repos_url":"https://api.github.com/users/cramforce/repos","events_url":"https://api.github.com/users/cramforce/events{/privacy}","received_events_url":"https://api.github.com/users/cramforce/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/ampproject/amphtml/pulls/4916/commits","review_comments_url":"https://api.github.com/repos/ampproject/amphtml/pulls/4916/comments","review_comment_url":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ampproject/amphtml/issues/4916/comments","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/026567d2ae6a6038ff84acc44bbf72184d13139c","head":{"label":"dvoytenko:ife1","ref":"ife1","sha":"026567d2ae6a6038ff84acc44bbf72184d13139c","user":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"repo":{"id":43817704,"name":"amphtml","full_name":"dvoytenko/amphtml","owner":{"login":"dvoytenko","id":726049,"avatar_url":"https://avatars.githubusercontent.com/u/726049?v=3","gravatar_id":"","url":"https://api.github.com/users/dvoytenko","html_url":"https://github.com/dvoytenko","followers_url":"https://api.github.com/users/dvoytenko/followers","following_url":"https://api.github.com/users/dvoytenko/following{/other_user}","gists_url":"https://api.github.com/users/dvoytenko/gists{/gist_id}","starred_url":"https://api.github.com/users/dvoytenko/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dvoytenko/subscriptions","organizations_url":"https://api.github.com/users/dvoytenko/orgs","repos_url":"https://api.github.com/users/dvoytenko/repos","events_url":"https://api.github.com/users/dvoytenko/events{/privacy}","received_events_url":"https://api.github.com/users/dvoytenko/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dvoytenko/amphtml","description":"","fork":true,"url":"https://api.github.com/repos/dvoytenko/amphtml","forks_url":"https://api.github.com/repos/dvoytenko/amphtml/forks","keys_url":"https://api.github.com/repos/dvoytenko/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dvoytenko/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dvoytenko/amphtml/teams","hooks_url":"https://api.github.com/repos/dvoytenko/amphtml/hooks","issue_events_url":"https://api.github.com/repos/dvoytenko/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/dvoytenko/amphtml/events","assignees_url":"https://api.github.com/repos/dvoytenko/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/dvoytenko/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/dvoytenko/amphtml/tags","blobs_url":"https://api.github.com/repos/dvoytenko/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dvoytenko/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dvoytenko/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/dvoytenko/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dvoytenko/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/dvoytenko/amphtml/languages","stargazers_url":"https://api.github.com/repos/dvoytenko/amphtml/stargazers","contributors_url":"https://api.github.com/repos/dvoytenko/amphtml/contributors","subscribers_url":"https://api.github.com/repos/dvoytenko/amphtml/subscribers","subscription_url":"https://api.github.com/repos/dvoytenko/amphtml/subscription","commits_url":"https://api.github.com/repos/dvoytenko/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/dvoytenko/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/dvoytenko/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/dvoytenko/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/dvoytenko/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/dvoytenko/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dvoytenko/amphtml/merges","archive_url":"https://api.github.com/repos/dvoytenko/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dvoytenko/amphtml/downloads","issues_url":"https://api.github.com/repos/dvoytenko/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/dvoytenko/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/dvoytenko/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/dvoytenko/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dvoytenko/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/dvoytenko/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/dvoytenko/amphtml/deployments","created_at":"2015-10-07T13:30:20Z","updated_at":"2016-01-11T18:44:41Z","pushed_at":"2016-09-15T20:54:53Z","git_url":"git://github.com/dvoytenko/amphtml.git","ssh_url":"git@github.com:dvoytenko/amphtml.git","clone_url":"https://github.com/dvoytenko/amphtml.git","svn_url":"https://github.com/dvoytenko/amphtml","homepage":"","size":176204,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ampproject:master","ref":"master","sha":"7852dc82bb0c889a3f9c34bd1d7e5c67cd458507","user":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"repo":{"id":41766002,"name":"amphtml","full_name":"ampproject/amphtml","owner":{"login":"ampproject","id":14114390,"avatar_url":"https://avatars.githubusercontent.com/u/14114390?v=3","gravatar_id":"","url":"https://api.github.com/users/ampproject","html_url":"https://github.com/ampproject","followers_url":"https://api.github.com/users/ampproject/followers","following_url":"https://api.github.com/users/ampproject/following{/other_user}","gists_url":"https://api.github.com/users/ampproject/gists{/gist_id}","starred_url":"https://api.github.com/users/ampproject/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ampproject/subscriptions","organizations_url":"https://api.github.com/users/ampproject/orgs","repos_url":"https://api.github.com/users/ampproject/repos","events_url":"https://api.github.com/users/ampproject/events{/privacy}","received_events_url":"https://api.github.com/users/ampproject/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ampproject/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":false,"url":"https://api.github.com/repos/ampproject/amphtml","forks_url":"https://api.github.com/repos/ampproject/amphtml/forks","keys_url":"https://api.github.com/repos/ampproject/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ampproject/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ampproject/amphtml/teams","hooks_url":"https://api.github.com/repos/ampproject/amphtml/hooks","issue_events_url":"https://api.github.com/repos/ampproject/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/ampproject/amphtml/events","assignees_url":"https://api.github.com/repos/ampproject/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/ampproject/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/ampproject/amphtml/tags","blobs_url":"https://api.github.com/repos/ampproject/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ampproject/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ampproject/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/ampproject/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ampproject/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/ampproject/amphtml/languages","stargazers_url":"https://api.github.com/repos/ampproject/amphtml/stargazers","contributors_url":"https://api.github.com/repos/ampproject/amphtml/contributors","subscribers_url":"https://api.github.com/repos/ampproject/amphtml/subscribers","subscription_url":"https://api.github.com/repos/ampproject/amphtml/subscription","commits_url":"https://api.github.com/repos/ampproject/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/ampproject/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/ampproject/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/ampproject/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/ampproject/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/ampproject/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ampproject/amphtml/merges","archive_url":"https://api.github.com/repos/ampproject/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ampproject/amphtml/downloads","issues_url":"https://api.github.com/repos/ampproject/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/ampproject/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/ampproject/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/ampproject/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ampproject/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/ampproject/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/ampproject/amphtml/deployments","created_at":"2015-09-01T22:10:53Z","updated_at":"2016-09-15T19:59:41Z","pushed_at":"2016-09-15T21:42:16Z","git_url":"git://github.com/ampproject/amphtml.git","ssh_url":"git@github.com:ampproject/amphtml.git","clone_url":"https://github.com/ampproject/amphtml.git","svn_url":"https://github.com/ampproject/amphtml","homepage":"https://ampproject.org","size":201262,"stargazers_count":8470,"watchers_count":8470,"language":"JavaScript","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1252,"mirror_url":null,"open_issues_count":749,"forks":1252,"open_issues":749,"watchers":8470,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4916"},"html":{"href":"https://github.com/ampproject/amphtml/pull/4916"},"issue":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/4916"},"comments":{"href":"https://api.github.com/repos/ampproject/amphtml/issues/4916/comments"},"review_comments":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4916/comments"},"review_comment":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ampproject/amphtml/pulls/4916/commits"},"statuses":{"href":"https://api.github.com/repos/ampproject/amphtml/statuses/026567d2ae6a6038ff84acc44bbf72184d13139c"}}}}
{"actor":{"display_login":"dvoytenko"}}