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

Delta Between Two Patch Sets: include.preload.js

Issue 5666188336037888: Issue 581 - Fixed element hiding/collapsing in anonymous frames on Chrome (Closed)
Left Patch Set: Rely on frame's src attribute again Created June 3, 2014, 8:34 a.m.
Right Patch Set: Addressed comments Created June 17, 2014, 2:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | lib/basedomain.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 } 58 }
59 } 59 }
60 60
61 function checkExceptionKey() 61 function checkExceptionKey()
62 { 62 {
63 var attr = document.documentElement.getAttribute("data-adblockkey"); 63 var attr = document.documentElement.getAttribute("data-adblockkey");
64 if (attr) 64 if (attr)
65 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr}); 65 ext.backgroundPage.sendMessage({type: "add-key-exception", token: attr});
66 } 66 }
67 67
68 function hasInlineURL(element, attribute)
69 {
70 var value = element.getAttribute(attribute);
71 return value == null || /^\s*(javascript:|about:|$)/i.test(value);
72 }
73
74 function isInlineFrame(element)
75 {
76 switch (element.localName)
77 {
78 case "iframe":
79 return hasInlineURL(element, "src") || element.hasAttribute("srcdoc");
80 case "frame":
81 return hasInlineURL(element, "src");
82 case "object":
83 return hasInlineURL(element, "data") && element.contentDocument;
84 default:
85 return false;
86 }
87 }
88
68 // Converts relative to absolute URL 89 // Converts relative to absolute URL
69 // e.g.: foo.swf on http://example.com/whatever/bar.html 90 // e.g.: foo.swf on http://example.com/whatever/bar.html
70 // -> http://example.com/whatever/foo.swf 91 // -> http://example.com/whatever/foo.swf
71 function relativeToAbsoluteUrl(url) 92 function relativeToAbsoluteUrl(url)
72 { 93 {
73 // If URL is already absolute, don't mess with it 94 // If URL is already absolute, don't mess with it
74 if (!url || /^[\w\-]+:/i.test(url)) 95 if (!url || /^[\w\-]+:/i.test(url))
75 return url; 96 return url;
76 97
77 // Leading / means absolute path 98 // Leading / means absolute path
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
183 document.addEventListener("error", function(event) 204 document.addEventListener("error", function(event)
184 { 205 {
185 checkCollapse(event.target); 206 checkCollapse(event.target);
186 }, true); 207 }, true);
187 208
188 document.addEventListener("load", function(event) 209 document.addEventListener("load", function(event)
189 { 210 {
190 var element = event.target; 211 var element = event.target;
191 212
192 if (/^i?frame$/.test(element.localName)) 213 if (/^i?frame$/.test(element.localName))
193 {
194 checkCollapse(element); 214 checkCollapse(element);
195 215
196 if (fixInlineFrames && (element.hasAttribute("srcdoc") || !element.hasAttr ibute("src") || 216 if (fixInlineFrames && isInlineFrame(element))
197 /^\s*(javascript:|about:|$)/i.test(element.getAttr ibute("src")))) 217 {
Wladimir Palant 2014/06/04 14:12:49 What about data: URLs? Note that checking whether
Sebastian Noack 2014/06/04 16:12:30 This check intentionally don't match data: URLs, s
198 { 218 init(element.contentDocument);
199 var contentDocument = element.contentDocument; 219
200 init(contentDocument); 220 for (var tagName in typeMap)
Wladimir Palant 2014/06/04 14:12:49 Nit: It seems that the contentDocument variable is
Sebastian Noack 2014/06/04 16:12:30 Done.
201 221 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam e(tagName), checkCollapse);
202 for (var tagName in typeMap)
203 Array.prototype.forEach.call(contentDocument.getElementsByTagName(tagN ame), checkCollapse);
204 }
205 } 222 }
206 }, true); 223 }, true);
207 224
208 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); 225 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules);
209 } 226 }
210 227
211 if (document.documentElement instanceof HTMLElement) 228 if (document.documentElement instanceof HTMLElement)
212 { 229 {
213 checkExceptionKey(); 230 checkExceptionKey();
214 init(document); 231 init(document);
215 } 232 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld