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: Created March 4, 2015, 7:19 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,22 +79,29 @@
ext.backgroundPage.sendMessage({type: "add-sitekey", token: attr});
}
-function isInlineFrame(element)
+function isFrameWithoutContentScript(element)
{
- var contentDocument;
+ var contentWindow;
try
{
- contentDocument = element.contentDocument;
+ contentWindow = element.contentWindow;
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
}
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;
}
- if (!contentDocument)
- return false; // not a frame
+ // The element isn't a <frame>, <iframe> or <object> with "data" attribute.
+ if (!contentWindow)
+ 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 contentWindow);
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
}
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