diff options
| author | Stephen Blott | 2015-04-25 07:50:31 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-04-25 07:50:31 +0100 | 
| commit | e7ae8e0cc5aa5d4a8c7778c4a2f88b53d7cc4111 (patch) | |
| tree | cd9396584b0433c686983af3cf8cc3026e2edf30 /content_scripts/vimium_frontend.coffee | |
| parent | f85c65bb664fdc29b7c45c579ead4481238a24e0 (diff) | |
| parent | 8b7b4febdf8947b3a123e8dc2b289caa20976864 (diff) | |
| download | vimium-e7ae8e0cc5aa5d4a8c7778c4a2f88b53d7cc4111.tar.bz2 | |
Merge remote-tracking branch 'origin/focus-main-frame' into focus-main-frame-merge
Conflicts:
	content_scripts/vimium_frontend.coffee
Also rework to remove dependency on Chrome 41+ sendMessage API
(specifically, relating to optional target frameId argument).
Diffstat (limited to 'content_scripts/vimium_frontend.coffee')
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 23 | 
1 files changed, 13 insertions, 10 deletions
| diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index b5a5f51e..ec39ccde 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -99,9 +99,9 @@ settings =      @eventListeners[eventName].push(callback)  # -# Give this frame a unique id. +# Give this frame a unique (non-zero) id.  # -frameId = Math.floor(Math.random()*999999999) +frameId = 1 + Math.floor(Math.random()*999999999)  # For debugging only. This logs to the console on the background page.  bgLog = (args...) -> @@ -187,20 +187,23 @@ initializePreDomReady = ->      currentKeyQueue: (request) ->        keyQueue = request.keyQueue        handlerStack.bubbleEvent "registerKeyQueue", { keyQueue: keyQueue } -    frameFocused: -> # A frame has received the focus.  We don't care, here. The Vomnibar/UI-component cares. +    # A frame has received the focus.  We don't care, here (the Vomnibar/UI-component handles this). +    frameFocused: ->    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://' -    # We handle the message if we're enabled, or if it's one of these listed message types. -    return unless isEnabledForUrl or request.name in [ "executePageCommand" ]      # These requests are delivered to the options page, but there are no handlers there. -    return if request.handler in [ "registerFrame", "unregisterFrame" ] -    # We don't handle these here.  They're handled elsewhere (e.g. in the vomnibar/UI component). -    return if request.name in [ "frameFocused" ] -    # Handle the request. -    sendResponse requestHandlers[request.name](request, sender) +    return if request.handler in [ "registerFrame", "frameFocused", "unregisterFrame" ] +    # We handle the message if we're enabled, or if it's one of these listed message types. +    shouldHandleRequest = isEnabledForUrl or request.name in [ "executePageCommand" ] +    # Requests with a frameId of zero should only be handled in the main/top frame (regardless of whether +    # Vimium is enabled there). +    if request.frameId == 0 and DomUtils.isTopFrame() +      request.frameId = frameId +      shouldHandleRequest = true +    sendResponse requestHandlers[request.name](request, sender) if shouldHandleRequest      # Ensure the sendResponse callback is freed.      false | 
