aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorStephen Blott2016-04-18 11:43:53 +0100
committerStephen Blott2016-04-18 11:43:53 +0100
commit0a49cc45732175c65651b5f054c677d6c42a28c0 (patch)
tree1d7484720ba22c52737f5b52a80f5a1b8a95a1dc /background_scripts
parent2e9e0d30f8f6ecb4c0c7ba6e6192006c19264d0b (diff)
downloadvimium-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 'background_scripts')
-rw-r--r--background_scripts/main.coffee14
1 files changed, 7 insertions, 7 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 4aa2fc41..ab1c8610 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -129,14 +129,15 @@ helpDialogHtmlForCommand = (html, isAdvanced, bindings, description, showCommand
html.push "<td class='vimiumReset' colspan='3' style='text-align: left;'>", Utils.escapeHtml(bindings)
html.push("</td></tr>")
-#
-# Fetches the contents of a file bundled with this extension.
-#
-fetchFileContents = (extensionFileName) ->
+# Cache "content_scripts/vimium.css" in chrome.storage.local for UI components.
+do ->
+ # Bail if we don't have these (specifically, we don't have them in the tests).
+ return unless XMLHttpRequest? and chrome.runtime.getURL? and chrome.storage.local.set?
req = new XMLHttpRequest()
- req.open("GET", chrome.runtime.getURL(extensionFileName), false) # false => synchronous
+ req.open "GET", chrome.runtime.getURL("content_scripts/vimium.css"), true # true -> asynchronous.
+ req.onload = ({status, responseText}) ->
+ chrome.storage.local.set vimiumCSSInChromeStorage: responseText if status == 200
req.send()
- req.responseText
TabOperations =
# Opens the url in the current tab.
@@ -417,7 +418,6 @@ sendRequestHandlers =
gotoMark: Marks.goto.bind(Marks)
# Send a message to all frames in the current tab.
sendMessageToFrames: (request, sender) -> chrome.tabs.sendMessage sender.tab.id, request.message
- fetchFileContents: (request, sender) -> fetchFileContents request.fileName
# For debugging only. This allows content scripts to log messages to the extension's logging page.
log: ({frameId, message}, sender) -> BgUtils.log "#{frameId} #{message}", sender