aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md1
-rw-r--r--background_scripts/commands.coffee3
-rw-r--r--background_scripts/main.coffee4
-rw-r--r--content_scripts/vimium_frontend.coffee23
4 files changed, 21 insertions, 10 deletions
diff --git a/README.md b/README.md
index 96cde9bb..002cb7d8 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,7 @@ Navigating the current page:
yy copy the current url to the clipboard
yf copy a link url to the clipboard
gf cycle forward to the next frame
+ gF focus the main/top frame
Navigating to new pages:
diff --git a/background_scripts/commands.coffee b/background_scripts/commands.coffee
index 9aa90c45..bca1c3a4 100644
--- a/background_scripts/commands.coffee
+++ b/background_scripts/commands.coffee
@@ -129,6 +129,7 @@ Commands =
"goPrevious",
"goNext",
"nextFrame",
+ "mainFrame",
"Marks.activateCreateMode",
"Vomnibar.activateEditUrl",
"Vomnibar.activateEditUrlInNewTab",
@@ -255,6 +256,7 @@ defaultKeyMappings =
"gE": "Vomnibar.activateEditUrlInNewTab"
"gf": "nextFrame"
+ "gF": "mainFrame"
"m": "Marks.activateCreateMode"
"`": "Marks.activateGotoMode"
@@ -350,6 +352,7 @@ commandDescriptions =
"Vomnibar.activateEditUrlInNewTab": ["Edit the current URL and open in a new tab", { noRepeat: true }]
nextFrame: ["Cycle forward to the next frame on the page", { background: true, passCountToFunction: true }]
+ mainFrame: ["Select the tab's main/top frame", { background: true, noRepeat: true }]
"Marks.activateCreateMode": ["Create a new mark", { noRepeat: true }]
"Marks.activateGotoMode": ["Go to a mark", { noRepeat: true }]
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 94cbb08e..642913a5 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -298,6 +298,10 @@ BackgroundCommands =
count = (count + Math.max 0, frameIdsForTab[tab.id].indexOf frameId) % frames.length
frames = frameIdsForTab[tab.id] = [frames[count..]..., frames[0...count]...]
chrome.tabs.sendMessage(tab.id, { name: "focusFrame", frameId: frames[0], highlight: true }))
+ mainFrame: ->
+ chrome.tabs.getSelected null, (tab) ->
+ # The front end interprets a frameId of 0 to mean the main/top from.
+ chrome.tabs.sendMessage tab.id, name: "focusFrame", frameId: 0, highlight: true
closeTabsOnLeft: -> removeTabsRelative "before"
closeTabsOnRight: -> removeTabsRelative "after"
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