| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 * @fileoverview this file provides the bootstrap interface between the | 6 * @fileoverview this file provides the bootstrap interface between the |
| 7 * Chrome event and extension bindings JavaScript files, and the CEEE | 7 * Chrome event and extension bindings JavaScript files, and the CEEE |
| 8 * native IE interface, as well as initialization hooks for the native | 8 * native IE interface, as well as initialization hooks for the native |
| 9 * interface. | 9 * interface. |
| 10 */ | 10 */ |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // TODO(siggi@chromium.org): If there is a different global | 107 // TODO(siggi@chromium.org): If there is a different global |
| 108 // environment at this point (i.e. we have cloned the scripting | 108 // environment at this point (i.e. we have cloned the scripting |
| 109 // engine for a new window) this is where we can restore goog, | 109 // engine for a new window) this is where we can restore goog, |
| 110 // JSON and chrome. | 110 // JSON and chrome. |
| 111 | 111 |
| 112 // Delete the ceee namespace from globals. | 112 // Delete the ceee namespace from globals. |
| 113 delete ceee; | 113 delete ceee; |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 ceee.initGlobals_ = function() { | 116 ceee.initGlobals_ = function() { |
| 117 // We expose a subset of the Window interface defined at | 117 // The window object of the page is exposed in its entirety to the script |
| 118 // host via the 'unsafeWindow' variable similar to how greasemonkey scripts |
| 119 // implement access to it. We expose a 'safe' window object as 'window' that |
| 120 // only has access to a subset of the actual window's native properties. |
| 121 |
| 122 // Create the window variable and assign it to 'this' which is the context |
| 123 // of the global scope. Doing this will make variables defined in the global |
| 124 // scope or defined as properties of window be one and the same. |
| 125 window = this; |
| 126 |
| 127 // Now expose a subset of the Window interface defined at |
| 118 // http://www.w3.org/TR/html5/browsers.html#the-window-object | 128 // http://www.w3.org/TR/html5/browsers.html#the-window-object |
| 119 // to the global namespace. We purposely skip all event handler | 129 // to the global namespace and to the 'safe' window object. We purposely skip |
| 120 // attributes (e.g. onclick). | 130 // all event handler attributes (e.g. onclick). |
| 121 | 131 |
| 122 // Browsing context. | 132 // Browsing context. |
| 123 self = window.self; | 133 self = unsafeWindow.self; |
| 124 document = window.document; | 134 document = unsafeWindow.document; |
| 125 name = window.name; | 135 name = unsafeWindow.name; |
| 126 location = window.location; | 136 location = unsafeWindow.location; |
| 127 history = window.history; | 137 history = unsafeWindow.history; |
| 128 undoManager = window.undoManager; | 138 undoManager = unsafeWindow.undoManager; |
| 129 locationbar = window.locationbar; | 139 locationbar = unsafeWindow.locationbar; |
| 130 menubar = window.menubar; | 140 menubar = unsafeWindow.menubar; |
| 131 scrollbars = window.scrollbars; | 141 scrollbars = unsafeWindow.scrollbars; |
| 132 statusbar = window.statusbar; | 142 statusbar = unsafeWindow.statusbar; |
| 133 toolbar = window.toolbar; | 143 toolbar = unsafeWindow.toolbar; |
| 134 close = window.close; | 144 close = unsafeWindow.close; |
| 135 stop = window.stop; | 145 stop = unsafeWindow.stop; |
| 136 focus = window.focus; | 146 focus = unsafeWindow.focus; |
| 137 blur = window.blur; | 147 blur = unsafeWindow.blur; |
| 138 | 148 |
| 139 // Other browsing contexts. | 149 // Other browsing contexts. |
| 140 frames = window.frames; | 150 frames = unsafeWindow.frames; |
| 141 length = window.length; | 151 length = unsafeWindow.length; |
| 142 top = window.top; | 152 top = unsafeWindow.top; |
| 143 opener = window.opener; | 153 opener = unsafeWindow.opener; |
| 144 parent = window.parent; | 154 parent = unsafeWindow.parent; |
| 145 frameElement = window.frameElement; | 155 frameElement = unsafeWindow.frameElement; |
| 146 open = window.open; | 156 open = unsafeWindow.open; |
| 147 | 157 |
| 148 // User agent. | 158 // User agent. |
| 149 navigator = window.navigator; | 159 navigator = unsafeWindow.navigator; |
| 150 applicationCache = window.applicationCache; | 160 applicationCache = unsafeWindow.applicationCache; |
| 151 | 161 |
| 152 // User prompts. | 162 // User prompts. |
| 153 alert = window.alert; | 163 alert = unsafeWindow.alert; |
| 154 confirm = window.confirm; | 164 confirm = unsafeWindow.confirm; |
| 155 prompt = window.prompt; | 165 prompt = unsafeWindow.prompt; |
| 156 print = window.print; | 166 print = unsafeWindow.print; |
| 157 showModalDialog = window.showModalDialog; | 167 showModalDialog = unsafeWindow.showModalDialog; |
| 158 | 168 |
| 159 // EventTarget interface. | 169 // EventTarget interface. |
| 160 addEventListener = window.addEventListener; | 170 addEventListener = unsafeWindow.addEventListener; |
| 161 removeEventListener = window.removeEventListener; | 171 removeEventListener = unsafeWindow.removeEventListener; |
| 162 dispatchEvent = window.dispatchEvent; | 172 dispatchEvent = unsafeWindow.dispatchEvent; |
| 163 | 173 |
| 164 // Old IE event model. | 174 // Old IE event model. |
| 165 attachEvent = window.attachEvent; | 175 attachEvent = unsafeWindow.attachEvent; |
| 166 detachEvent = window.detachEvent; | 176 detachEvent = unsafeWindow.detachEvent; |
| 167 }; | 177 }; |
| 168 | 178 |
| 169 console.log = console.log || function (msg) { | 179 console.log = console.log || function (msg) { |
| 170 if (nativeContentScriptApi) | 180 if (nativeContentScriptApi) |
| 171 nativeContentScriptApi.Log("info", msg); | 181 nativeContentScriptApi.Log("info", msg); |
| 172 }; | 182 }; |
| 173 | 183 |
| 174 console.error = console.error || function (msg) { | 184 console.error = console.error || function (msg) { |
| 175 if (nativeContentScriptApi) | 185 if (nativeContentScriptApi) |
| 176 nativeContentScriptApi.Log("error", msg); | 186 nativeContentScriptApi.Log("error", msg); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 189 | 199 |
| 190 for (; from < len; from++) { | 200 for (; from < len; from++) { |
| 191 if (from in this && this[from] === elt) | 201 if (from in this && this[from] === elt) |
| 192 return from; | 202 return from; |
| 193 } | 203 } |
| 194 return -1; | 204 return -1; |
| 195 } | 205 } |
| 196 }; | 206 }; |
| 197 | 207 |
| 198 })(); | 208 })(); |
| OLD | NEW |