               # The original tab no longer exists.
               @focusOrLaunch markInfo
 
+  # Focus an existing tab and scroll to the given position within it.
   gotoPositionInTab: ({ tabId, scrollX, scrollY, markName }) ->
     chrome.tabs.update tabId, { selected: true }, ->
       chrome.tabs.sendMessage tabId,

  getBaseUrl: (url) -> url.split("#")[0]

  # Create a global mark.  We record vimiumSecret with the mark so that we can tell later, when the mark is
  # used, whether this is the original Vimium instantiation or a subsequent instantiation.  This affects
  # whether or not tabId can be considered valid.
  create: (req, sender) ->
    chrome.storage.local.get "vimiumSecret", (items) =>
      item = {}
      item[@getLocationKey req.markName] =
        vimiumSecret: items.vimiumSecret
        tabId: sender.tab.id
        url: @getBaseUrl sender.tab.url
        scrollX: req.scrollX
        scrollY: req.scrollY
        markName: req.markName
      chrome.storage.sync.set item

  goto: (req, sender) ->
    chrome.storage.local.get "vimiumSecret", (items) =>
      vimiumSecret = items.vimiumSecret

            @gotoPositionInTab extend markInfo, tabId: tab.id
            return
      # There is no existing matching tab, we'll have to create one.
      chrome.tabs.create { url: @getBaseUrl markInfo.url }, (tab) =>
        # Note. tabLoadedHandlers is defined in "main.coffee".  The handler below will be called when the tab
        # is loaded, its DOM is ready and it registers with the background page.
        tabLoadedHandlers[tab.id] = => @gotoPositionInTab extend markInfo, tabId: tab.id
