From c64cc382aec1ef500d50417b5214854e28e4b952 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 21 Apr 2015 13:23:03 +0100 Subject: Implement mainFrame command. Fixes #426. --- content_scripts/vimium_frontend.coffee | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 6c09ab72..27d864fb 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -92,9 +92,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) # If an input grabs the focus before the user has interacted with the page, then grab it back (if the # grabBackFocus option is set). @@ -167,7 +167,7 @@ initializePreDomReady = -> requestHandlers = showHUDforDuration: (request) -> HUD.showForDuration request.text, request.duration toggleHelpDialog: (request) -> toggleHelpDialog(request.dialogHtml, request.frameId) - focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame(request.highlight) + focusFrame: (request) -> if (request.frameId in [ frameId, 0 ]) then focusThisFrame(request.highlight) refreshCompletionKeys: refreshCompletionKeys getScrollPosition: -> scrollX: window.scrollX, scrollY: window.scrollY setScrollPosition: (request) -> setScrollPosition request.scrollX, request.scrollY @@ -180,7 +180,7 @@ initializePreDomReady = -> # 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://' - return unless isEnabledForUrl + return unless isEnabledForUrl or (request.frameId == 0 and request.name in [ "focusFrame" ]) # These requests are delivered to the options page, but there are no handlers there. return if request.handler in [ "registerFrame", "frameFocused", "unregisterFrame" ] sendResponse requestHandlers[request.name](request, sender) -- cgit v1.2.3 From 85e9cdc865604980dcfe3eed364d621ff8075172 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Tue, 21 Apr 2015 13:51:24 +0100 Subject: mainFrame; simplify logic. --- content_scripts/vimium_frontend.coffee | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 27d864fb..fde3d167 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -167,7 +167,7 @@ initializePreDomReady = -> requestHandlers = showHUDforDuration: (request) -> HUD.showForDuration request.text, request.duration toggleHelpDialog: (request) -> toggleHelpDialog(request.dialogHtml, request.frameId) - focusFrame: (request) -> if (request.frameId in [ frameId, 0 ]) then focusThisFrame(request.highlight) + focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame(request.highlight) refreshCompletionKeys: refreshCompletionKeys getScrollPosition: -> scrollX: window.scrollX, scrollY: window.scrollY setScrollPosition: (request) -> setScrollPosition request.scrollX, request.scrollY @@ -180,10 +180,15 @@ initializePreDomReady = -> # 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://' - return unless isEnabledForUrl or (request.frameId == 0 and request.name in [ "focusFrame" ]) # These requests are delivered to the options page, but there are no handlers there. return if request.handler in [ "registerFrame", "frameFocused", "unregisterFrame" ] - sendResponse requestHandlers[request.name](request, sender) + shouldHandleRequest = isEnabledForUrl + # Requests with a frameId of zero are sent to and only received by the tab's main frame. We *always* + # handle the listed requests in that frame (even if Vimium is otherwise disabled). + if request.frameId == 0 and request.name in [ "focusFrame" ] + request.frameId = frameId + shouldHandleRequest = true + sendResponse requestHandlers[request.name](request, sender) if shouldHandleRequest # Ensure the sendResponse callback is freed. false -- cgit v1.2.3