* @param {!../../../src/service/ampdoc-impl.AmpDoc} ampdoc
(ampdoc)
| 41 | * @param {!../../../src/service/ampdoc-impl.AmpDoc} ampdoc |
| 42 | */ |
| 43 | constructor(ampdoc) { |
| 44 | /** @private {!../../../src/service/ampdoc-impl.AmpDoc} */ |
| 45 | this.ampdoc_ = ampdoc; |
| 46 | |
| 47 | /** @private {boolean} */ |
| 48 | this.registeredWithHostServices_ = false; |
| 49 | |
| 50 | /** @private */ |
| 51 | this.mraid_ = null; |
| 52 | |
| 53 | /** @private {boolean} */ |
| 54 | this.fallback_ = true; |
| 55 | |
| 56 | const ampMraidScripts = this.ampdoc_ |
| 57 | .getHeadNode() |
| 58 | .querySelectorAll('script[host-service="amp-mraid"]'); |
| 59 | if (ampMraidScripts.length > 1) { |
| 60 | dev().error(TAG, 'Multiple amp-mraid scripts.'); |
| 61 | return; |
| 62 | } else if (ampMraidScripts.length < 1) { |
| 63 | dev().error(TAG, 'Missing amp-mraid scripts.'); |
| 64 | return; |
| 65 | } |
| 66 | const element = ampMraidScripts[0]; |
| 67 | if (element.getAttribute(NO_FALLBACK) != null) { |
| 68 | this.fallback_ = false; |
| 69 | } |
| 70 | |
| 71 | if (getMode().runtime !== 'inabox') { |
| 72 | dev().fine(TAG, 'Only supported with Inabox'); |
| 73 | this.handleMismatch_(); |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | // It looks like we're initiating a network load for mraid.js, but if we're |
| 78 | // in a mobile app this will actually be intercepted by the mobile app SDK |
| 79 | // and handled locally. |
| 80 | // |
| 81 | // In cases where this won't be intercepted by an SDK we don't want it to |
| 82 | // suceed, so we intentionally use a URL that will 404. This isn't |
| 83 | // technically correct, since the MRAID spec says you must use a relative |
| 84 | // URL reference, but the interception API that platforms provide only lets |
| 85 | // them see post-resolution URLs. Platforms just check if the URL ends with |
| 86 | // "/mraid.js". |
| 87 | // |
| 88 | // We use cdn.ampproject.org so we can learn how often this happens from |
| 89 | // server logs for 404s. |
| 90 | const mraidJs = document.createElement('script'); |
| 91 | mraidJs.setAttribute('type', 'text/javascript'); |
| 92 | mraidJs.setAttribute('src', `${urls.cdn}/mraid.js`); |
| 93 | mraidJs.addEventListener('load', () => { |
| 94 | this.mraidLoadSuccess_(); |
| 95 | }); |
| 96 | mraidJs.addEventListener('error', () => { |
| 97 | if (!this.registeredWithHostServices_) { |
| 98 | this.handleMismatch_(); |
| 99 | } |
| 100 | }); |
nothing calls this directly
no test coverage detected