@@ -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