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

Modified A4A from shadow DOM to installFriendlyIframeEmbed #5196

Merged
merged 22 commits into from Oct 4, 2016
Merged

Modified A4A from shadow DOM to installFriendlyIframeEmbed #5196

merged 22 commits into from Oct 4, 2016

Conversation

keithwrightbos
Copy link
Contributor

Only implementation, still need to update tests.

@jridgewell
Copy link
Contributor

/to @lannka

Copy link
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

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

LGTM in general. some minor comments

bodyElement./*OK*/innerHTML = bodyBlock;
this.rendered_ = true;
this.onAmpCreativeShadowDomRender();
return this.vsync_.mutatePromise().then(() => {
Copy link
Contributor

@lannka lannka Sep 23, 2016

Choose a reason for hiding this comment

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

you might want to do this.vsync_.mutatePromise(() => {

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. It definitely should be mutatePromise(() => {...}). But generally, only appendChild would need to go in vsync. Since installFriendlyIframeEmbed is not quite ready for that, I recommend to just to just remove vsync.mutate completely and I will instead implement vsync.mutate inside installFriendlyIframeEmbed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Contributor

Choose a reason for hiding this comment

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

Did you push already? Not seeing changes...

this.onAmpCreativeShadowDomRender();
return this.vsync_.mutatePromise().then(() => {
// Create and setup friendly iframe.
const iframe = this.element.ownerDocument.createElement('iframe');
Copy link
Contributor

Choose a reason for hiding this comment

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

you can leverage the util createElementWithAttributes in dom.js to save some lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

for (let i = 0; i <= extensions.length; i++) {
// Remove AMP runtime as well.
const extensionName =
(i == extensions.length) ? 'v0\.js' : extensions[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm, this is not that intuitive.
instead, we can do

extensions.push('v0\.js`);

before the for loop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done... note that I have to then pop it from the array as it is passed to installFriendlyIframeEmbed

bodyElement./*OK*/innerHTML = bodyBlock;
this.rendered_ = true;
this.onAmpCreativeShadowDomRender();
return this.vsync_.mutatePromise().then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. It definitely should be mutatePromise(() => {...}). But generally, only appendChild would need to go in vsync. Since installFriendlyIframeEmbed is not quite ready for that, I recommend to just to just remove vsync.mutate completely and I will instead implement vsync.mutate inside installFriendlyIframeEmbed.

creativeMetaData.customElementExtensions || [];
for (let i = 0; i <= extensions.length; i++) {
// Remove AMP runtime as well.
const extensionName =
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quiet understand these changes. Why not just use the old way of doing this as was before, but simply combine cssBlock and bodyBlock into one string before sending it to installFriendlyIframeEmbed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, I want to minimize that amount of work done by the validator rewrite. Had we done this from the beginning, we would only have required it provide an array of extension ids and how to remove script tags (including v0.js).

@@ -410,18 +405,19 @@ export class AmpA4A extends AMP.BaseElement {
// valid AMP.
this.timerId_ = incrementLoadingAds(this.win);
return this.adPromise_.then(rendered => {
console.log('layoutCallback promise result', rendered, this.rendered_);
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

bodyElement./*OK*/innerHTML = bodyBlock;
this.rendered_ = true;
this.onAmpCreativeShadowDomRender();
return this.vsync_.mutatePromise().then(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you push already? Not seeing changes...

@keithwrightbos
Copy link
Contributor Author

Yes apologies, just pushed update to a4a.js. Working on test modifications now.

this.rendered_ = true;
this.onAmpCreativeShadowDomRender();
// Create and setup friendly iframe.
const iframe = createElementWithAttributes(
Copy link
Contributor

Choose a reason for hiding this comment

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

what i understand is A4A will always create an iframe (friendly / cross domain) now. Can we make iframe a variable of the class this.iframe = iframe here to make code sharing class cleaner?

Copy link
Contributor

@lannka lannka Sep 30, 2016

Choose a reason for hiding this comment

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

hm, I actually start to think this is a good idea now. we could instantiate the class with this.iframe = null. Making it a public field so that other shared modules can access.

But not necessary in this PR. We can change it in your own refactoring PR for code-sharing .

Copy link
Contributor

@lannka lannka left a comment

Choose a reason for hiding this comment

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

LGTM with some indentation nitpicks.

// validation providing offsets to extension & AMP runtime
// locations.
const extensions =
creativeMetaData.customElementExtensions || [];
Copy link
Contributor

@lannka lannka Sep 30, 2016

Choose a reason for hiding this comment

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

for forced line breaks, I think we indent 4 spaces.

extensions.push('v0\.js');
extensions.forEach(extension => {
creative = creative.replace(new RegExp(
`<script[^>]+${extensionName}[^>]+>\s*</script\s*>\n?`),
Copy link
Contributor

Choose a reason for hiding this comment

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

4 spaces here as well.

the previous line is fine though, as it's not a forced line break.

// have moved to AMP AD document format validation, ensure it does
// not match amp4ads-boilerplate.
creative = creative.replace(
/<style\s+([^>]*\s+)?amp-boilerplate[^>]*>[^>]+<\/style\s*>/, '');
Copy link
Contributor

Choose a reason for hiding this comment

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

here

creative = creative.replace(
/<style\s+([^>]*\s+)?amp-boilerplate[^>]*>[^>]+<\/style\s*>/, '');
return installFriendlyIframeEmbed(
iframe, this.element, {
Copy link
Contributor

Choose a reason for hiding this comment

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

and here

@lannka lannka added LGTM and removed NEEDS REVIEW labels Sep 30, 2016
@zhouyx zhouyx mentioned this pull request Sep 30, 2016
@lannka
Copy link
Contributor

lannka commented Oct 4, 2016

We need this PR to get in to unblock some other work.
@keithwrightbos would you fix the lint and resolve the conflicts?
@dvoytenko do you still want to take another look?

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@keithwrightbos
Copy link
Contributor Author

@lannka @dvoytenko - after discussions with AMP team, modified code to stitch together creative from validator rewrite meta object as opposed to using regexps to remove portions. Validator team is working on modifying output to place portions to be removed (scripts & boilerplate) next to each other and provide offsets to ease removal. PTAL

@googlebot
Copy link

CLAs look good, thanks!

@keithwrightbos
Copy link
Contributor Author

@lannka I fixed the lint errors and merged to upstream/master so I believe conflicts have been addressed (correct me if I'm wrong!). FYI - I'm OOTO tomorrow through Monday so please contact @tdrl for assistance going forward. Thanks!

Copy link
Contributor

@dvoytenko dvoytenko left a comment

Choose a reason for hiding this comment

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

Just a couple of nits.

const iframe = /** @type {!HTMLIFrameElement} */(
createElementWithAttributes(
/** @type {!Document} */(this.element.ownerDocument), 'iframe', {
'frameborder': '0', 'allowfullscreen': '',
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I property per line.

const modifiedCreative =
`<!doctype html><html ⚡4ads>
<head>
<style amp4ads-boilerplate>body{visibility:hidden}</style>
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, this is not needed for friendly iframes. My code manages the visibility state.

@lannka
Copy link
Contributor

lannka commented Oct 4, 2016

I'll merge this PR now to unblock other's work, and we can get the nit fixed in separate PR.

@lannka lannka merged commit 49a0a48 into ampproject:master Oct 4, 2016
dreamofabear pushed a commit to dreamofabear/amphtml that referenced this pull request Oct 12, 2016
…t#5196)

* Update amp-ad-network-doubleclick-impl.md

* Reverting doc changes

The previous change was made in error (wrong branch).

* Initial integration with installFriendlyIframeEmbed

* Review comments

* Update amp-ad-network-doubleclick-impl.md

* Reverting doc changes

The previous change was made in error (wrong branch).

* Initial integration with installFriendlyIframeEmbed

* Review comments

* Change to stitching creative instead of removing portions

* Update unit tests

* Fix after merge with upstream/master; correct type failures within friendly-iframe-embed

* Fix lint errors

* remove console log
mityaha pushed a commit to ooyala/amphtml that referenced this pull request Nov 30, 2016
…t#5196)

* Update amp-ad-network-doubleclick-impl.md

* Reverting doc changes

The previous change was made in error (wrong branch).

* Initial integration with installFriendlyIframeEmbed

* Review comments

* Update amp-ad-network-doubleclick-impl.md

* Reverting doc changes

The previous change was made in error (wrong branch).

* Initial integration with installFriendlyIframeEmbed

* Review comments

* Change to stitching creative instead of removing portions

* Update unit tests

* Fix after merge with upstream/master; correct type failures within friendly-iframe-embed

* Fix lint errors

* remove console log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants