Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creative API: resize - attempt 2 #4236

Merged
merged 12 commits into from Aug 5, 2016

Conversation

nekodo
Copy link
Contributor

@nekodo nekodo commented Jul 27, 2016

Adds support for requesting resize using embed-size messages from nested frames. This time should dodge the issues my previous patch had by no longer having the weird "fail the pending request" logic since attemptChangeSize is now more reasonable and takes a failure callback.

});
updateSize_(height, width, source, origin) {
this.baseInstance_.attemptChangeSize(height, width,
() => this.sendEmbedSizeResponse_(
Copy link
Contributor

Choose a reason for hiding this comment

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

#attemptChangeSize doesn't take a success and failure callback, it returns a Promise. You'll have to put these in a #then:

attemptChangeSize(height, width).then(success, failure);

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You seem to be correct, but that is not what the code at head is doing: https://github.com/ampproject/amphtml/blob/master/extensions/amp-ad/0.1/amp-ad-api-handler.js#L159.

Is the code at head actually broken?

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the code at head actually broken?

😭. @zhouyx

Copy link
Contributor

Choose a reason for hiding this comment

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

😢 My bad. messed up on rebase, #4258

Copy link
Contributor

Choose a reason for hiding this comment

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

This should be fixed now. Please rebase.

@jridgewell
Copy link
Contributor

Re: #4023

success, requestedWidth, requestedHeight, source, origin) {
postMessageToWindows(
this.iframe_,
[{win: source, origin}],
Copy link
Contributor

Choose a reason for hiding this comment

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

origin & source should already be present in the event object right? why do we have to pass them around?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to tell postMessageToWindows which windows to send the message to. With this change we are no longer messaging only the contentWindow of the iframe, but potentially also any of the child windows within that iframe. That's the point of the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

forgive my ignorance. Why do other windows care about resize response? only the requestor should benefit from it right?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is for a nested child iframe to send message to its ancestor.

Copy link
Contributor

Choose a reason for hiding this comment

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

So, I'm joining this a bit late and I see (most likely) the original GitHub issue in #3019. Could you please catch me up:

  1. Is Intent to implement: postMessage API for 3rd party iframes #3019 indeed the origin issue?
  2. Why did we decide to allow amp-ad to communicate with child frames directly vs proxying these messages with 3p iframe (most immediate child of amp-ad)? I'm not saying that this is wrong, I'd just like to get into right context on this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, #3019 is the issue that this PR pertains to.

Direct communication achieves a few different things:

  1. It offers better performance, especially for things like IntersectionObserver emulation, as it avoids adding forwarding. It also makes it easier to handle double-nesting without adding extra complexity.
  2. It supports A4A use case where the returned ad is a non-AMP creative. In that case the ad is rendered in a 3P iframe, but it does not have access to the normal window.context. With the current implementation of messaging there will be no extra work required to support IntersectionObserver or resizing in that case.

Note that the nested iframes can only communicate if they know a per-3P-frame unique sentinel value. This sentinel is available within the frame's contextWindow and has to be explicitly passed to any child iframes (i.e. it functions as an authorization token).

FYI, the underlying changes to the messaging code happened some time ago in #3327 along with the changes for IntersectionObserver and for page visibility in #4021.

Copy link
Contributor

Choose a reason for hiding this comment

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

@nekodo Thanks. This all sounds good.

@sriramkrish85 I'm ok with these changes.

@lannka
Copy link
Contributor

lannka commented Jul 28, 2016

LGTM. Defer to @sriramkrish85 for the final approval.

@jridgewell
Copy link
Contributor

This'll need to be rebased after #4258.

@jridgewell
Copy link
Contributor

Ping @lannka.

@lannka
Copy link
Contributor

lannka commented Aug 2, 2016

LGTM.
Defer to @sriramkrish85 for the final approval.

@camelburrito
Copy link
Contributor

@nekodo let me know if you want me to merge this.

@nekodo
Copy link
Contributor Author

nekodo commented Aug 5, 2016

@sriramkrish85 Yes please:)

@camelburrito camelburrito merged commit 13d1c6c into ampproject:master Aug 5, 2016
ariangibson pushed a commit to Mixpo/amphtml that referenced this pull request Sep 7, 2016
* Changed <amp-ad> to allow nested frames to request resize using embed-size messages. Added a test using a nested frame to verify that these messages are received correctly.

* Fixed function name in a test.

* Made linter happy.

* Refactored a bit around sendEmbedContext.

* OK lint, you win again.

* Begone lint errors!

* Switched to use the returned Promise from attemptChangeSize.
mityaha pushed a commit to ooyala/amphtml that referenced this pull request Nov 30, 2016
* Changed <amp-ad> to allow nested frames to request resize using embed-size messages. Added a test using a nested frame to verify that these messages are received correctly.

* Fixed function name in a test.

* Made linter happy.

* Refactored a bit around sendEmbedContext.

* OK lint, you win again.

* Begone lint errors!

* Switched to use the returned Promise from attemptChangeSize.
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.

None yet

6 participants