diff options
| author | mrmr1993 | 2014-12-08 01:15:06 +0000 |
|---|---|---|
| committer | mrmr1993 | 2014-12-08 01:15:06 +0000 |
| commit | 1c33590eb994403ec8520c1c02bfb4fe63831745 (patch) | |
| tree | bab9a975cb4e7a17208c4925ccfc7244df1dd7e8 /content_scripts | |
| parent | b6125a2b13d6927c10f381f51b207445fd3f049b (diff) | |
| download | vimium-1c33590eb994403ec8520c1c02bfb4fe63831745.tar.bz2 | |
Detect port disconnects (ie. extension is disabled) and disable frontend
Diffstat (limited to 'content_scripts')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 469afe71..f7bd805d 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -57,6 +57,16 @@ 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 + _get = @get # @get doesn't depend on @port, so we can continue to support it to try and reduce errors. + for own property, value of this + @[property] = (->) if "function" == typeof value + @get = _get + + get: (key) -> @values[key] set: (key, value) -> @@ -109,6 +119,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() |
