Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: include.preload.js

Issue 4734012065054720: Issue 2634 - Consider alternative URLs for element collapsing (Closed)
Patch Set: Consider all URLs for element collapsing Created June 7, 2015, 3:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include.postload.js ('k') | lib/filterComposer.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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)
33 {
34 var url = element.getAttribute("data");
35 if (url)
36 return [url];
37
38 for (var i = 0; i < element.children.length; i++)
39 {
40 var child = element.children[i];
41 if (child.localName != "param")
42 continue;
43
44 var name = child.getAttribute("name");
45 if (name != "movie" && // Adobe Flash
46 name != "source" && // Silverlight
47 name != "src" && // Real Media + Quicktime
48 name != "FileName") // Windows Media
49 continue;
50
51 var value = child.getAttribute("value");
52 if (!value)
53 continue;
54
55 return [value];
56 }
57
58 return [];
59 }
60
61 function getURLsFromAttributes(element)
62 {
63 var urls = [];
64
65 if (element.src)
66 urls.push(element.src);
67
68 if (element.srcset)
69 {
70 var candidates = element.srcset.split(",");
71 for (var i = 0; i < candidates.length; i++)
72 {
73 var url = candidates[i].trim().replace(/\s+\S+$/, "");
74 if (url)
75 urls.push(url);
76 }
77 }
78
79 return urls;
80 }
81
82 function getURLsFromMediaElement(element)
83 {
84 var urls = getURLsFromAttributes(element);
85
86 for (var i = 0; i < element.children.length; i++)
87 {
88 var child = element.children[i];
89 if (child.localName == "source" || child.localName == "track")
90 urls.push.apply(urls, getURLsFromAttributes(child));
91 }
92
93 if (element.poster)
94 urls.push(element.poster);
95
96 return urls;
97 }
98
99 function getURLsFromElement(element)
100 {
101 var urls;
102 switch (element.localName)
103 {
104 case "object":
105 urls = getURLsFromObjectElement(element);
106 break;
107
108 case "video":
109 case "audio":
110 case "picture":
111 urls = getURLsFromMediaElement(element);
112 break;
113
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;
126 }
127
32 function checkCollapse(element) 128 function checkCollapse(element)
33 { 129 {
34 var tag = element.localName; 130 var tag = element.localName;
35 if (tag in typeMap) 131 if (tag in typeMap)
36 { 132 {
37 // This element failed loading, did we block it? 133 // This element failed loading, did we block it?
38 var url = element.src; 134 var urls = getURLsFromElement(element);
39 if (!url || !/^https?:/i.test(url)) 135 if (urls.length == 0)
40 return; 136 return;
41 137
42 ext.backgroundPage.sendMessage( 138 ext.backgroundPage.sendMessage(
43 { 139 {
44 type: "should-collapse", 140 type: "should-collapse",
45 url: url, 141 urls: urls,
46 mediatype: typeMap[tag] 142 mediatype: typeMap[tag],
143 baseURL: document.location.href
47 }, 144 },
48 145
49 function(response) 146 function(response)
50 { 147 {
51 if (response && element.parentNode) 148 if (response && element.parentNode)
52 { 149 {
53 var property = "display"; 150 var property = "display";
54 var value = "none"; 151 var value = "none";
55 152
56 // <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
298 }, true); 395 }, true);
299 396
300 return updateStylesheet; 397 return updateStylesheet;
301 } 398 }
302 399
303 if (document instanceof HTMLDocument) 400 if (document instanceof HTMLDocument)
304 { 401 {
305 checkSitekey(); 402 checkSitekey();
306 window.updateStylesheet = init(document); 403 window.updateStylesheet = init(document);
307 } 404 }
OLDNEW
« no previous file with comments | « include.postload.js ('k') | lib/filterComposer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld