diff options
| author | Stephen Blott | 2016-03-14 11:42:27 +0000 | 
|---|---|---|
| committer | Stephen Blott | 2016-03-17 11:17:03 +0000 | 
| commit | 8be6acd660be212926bff495c8e8f83d3f5917be (patch) | |
| tree | 1d116650666191d8afb0966552adb81557f47a1b /background_scripts/main.coffee | |
| parent | 6653fa0e588d9fb777b627c947b377fa0518bfc8 (diff) | |
| download | vimium-8be6acd660be212926bff495c8e8f83d3f5917be.tar.bz2 | |
Use Chrome frameIds.
Diffstat (limited to 'background_scripts/main.coffee')
| -rw-r--r-- | background_scripts/main.coffee | 31 | 
1 files changed, 14 insertions, 17 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 2e0330ee..6fddb6e3 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -76,7 +76,7 @@ chrome.runtime.onConnect.addListener (port, name) ->        toCall.call()    if (portHandlers[port.name]) -    port.onMessage.addListener portHandlers[port.name] sender +    port.onMessage.addListener portHandlers[port.name] sender, port  chrome.runtime.onMessage.addListener((request, sender, sendResponse) ->    if (sendRequestHandlers[request.handler]) @@ -378,31 +378,28 @@ openOptionsPageInNewTab = ->      chrome.tabs.create({ url: chrome.runtime.getURL("pages/options.html"), index: tab.index + 1 }))  Frames = -  onConnect: (sender) -> -    (request, port) => -      this[request.handler] request, sender, port +  onConnect: (sender, port) -> +    [tabId, frameId] = [sender.tab.id, sender.frameId] +    (frameIdsForTab[tabId] ?= []).push frameId +    port.postMessage name: "registerFrameId", chromeFrameId: frameId -  registerFrame: (request, sender, port) -> -    (frameIdsForTab[sender.tab.id] ?= []).push request.frameId - -    [tabId, frameId, isTopFrame] = [sender.tab.id, request.frameId, request.isTopFrame]      port.onDisconnect.addListener -> -      if isTopFrame +      if frameId == 0 # This is the top frame in the tab.          delete frameIdsForTab[tabId]        else          if tabId of frameIdsForTab            frameIdsForTab[tabId] = frameIdsForTab[tabId].filter (fId) -> fId != frameId +          # Sub-frames can connect before the top frame; so we can't rely on seeing the top frame at all. +          delete frameIdsForTab[tabId] if frameIdsForTab[tabId].length == 0  handleFrameFocused = (request, sender) -> -  tabId = sender.tab.id -  # Cycle frameIdsForTab to the focused frame.  However, also ensure that we don't inadvertently register a -  # frame which wasn't previously registered (such as a frameset). -  if frameIdsForTab[tabId]? -    frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], request.frameId +  [tabId, frameId] = [sender.tab.id, sender.frameId] +  # This might be the first time we've heard from this tab. +  frameIdsForTab[tabId] ?= [] +  # Cycle frameIdsForTab to the focused frame. +  frameIdsForTab[tabId] = cycleToFrame frameIdsForTab[tabId], frameId    # Inform all frames that a frame has received the focus. -  chrome.tabs.sendMessage sender.tab.id, -    name: "frameFocused" -    focusFrameId: request.frameId +  chrome.tabs.sendMessage tabId, name: "frameFocused", focusFrameId: frameId  # Rotate through frames to the frame count places after frameId.  cycleToFrame = (frames, frameId, count = 0) ->  | 
