diff options
| author | Stephen Blott | 2015-03-17 12:06:15 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2015-03-17 12:06:15 +0000 | 
| commit | 4399e2e4fffc4faba9f1505dfc0ad3150a948632 (patch) | |
| tree | 078d0ad4e226372fac0a93bb56f21259df1a0c1d | |
| parent | 8bc811aae1118e28faa7c17e67b039c67f637274 (diff) | |
| download | vimium-4399e2e4fffc4faba9f1505dfc0ad3150a948632.tar.bz2 | |
Activate vomnibar in window.top; more clean up.
| -rw-r--r-- | background_scripts/main.coffee | 4 | ||||
| -rw-r--r-- | content_scripts/ui_component.coffee | 10 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 12 | ||||
| -rw-r--r-- | content_scripts/vomnibar.coffee | 18 | ||||
| -rw-r--r-- | lib/dom_utils.coffee | 6 | 
5 files changed, 29 insertions, 21 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 07e89e08..a64c7e37 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -660,9 +660,9 @@ handleFrameFocused = (request, sender) ->    # Inform all frames that a frame has received the focus.    chrome.tabs.sendMessage sender.tab.id,       name: "frameFocused" -    frameId: request.frameId +    focusFrameId: request.frameId -# Send a message to a all frames in the current tab. +# Send a message to all frames in the current tab.  sendMessageToFrames = (request, sender) ->    chrome.tabs.sendMessage sender.tab.id, request.message diff --git a/content_scripts/ui_component.coffee b/content_scripts/ui_component.coffee index 3d8cef29..185d525a 100644 --- a/content_scripts/ui_component.coffee +++ b/content_scripts/ui_component.coffee @@ -15,9 +15,11 @@ class UIComponent      # Hide the iframe, but don't interfere with the focus.      @hide false -    # If any other frame in the current tab receives the focus, then we hide the vomnibar. +    # If any other frame in the current tab receives the focus, then we hide the UI component. +    # NOTE(smblott) This is correct for the vomnibar, but might be incorrect (and need to be revisited) for +    # other UI components.      chrome.runtime.onMessage.addListener (request) => -      @hide false if @showing and request.name == "frameFocused" and request.frameId != frameId +      @hide false if @showing and request.name == "frameFocused" and request.focusFrameId != frameId        false # Free up response handler.    # Open a port and pass it to the iframe via window.postMessage. @@ -57,12 +59,12 @@ class UIComponent      @iframeElement.classList.add "vimiumUIComponentHidden"      window.removeEventListener "focus", @onFocus if @onFocus      @onFocus = null -    if focusWindow and @options?.frameId? +    if focusWindow and @options?.sourceFrameId?        chrome.runtime.sendMessage          handler: "sendMessageToFrames"          message:            name: "focusFrame" -          frameId: @options.frameId +          frameId: @options.sourceFrameId            highlight: true # true for debugging; should be false when live.      @options = null      @showing = false diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 90b25a40..072789a4 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -237,11 +237,11 @@ getActiveState = ->  #  registerFocus = (event) ->    if event.target == window -    # settings may have changed since the frame last had focus +    # Settings may have changed since the frame last had focus.      settings.load()      # Don't register frameset containers; focusing them is no use.      unless document.body?.tagName.toLowerCase() == "frameset" -      chrome.runtime.sendMessage({ handler: "frameFocused", frameId: frameId }) +      chrome.runtime.sendMessage handler: "frameFocused", frameId: frameId  #  # Initialization tasks that must wait for the document to be ready. @@ -250,7 +250,7 @@ initializeOnDomReady = ->    # Tell the background page we're in the dom ready state.    chrome.runtime.connect({ name: "domReady" })    CursorHider.init() -  Vomnibar.init() if window.top == window +  Vomnibar.init() if DomUtils.isTopFrame()  registerFrame = ->    # Don't register frameset containers; focusing them is no use. @@ -264,12 +264,12 @@ unregisterFrame = ->    chrome.runtime.sendMessage      handler: "unregisterFrame"      frameId: frameId -    tab_is_closing: window.top == window.self +    tab_is_closing: DomUtils.isTopFrame()  executePageCommand = (request) -> -  # Vomnibar commands are handled in the tab's main frame. +  # Vomnibar commands are handled in the tab's main/top frame.    if request.command.split(".")[0] == "Vomnibar" -    if window.top == window +    if DomUtils.isTopFrame()        # 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 ] diff --git a/content_scripts/vomnibar.coffee b/content_scripts/vomnibar.coffee index 823dcd01..3d54e643 100644 --- a/content_scripts/vomnibar.coffee +++ b/content_scripts/vomnibar.coffee @@ -4,33 +4,33 @@  Vomnibar =    vomnibarUI: null -  # frameId here (and below) is the ID of the frame from which this request originates, which may be different +  # sourceFrameId 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, { +  activate: (sourceFrameId) -> @open sourceFrameId, {completer:"omni"} +  activateInNewTab: (sourceFrameId) -> @open sourceFrameId, {      completer: "omni"      selectFirst: false      newTab: true    } -  activateTabSelection: (frameId) -> @open frameId, { +  activateTabSelection: (sourceFrameId) -> @open sourceFrameId, {      completer: "tabs"      selectFirst: true    } -  activateBookmarks: (frameId) -> @open frameId, { +  activateBookmarks: (sourceFrameId) -> @open sourceFrameId, {      completer: "bookmarks"      selectFirst: true    } -  activateBookmarksInNewTab: (frameId) -> @open frameId, { +  activateBookmarksInNewTab: (sourceFrameId) -> @open sourceFrameId, {      completer: "bookmarks"      selectFirst: true      newTab: true    } -  activateEditUrl: (frameId) -> @open frameId, { +  activateEditUrl: (sourceFrameId) -> @open sourceFrameId, {      completer: "omni"      selectFirst: false      query: window.location.href    } -  activateEditUrlInNewTab: (frameId) -> @open frameId, { +  activateEditUrlInNewTab: (sourceFrameId) -> @open sourceFrameId, {      completer: "omni"      selectFirst: false      query: window.location.href @@ -50,7 +50,7 @@ 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: (frameId, options) -> @vomnibarUI.activate extend options, { frameId } +  open: (sourceFrameId, options) -> @vomnibarUI.activate extend options, { sourceFrameId }  root = exports ? window  root.Vomnibar = Vomnibar diff --git a/lib/dom_utils.coffee b/lib/dom_utils.coffee index 0231f994..efb125f6 100644 --- a/lib/dom_utils.coffee +++ b/lib/dom_utils.coffee @@ -27,6 +27,12 @@ DomUtils =    removeElement: (el) -> el.parentNode.removeChild el    # +  # Test whether the current frame is the top/main frame. +  # +  isTopFrame: -> +    window.top == window.self + +  #    # Takes an array of XPath selectors, adds the necessary namespaces (currently only XHTML), and applies them    # to the document root. The namespaceResolver in evaluateXPath should be kept in sync with the namespaces    # here. | 
