diff options
| author | Stephen Blott | 2016-04-18 11:43:53 +0100 |
|---|---|---|
| committer | Stephen Blott | 2016-04-18 11:43:53 +0100 |
| commit | 0a49cc45732175c65651b5f054c677d6c42a28c0 (patch) | |
| tree | 1d7484720ba22c52737f5b52a80f5a1b8a95a1dc /content_scripts/ui_component.coffee | |
| parent | 2e9e0d30f8f6ecb4c0c7ba6e6192006c19264d0b (diff) | |
| download | vimium-0a49cc45732175c65651b5f054c677d6c42a28c0.tar.bz2 | |
Cache content_scripts/vimium.css in chrome.storage.local.
Previously, we had two different approaches. This seems like a simpler
approach.
We simply cache the Vimium CSS in chrome.storage.local (in the
background page) and fetch it from there (in UI components).
There is also a minor change in the we no longer cache the CSS in
memory. This seems to be the right thing to do. Caching the CSS in
memory consumes a small amount of memory. However, it can only speed up
the fastest loads. It cannot speed up the first load -- which is likely
the one that matters most. So caching the CSS in memory seems to make
little sense.
Diffstat (limited to 'content_scripts/ui_component.coffee')
| -rw-r--r-- | content_scripts/ui_component.coffee | 29 |
1 files changed, 3 insertions, 26 deletions
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 1a7a1634..7422aada 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -5,7 +5,6 @@ class UIComponent iframeFrameId: null options: null shadowDOM: null - styleSheetGetter: null toggleIframeElementClasses: (removeClass, addClass) -> @iframeElement.classList.remove removeClass @@ -18,10 +17,9 @@ class UIComponent # Default to everything hidden while the stylesheet loads. styleSheet.innerHTML = "iframe {display: none;}" - # Use an XMLHttpRequest, possibly via the background page, to fetch the stylesheet. This allows us to - # catch and recover from failures that we could not have caught when using CSS @include (eg. #1817). - UIComponent::styleSheetGetter ?= new AsyncDataFetcher @fetchFileContents "content_scripts/vimium.css" - @styleSheetGetter.use (styles) -> styleSheet.innerHTML = styles + # Fetch "content_scripts/vimium.css" from chrome.storage.local; the background page caches it there. + chrome.storage.local.get "vimiumCSSInChromeStorage", (items) -> + styleSheet.innerHTML = items.vimiumCSSInChromeStorage @iframeElement = DomUtils.createElement "iframe" extend @iframeElement, @@ -99,26 +97,5 @@ class UIComponent @options = null @postMessage "hidden" # Inform the UI component that it is hidden. - # 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 |
