Skip to content

Commit a61ddf8

Browse files
committed
Addressed comments'
1 parent e0363bf commit a61ddf8

2 files changed

Lines changed: 3 additions & 33 deletions

File tree

3p/ampcontext.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class AmpContext {
2929
// if the window sentinel is set directly, that means we are running
3030
// in a situation where we couldn't attach the name attribute before
3131
// creating the iframe, so don't try to parse the metadata
32-
if (!this.getWindowSentinel_()) {
32+
if (!this.hasSafeframeSentinel_()) {
3333
this.setupMetadata_();
3434
}
3535
this.client_ = new IframeMessagingClient(win);
@@ -151,7 +151,7 @@ export class AmpContext {
151151
* sentinel value, sets it, and returns true if so.
152152
* @private
153153
*/
154-
getWindowSentinel_() {
154+
hasSafeframeSentinel_() {
155155
this.sentinel = this.win_.SAFEFRAME_SENTINEL || null;
156156
return !!this.sentinel;
157157
}

src/iframe-helper.js

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,6 @@ function getListenForEvents(parentWin, sentinel, origin, triggerWin) {
126126
const contentWindow = we.frame.contentWindow;
127127
if (!contentWindow) {
128128
setTimeout(dropListenSentinel, 0, listenSentinel);
129-
} else if (sentinel === 'amp') {
130-
// A non-3P code path, origin must match.
131-
if (we.origin === origin && contentWindow == triggerWin) {
132-
windowEvents = we;
133-
break;
134-
}
135129
} else if (triggerWin == contentWindow ||
136130
isDescendantWindow(contentWindow, triggerWin)) {
137131
// 3P code path, we may accept messages from nested frames.
@@ -199,7 +193,7 @@ function registerGlobalListenerIfNeeded(parentWin) {
199193
if (!event.data) {
200194
return;
201195
}
202-
const data = parseIfNeeded(event.data);
196+
const data = deserializeMessage(event.data);
203197
if (!data.sentinel) {
204198
return;
205199
}
@@ -378,30 +372,6 @@ function getSentinel_(iframe, opt_is3P) {
378372
return opt_is3P ? iframe.getAttribute('data-amp-3p-sentinel') : 'amp';
379373
}
380374

381-
/**
382-
* Json parses event.data if it needs to be
383-
* @returns {!Object} object message
384-
* @private
385-
*/
386-
function parseIfNeeded(data) {
387-
const shouldBeParsed = typeof data === 'string'
388-
&& data.charAt(0) === '{';
389-
let msg;
390-
if (shouldBeParsed) {
391-
try {
392-
data = JSON.parse(data);
393-
} catch (e) {
394-
dev().warn('IFRAME-HELPER', 'Postmessage could not be parsed. ' +
395-
'Is it in a valid JSON format?', e);
396-
}
397-
} else {
398-
msg = deserializeMessage(data);
399-
}
400-
return msg ? msg : /** @type {!Object} */ (data) ;
401-
}
402-
403-
404-
405375
/**
406376
* Manages a postMessage API for an iframe with a subscription message and
407377
* a way to broadcast messages to all subscribed windows, which

0 commit comments

Comments
 (0)