| 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 all the expected events for elements that |
| 109 // from loading by cancelling the "beforeload" event. So we have to | 108 // have been prevented from loading by having their "beforeload" event |
| 110 // dispatch it manually. Otherwise element collapsing wouldn't work. | 109 // cancelled. "error" events are never dispatched, and since Safari 8 |
| 111 if (type != "sub_frame") | 110 // "load" events are also not dispatched, when blocking frames. |
| 111 // We need to dispatch those events manually here to avoid breaking |
| 112 // element collapsing and pages that rely on those events. |
| 113 if (type != "sub_frame" || parseInt(navigator.userAgent.match(/\bVersion\/
(\d+)/)[1], 10) >= 8) |
| 112 { | 114 { |
| 113 setTimeout(function() | 115 setTimeout(function() |
| 114 { | 116 { |
| 115 var evt = document.createEvent("Event"); | 117 var evt = document.createEvent("Event"); |
| 116 evt.initEvent("error"); | 118 evt.initEvent(eventName); |
| 117 event.target.dispatchEvent(evt); | 119 event.target.dispatchEvent(evt); |
| 118 }, 0); | 120 }, 0); |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 }, true); | 123 }, true); |
| 122 | 124 |
| 123 | 125 |
| 124 /* Context menus */ | 126 /* Context menus */ |
| 125 | 127 |
| 126 document.addEventListener("contextmenu", function(event) | 128 document.addEventListener("contextmenu", function(event) |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 424 messageProxy.handleResponse(event.message); | 426 messageProxy.handleResponse(event.message); |
| 425 break; | 427 break; |
| 426 case "proxyCallback": | 428 case "proxyCallback": |
| 427 backgroundPageProxy.handleCallback(event.message); | 429 backgroundPageProxy.handleCallback(event.message); |
| 428 break; | 430 break; |
| 429 } | 431 } |
| 430 } | 432 } |
| 431 } | 433 } |
| 432 }); | 434 }); |
| 433 })(); | 435 })(); |
| OLD | NEW |