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

Unified Diff: include.preload.js

Issue 5978149049335808: Issue 1290 - Added support for un-prefixedcreateShadowRoot (Closed)
Patch Set: Addressed comment Created Aug. 29, 2014, 10:18 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
@@ -114,34 +114,20 @@
function init(document)
{
- var canUseShadow = "webkitCreateShadowRoot" in document.documentElement;
- var fixInlineFrames = false;
-
+ // prior to Chrome 37, content scripts don't run on about:blank
+ // and about:srcdoc. So we have to apply element hiding and collapsing
+ // from the parent frame, when inline frames are loaded.
var match = navigator.userAgent.match(/\bChrome\/(\d+)/);
- if (match)
- {
- var chromeVersion = parseInt(match[1]);
-
- // the <shadow> element is ignored in Chrome 32 (#309). Also Chrome 31-33
- // crashes in some situations on some pages when using shadow DOM (#498).
- // So we must not use Shadow DOM on those versions of Chrome.
- if (chromeVersion >= 31 && chromeVersion <= 33)
- canUseShadow = false;
-
- // prior to Chrome 37, content scripts don't run on about:blank
- // and about:srcdoc. So we have to apply element hiding and collapsing
- // from the parent frame, when inline frames are loaded.
- if (chromeVersion < 37)
- fixInlineFrames = true;
- }
+ var fixInlineFrames = match && parseInt(match[1]) < 37);
// use Shadow DOM if available to don't mess with web pages that
// rely on the order of their own <style> tags (#309). However we
// must not create the shadow root in the response callback passed
// to sendMessage(), otherwise Chrome breaks some websites (#450).
- if (canUseShadow)
+ var shadow = null;
+ if ("createShadowRoot" in document.documentElement)
{
- var shadow = document.documentElement.webkitCreateShadowRoot();
+ shadow = document.documentElement.createShadowRoot();
shadow.appendChild(document.createElement("shadow"));
}
@@ -154,22 +140,12 @@
var style = document.createElement("style");
style.setAttribute("type", "text/css");
- if (canUseShadow)
+ if (shadow)
{
shadow.appendChild(style);
- try
- {
- document.querySelector("::content");
-
- for (var i = 0; i < selectors.length; i++)
- selectors[i] = "::content " + selectors[i];
- }
- catch (e)
- {
- for (var i = 0; i < selectors.length; i++)
- selectors[i] = "::-webkit-distributed(" + selectors[i] + ")";
- }
+ for (var i = 0; i < selectors.length; i++)
+ selectors[i] = "::content " + selectors[i];
}
else
{
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld