* Applies the runtime to a given global scope for a single-doc mode. Multi * frame support is currently incomplete. * @param {!Window} global Global scope to adopt. * @param {function(!Window, !./service/extensions-impl.Extensions):!Promise} callback * @return {!Promise}
(global, callback)
| 69 | * @return {!Promise} |
| 70 | */ |
| 71 | function adoptShared(global, callback) { |
| 72 | // Tests can adopt the same window twice. sigh. |
| 73 | if (global.__AMP_TAG) { |
| 74 | return Promise.resolve(); |
| 75 | } |
| 76 | global.__AMP_TAG = true; |
| 77 | // If there is already a global AMP object we assume it is an array |
| 78 | // of functions |
| 79 | /** @const {!Array<function(!Object)|!ExtensionPayload>} */ |
| 80 | const preregisteredExtensions = global.AMP || []; |
| 81 | |
| 82 | installExtensionsService(global); |
| 83 | /** @const {!./service/extensions-impl.Extensions} */ |
| 84 | const extensions = Services.extensionsFor(global); |
| 85 | installRuntimeServices(global); |
| 86 | stubLegacyElements(global); |
| 87 | |
| 88 | global.AMP = { |
| 89 | win: global, |
| 90 | // Might not be available in tests. |
| 91 | '_': global.AMP ? global.AMP['_'] : undefined, |
| 92 | }; |
| 93 | |
| 94 | // `AMP.extension()` function is only installed in a non-minified mode. |
| 95 | // This function is meant to play the same role for development and testing |
| 96 | // as `AMP.push()` in production. |
| 97 | if (!mode.isMinified()) { |
| 98 | /** |
| 99 | * @param {string} unusedName |
| 100 | * @param {string} unusedVersion |
| 101 | * @param {function(!Object)} installer |
| 102 | * @const |
| 103 | */ |
| 104 | global.AMP.extension = function (unusedName, unusedVersion, installer) { |
| 105 | installer(global.AMP); |
| 106 | }; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @const {{ |
| 111 | * urls: { |
| 112 | * thirdParty: string, |
| 113 | * thirdPartyFrameHost: string, |
| 114 | * thirdPartyFrameRegex: !RegExp, |
| 115 | * cdn: string, |
| 116 | * cdnProxyRegex: !RegExp, |
| 117 | * localhostRegex: !RegExp, |
| 118 | * errorReporting: string, |
| 119 | * betaErrorReporting: string, |
| 120 | * localDev: boolean, |
| 121 | * trustedViewerHosts: !Array<!RegExp>, |
| 122 | * geoApi: ?string, |
| 123 | * } |
| 124 | * }} |
| 125 | */ |
| 126 | global.AMP.config = { |
| 127 | urls: { |
| 128 | thirdParty: urls.thirdParty, |
no test coverage detected