aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-10-09 14:22:32 +0100
committerStephen Blott2016-10-09 14:22:32 +0100
commit801dd4ea5edfff8b22c3c8c875808ee33e96571e (patch)
treedae725d79b1964dd6fd39fed11d21bebc7284d7c
parent8535fdde4f7dae1a1a5148d25ee0829423e92e7e (diff)
downloadvimium-801dd4ea5edfff8b22c3c8c875808ee33e96571e.tar.bz2
Move logging to the frame's port.
Comminication by the frame's port is faster, and no response is sent.
-rw-r--r--background_scripts/main.coffee17
-rw-r--r--content_scripts/vimium_frontend.coffee5
2 files changed, 12 insertions, 10 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 57b5bf67..e57e061d 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -66,12 +66,12 @@ chrome.runtime.onConnect.addListener (port) ->
if (portHandlers[port.name])
port.onMessage.addListener portHandlers[port.name] port.sender, port
-chrome.runtime.onMessage.addListener((request, sender, sendResponse) ->
+chrome.runtime.onMessage.addListener (request, sender, sendResponse) ->
request = extend {count: 1, frameId: sender.frameId}, extend request, tab: sender.tab, tabId: sender.tab.id
- if (sendRequestHandlers[request.handler])
- sendResponse(sendRequestHandlers[request.handler](request, sender))
- # Ensure the sendResponse callback is freed.
- return false)
+ if sendRequestHandlers[request.handler]
+ sendResponse sendRequestHandlers[request.handler] request, sender
+ # Ensure that the sendResponse callback is freed.
+ false
onURLChange = (details) ->
chrome.tabs.sendMessage details.tabId, name: "checkEnabledAfterURLChange"
@@ -311,7 +311,7 @@ Frames =
# Return our onMessage handler for this port.
(request, port) =>
- this[request.handler] {request, tabId, frameId, port}
+ this[request.handler] {request, tabId, frameId, port, sender}
registerFrame: ({tabId, frameId, port}) ->
frameIdsForTab[tabId].push frameId unless frameId in frameIdsForTab[tabId] ?= []
@@ -353,6 +353,9 @@ Frames =
linkHintsMessage: ({request, tabId, frameId}) ->
HintCoordinator.onMessage tabId, frameId, request
+ # For debugging only. This allows content scripts to log messages to the extension's logging page.
+ log: ({frameId, sender, request: {message}}) -> BgUtils.log "#{frameId} #{message}", sender
+
handleFrameFocused = ({tabId, frameId}) ->
frameIdsForTab[tabId] ?= []
frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], frameId
@@ -444,8 +447,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
- # 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
# We always remove chrome.storage.local/findModeRawQueryListIncognito on startup.
chrome.storage.local.remove "findModeRawQueryListIncognito"
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index c02c573b..2dc39ad5 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -32,10 +32,11 @@ textInputXPath = (->
# This is set by Frame.registerFrameId(). A frameId of 0 indicates that this is the top frame in the tab.
frameId = null
-# For debugging only. This logs to the console on the background page.
+# For debugging only. This writes to the Vimium log page, the URL of whichis shown on the console on the
+# background page.
bgLog = (args...) ->
args = (arg.toString() for arg in args)
- chrome.runtime.sendMessage handler: "log", message: args.join " "
+ Frame.postMessage "log", message: args.join " "
# If an input grabs the focus before the user has interacted with the page, then grab it back (if the
# grabBackFocus option is set).