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

Side by Side Diff: include.preload.js

Issue 9756009: Make sure to collapse <frame> tags as well (Closed)
Patch Set: Created March 11, 2013, 1:59 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 } 56 }
57 setRules(); 57 setRules();
58 } 58 }
59 59
60 var typeMap = { 60 var typeMap = {
61 "img": "IMAGE", 61 "img": "IMAGE",
62 "input": "IMAGE", 62 "input": "IMAGE",
63 "audio": "MEDIA", 63 "audio": "MEDIA",
64 "video": "MEDIA", 64 "video": "MEDIA",
65 "frame": "SUBDOCUMENT",
65 "iframe": "SUBDOCUMENT" 66 "iframe": "SUBDOCUMENT"
66 }; 67 };
67 68
68 function checkCollapse(event) 69 function checkCollapse(event)
69 { 70 {
70 var target = event.target; 71 var target = event.target;
71 var tag = target.localName; 72 var tag = target.localName;
72 if (tag in typeMap && event.type == (tag == "iframe" ? "load" : "error")) 73 var expectedEvent = (tag == "iframe" || tag == "frame" ? "load" : "error");
74 if (tag in typeMap && event.type == expectedEvent)
73 { 75 {
74 // This element failed loading, did we block it? 76 // This element failed loading, did we block it?
75 var url = target.src; 77 var url = target.src;
76 if (!url) 78 if (!url)
77 return; 79 return;
78 80
79 var type = typeMap[tag]; 81 var type = typeMap[tag];
80 chrome.extension.sendRequest({reqtype: "should-collapse", url: url, document Url: document.URL, type: type}, function(response) 82 chrome.extension.sendRequest({reqtype: "should-collapse", url: url, document Url: document.URL, type: type}, function(response)
81 { 83 {
82 if (response && target.parentNode) 84 if (response && target.parentNode)
83 target.parentNode.removeChild(target); 85 {
86 // <frame> cannot be removed, doing that will mess up the frameset
87 if (tag == "frame")
88 target.style.setProperty("visibility", "hidden", "!important");
89 else
90 target.parentNode.removeChild(target);
91 }
84 }); 92 });
85 } 93 }
86 } 94 }
87 95
88 function init() 96 function init()
89 { 97 {
90 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything 98 // Make sure this is really an HTML page, as Chrome runs these scripts on just about everything
91 if (!(document.documentElement instanceof HTMLElement)) 99 if (!(document.documentElement instanceof HTMLElement))
92 return; 100 return;
93 101
94 document.addEventListener("error", checkCollapse, true); 102 document.addEventListener("error", checkCollapse, true);
95 document.addEventListener("load", checkCollapse, true); 103 document.addEventListener("load", checkCollapse, true);
96 104
97 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response) 105 chrome.extension.sendRequest({reqtype: "get-settings", selectors: true, frameU rl: window.location.href}, function(response)
98 { 106 {
99 setElemhideCSSRules(response.selectors); 107 setElemhideCSSRules(response.selectors);
100 }); 108 });
101 } 109 }
102 110
103 // In Chrome 18 the document might not be initialized yet 111 // In Chrome 18 the document might not be initialized yet
104 if (document.documentElement) 112 if (document.documentElement)
105 init(); 113 init();
106 else 114 else
107 window.setTimeout(init, 0); 115 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