{"action":"created","comment":{"url":"https://api.github.com/repos/google/amphtml/pulls/comments/69817986","id":69817986,"diff_hunk":"@@ -0,0 +1,250 @@\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 {topWindowUrlOrDomain} from './iframe-utils';\n+import {QueryParameter, buildUrl} from './url-builder';\n+import {AmpA4A} from '../../amp-a4a/0.1/amp-a4a';\n+import {makeCorrelator} from '../../../ads/google/correlator';\n+import {\n+  isGoogleAdsA4AValidEnvironment,\n+} from '../../../ads/google/a4a/google-ads-a4a-config';\n+import {getAdCid} from '../../../src/ad-cid';\n+import {documentInfoFor} from '../../../src/document-info';\n+import {timer} from '../../../src/timer';\n+import {viewerFor} from '../../../src/viewer';\n+import {viewportFor} from '../../../src/viewport';\n+\n+/**\n+ * @typedef {{\n+ *   baseUrl: string,\n+ *   requiredQueryParams: !Array<!QueryParameter>,\n+ *   optionalQueryParams: !Array<!QueryParameter>,\n+ * }}\n+ */\n+let GoogleAdRequestDataDef;\n+\n+/** @const {string} */\n+const AMP_SIGNATURE_HEADER = 'X-AmpAdSignature';\n+\n+/** @const {number} */\n+const MAX_URL_LENGTH = 4096;\n+\n+/**\n+ * encodeURIComponent('http://').length\n+ * @const {number}\n+ */\n+const MIN_USEFUL_URL_PARAM_LENGTH = 13;\n+\n+/** @enum {string} */\n+const AmpAdImplementation = {\n+  AMP_AD_XHR_TO_IFRAME: '2',\n+  AMP_AD_XHR_TO_IFRAME_OR_AMP: '3',\n+};\n+\n+export class AmpAdNetworkGoogleAdsImpl extends AmpA4A {\n+\n+  /**\n+   * @param {!Element} element\n+   */\n+  constructor(element) {\n+    super(element);\n+  }\n+\n+  /**\n+   * @param {number} unusedSlotNumber\n+   * @return {!GoogleAdRequestDataDef}\n+   */\n+  getGoogleAdRequestData(unusedSlotNumber) {\n+    throw new Error('getGoogleAdRequestData not implemented!');\n+  }\n+\n+  /** @override */\n+  isValidElement() {\n+    return isGoogleAdsA4AValidEnvironment(this.getWin()) && this.isInAmpAdTag();\n+  }\n+\n+  /** @override */\n+  getAdUrl() {\n+    const startTime = timer.now();\n+    const referrerPromise = viewerFor(this.getWin()).getReferrerUrl();\n+    return getAdCid(this).then(clientId => referrerPromise.then(referrer =>\n+        this.buildAdUrl_(startTime, clientId, referrer)));\n+  }\n+\n+  /** @override */\n+  extractCreativeAndSignature(responseText, responseHeaders) {\n+    const adResponse = {\n+      creativeArrayBuffer: responseText,\n+      signature: null,\n+    };\n+    try {\n+      adResponse['signature'] = responseHeaders.get(AMP_SIGNATURE_HEADER);\n+    } finally {\n+      return Promise.resolve(adResponse);\n+    }\n+  }\n+\n+  /**\n+   * @param {number} startTime\n+   * @param {(string|undefined)} clientId\n+   * @param {string} referrer\n+   * @return {string}\n+   * @private\n+   */\n+  buildAdUrl_(startTime, clientId, referrer) {\n+    const global = this.getWin();\n+    const documentInfo = documentInfoFor(global);\n+    if (!global.gaGlobal) {\n+      // Read by GPT for GA/GPT integration.\n+      global.gaGlobal = {\n+        vid: clientId,\n+        hid: documentInfo.pageViewId,\n+      };\n+    }\n+    const slotNumber = getGoogleAdSlotCounter(global).nextSlotNumber();\n+    const viewport = viewportFor(global);\n+    const slotRect = viewport.getLayoutRect(this.element);\n+    const viewportRect = viewport.getRect();\n+    const iframeDepth = iframeNestingDepth(global);\n+    const requestData = this.getGoogleAdRequestData(slotNumber);\n+    const requiredQueryParams = [\n+      new QueryParameter(\n+          'is_amp',\n+          this.supportsShadowDom() ?\n+              AmpAdImplementation.AMP_AD_XHR_TO_IFRAME_OR_AMP :\n+              AmpAdImplementation.AMP_AD_XHR_TO_IFRAME),\n+      new QueryParameter('amp_v', '$internalRuntimeVersion$'),\n+      new QueryParameter('dt', String(startTime)),\n+      new QueryParameter(\n+          'adk', adKey(slotNumber, slotRect, viewportRect)),\n+      new QueryParameter(\n+          'c', String(makeCorrelator(clientId, documentInfo.pageViewId))),\n+      new QueryParameter('output', 'html'),\n+      new QueryParameter('nhd', String(iframeDepth)),\n+      new QueryParameter(\n+          'eid', this.element.getAttribute('data-experiment-id')),\n+      new QueryParameter('bih', String(viewportRect.height)),","path":"extensions/amp-ad-network-google-ads-impl/0.1/amp-ad-network-google-ads-impl.js","position":139,"original_position":139,"commit_id":"b1133068775d5c81d7271b7a6913a4ad687107ab","original_commit_id":"b1133068775d5c81d7271b7a6913a4ad687107ab","user":{"login":"taymonbeal","id":1991427,"avatar_url":"https://avatars.githubusercontent.com/u/1991427?v=3","gravatar_id":"","url":"https://api.github.com/users/taymonbeal","html_url":"https://github.com/taymonbeal","followers_url":"https://api.github.com/users/taymonbeal/followers","following_url":"https://api.github.com/users/taymonbeal/following{/other_user}","gists_url":"https://api.github.com/users/taymonbeal/gists{/gist_id}","starred_url":"https://api.github.com/users/taymonbeal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taymonbeal/subscriptions","organizations_url":"https://api.github.com/users/taymonbeal/orgs","repos_url":"https://api.github.com/users/taymonbeal/repos","events_url":"https://api.github.com/users/taymonbeal/events{/privacy}","received_events_url":"https://api.github.com/users/taymonbeal/received_events","type":"User","site_admin":false},"body":"Done.","created_at":"2016-07-06T21:48:53Z","updated_at":"2016-07-06T21:48:53Z","html_url":"https://github.com/google/amphtml/pull/7#discussion_r69817986","pull_request_url":"https://api.github.com/repos/google/amphtml/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/google/amphtml/pulls/comments/69817986"},"html":{"href":"https://github.com/google/amphtml/pull/7#discussion_r69817986"},"pull_request":{"href":"https://api.github.com/repos/google/amphtml/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/google/amphtml/pulls/7","id":76471991,"html_url":"https://github.com/google/amphtml/pull/7","diff_url":"https://github.com/google/amphtml/pull/7.diff","patch_url":"https://github.com/google/amphtml/pull/7.patch","issue_url":"https://api.github.com/repos/google/amphtml/issues/7","number":7,"state":"open","locked":false,"title":"A4A for AdSense and DoubleClick","user":{"login":"taymonbeal","id":1991427,"avatar_url":"https://avatars.githubusercontent.com/u/1991427?v=3","gravatar_id":"","url":"https://api.github.com/users/taymonbeal","html_url":"https://github.com/taymonbeal","followers_url":"https://api.github.com/users/taymonbeal/followers","following_url":"https://api.github.com/users/taymonbeal/following{/other_user}","gists_url":"https://api.github.com/users/taymonbeal/gists{/gist_id}","starred_url":"https://api.github.com/users/taymonbeal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taymonbeal/subscriptions","organizations_url":"https://api.github.com/users/taymonbeal/orgs","repos_url":"https://api.github.com/users/taymonbeal/repos","events_url":"https://api.github.com/users/taymonbeal/events{/privacy}","received_events_url":"https://api.github.com/users/taymonbeal/received_events","type":"User","site_admin":false},"body":"For internal review, not yet for external submission. Includes some changes that weren't part of Google Ads A4A due to merge conflicts that need to be resolved.","created_at":"2016-07-06T17:41:22Z","updated_at":"2016-07-06T21:48:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"44ac2ffcf958d03b2f25246a55d94bf30d8bb301","assignee":{"login":"keithwrightbos","id":1766447,"avatar_url":"https://avatars.githubusercontent.com/u/1766447?v=3","gravatar_id":"","url":"https://api.github.com/users/keithwrightbos","html_url":"https://github.com/keithwrightbos","followers_url":"https://api.github.com/users/keithwrightbos/followers","following_url":"https://api.github.com/users/keithwrightbos/following{/other_user}","gists_url":"https://api.github.com/users/keithwrightbos/gists{/gist_id}","starred_url":"https://api.github.com/users/keithwrightbos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithwrightbos/subscriptions","organizations_url":"https://api.github.com/users/keithwrightbos/orgs","repos_url":"https://api.github.com/users/keithwrightbos/repos","events_url":"https://api.github.com/users/keithwrightbos/events{/privacy}","received_events_url":"https://api.github.com/users/keithwrightbos/received_events","type":"User","site_admin":false},"assignees":[{"login":"keithwrightbos","id":1766447,"avatar_url":"https://avatars.githubusercontent.com/u/1766447?v=3","gravatar_id":"","url":"https://api.github.com/users/keithwrightbos","html_url":"https://github.com/keithwrightbos","followers_url":"https://api.github.com/users/keithwrightbos/followers","following_url":"https://api.github.com/users/keithwrightbos/following{/other_user}","gists_url":"https://api.github.com/users/keithwrightbos/gists{/gist_id}","starred_url":"https://api.github.com/users/keithwrightbos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keithwrightbos/subscriptions","organizations_url":"https://api.github.com/users/keithwrightbos/orgs","repos_url":"https://api.github.com/users/keithwrightbos/repos","events_url":"https://api.github.com/users/keithwrightbos/events{/privacy}","received_events_url":"https://api.github.com/users/keithwrightbos/received_events","type":"User","site_admin":false},{"login":"tdrl","id":17705064,"avatar_url":"https://avatars.githubusercontent.com/u/17705064?v=3","gravatar_id":"","url":"https://api.github.com/users/tdrl","html_url":"https://github.com/tdrl","followers_url":"https://api.github.com/users/tdrl/followers","following_url":"https://api.github.com/users/tdrl/following{/other_user}","gists_url":"https://api.github.com/users/tdrl/gists{/gist_id}","starred_url":"https://api.github.com/users/tdrl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tdrl/subscriptions","organizations_url":"https://api.github.com/users/tdrl/orgs","repos_url":"https://api.github.com/users/tdrl/repos","events_url":"https://api.github.com/users/tdrl/events{/privacy}","received_events_url":"https://api.github.com/users/tdrl/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/google/amphtml/pulls/7/commits","review_comments_url":"https://api.github.com/repos/google/amphtml/pulls/7/comments","review_comment_url":"https://api.github.com/repos/google/amphtml/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/amphtml/issues/7/comments","statuses_url":"https://api.github.com/repos/google/amphtml/statuses/b1133068775d5c81d7271b7a6913a4ad687107ab","head":{"label":"google:a4a-google-ads","ref":"a4a-google-ads","sha":"b1133068775d5c81d7271b7a6913a4ad687107ab","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":51965089,"name":"amphtml","full_name":"google/amphtml","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/google/amphtml","forks_url":"https://api.github.com/repos/google/amphtml/forks","keys_url":"https://api.github.com/repos/google/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/amphtml/teams","hooks_url":"https://api.github.com/repos/google/amphtml/hooks","issue_events_url":"https://api.github.com/repos/google/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/google/amphtml/events","assignees_url":"https://api.github.com/repos/google/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/google/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/google/amphtml/tags","blobs_url":"https://api.github.com/repos/google/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/google/amphtml/languages","stargazers_url":"https://api.github.com/repos/google/amphtml/stargazers","contributors_url":"https://api.github.com/repos/google/amphtml/contributors","subscribers_url":"https://api.github.com/repos/google/amphtml/subscribers","subscription_url":"https://api.github.com/repos/google/amphtml/subscription","commits_url":"https://api.github.com/repos/google/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/google/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/amphtml/merges","archive_url":"https://api.github.com/repos/google/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/amphtml/downloads","issues_url":"https://api.github.com/repos/google/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/google/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/google/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/google/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/google/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/google/amphtml/deployments","created_at":"2016-02-18T00:04:16Z","updated_at":"2016-07-01T17:37:54Z","pushed_at":"2016-07-06T17:41:22Z","git_url":"git://github.com/google/amphtml.git","ssh_url":"git@github.com:google/amphtml.git","clone_url":"https://github.com/google/amphtml.git","svn_url":"https://github.com/google/amphtml","homepage":"https://ampproject.org","size":103964,"stargazers_count":16,"watchers_count":16,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":4,"forks":8,"open_issues":4,"watchers":16,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"610b01ebecaece93d94c9da414fcb1255fde08c8","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":51965089,"name":"amphtml","full_name":"google/amphtml","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/amphtml","description":"AMP HTML source code, samples, and documentation.  See below for more info.","fork":true,"url":"https://api.github.com/repos/google/amphtml","forks_url":"https://api.github.com/repos/google/amphtml/forks","keys_url":"https://api.github.com/repos/google/amphtml/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/amphtml/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/amphtml/teams","hooks_url":"https://api.github.com/repos/google/amphtml/hooks","issue_events_url":"https://api.github.com/repos/google/amphtml/issues/events{/number}","events_url":"https://api.github.com/repos/google/amphtml/events","assignees_url":"https://api.github.com/repos/google/amphtml/assignees{/user}","branches_url":"https://api.github.com/repos/google/amphtml/branches{/branch}","tags_url":"https://api.github.com/repos/google/amphtml/tags","blobs_url":"https://api.github.com/repos/google/amphtml/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/amphtml/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/amphtml/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/amphtml/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/amphtml/statuses/{sha}","languages_url":"https://api.github.com/repos/google/amphtml/languages","stargazers_url":"https://api.github.com/repos/google/amphtml/stargazers","contributors_url":"https://api.github.com/repos/google/amphtml/contributors","subscribers_url":"https://api.github.com/repos/google/amphtml/subscribers","subscription_url":"https://api.github.com/repos/google/amphtml/subscription","commits_url":"https://api.github.com/repos/google/amphtml/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/amphtml/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/amphtml/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/amphtml/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/amphtml/contents/{+path}","compare_url":"https://api.github.com/repos/google/amphtml/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/amphtml/merges","archive_url":"https://api.github.com/repos/google/amphtml/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/amphtml/downloads","issues_url":"https://api.github.com/repos/google/amphtml/issues{/number}","pulls_url":"https://api.github.com/repos/google/amphtml/pulls{/number}","milestones_url":"https://api.github.com/repos/google/amphtml/milestones{/number}","notifications_url":"https://api.github.com/repos/google/amphtml/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/amphtml/labels{/name}","releases_url":"https://api.github.com/repos/google/amphtml/releases{/id}","deployments_url":"https://api.github.com/repos/google/amphtml/deployments","created_at":"2016-02-18T00:04:16Z","updated_at":"2016-07-01T17:37:54Z","pushed_at":"2016-07-06T17:41:22Z","git_url":"git://github.com/google/amphtml.git","ssh_url":"git@github.com:google/amphtml.git","clone_url":"https://github.com/google/amphtml.git","svn_url":"https://github.com/google/amphtml","homepage":"https://ampproject.org","size":103964,"stargazers_count":16,"watchers_count":16,"language":"JavaScript","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":8,"mirror_url":null,"open_issues_count":4,"forks":8,"open_issues":4,"watchers":16,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/amphtml/pulls/7"},"html":{"href":"https://github.com/google/amphtml/pull/7"},"issue":{"href":"https://api.github.com/repos/google/amphtml/issues/7"},"comments":{"href":"https://api.github.com/repos/google/amphtml/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/google/amphtml/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/google/amphtml/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/amphtml/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/google/amphtml/statuses/b1133068775d5c81d7271b7a6913a4ad687107ab"}}}}
{"actor":{"display_login":"taymonbeal"}}