OLD | NEW |
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-2014 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 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 { | 59 { |
60 var url = resolveURL(event.url); | 60 var url = resolveURL(event.url); |
61 | 61 |
62 // we don't block non-HTTP requests anyway, so we can bail out | 62 // we don't block non-HTTP requests anyway, so we can bail out |
63 // without asking the background page. This is even necessary | 63 // without asking the background page. This is even necessary |
64 // because passing large data (like a photo encoded as data: URL) | 64 // because passing large data (like a photo encoded as data: URL) |
65 // to the background page, freezes Safari. | 65 // to the background page, freezes Safari. |
66 if (!/^https?:/.test(url)) | 66 if (!/^https?:/.test(url)) |
67 return; | 67 return; |
68 | 68 |
69 var type; | 69 var type = "other"; |
| 70 var eventName = "error"; |
| 71 |
70 switch(event.target.localName) | 72 switch(event.target.localName) |
71 { | 73 { |
72 case "frame": | 74 case "frame": |
73 case "iframe": | 75 case "iframe": |
74 type = "sub_frame"; | 76 type = "sub_frame"; |
| 77 eventName = "load"; |
75 break; | 78 break; |
76 case "img": | 79 case "img": |
77 type = "image"; | 80 type = "image"; |
78 break; | 81 break; |
79 case "object": | 82 case "object": |
80 case "embed": | 83 case "embed": |
81 type = "object"; | 84 type = "object"; |
82 break; | 85 break; |
83 case "script": | 86 case "script": |
84 type = "script"; | 87 type = "script"; |
85 break; | 88 break; |
86 case "link": | 89 case "link": |
87 if (/\bstylesheet\b/i.test(event.target.rel)) | 90 if (/\bstylesheet\b/i.test(event.target.rel)) |
88 { | |
89 type = "stylesheet"; | 91 type = "stylesheet"; |
90 break; | 92 break; |
91 } | |
92 default: | |
93 type = "other"; | |
94 } | 93 } |
95 | 94 |
96 if (!safari.self.tab.canLoad( | 95 if (!safari.self.tab.canLoad( |
97 event, { | 96 event, { |
98 category: "webRequest", | 97 category: "webRequest", |
99 url: url, | 98 url: url, |
100 type: type, | 99 type: type, |
101 pageId: documentInfo.pageId, | 100 pageId: documentInfo.pageId, |
102 frameId: documentInfo.frameId | 101 frameId: documentInfo.frameId |
103 } | 102 } |
104 )) | 103 )) |
105 { | 104 { |
106 event.preventDefault(); | 105 event.preventDefault(); |
107 | 106 |
108 // Safari doesn't dispatch an "error" event when preventing an element | 107 // Safari doesn't dispatch the expected events for elements that have been |
109 // from loading by cancelling the "beforeload" event. So we have to | 108 // prevented from loading by having their "beforeload" event cancelled. |
110 // dispatch it manually. Otherwise element collapsing wouldn't work. | 109 // That is a "load" event for blocked frames, and an "error" event for |
111 if (type != "sub_frame") | 110 // other blocked elements. We need to dispatch those events manually here |
| 111 // to avoid breaking element collapsing and pages that rely on those event
s. |
| 112 setTimeout(function() |
112 { | 113 { |
113 setTimeout(function() | 114 var evt = document.createEvent("Event"); |
114 { | 115 evt.initEvent(eventName); |
115 var evt = document.createEvent("Event"); | 116 event.target.dispatchEvent(evt); |
116 evt.initEvent("error"); | 117 }, 0); |
117 event.target.dispatchEvent(evt); | |
118 }, 0); | |
119 } | |
120 } | 118 } |
121 }, true); | 119 }, true); |
122 | 120 |
123 | 121 |
124 /* Context menus */ | 122 /* Context menus */ |
125 | 123 |
126 document.addEventListener("contextmenu", function(event) | 124 document.addEventListener("contextmenu", function(event) |
127 { | 125 { |
128 var element = event.srcElement; | 126 var element = event.srcElement; |
129 safari.self.tab.setContextMenuEventUserInfo(event, { | 127 safari.self.tab.setContextMenuEventUserInfo(event, { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 messageProxy.handleResponse(event.message); | 422 messageProxy.handleResponse(event.message); |
425 break; | 423 break; |
426 case "proxyCallback": | 424 case "proxyCallback": |
427 backgroundPageProxy.handleCallback(event.message); | 425 backgroundPageProxy.handleCallback(event.message); |
428 break; | 426 break; |
429 } | 427 } |
430 } | 428 } |
431 } | 429 } |
432 }); | 430 }); |
433 })(); | 431 })(); |
OLD | NEW |