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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 document.removeEventListener("visibilitychange", onVisibilitychange); | 51 document.removeEventListener("visibilitychange", onVisibilitychange); |
52 }; | 52 }; |
53 document.addEventListener("visibilitychange", onVisibilitychange); | 53 document.addEventListener("visibilitychange", onVisibilitychange); |
54 } | 54 } |
55 | 55 |
56 | 56 |
57 /* Web requests */ | 57 /* Web requests */ |
58 | 58 |
59 document.addEventListener("beforeload", function(event) | 59 document.addEventListener("beforeload", function(event) |
60 { | 60 { |
| 61 var url = relativeToAbsoluteUrl(event.url); |
| 62 |
61 // we don't block non-HTTP requests anyway, so we can bail out | 63 // we don't block non-HTTP requests anyway, so we can bail out |
62 // without asking the background page. This is even necessary | 64 // without asking the background page. This is even necessary |
63 // because passing large data (like a photo encoded as data: URL) | 65 // because passing large data (like a photo encoded as data: URL) |
64 // to the background page, freezes Safari. | 66 // to the background page, freezes Safari. |
65 if (!/^https?:/.test(event.url)) | 67 if (!/^https?:/.test(url)) |
66 return; | 68 return; |
67 | 69 |
68 var type; | 70 var type; |
69 switch(event.target.localName) | 71 switch(event.target.localName) |
70 { | 72 { |
71 case "frame": | 73 case "frame": |
72 case "iframe": | 74 case "iframe": |
73 type = "sub_frame"; | 75 type = "sub_frame"; |
74 break; | 76 break; |
75 case "img": | 77 case "img": |
(...skipping 12 matching lines...) Expand all Loading... |
88 type = "stylesheet"; | 90 type = "stylesheet"; |
89 break; | 91 break; |
90 } | 92 } |
91 default: | 93 default: |
92 type = "other"; | 94 type = "other"; |
93 } | 95 } |
94 | 96 |
95 if (!safari.self.tab.canLoad( | 97 if (!safari.self.tab.canLoad( |
96 event, { | 98 event, { |
97 category: "webRequest", | 99 category: "webRequest", |
98 url: event.url, | 100 url: url, |
99 type: type, | 101 type: type, |
100 pageId: documentInfo.pageId, | 102 pageId: documentInfo.pageId, |
101 frameId: documentInfo.frameId | 103 frameId: documentInfo.frameId |
102 } | 104 } |
103 )) | 105 )) |
104 { | 106 { |
105 event.preventDefault(); | 107 event.preventDefault(); |
106 | 108 |
107 // Safari doesn't dispatch an "error" event when preventing an element | 109 // Safari doesn't dispatch an "error" event when preventing an element |
108 // from loading by cancelling the "beforeload" event. So we have to | 110 // from loading by cancelling the "beforeload" event. So we have to |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 messageProxy.handleResponse(event.message); | 410 messageProxy.handleResponse(event.message); |
409 break; | 411 break; |
410 case "proxyCallback": | 412 case "proxyCallback": |
411 backgroundPageProxy.handleCallback(event.message); | 413 backgroundPageProxy.handleCallback(event.message); |
412 break; | 414 break; |
413 } | 415 } |
414 } | 416 } |
415 } | 417 } |
416 }); | 418 }); |
417 })(); | 419 })(); |
OLD | NEW |