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

Delta Between Two Patch Sets: include.preload.js

Issue 6677078657204224: Issue 2084 - Detect our content script instead checking for anonymous frames (Closed)
Left Patch Set: Created March 4, 2015, 7:19 p.m.
Right Patch Set: Use contentDocument.defaultView instead contentWindow Created March 4, 2015, 8:35 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 | « no previous file | no next file » | 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 <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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 function checkSitekey() 75 function checkSitekey()
76 { 76 {
77 var attr = document.documentElement.getAttribute("data-adblockkey"); 77 var attr = document.documentElement.getAttribute("data-adblockkey");
78 if (attr) 78 if (attr)
79 ext.backgroundPage.sendMessage({type: "add-sitekey", token: attr}); 79 ext.backgroundPage.sendMessage({type: "add-sitekey", token: attr});
80 } 80 }
81 81
82 function isFrameWithoutContentScript(element) 82 function isFrameWithoutContentScript(element)
83 { 83 {
84 var contentWindow; 84 var contentDocument;
85 try 85 try
86 { 86 {
87 contentWindow = element.contentWindow; 87 contentDocument = element.contentDocument;
Wladimir Palant 2015/03/04 19:31:36 Accessing element.contentWindow is actually allowe
Sebastian Noack 2015/03/04 20:36:13 You are right. Also I realized that we can actuall
88 } 88 }
89 catch (e) 89 catch (e)
90 { 90 {
91 // This is a third-party frame. Hence we can't access it. 91 // This is a third-party frame. Hence we can't access it.
92 // But that's fine, our content script should already run there. 92 // But that's fine, our content script should already run there.
93 return false; 93 return false;
94 } 94 }
95 95
96 // The element isn't a <frame>, <iframe> or <object> with "data" attribute. 96 // The element isn't a <frame>, <iframe> or <object> with "data" attribute.
97 if (!contentWindow) 97 if (!contentDocument)
98 return false; 98 return false;
99 99
100 // Return true, if the element is a first-party frame which doesn't 100 // Return true, if the element is a first-party frame which doesn't
101 // have this function, hence our content script isn't running there. 101 // have this function, hence our content script isn't running there.
102 // Those are dynamically created frames as well as frames 102 // Those are dynamically created frames as well as frames
103 // with "about:blank", "about:srcdoc" and "javascript:" URL. 103 // with "about:blank", "about:srcdoc" and "javascript:" URL.
104 return !("isFrameWithoutContentScript" in contentWindow); 104 return !("isFrameWithoutContentScript" in contentDocument.defaultView);
Wladimir Palant 2015/03/04 19:31:36 I wonder whether there can be any timing issues he
Sebastian Noack 2015/03/04 20:36:13 Yes, I tested it on a few websites of course, but
105 } 105 }
106 106
107 function reinjectRulesWhenRemoved(document, style) 107 function reinjectRulesWhenRemoved(document, style)
108 { 108 {
109 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve r; 109 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve r;
110 if (!MutationObserver) 110 if (!MutationObserver)
111 return; 111 return;
112 112
113 var observer = new MutationObserver(function(mutations) 113 var observer = new MutationObserver(function(mutations)
114 { 114 {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 }, true); 273 }, true);
274 274
275 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); 275 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules);
276 } 276 }
277 277
278 if (document instanceof HTMLDocument) 278 if (document instanceof HTMLDocument)
279 { 279 {
280 checkSitekey(); 280 checkSitekey();
281 init(document); 281 init(document);
282 } 282 }
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld