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

Unified Diff: include.preload.js

Issue 6677078657204224: Issue 2084 - Detect our content script instead checking for anonymous frames (Closed)
Patch Set: Use contentDocument.defaultView instead contentWindow Created March 4, 2015, 8:35 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include.preload.js
===================================================================
--- a/include.preload.js
+++ b/include.preload.js
@@ -79,7 +79,7 @@
ext.backgroundPage.sendMessage({type: "add-sitekey", token: attr});
}
-function isInlineFrame(element)
+function isFrameWithoutContentScript(element)
{
var contentDocument;
try
@@ -88,13 +88,20 @@
}
catch (e)
{
- return false; // third-party
+ // This is a third-party frame. Hence we can't access it.
+ // But that's fine, our content script should already run there.
+ return false;
}
+ // The element isn't a <frame>, <iframe> or <object> with "data" attribute.
if (!contentDocument)
- return false; // not a frame
+ return false;
- return contentDocument.location.protocol == "about:";
+ // Return true, if the element is a first-party frame which doesn't
+ // have this function, hence our content script isn't running there.
+ // Those are dynamically created frames as well as frames
+ // with "about:blank", "about:srcdoc" and "javascript:" URL.
+ return !("isFrameWithoutContentScript" in contentDocument.defaultView);
}
function reinjectRulesWhenRemoved(document, style)
@@ -256,7 +263,7 @@
// about:srcdoc and javascript: URLs. Moreover, as of Chrome 40
// "load" and "error" events aren't dispatched there. So we have
// to apply element hiding and collapsing from the parent frame.
- if (/\bChrome\//.test(navigator.userAgent) && isInlineFrame(element))
+ if (/\bChrome\//.test(navigator.userAgent) && isFrameWithoutContentScript(element))
{
init(element.contentDocument);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld