OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** | 5 /** |
6 * Returns a function that throws a 'not available' exception when called. | 6 * Returns a function that throws a 'not available' exception when called. |
7 * | 7 * |
8 * @param {string} messagePrefix text to prepend to the exception message. | 8 * @param {string} messagePrefix text to prepend to the exception message. |
9 */ | 9 */ |
10 function generateDisabledMethodStub(messagePrefix, opt_messageSuffix) { | 10 function generateDisabledMethodStub(messagePrefix, opt_messageSuffix) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 }); | 72 }); |
73 } | 73 } |
74 | 74 |
75 // Disable document.open|close|write|etc. | 75 // Disable document.open|close|write|etc. |
76 disableMethods(HTMLDocument.prototype, 'document', | 76 disableMethods(HTMLDocument.prototype, 'document', |
77 ['open', 'clear', 'close', 'write', 'writeln']); | 77 ['open', 'clear', 'close', 'write', 'writeln']); |
78 | 78 |
79 // Disable history. | 79 // Disable history. |
80 window.history = {}; | 80 window.history = {}; |
81 disableMethods(window.history, 'history', | 81 disableMethods(window.history, 'history', |
82 ['back', 'forward', 'go', 'pushState', 'replaceState']); | 82 ['back', 'forward', 'go']); |
83 disableGetters(window.history, 'history', ['length', 'state']); | 83 disableGetters(window.history, 'history', ['length']); |
84 | 84 |
85 // Disable find. | 85 // Disable find. |
86 disableMethods(Window.prototype, 'window', ['find']); | 86 disableMethods(Window.prototype, 'window', ['find']); |
87 | 87 |
88 // Disable modal dialogs. Shell windows disable these anyway, but it's nice to | 88 // Disable modal dialogs. Shell windows disable these anyway, but it's nice to |
89 // warn. | 89 // warn. |
90 disableMethods(Window.prototype, 'window', ['alert', 'confirm', 'prompt']); | 90 disableMethods(Window.prototype, 'window', ['alert', 'confirm', 'prompt']); |
91 | 91 |
92 // Disable window.*bar. | 92 // Disable window.*bar. |
93 disableGetters(window, 'window', | 93 disableGetters(window, 'window', |
(...skipping 27 matching lines...) Expand all Loading... |
121 'onbeforeunload', generateDisabledMethodStub('onbeforeunload')); | 121 'onbeforeunload', generateDisabledMethodStub('onbeforeunload')); |
122 Window.prototype.__defineSetter__( | 122 Window.prototype.__defineSetter__( |
123 'onunload', generateDisabledMethodStub('onunload')); | 123 'onunload', generateDisabledMethodStub('onunload')); |
124 var windowAddEventListener = Window.prototype.addEventListener; | 124 var windowAddEventListener = Window.prototype.addEventListener; |
125 Window.prototype.addEventListener = function(type) { | 125 Window.prototype.addEventListener = function(type) { |
126 if (type === 'unload' || type === 'beforeunload') | 126 if (type === 'unload' || type === 'beforeunload') |
127 generateDisabledMethodStub(type)(); | 127 generateDisabledMethodStub(type)(); |
128 else | 128 else |
129 return windowAddEventListener.apply(window, arguments); | 129 return windowAddEventListener.apply(window, arguments); |
130 }; | 130 }; |
OLD | NEW |