diff --git a/.eslintrc b/.eslintrc index a4ac3f0748d..69b7b803c2b 100644 --- a/.eslintrc +++ b/.eslintrc @@ -26,8 +26,8 @@ clearTimeout: true, setInterval: true, clearInterval: true, + CSSStyleSheet: true, Blob: true, - cvox: true, alert: true, prompt: true, XMLHttpRequest: true, diff --git a/demo/csp-simple.html b/demo/csp-simple.html new file mode 100644 index 00000000000..e1d66f7cabd --- /dev/null +++ b/demo/csp-simple.html @@ -0,0 +1,34 @@ + + + + + + + Editor + + +

+
+
+
+
+
+
+
+
+
diff --git a/demo/csp.html b/demo/csp.html
index a03f0fcae37..77f08a2ebf8 100644
--- a/demo/csp.html
+++ b/demo/csp.html
@@ -6,7 +6,7 @@
   
   Editor
diff --git a/src/lib/dom.js b/src/lib/dom.js
index 6a53ef8ae11..c1ffbda13e9 100644
--- a/src/lib/dom.js
+++ b/src/lib/dom.js
@@ -260,15 +260,38 @@ function importCssString(cssText, id, target) {
     if (id)
         cssText += "\n/*# sourceURL=ace/css/" + id + " */";
     
+    if (!USE_STYLE_TAG) {
+        try {
+            var stylesheet = styles[id];
+            if (!stylesheet) {
+                stylesheet = styles[id] = new CSSStyleSheet();
+                stylesheet.replaceSync(cssText);
+            }
+            container.adoptedStyleSheets.push(stylesheet);
+            USE_STYLE_TAG = false;
+            return;
+        } catch(e) {
+            if (USE_STYLE_TAG === null) {
+                USE_STYLE_TAG = true;
+            } else {
+                setTimeout(function() {
+                    throw e;
+                });
+            }
+        }
+    }
+    
     var style = exports.createElement("style");
     style.appendChild(doc.createTextNode(cssText));
     if (id)
         style.id = id;
-
     if (container == doc)
         container = exports.getDocumentHead(doc);
     container.insertBefore(style, container.firstChild);
 }
+var USE_STYLE_TAG = null;
+var styles = Object.create(null);
+
 exports.importCssString = importCssString;
 
 /**