| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <http://adblockplus.org/>, | 2 * This file is part of Adblock Plus <http://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2013 Eyeo GmbH | 3 * Copyright (C) 2006-2013 Eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 (function() | 18 (function() |
| 19 { | 19 { |
| 20 // the safari object is missing in frames created from javascript: URLs. |
| 21 // So we have to fallback to the safari object from the parent frame. |
| 22 if (!("safari" in window)) |
| 23 window.safari = window.parent.safari; |
| 24 |
| 25 |
| 20 /* Intialization */ | 26 /* Intialization */ |
| 21 | 27 |
| 22 var beforeLoadEvent = document.createEvent("Event"); | 28 var beforeLoadEvent = document.createEvent("Event"); |
| 23 beforeLoadEvent.initEvent("beforeload"); | 29 beforeLoadEvent.initEvent("beforeload"); |
| 24 | 30 |
| 25 var isTopLevel = window == window.top; | 31 var isTopLevel = window == window.top; |
| 26 var isPrerendered = document.visibilityState == "prerender"; | 32 var isPrerendered = document.visibilityState == "prerender"; |
| 27 | 33 |
| 28 var documentInfo = safari.self.tab.canLoad( | 34 var documentInfo = safari.self.tab.canLoad( |
| 29 beforeLoadEvent, | 35 beforeLoadEvent, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 category: "webRequest", | 89 category: "webRequest", |
| 84 url: event.url, | 90 url: event.url, |
| 85 type: type, | 91 type: type, |
| 86 pageId: documentInfo.pageId, | 92 pageId: documentInfo.pageId, |
| 87 frameId: documentInfo.frameId | 93 frameId: documentInfo.frameId |
| 88 } | 94 } |
| 89 )) | 95 )) |
| 90 { | 96 { |
| 91 event.preventDefault(); | 97 event.preventDefault(); |
| 92 | 98 |
| 93 // Safari doesn't dispatch an "error" or "load" event when preventing an | 99 // Safari doesn't dispatch an "error" event when preventing an element |
| 94 // element from loading by cancelling the "beforeload" event. So we have | 100 // from loading by cancelling the "beforeload" event. So we have to |
| 95 // to dispatch it manually. Otherwise element collapsing wouldn't work. | 101 // dispatch it manually. Otherwise element collapsing wouldn't work. |
| 96 var evt = document.createEvent("Event"); | 102 if (type != "sub_frame") |
| 97 evt.initEvent(type == "sub_frame" ? "load" : "error"); | 103 { |
| 98 event.target.dispatchEvent(evt); | 104 var evt = document.createEvent("Event"); |
| 105 evt.initEvent(type == "error"); |
| 106 event.target.dispatchEvent(evt); |
| 107 } |
| 99 } | 108 } |
| 100 }, true); | 109 }, true); |
| 101 | 110 |
| 102 | 111 |
| 103 /* Context menus */ | 112 /* Context menus */ |
| 104 | 113 |
| 105 document.addEventListener("contextmenu", function(event) | 114 document.addEventListener("contextmenu", function(event) |
| 106 { | 115 { |
| 107 var element = event.srcElement; | 116 var element = event.srcElement; |
| 108 safari.self.tab.setContextMenuEventUserInfo(event, { | 117 safari.self.tab.setContextMenuEventUserInfo(event, { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 131 if (!result.succeed) | 140 if (!result.succeed) |
| 132 throw result.error; | 141 throw result.error; |
| 133 }, | 142 }, |
| 134 deserializeResult: function(result) | 143 deserializeResult: function(result) |
| 135 { | 144 { |
| 136 this.checkResult(result); | 145 this.checkResult(result); |
| 137 return this.deserialize(result.result); | 146 return this.deserialize(result.result); |
| 138 }, | 147 }, |
| 139 serialize: function(obj, memo) | 148 serialize: function(obj, memo) |
| 140 { | 149 { |
| 141 if ((typeof obj == "object" || typeof obj == "function") && obj != null) | 150 if (typeof obj == "object" && obj != null || typeof obj == "function") |
| 142 { | 151 { |
| 143 if ("__proxyObjectId" in obj) | 152 if ("__proxyObjectId" in obj) |
| 144 return {type: "hosted", objectId: obj.__proxyObjectId}; | 153 return {type: "hosted", objectId: obj.__proxyObjectId}; |
| 145 | 154 |
| 146 if (typeof obj == "function") | 155 if (typeof obj == "function") |
| 147 { | 156 { |
| 148 var callbackId; | 157 var callbackId; |
| 149 if ("__proxyCallbackId" in obj) | 158 if ("__proxyCallbackId" in obj) |
| 150 callbackId = obj.__proxyCallbackId; | 159 callbackId = obj.__proxyCallbackId; |
| 151 else | 160 else |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 { | 313 { |
| 305 if (objectInfo.isFunction) | 314 if (objectInfo.isFunction) |
| 306 obj = this.createFunction(objectId); | 315 obj = this.createFunction(objectId); |
| 307 else | 316 else |
| 308 obj = {}; | 317 obj = {}; |
| 309 | 318 |
| 310 this.objects[objectId] = obj; | 319 this.objects[objectId] = obj; |
| 311 Object.defineProperty(obj, "__proxyObjectId", {value: objectId}); | 320 Object.defineProperty(obj, "__proxyObjectId", {value: objectId}); |
| 312 } | 321 } |
| 313 | 322 |
| 314 var ignored = []; | 323 var excluded = []; |
| 324 var included = []; |
| 315 if ("prototypeOf" in objectInfo) | 325 if ("prototypeOf" in objectInfo) |
| 316 { | 326 { |
| 317 var prototype = window[objectInfo.prototypeOf].prototype; | 327 var prototype = window[objectInfo.prototypeOf].prototype; |
| 318 | 328 |
| 319 ignored = Object.getOwnPropertyNames(prototype); | 329 excluded = Object.getOwnPropertyNames(prototype); |
| 320 ignored.splice(ignored.indexOf("constructor"), 1); | 330 included = ["constructor"]; |
| 321 | 331 |
| 322 obj.__proto__ = prototype; | 332 obj.__proto__ = prototype; |
| 323 } | 333 } |
| 324 else | 334 else |
| 325 { | 335 { |
| 326 if (objectInfo.isFunction) | 336 if (objectInfo.isFunction) |
| 327 ignored = Object.getOwnPropertyNames(function() {}); | 337 { |
| 328 else | 338 excluded = Object.getOwnPropertyNames(function() {}); |
| 329 ignored = []; | 339 included = ["prototype"]; |
| 340 } |
| 330 | 341 |
| 331 if ("prototypeId" in objectInfo) | 342 if ("prototypeId" in objectInfo) |
| 332 obj.__proto__ = this.getObject(objectInfo.prototypeId); | 343 obj.__proto__ = this.getObject(objectInfo.prototypeId); |
| 333 else | 344 else |
| 334 obj.__proto__ = null; | 345 obj.__proto__ = null; |
| 335 } | 346 } |
| 336 | 347 |
| 337 for (var property in objectInfo.properties) | 348 for (var property in objectInfo.properties) |
| 338 { | 349 { |
| 339 if (ignored.indexOf(property) == -1) | 350 if (excluded.indexOf(property) == -1 || included.indexOf(property) != -1
) |
| 340 { | 351 { |
| 341 var desc = Object.getOwnPropertyDescriptor(obj, property); | 352 var desc = Object.getOwnPropertyDescriptor(obj, property); |
| 342 | 353 |
| 343 if (!desc || desc.configurable) | 354 if (!desc || desc.configurable) |
| 344 { | 355 { |
| 345 Object.defineProperty(obj, property, this.createProperty( | 356 Object.defineProperty(obj, property, this.createProperty( |
| 346 property, objectInfo.properties[property].enumerable | 357 property, objectInfo.properties[property].enumerable |
| 347 )); | 358 )); |
| 348 } | 359 } |
| 349 else if (desc.writable) | 360 else if (desc.writable) |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 messageProxy.handleResponse(event.message); | 400 messageProxy.handleResponse(event.message); |
| 390 break; | 401 break; |
| 391 case "proxyCallback": | 402 case "proxyCallback": |
| 392 backgroundPageProxy.handleCallback(event.message); | 403 backgroundPageProxy.handleCallback(event.message); |
| 393 break; | 404 break; |
| 394 } | 405 } |
| 395 } | 406 } |
| 396 } | 407 } |
| 397 }); | 408 }); |
| 398 })(); | 409 })(); |
| LEFT | RIGHT |