diff options
| author | Stephen Blott | 2015-09-19 12:05:47 +0100 |
|---|---|---|
| committer | Stephen Blott | 2015-09-19 12:05:47 +0100 |
| commit | b0c3eb6ea8812240e42ea355bf67f9ba4ead10e0 (patch) | |
| tree | 3876f3c7b691efb07a8edfd30c5afbca716db6df | |
| parent | 95f81e00d3c2002befe47c1b756907164148351f (diff) | |
| parent | 2eb6d9a7d3412e4b46e081caa7054f925ffe7e92 (diff) | |
| download | vimium-b0c3eb6ea8812240e42ea355bf67f9ba4ead10e0.tar.bz2 | |
Merge branch 'mrmr1993/xmlhttprequest-uicomponent-styles'
| -rw-r--r-- | background_scripts/main.coffee | 1 | ||||
| -rw-r--r-- | content_scripts/ui_component.coffee | 31 |
2 files changed, 28 insertions, 4 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index df841028..10f7500e 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -668,6 +668,7 @@ sendRequestHandlers = setIcon: setIcon sendMessageToFrames: sendMessageToFrames log: bgLog + fetchFileContents: (request, sender) -> fetchFileContents request.fileName # We always remove chrome.storage.local/findModeRawQueryListIncognito on startup. chrome.storage.local.remove "findModeRawQueryListIncognito" diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 2348d00b..72627f69 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -4,15 +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")}"); - iframe {display: none;} - """ + 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, @@ -115,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 |
