Skip to content

WIP - sentinel refactor#6506

Closed
bradfrizzell wants to merge 13 commits intoampproject:masterfrom
google:frizz-postmessage-api-sentinel-refactor
Closed

WIP - sentinel refactor#6506
bradfrizzell wants to merge 13 commits intoampproject:masterfrom
google:frizz-postmessage-api-sentinel-refactor

Conversation

@bradfrizzell
Copy link
Copy Markdown
Contributor

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.

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
@bradfrizzell
Copy link
Copy Markdown
Contributor Author

@lannka

attributes._context = {
referrer: self.document.referrer,
canonicalUrl,
pageViewId: getPageViewId(parentWindow),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get values from documentInfoForDoc(element)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can get it from documentInfoForDoc(parentWindow)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that makes sense. thanks

@lannka lannka self-assigned this Dec 6, 2016

let canonicalUrl;
try{
canonicalUrl = self.document.querySelector(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use self, use parentWindow instead.
If the naming parentWindow is confusing, i suggest to switch to win

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can actually use the documentInfoForDoc here as well

@lannka
Copy link
Copy Markdown
Contributor

lannka commented Dec 7, 2016

I saw you duplicated some logic from 3p-iframe.js to attributes.js, do you plan to consolidate?

@bradfrizzell
Copy link
Copy Markdown
Contributor Author

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing is incorrect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

this.updateSize_(data.height, data.width, source, origin);
}, true, true));
this.unlisteners_.push(listenFor(this.iframe, this.sentinel, 'embed-size',
(data, source, origin) => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

@bradfrizzell bradfrizzell Dec 9, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, this PR really should go out after #6498, that's why this was here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants