aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-03-17 09:18:52 +0000
committerStephen Blott2015-03-17 09:18:52 +0000
commitefada88f419933c5bd1478faada3b4eff3082103 (patch)
treed65543b704ed2da6545c89bf1996ff7c84e02e78
parent1ae621489da091e6d9430da248d0e6eaab606f35 (diff)
downloadvimium-efada88f419933c5bd1478faada3b4eff3082103.tar.bz2
Activate vomnibar in window.top; refocus original frame.
-rw-r--r--background_scripts/main.coffee10
-rw-r--r--content_scripts/ui_component.coffee14
-rw-r--r--content_scripts/vimium_frontend.coffee9
-rw-r--r--content_scripts/vomnibar.coffee19
4 files changed, 39 insertions, 13 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index fe6cc70b..f031eeaf 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -658,6 +658,15 @@ handleFrameFocused = (request, sender) ->
frameIdsForTab[tabId] =
[request.frameId, (frameIdsForTab[tabId].filter (id) -> id != request.frameId)...]
+# Send a message to a frame (in the sender's tab). The sender should set:
+# - request.targetFrameId (the target frame)
+# - request.name (the name of the handler in the target frame, e.g. "focusFrame")
+# In addition, request.senderFrameId will be set to the frameId of the sender.
+sendMessageToFrame = (request, sender) ->
+ request.senderFrameId = request.frameId
+ request.frameId = request.targetFrameId
+ chrome.tabs.sendMessage sender.tab.id, request
+
# Port handler mapping
portHandlers =
keyDown: handleKeyDown,
@@ -685,6 +694,7 @@ sendRequestHandlers =
createMark: Marks.create.bind(Marks)
gotoMark: Marks.goto.bind(Marks)
setBadge: setBadge
+ sendMessageToFrame: sendMessageToFrame
# We always remove chrome.storage.local/findModeRawQueryListIncognito on startup.
chrome.storage.local.remove "findModeRawQueryListIncognito"
diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee
index b582cb5d..3a4af6b5 100644
--- a/content_scripts/ui_component.coffee
+++ b/content_scripts/ui_component.coffee
@@ -2,6 +2,7 @@ class UIComponent
iframeElement: null
iframePort: null
showing: null
+ options: null
constructor: (iframeUrl, className, @handleMessage) ->
@iframeElement = document.createElement "iframe"
@@ -27,8 +28,8 @@ class UIComponent
postMessage: (message) ->
@iframePort.postMessage message
- activate: (message) ->
- @postMessage message if message?
+ activate: (@options) ->
+ @postMessage @options if @options?
@show() unless @showing
@iframeElement.focus()
@@ -51,7 +52,14 @@ class UIComponent
@iframeElement.classList.add "vimiumUIComponentHidden"
window.removeEventListener "focus", @onFocus if @onFocus
@onFocus = null
- window.focus() if focusWindow
+ if focusWindow and @options?.frameId?
+ chrome.runtime.sendMessage
+ handler: "sendMessageToFrame"
+ frameId: frameId
+ targetFrameId: @options.frameId
+ name: "focusFrame"
+ highlight: true # true for debugging; should be false when live.
+ @options = null
@showing = false
root = exports ? window
diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 0aaee3db..cdb47613 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -232,7 +232,9 @@ getActiveState = ->
registerFocus = ->
# settings may have changed since the frame last had focus
settings.load()
- chrome.runtime.sendMessage({ handler: "frameFocused", frameId: frameId })
+ # Don't register frameset containers; focusing them is no use.
+ unless document.body?.tagName.toLowerCase() == "frameset"
+ chrome.runtime.sendMessage({ handler: "frameFocused", frameId: frameId })
#
# Initialization tasks that must wait for the document to be ready.
@@ -261,7 +263,9 @@ executePageCommand = (request) ->
# Vomnibar commands are handled in the tab's main frame.
if request.command.split(".")[0] == "Vomnibar"
if window.top == window
- Utils.invokeCommandString request.command
+ # We pass the frameId from request. That's the frame which originated the request, so that's the frame
+ # that needs to receive the focus when we're done.
+ Utils.invokeCommandString request.command, [ request.frameId ]
refreshCompletionKeys request
return
@@ -283,6 +287,7 @@ setScrollPosition = (scrollX, scrollY) ->
# Called from the backend in order to change frame focus.
#
window.focusThisFrame = (shouldHighlight) ->
+ console.log "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
if window.innerWidth < 3 or window.innerHeight < 3
# This frame is too small to focus. Cancel and tell the background frame to focus the next one instead.
# This affects sites like Google Inbox, which have many tiny iframes. See #1317.
diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee
index c4cfc8b9..c2b7fc5b 100644
--- a/content_scripts/vomnibar.coffee
+++ b/content_scripts/vomnibar.coffee
@@ -4,31 +4,33 @@
Vomnibar =
vomnibarUI: null
- activate: -> @open {completer:"omni"}
- activateInNewTab: -> @open {
+ # frameId here (and below) is the ID of the frame from which this request originates, which may be different
+ # from the current frame.
+ activate: (frameId) -> @open frameId, {completer:"omni"}
+ activateInNewTab: (frameId) -> @open frameId, {
completer: "omni"
selectFirst: false
newTab: true
}
- activateTabSelection: -> @open {
+ activateTabSelection: (frameId) -> @open frameId, {
completer: "tabs"
selectFirst: true
}
- activateBookmarks: -> @open {
+ activateBookmarks: (frameId) -> @open frameId, {
completer: "bookmarks"
selectFirst: true
}
- activateBookmarksInNewTab: -> @open {
+ activateBookmarksInNewTab: (frameId) -> @open frameId, {
completer: "bookmarks"
selectFirst: true
newTab: true
}
- activateEditUrl: -> @open {
+ activateEditUrl: (frameId) -> @open frameId, {
completer: "omni"
selectFirst: false
query: window.location.href
}
- activateEditUrlInNewTab: -> @open {
+ activateEditUrlInNewTab: (frameId) -> @open frameId, {
completer: "omni"
selectFirst: false
query: window.location.href
@@ -48,7 +50,8 @@ Vomnibar =
# query - Optional. Text to prefill the Vomnibar with.
# selectFirst - Optional, boolean. Whether to select the first entry.
# newTab - Optional, boolean. Whether to open the result in a new tab.
- open: (options) -> @vomnibarUI.activate options
+ open: (frameId, options) ->
+ @vomnibarUI.activate extend options, { frameId }
root = exports ? window
root.Vomnibar = Vomnibar