MCPcopy
hub / github.com/ampproject/amphtml / constructor

Method constructor

3p/iframe-transport-client.js:19–82  ·  view source on GitHub ↗

@param {!Window} win

(win)

Source from the content-addressed store, hash-verified

17export class IframeTransportClient {
18 /** @param {!Window} win */
19 constructor(win) {
20 /** @private {!Window} */
21 this.win_ = win;
22
23 /** @private {!{[key: string]: IframeTransportContext}} */
24 this.creativeIdToContext_ = {};
25
26 const parsedFrameName = tryParseJson(this.win_.name);
27
28 /** @private {string} */
29 this.vendor_ = dev().assertString(
30 parsedFrameName['type'],
31 'Parent frame must supply vendor name as type in ' +
32 this.win_.location.href
33 );
34 // Note: amp-ad-exit will validate the vendor name before performing
35 // variable substitution, so if the vendor name is not a valid one from
36 // vendors.js, then its response messages will have no effect.
37 devAssert(
38 this.vendor_.length,
39 'Vendor name cannot be empty in ' + this.win_.location.href
40 );
41
42 /** @protected {!IframeMessagingClient} */
43 this.iframeMessagingClient_ = new IframeMessagingClient(win, win.parent);
44 this.iframeMessagingClient_.setSentinel(
45 dev().assertString(
46 parsedFrameName['sentinel'],
47 'Invalid/missing sentinel on iframe name attribute' + this.win_.name
48 )
49 );
50 this.iframeMessagingClient_.makeRequest(
51 MessageType_Enum.SEND_IFRAME_TRANSPORT_EVENTS,
52 MessageType_Enum.IFRAME_TRANSPORT_EVENTS,
53 (eventData) => {
54 const events = /** @type {!Array<IframeTransportEventDef>} */ (
55 eventData['events']
56 );
57 devAssert(
58 events,
59 'Received malformed events list in ' + this.win_.location.href
60 );
61 devAssert(
62 events.length,
63 'Received empty events list in ' + this.win_.location.href
64 );
65 events.forEach((event) => {
66 try {
67 devAssert(
68 event.creativeId,
69 'Received malformed event in ' + this.win_.location.href
70 );
71 this.contextFor_(event.creativeId).dispatch(event.message);
72 } catch (e) {
73 user().error(
74 TAG_,
75 'Exception in callback passed to onAnalyticsEvent',
76 e

Callers

nothing calls this directly

Calls 11

contextFor_Method · 0.95
tryParseJsonFunction · 0.90
devFunction · 0.90
devAssertFunction · 0.90
userFunction · 0.90
assertStringMethod · 0.80
setSentinelMethod · 0.80
makeRequestMethod · 0.80
forEachMethod · 0.45
dispatchMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected