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

Handle legacy alert, etc. in AMP ads. #2522

Merged
merged 1 commit into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions 3p/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function manageWin_(win) {
installObserver(win);
// Existing iframes.
maybeInstrumentsNodes(win, win.document.querySelectorAll('iframe'));
blockSyncPopups(win);
}


Expand Down Expand Up @@ -237,6 +238,33 @@ function instrumentEntryPoints(win) {
}
}

/**
* Blackhole the legacy popups since they should never be used for anything.
* @param {!Window} win
*/
function blockSyncPopups(win) {
let count = 0;
function maybeThrow() {
// Prevent deep recursion.
if (count++ > 2) {
throw new Error('security error');
}
}
try {
win.alert = maybeThrow;
win.prompt = function() {
maybeThrow();
return '';
};
win.confirm = function() {
maybeThrow();
return false;
};
} catch (e) {
console./*OK*/error(e.message, e.stack);
}
}

/**
* Run when we just became visible again. Runs all the queued up rafs.
* @visibleForTesting
Expand Down
10 changes: 10 additions & 0 deletions test/functional/test-3p-environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,16 @@ describe('3p environment', () => {
if (win.webkitRequestAnimationFrame) {
expect(win.webkitRequestAnimationFrame).to.not.match(/native/);
}
expect(win.alert.toString()).to.not.match(/native/);
expect(win.prompt.toString()).to.not.match(/native/);
expect(win.confirm.toString()).to.not.match(/native/);
expect(win.alert()).to.be.undefined;
expect(win.prompt()).to.equal('');
expect(win.confirm()).to.be.false;
// We only allow 3 calls to these functions.
expect(() => win.alert()).to.throw(/security error/);
expect(() => win.prompt()).to.throw(/security error/);
expect(() => win.confirm()).to.throw(/security error/);
}

function waitForMutationObserver(iframe) {
Expand Down