| LEFT | RIGHT |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-2015 Eyeo GmbH | 3 * Copyright (C) 2006-2015 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 11 matching lines...) Expand all Loading... |
| 22 "input": "IMAGE", | 22 "input": "IMAGE", |
| 23 "picture": "IMAGE", | 23 "picture": "IMAGE", |
| 24 "audio": "MEDIA", | 24 "audio": "MEDIA", |
| 25 "video": "MEDIA", | 25 "video": "MEDIA", |
| 26 "frame": "SUBDOCUMENT", | 26 "frame": "SUBDOCUMENT", |
| 27 "iframe": "SUBDOCUMENT", | 27 "iframe": "SUBDOCUMENT", |
| 28 "object": "OBJECT", | 28 "object": "OBJECT", |
| 29 "embed": "OBJECT" | 29 "embed": "OBJECT" |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 function getURLsFromObjectElement(element) | 32 function getURLsFromObjectElement(element) |
| 33 { | 33 { |
| 34 var url = element.getAttribute("data"); | 34 var url = element.getAttribute("data"); |
| 35 if (url) | 35 if (url) |
| 36 return [url]; | 36 return [url]; |
| 37 | 37 |
| 38 for (var i = 0; i < element.children.length; i++) | 38 for (var i = 0; i < element.children.length; i++) |
| 39 { | 39 { |
| 40 var child = element.children[i]; | 40 var child = element.children[i]; |
| 41 if (child.localName != "param") | 41 if (child.localName != "param") |
| 42 continue; | 42 continue; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 if (child.localName == "source" || child.localName == "track") | 89 if (child.localName == "source" || child.localName == "track") |
| 90 urls.push.apply(urls, getURLsFromAttributes(child)); | 90 urls.push.apply(urls, getURLsFromAttributes(child)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 if (element.poster) | 93 if (element.poster) |
| 94 urls.push(element.poster); | 94 urls.push(element.poster); |
| 95 | 95 |
| 96 return urls; | 96 return urls; |
| 97 } | 97 } |
| 98 | 98 |
| 99 function getURLsFromElement(element) { | 99 function getURLsFromElement(element) |
| 100 { |
| 101 var urls; |
| 100 switch (element.localName) | 102 switch (element.localName) |
| 101 { | 103 { |
| 102 case "object": | 104 case "object": |
| 103 return getURLsFromObjectElement(element); | 105 urls = getURLsFromObjectElement(element); |
| 106 break; |
| 104 | 107 |
| 105 case "video": | 108 case "video": |
| 106 case "audio": | 109 case "audio": |
| 107 case "picture": | 110 case "picture": |
| 108 return getURLsFromMediaElement(element); | 111 urls = getURLsFromMediaElement(element); |
| 109 } | 112 break; |
| 110 | 113 |
| 111 return getURLsFromAttributes(element); | 114 default: |
| 115 urls = getURLsFromAttributes(element); |
| 116 break; |
| 117 } |
| 118 |
| 119 for (var i = 0; i < urls.length; i++) |
| 120 { |
| 121 if (/^(?!https?:)[\w-]+:/i.test(urls[i])) |
| 122 urls.splice(i--, 1); |
| 123 } |
| 124 |
| 125 return urls; |
| 112 } | 126 } |
| 113 | 127 |
| 114 function checkCollapse(element) | 128 function checkCollapse(element) |
| 115 { | 129 { |
| 116 var tag = element.localName; | 130 var tag = element.localName; |
| 117 if (tag in typeMap) | 131 if (tag in typeMap) |
| 118 { | 132 { |
| 119 // This element failed loading, did we block it? | 133 // This element failed loading, did we block it? |
| 120 var url = element.src; | 134 var urls = getURLsFromElement(element); |
| 121 if (!url || !/^https?:/i.test(url)) | 135 if (urls.length == 0) |
| 122 return; | 136 return; |
| 123 | 137 |
| 124 ext.backgroundPage.sendMessage( | 138 ext.backgroundPage.sendMessage( |
| 125 { | 139 { |
| 126 type: "should-collapse", | 140 type: "should-collapse", |
| 127 url: url, | 141 urls: urls, |
| 128 mediatype: typeMap[tag] | 142 mediatype: typeMap[tag], |
| 143 baseURL: document.location.href |
| 129 }, | 144 }, |
| 130 | 145 |
| 131 function(response) | 146 function(response) |
| 132 { | 147 { |
| 133 if (response && element.parentNode) | 148 if (response && element.parentNode) |
| 134 { | 149 { |
| 135 var property = "display"; | 150 var property = "display"; |
| 136 var value = "none"; | 151 var value = "none"; |
| 137 | 152 |
| 138 // <frame> cannot be removed, doing that will mess up the frameset | 153 // <frame> cannot be removed, doing that will mess up the frameset |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 }, true); | 395 }, true); |
| 381 | 396 |
| 382 return updateStylesheet; | 397 return updateStylesheet; |
| 383 } | 398 } |
| 384 | 399 |
| 385 if (document instanceof HTMLDocument) | 400 if (document instanceof HTMLDocument) |
| 386 { | 401 { |
| 387 checkSitekey(); | 402 checkSitekey(); |
| 388 window.updateStylesheet = init(document); | 403 window.updateStylesheet = init(document); |
| 389 } | 404 } |
| LEFT | RIGHT |