Skip to content

Commit

Permalink
bindings: Fixes exposed JS APIs for platform apps.
Browse files Browse the repository at this point in the history
We're disabling some of DOM attributes and operations for platform apps.
Since event handlers and operations in Window are going to move onto
the instance object, we need to update disabling code accordingly.

Also fixes a way to disable addEventListener.  It's defined on
EventTarget.prototype, not on Window.prototype.  Also it shouldn't
change |this| object.

This CL is a preparation of http://crrev.com/1333853002

BUG=43394, 516274
CQ_INCLUDE_TRYBOTS=tryserver.blink:linux_blink_rel

Review URL: https://codereview.chromium.org/1333303002

Cr-Commit-Position: refs/heads/master@{#349376}
  • Loading branch information
yuki3 authored and Commit bot committed Sep 17, 2015
1 parent e946b22 commit 37799a7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions extensions/renderer/resources/platform_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

var $console = window.console;

/**
* Returns a function that logs a 'not available' error to the console and
* returns undefined.
Expand All @@ -14,7 +12,7 @@ function generateDisabledMethodStub(messagePrefix, opt_messageSuffix) {
var message = messagePrefix + ' is not available in packaged apps.';
if (opt_messageSuffix) message = message + ' ' + opt_messageSuffix;
return function() {
$console.error(message);
console.error(message);
return;
};
}
Expand Down Expand Up @@ -157,10 +155,12 @@ disableGetters(window.history, 'history',
['back', 'forward', 'go', 'length', 'pushState', 'replaceState']);

// Disable find.
disableMethods(window, 'window', ['find']);
disableMethods(Window.prototype, 'window', ['find']);

// Disable modal dialogs. Shell windows disable these anyway, but it's nice to
// warn.
disableMethods(window, 'window', ['alert', 'confirm', 'prompt']);
disableMethods(Window.prototype, 'window', ['alert', 'confirm', 'prompt']);

// Disable window.*bar.
Expand Down Expand Up @@ -198,11 +198,12 @@ window.addEventListener('readystatechange', function(event) {
}, true);

// Disable onunload, onbeforeunload.
disableSetters(window, 'window', ['onbeforeunload', 'onunload']);
disableSetters(Window.prototype, 'window', ['onbeforeunload', 'onunload']);
var windowAddEventListener = Window.prototype.addEventListener;
Window.prototype.addEventListener = function(type) {
var eventTargetAddEventListener = EventTarget.prototype.addEventListener;
EventTarget.prototype.addEventListener = function(type) {
if (type === 'unload' || type === 'beforeunload')
generateDisabledMethodStub(type)();
else
return $Function.apply(windowAddEventListener, window, arguments);
return $Function.apply(eventTargetAddEventListener, this, arguments);
};

0 comments on commit 37799a7

Please sign in to comment.