diff options
| author | Stephen Blott | 2014-12-14 15:11:44 +0000 |
|---|---|---|
| committer | Stephen Blott | 2014-12-14 15:11:44 +0000 |
| commit | 99e387f9cb6654d88ba0fe5de1059b9d0df481b5 (patch) | |
| tree | cfd28908e852d6c6b0707bdfc57ad8fa7195fb83 | |
| parent | 9b8817593af71ddc106c60d44bc967a4bcc553e9 (diff) | |
| parent | fa06a27b906a83c01ded4e0fe3b96e8e51a1a52d (diff) | |
| download | vimium-99e387f9cb6654d88ba0fe5de1059b9d0df481b5.tar.bz2 | |
Merge branch 'disable-on-disable' of https://github.com/mrmr1993/vimium into mrmr1993-disable-on-disable
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 16 | ||||
| -rw-r--r-- | tests/dom_tests/chrome.coffee | 3 |
2 files changed, 19 insertions, 0 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index b4f0264c..ebdbb9aa 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -57,6 +57,15 @@ settings = @port = chrome.runtime.connect({ name: "settings" }) @port.onMessage.addListener(@receiveMessage) + # If the port is closed, the background page has gone away (since we never close it ourselves). Stub the + # settings object so we don't keep trying to connect to the extension even though it's gone away. + @port.onDisconnect.addListener => + @port = null + for own property, value of this + # @get doesn't depend on @port, so we can continue to support it to try and reduce errors. + @[property] = (->) if "function" == typeof value and property != "get" + + get: (key) -> @values[key] set: (key, value) -> @@ -109,6 +118,13 @@ initializePreDomReady = -> # Send the key to the key handler in the background page. keyPort = chrome.runtime.connect({ name: "keyDown" }) + # If the port is closed, the background page has gone away (since we never close it ourselves). Disable all + # our event listeners, and stub out chrome.runtime.sendMessage/connect (to prevent errors). + # TODO(mrmr1993): Do some actual cleanup to free resources, hide UI, etc. + keyPort.onDisconnect.addListener -> + isEnabledForUrl = false + chrome.runtime.sendMessage = -> + chrome.runtime.connect = -> requestHandlers = hideUpgradeNotification: -> HUD.hideUpgradeNotification() diff --git a/tests/dom_tests/chrome.coffee b/tests/dom_tests/chrome.coffee index 7f99e27f..15ed4339 100644 --- a/tests/dom_tests/chrome.coffee +++ b/tests/dom_tests/chrome.coffee @@ -10,6 +10,9 @@ root.chrome = { onMessage: { addListener: -> } + onDisconnect: { + addListener: -> + } postMessage: -> } onMessage: { |
