diff options
Diffstat (limited to 'content_scripts/ui_component.coffee')
| -rw-r--r-- | content_scripts/ui_component.coffee | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index d935079d..72627f69 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -4,12 +4,16 @@ class UIComponent showing: null options: null shadowDOM: null + styleSheetGetter: null constructor: (iframeUrl, className, @handleMessage) -> styleSheet = DomUtils.createElement "style" styleSheet.type = "text/css" # Default to everything hidden while the stylesheet loads. - styleSheet.innerHTML = "@import url(\"#{chrome.runtime.getURL("content_scripts/vimium.css")}\");" + styleSheet.innerHTML = "iframe {display: none;}" + + UIComponent::styleSheetGetter ?= new AsyncDataFetcher @fetchFileContents "content_scripts/vimium.css" + @styleSheetGetter.use (styles) -> styleSheet.innerHTML = styles @iframeElement = DomUtils.createElement "iframe" extend @iframeElement, @@ -112,5 +116,27 @@ class UIComponent window.removeEventListener "focus", handler refocusSourceFrame() + # Fetch a Vimium file/resource (such as "content_scripts/vimium.css"). + # We try making an XMLHttpRequest request. That can fail (see #1817), in which case we fetch the + # file/resource via the background page. + fetchFileContents: (file) -> (callback) -> + request = new XMLHttpRequest() + + request.onload = -> + if request.status == 200 + callback request.responseText + else + request.onerror() + + request.onerror = -> + chrome.runtime.sendMessage + handler: "fetchFileContents" + fileName: file + , callback + + request.open "GET", (chrome.runtime.getURL file), true + request.send() + + root = exports ? window root.UIComponent = UIComponent |
