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-2014 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 14 matching lines...) Expand all Loading... |
44 document.removeEventListener("visibilitychange", onVisibilitychange); | 50 document.removeEventListener("visibilitychange", onVisibilitychange); |
45 }; | 51 }; |
46 document.addEventListener("visibilitychange", onVisibilitychange); | 52 document.addEventListener("visibilitychange", onVisibilitychange); |
47 } | 53 } |
48 | 54 |
49 | 55 |
50 /* Web requests */ | 56 /* Web requests */ |
51 | 57 |
52 document.addEventListener("beforeload", function(event) | 58 document.addEventListener("beforeload", function(event) |
53 { | 59 { |
| 60 // we don't block non-HTTP requests anyway, so we can bail out |
| 61 // without asking the background page. This is even necessary |
| 62 // because passing large data (like a photo encoded as data: URL) |
| 63 // to the background page, freezes Safari. |
| 64 if (!/^https?:/.test(event.url)) |
| 65 return; |
| 66 |
54 var type; | 67 var type; |
55 switch(event.target.localName) | 68 switch(event.target.localName) |
56 { | 69 { |
57 case "frame": | 70 case "frame": |
58 case "iframe": | 71 case "iframe": |
59 type = "sub_frame"; | 72 type = "sub_frame"; |
60 break; | 73 break; |
61 case "img": | 74 case "img": |
62 type = "image"; | 75 type = "image"; |
63 break; | 76 break; |
(...skipping 19 matching lines...) Expand all Loading... |
83 category: "webRequest", | 96 category: "webRequest", |
84 url: event.url, | 97 url: event.url, |
85 type: type, | 98 type: type, |
86 pageId: documentInfo.pageId, | 99 pageId: documentInfo.pageId, |
87 frameId: documentInfo.frameId | 100 frameId: documentInfo.frameId |
88 } | 101 } |
89 )) | 102 )) |
90 { | 103 { |
91 event.preventDefault(); | 104 event.preventDefault(); |
92 | 105 |
93 // Safari doesn't dispatch an "error" or "load" event when preventing an | 106 // Safari doesn't dispatch an "error" event when preventing an element |
94 // element from loading by cancelling the "beforeload" event. So we have | 107 // from loading by cancelling the "beforeload" event. So we have to |
95 // to dispatch it manually. Otherwise element collapsing wouldn't work. | 108 // dispatch it manually. Otherwise element collapsing wouldn't work. |
96 var evt = document.createEvent("Event"); | 109 if (type != "sub_frame") |
97 evt.initEvent(type == "sub_frame" ? "load" : "error"); | 110 { |
98 event.target.dispatchEvent(evt); | 111 var evt = document.createEvent("Event"); |
| 112 evt.initEvent("error"); |
| 113 event.target.dispatchEvent(evt); |
| 114 } |
99 } | 115 } |
100 }, true); | 116 }, true); |
101 | 117 |
102 | 118 |
103 /* Context menus */ | 119 /* Context menus */ |
104 | 120 |
105 document.addEventListener("contextmenu", function(event) | 121 document.addEventListener("contextmenu", function(event) |
106 { | 122 { |
107 var element = event.srcElement; | 123 var element = event.srcElement; |
108 safari.self.tab.setContextMenuEventUserInfo(event, { | 124 safari.self.tab.setContextMenuEventUserInfo(event, { |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 messageProxy.handleResponse(event.message); | 396 messageProxy.handleResponse(event.message); |
381 break; | 397 break; |
382 case "proxyCallback": | 398 case "proxyCallback": |
383 backgroundPageProxy.handleCallback(event.message); | 399 backgroundPageProxy.handleCallback(event.message); |
384 break; | 400 break; |
385 } | 401 } |
386 } | 402 } |
387 } | 403 } |
388 }); | 404 }); |
389 })(); | 405 })(); |
LEFT | RIGHT |