aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/vimium_frontend.coffee
diff options
context:
space:
mode:
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
-rw-r--r--content_scripts/vimium_frontend.coffee23
1 files changed, 12 insertions, 11 deletions
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 70ff19f5..36ca7834 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -1,8 +1,5 @@
#
-# This content script takes input from its webpage and executes commands locally on behalf of the background
-# page. It must be run prior to domReady so that we perform some operations very early. We tell the
-# background page that we're in domReady and ready to accept normal commands by connectiong to a port named
-# "domReady".
+# This content script must be run prior to domReady so that we perform some operations very early.
#
isEnabledForUrl = true
@@ -208,13 +205,9 @@ onFocus = (event) ->
window.addEventListener "focus", onFocus
window.addEventListener "hashchange", onFocus
-DomUtils.documentReady ->
+initializeOnDomReady = ->
# Tell the background page we're in the domReady state.
- chrome.runtime.connect({name: "domReady"}).onDisconnect.addListener ->
- # We disable content scripts when we lose contact with the background page.
- isEnabledForUrl = false
- chrome.runtime.sendMessage = ->
- window.removeEventListener "focus", onFocus
+ Frame.postMessage "domReady"
Frame =
port: null
@@ -227,10 +220,17 @@ Frame =
init: (callback) ->
@addEventListener "registerFrameId", Frame.registerFrameId
@port = chrome.runtime.connect name: "frames"
- @port.onDisconnect.addListener => @port.postMessage = ->
+
@port.onMessage.addListener (request) =>
handler request for handler in @listeners[request.handler]
+ @port.onDisconnect.addListener =>
+ # We disable content scripts when we lose contact with the background page.
+ isEnabledForUrl = false
+ chrome.runtime.sendMessage = ->
+ window.removeEventListener "focus", onFocus
+ @port.postMessage = ->
+
handleShowHUDforDuration = ({ text, duration }) ->
if DomUtils.isTopFrame()
DomUtils.documentReady -> HUD.showForDuration text, duration
@@ -658,6 +658,7 @@ window.HelpDialog ?=
if @showing then @hide() else @show html
initializePreDomReady()
+DomUtils.documentReady initializeOnDomReady
root = exports ? window
root.handlerStack = handlerStack