| OLD | NEW |
| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 72 } |
| 73 } | 73 } |
| 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 isInlineFrame(element) | 82 function isFrameWithoutContentScript(element) |
| 83 { | 83 { |
| 84 var contentDocument; | 84 var contentDocument; |
| 85 try | 85 try |
| 86 { | 86 { |
| 87 contentDocument = element.contentDocument; | 87 contentDocument = element.contentDocument; |
| 88 } | 88 } |
| 89 catch (e) | 89 catch (e) |
| 90 { | 90 { |
| 91 return false; // third-party | 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. |
| 93 return false; |
| 92 } | 94 } |
| 93 | 95 |
| 96 // The element isn't a <frame>, <iframe> or <object> with "data" attribute. |
| 94 if (!contentDocument) | 97 if (!contentDocument) |
| 95 return false; // not a frame | 98 return false; |
| 96 | 99 |
| 97 return contentDocument.location.protocol == "about:"; | 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. |
| 102 // Those are dynamically created frames as well as frames |
| 103 // with "about:blank", "about:srcdoc" and "javascript:" URL. |
| 104 return !("isFrameWithoutContentScript" in contentDocument.defaultView); |
| 98 } | 105 } |
| 99 | 106 |
| 100 function reinjectRulesWhenRemoved(document, style) | 107 function reinjectRulesWhenRemoved(document, style) |
| 101 { | 108 { |
| 102 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve
r; | 109 var MutationObserver = window.MutationObserver || window.WebKitMutationObserve
r; |
| 103 if (!MutationObserver) | 110 if (!MutationObserver) |
| 104 return; | 111 return; |
| 105 | 112 |
| 106 var observer = new MutationObserver(function(mutations) | 113 var observer = new MutationObserver(function(mutations) |
| 107 { | 114 { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 { | 256 { |
| 250 var element = event.target; | 257 var element = event.target; |
| 251 | 258 |
| 252 if (/^i?frame$/.test(element.localName)) | 259 if (/^i?frame$/.test(element.localName)) |
| 253 checkCollapse(element); | 260 checkCollapse(element); |
| 254 | 261 |
| 255 // prior to Chrome 37, content scripts cannot run on about:blank, | 262 // prior to Chrome 37, content scripts cannot run on about:blank, |
| 256 // about:srcdoc and javascript: URLs. Moreover, as of Chrome 40 | 263 // about:srcdoc and javascript: URLs. Moreover, as of Chrome 40 |
| 257 // "load" and "error" events aren't dispatched there. So we have | 264 // "load" and "error" events aren't dispatched there. So we have |
| 258 // to apply element hiding and collapsing from the parent frame. | 265 // to apply element hiding and collapsing from the parent frame. |
| 259 if (/\bChrome\//.test(navigator.userAgent) && isInlineFrame(element)) | 266 if (/\bChrome\//.test(navigator.userAgent) && isFrameWithoutContentScript(el
ement)) |
| 260 { | 267 { |
| 261 init(element.contentDocument); | 268 init(element.contentDocument); |
| 262 | 269 |
| 263 for (var tagName in typeMap) | 270 for (var tagName in typeMap) |
| 264 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam
e(tagName), checkCollapse); | 271 Array.prototype.forEach.call(element.contentDocument.getElementsByTagNam
e(tagName), checkCollapse); |
| 265 } | 272 } |
| 266 }, true); | 273 }, true); |
| 267 | 274 |
| 268 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); | 275 ext.backgroundPage.sendMessage({type: "get-selectors"}, setElemhideCSSRules); |
| 269 } | 276 } |
| 270 | 277 |
| 271 if (document instanceof HTMLDocument) | 278 if (document instanceof HTMLDocument) |
| 272 { | 279 { |
| 273 checkSitekey(); | 280 checkSitekey(); |
| 274 init(document); | 281 init(document); |
| 275 } | 282 } |
| OLD | NEW |