WIP - sentinel refactor#6506
WIP - sentinel refactor#6506bradfrizzell wants to merge 13 commits intoampproject:masterfrom google:frizz-postmessage-api-sentinel-refactor
Conversation
Previously, the sentinel had been passed both on the hash of the iframe src, and as a data attribute. The data attribute was how the sentinel was referenced on the runtime side, even though there was no reason it could not simply be passed. Now, the sentinel is only passed to the iframe as a member of an object that is stringified and attached to the iframe name. On the runtime side, the sentinel is now passed and expected as a parameter to multiple functions that used to ultimately rely on it being available as a data attribute of the iframe.
Previously, the sentinel had been passed both on the hash of the iframe src, and as a data attribute. The data attribute was how the sentinel was referenced on the runtime side, even though there was no reason it could not simply be passed. Now, the sentinel is only passed to the iframe as a member of an object that is stringified and attached to the iframe name. On the runtime side, the sentinel is now passed and expected as a parameter to multiple functions that used to ultimately rely on it being available as a data attribute of the iframe.
…google/amphtml into frizz-postmessage-api-sentinel-refactor
Previously, the sentinel had been passed both on the hash of the iframe src, and as a data attribute. The data attribute was how the sentinel was referenced on the runtime side, even though there was no reason it could not simply be passed. Now, the sentinel is only passed to the iframe as a member of an object that is stringified and attached to the iframe name. On the runtime side, the sentinel is now passed and expected as a parameter to multiple functions that used to ultimately rely on it being available as a data attribute of the iframe.
…google/amphtml into frizz-postmessage-api-sentinel-refactor
…e-api-sentinel-refactor
src/attributes.js
Outdated
| attributes._context = { | ||
| referrer: self.document.referrer, | ||
| canonicalUrl, | ||
| pageViewId: getPageViewId(parentWindow), |
There was a problem hiding this comment.
We should get values from documentInfoForDoc(element)
There was a problem hiding this comment.
documentInfoForDoc only works if the element passed in is already attached to the DOM. The element here (the iframe) is not yet connected to the dom. Thus, documentInfoForDoc will throw. We can't write the element to the dom until its name attribute is set, and we can't set the name until we get the pageViewId. That is why I broke the pageViewId out from documentInfoForDoc. Maybe there is a better fix
There was a problem hiding this comment.
you can get it from documentInfoForDoc(parentWindow)
There was a problem hiding this comment.
ah that makes sense. thanks
src/attributes.js
Outdated
|
|
||
| let canonicalUrl; | ||
| try{ | ||
| canonicalUrl = self.document.querySelector( |
There was a problem hiding this comment.
don't use self, use parentWindow instead.
If the naming parentWindow is confusing, i suggest to switch to win
There was a problem hiding this comment.
can actually use the documentInfoForDoc here as well
|
I saw you duplicated some logic from |
|
Yes, working on consolidating that now. |
| this.lifecycleReporter.sendPing('adRequestStart'); | ||
| const iframe = getIframe(this.element.ownerDocument.defaultView, | ||
| this.element, undefined, opt_context); | ||
| this.element, undefined, opt_context); |
| this.updateSize_(data.height, data.width, source, origin); | ||
| }, true, true)); | ||
| this.unlisteners_.push(listenFor(this.iframe, this.sentinel, 'embed-size', | ||
| (data, source, origin) => { |
| const iframe = getIframe(this.element.ownerDocument.defaultView, | ||
| this.element, undefined, opt_context); | ||
| this.element, undefined, opt_context); | ||
| const sentinel = JSON.parse(iframe.name).attributes._context.sentinel; |
There was a problem hiding this comment.
This is not a JSON encoded value, it's https://github.com/ampproject/amphtml/pull/6506/files#diff-34e84f9cf5e8134d86bf1fc893ab293aR123
There was a problem hiding this comment.
sorry, this PR really should go out after #6498, that's why this was here
Refactored the passing of the sentinel value. No need to have a data attribute on the html element. Should just pass the sentinel as required.