| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 var $console = window.console; | |
| 6 | |
| 7 /** | 5 /** |
| 8 * Returns a function that logs a 'not available' error to the console and | 6 * Returns a function that logs a 'not available' error to the console and |
| 9 * returns undefined. | 7 * returns undefined. |
| 10 * | 8 * |
| 11 * @param {string} messagePrefix text to prepend to the exception message. | 9 * @param {string} messagePrefix text to prepend to the exception message. |
| 12 */ | 10 */ |
| 13 function generateDisabledMethodStub(messagePrefix, opt_messageSuffix) { | 11 function generateDisabledMethodStub(messagePrefix, opt_messageSuffix) { |
| 14 var message = messagePrefix + ' is not available in packaged apps.'; | 12 var message = messagePrefix + ' is not available in packaged apps.'; |
| 15 if (opt_messageSuffix) message = message + ' ' + opt_messageSuffix; | 13 if (opt_messageSuffix) message = message + ' ' + opt_messageSuffix; |
| 16 return function() { | 14 return function() { |
| 17 $console.error(message); | 15 console.error(message); |
| 18 return; | 16 return; |
| 19 }; | 17 }; |
| 20 } | 18 } |
| 21 | 19 |
| 22 /** | 20 /** |
| 23 * Returns a function that throws a 'not available' error. | 21 * Returns a function that throws a 'not available' error. |
| 24 * | 22 * |
| 25 * @param {string} messagePrefix text to prepend to the exception message. | 23 * @param {string} messagePrefix text to prepend to the exception message. |
| 26 */ | 24 */ |
| 27 function generateThrowingMethodStub(messagePrefix, opt_messageSuffix) { | 25 function generateThrowingMethodStub(messagePrefix, opt_messageSuffix) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 148 |
| 151 // Replace evil Document methods with exception-throwing stubs. | 149 // Replace evil Document methods with exception-throwing stubs. |
| 152 disableMethods(HTMLDocument.prototype, 'document', ['write', 'writeln'], true); | 150 disableMethods(HTMLDocument.prototype, 'document', ['write', 'writeln'], true); |
| 153 | 151 |
| 154 // Disable history. | 152 // Disable history. |
| 155 Object.defineProperty(window, "history", { value: {} }); | 153 Object.defineProperty(window, "history", { value: {} }); |
| 156 disableGetters(window.history, 'history', | 154 disableGetters(window.history, 'history', |
| 157 ['back', 'forward', 'go', 'length', 'pushState', 'replaceState']); | 155 ['back', 'forward', 'go', 'length', 'pushState', 'replaceState']); |
| 158 | 156 |
| 159 // Disable find. | 157 // Disable find. |
| 158 disableMethods(window, 'window', ['find']); |
| 160 disableMethods(Window.prototype, 'window', ['find']); | 159 disableMethods(Window.prototype, 'window', ['find']); |
| 161 | 160 |
| 162 // Disable modal dialogs. Shell windows disable these anyway, but it's nice to | 161 // Disable modal dialogs. Shell windows disable these anyway, but it's nice to |
| 163 // warn. | 162 // warn. |
| 163 disableMethods(window, 'window', ['alert', 'confirm', 'prompt']); |
| 164 disableMethods(Window.prototype, 'window', ['alert', 'confirm', 'prompt']); | 164 disableMethods(Window.prototype, 'window', ['alert', 'confirm', 'prompt']); |
| 165 | 165 |
| 166 // Disable window.*bar. | 166 // Disable window.*bar. |
| 167 disableGetters(window, 'window', | 167 disableGetters(window, 'window', |
| 168 ['locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', | 168 ['locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', |
| 169 'toolbar']); | 169 'toolbar']); |
| 170 | 170 |
| 171 // Disable window.localStorage. | 171 // Disable window.localStorage. |
| 172 // Sometimes DOM security policy prevents us from doing this (e.g. for data: | 172 // Sometimes DOM security policy prevents us from doing this (e.g. for data: |
| 173 // URLs) so wrap in try-catch. | 173 // URLs) so wrap in try-catch. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 191 // https://developer.mozilla.org/en/DOM/document. | 191 // https://developer.mozilla.org/en/DOM/document. |
| 192 // To deprecate document.all, simply changing its getter and setter would | 192 // To deprecate document.all, simply changing its getter and setter would |
| 193 // activate its cache mechanism, and degrade the performance. Here we assign | 193 // activate its cache mechanism, and degrade the performance. Here we assign |
| 194 // it first to 'undefined' to avoid this. | 194 // it first to 'undefined' to avoid this. |
| 195 document.all = undefined; | 195 document.all = undefined; |
| 196 disableGetters(document, 'document', | 196 disableGetters(document, 'document', |
| 197 ['alinkColor', 'all', 'bgColor', 'fgColor', 'linkColor', 'vlinkColor']); | 197 ['alinkColor', 'all', 'bgColor', 'fgColor', 'linkColor', 'vlinkColor']); |
| 198 }, true); | 198 }, true); |
| 199 | 199 |
| 200 // Disable onunload, onbeforeunload. | 200 // Disable onunload, onbeforeunload. |
| 201 disableSetters(window, 'window', ['onbeforeunload', 'onunload']); |
| 201 disableSetters(Window.prototype, 'window', ['onbeforeunload', 'onunload']); | 202 disableSetters(Window.prototype, 'window', ['onbeforeunload', 'onunload']); |
| 202 var windowAddEventListener = Window.prototype.addEventListener; | 203 var eventTargetAddEventListener = EventTarget.prototype.addEventListener; |
| 203 Window.prototype.addEventListener = function(type) { | 204 EventTarget.prototype.addEventListener = function(type) { |
| 204 if (type === 'unload' || type === 'beforeunload') | 205 if (type === 'unload' || type === 'beforeunload') |
| 205 generateDisabledMethodStub(type)(); | 206 generateDisabledMethodStub(type)(); |
| 206 else | 207 else |
| 207 return $Function.apply(windowAddEventListener, window, arguments); | 208 return $Function.apply(eventTargetAddEventListener, this, arguments); |
| 208 }; | 209 }; |
| OLD | NEW |