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

Side by Side Diff: include.preload.js

Issue 8722030: Topic 11337 - Generalized placeholder blocking approach to cover image buttons and HTML5 media (Closed)
Patch Set: Created Oct. 31, 2012, 1:28 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 | « no previous file | no next file » | 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 the Adblock Plus extension, 2 * This file is part of the Adblock Plus extension,
3 * Copyright (C) 2006-2012 Eyeo GmbH 3 * Copyright (C) 2006-2012 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // So we split the elemhide selectors into groups. 46 // So we split the elemhide selectors into groups.
47 for (var i = 0, j = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE, j++) 47 for (var i = 0, j = 0; i < selectors.length; i += SELECTOR_GROUP_SIZE, j++)
48 { 48 {
49 var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", "); 49 var selector = selectors.slice(i, i + SELECTOR_GROUP_SIZE).join(", ");
50 elt.sheet.insertRule(selector + " { display: none !important; }", j); 50 elt.sheet.insertRule(selector + " { display: none !important; }", j);
51 } 51 }
52 } 52 }
53 setRules(); 53 setRules();
54 } 54 }
55 55
56 var typeMap = {
57 "img": "IMAGE",
58 "input": "IMAGE",
59 "audio": "MEDIA",
60 "video": "MEDIA",
61 "iframe": "SUBDOCUMENT"
62 };
63
56 function checkCollapse(event) 64 function checkCollapse(event)
57 { 65 {
58 var target = event.target; 66 var target = event.target;
59 if ((event.type == "error" && target instanceof HTMLImageElement) || 67 var tag = target.localName;
60 (event.type == "load" && target instanceof HTMLIFrameElement)) 68 if (tag in typeMap && event.type == (tag == "iframe" ? "load" : "error"))
61 { 69 {
62 // This element failed loading, did we block it? 70 // This element failed loading, did we block it?
63 var url = target.src; 71 var url = target.src;
64 if (!url) 72 if (!url)
65 return; 73 return;
66 74
67 var type = (target instanceof HTMLImageElement ? "IMAGE": "SUBDOCUMENT"); 75 var type = typeMap[tag];
68 chrome.extension.sendRequest({reqtype: "should-collapse", url: url, document Url: document.URL, type: type}, function(response) 76 chrome.extension.sendRequest({reqtype: "should-collapse", url: url, document Url: document.URL, type: type}, function(response)
69 { 77 {
70 if (response && target.parentNode) 78 if (response && target.parentNode)
71 target.parentNode.removeChild(target); 79 target.parentNode.removeChild(target);
72 }); 80 });
73 } 81 }
74 } 82 }
75 83
76 function sendRequests() 84 function init()
77 { 85 {
78 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything 86 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything
79 if (!(document.documentElement instanceof HTMLElement)) 87 if (!(document.documentElement instanceof HTMLElement))
80 return; 88 return;
81 89
90 document.addEventListener("error", checkCollapse, true);
91 document.addEventListener("load", checkCollapse, true);
92
82 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response) 93 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response)
83 { 94 {
84 setElemhideCSSRules(response.selectors); 95 setElemhideCSSRules(response.selectors);
85 }); 96 });
86 } 97 }
87 98
88 document.addEventListener("error", checkCollapse, true);
89 document.addEventListener("load", checkCollapse, true);
90
91 // In Chrome 18 the document might not be initialized yet 99 // In Chrome 18 the document might not be initialized yet
92 if (document.documentElement) 100 if (document.documentElement)
93 sendRequests(); 101 init();
94 else 102 else
95 window.setTimeout(sendRequests, 0); 103 window.setTimeout(init, 0);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld