diff options
| -rw-r--r-- | background_scripts/main.coffee | 9 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 42 | ||||
| -rw-r--r-- | manifest.json | 1 |
3 files changed, 33 insertions, 19 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 223b0d74..ab92559f 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -96,6 +96,15 @@ root.isEnabledForUrl = isEnabledForUrl = (request) -> passKeys: rule?.passKeys or "" } +isEnabledForUpdatedUrl = (details) -> + message = isEnabledForUrl details + message.name = "updateEnabledForUrlState" + chrome.tabs.sendMessage details.tabId, message, {frameId: details.frameId} + +# Re-check whether Vimium is enabled for a frame when the url changes without a reload. +chrome.webNavigation.onHistoryStateUpdated.addListener isEnabledForUpdatedUrl # history.pushState. +chrome.webNavigation.onReferenceFragmentUpdated.addListener isEnabledForUpdatedUrl # Hash changed. + # Retrieves the help dialog HTML template from a file, and populates it with the latest keybindings. # This is called by options.coffee. root.helpDialogHtml = (showUnboundCommands, showCommandNames, customTitle) -> diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 7b99287e..862118bc 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -175,12 +175,13 @@ initializePreDomReady = -> currentKeyQueue: (request) -> keyQueue = request.keyQueue handlerStack.bubbleEvent "registerKeyQueue", { keyQueue: keyQueue } + updateEnabledForUrlState: updateEnabledForUrlState chrome.runtime.onMessage.addListener (request, sender, sendResponse) -> # In the options page, we will receive requests from both content and background scripts. ignore those # from the former. return if sender.tab and not sender.tab.url.startsWith 'chrome-extension://' - return unless isEnabledForUrl + return unless isEnabledForUrl or request.name in ["updateEnabledForUrlState"] # These requests are delivered to the options page, but there are no handlers there. return if request.handler in [ "registerFrame", "frameFocused", "unregisterFrame" ] sendResponse requestHandlers[request.name](request, sender) @@ -550,24 +551,27 @@ onKeyup = (event) -> checkIfEnabledForUrl = -> url = window.location.toString() - chrome.runtime.sendMessage { handler: "isEnabledForUrl", url: url }, (response) -> - {isEnabledForUrl, passKeys} = response - if isEnabledForUrl - initializeWhenEnabled() - else if HUD.isReady() - # Quickly hide any HUD we might already be showing, e.g. if we entered insert mode on page load. - HUD.hide() - handlerStack.bubbleEvent "registerStateChange", - enabled: isEnabledForUrl - passKeys: passKeys - # Update the page icon, if necessary. - if document.hasFocus() - chrome.runtime.sendMessage - handler: "setIcon" - icon: - if isEnabledForUrl and not passKeys then "enabled" - else if isEnabledForUrl then "partial" - else "disabled" + chrome.runtime.sendMessage { handler: "isEnabledForUrl", url: url }, updateEnabledForUrlState + +updateEnabledForUrlState = (response) -> + {isEnabledForUrl, passKeys} = response + if isEnabledForUrl + initializeWhenEnabled() + else if HUD.isReady() + # Quickly hide any HUD we might already be showing, e.g. if we entered insert mode on page load. + HUD.hide() + handlerStack.bubbleEvent "registerStateChange", + enabled: isEnabledForUrl + passKeys: passKeys + # Update the page icon, if necessary. + if document.hasFocus() + chrome.runtime.sendMessage + handler: "setIcon" + icon: + if isEnabledForUrl and not passKeys then "enabled" + else if isEnabledForUrl then "partial" + else "disabled" + null # Exported to window, but only for DOM tests. diff --git a/manifest.json b/manifest.json index 4ba222fb..e8e51407 100644 --- a/manifest.json +++ b/manifest.json @@ -28,6 +28,7 @@ "storage", "sessions", "notifications", + "webNavigation", "<all_urls>" ], "content_scripts": [ |
