 
   # Receive hint descriptors from all frames and activate link-hints mode when we have them all.
   postHintDescriptors: (tabId, frameId, {hintDescriptors}) ->
-    if frameId in @tabState[tabId].frameIds
-      @tabState[tabId].hintDescriptors[frameId] = hintDescriptors
-      @tabState[tabId].frameIds = @tabState[tabId].frameIds.filter (fId) -> fId != frameId
-      if @tabState[tabId].frameIds.length == 0
-        for own frameId, port of @tabState[tabId].ports
-          if frameId of @tabState[tabId].hintDescriptors
-            hintDescriptors = extend {}, @tabState[tabId].hintDescriptors
-            # We do not send back the frame's own hint descriptors.  This is faster (approx. speedup 3/2) for
-            # link-busy sites like reddit.
-            delete hintDescriptors[frameId]
-            @postMessage tabId, parseInt(frameId), "activateMode", port,
-              originatingFrameId: @tabState[tabId].originatingFrameId
-              hintDescriptors: hintDescriptors
-              modeIndex: @tabState[tabId].modeIndex
+    if frameId not in @tabState[tabId].frameIds
+      return
+    @tabState[tabId].hintDescriptors[frameId] = hintDescriptors
+    @tabState[tabId].frameIds = @tabState[tabId].frameIds.filter (fId) -> fId != frameId
+    if @tabState[tabId].frameIds.length == 0
+      for own frameId, port of @tabState[tabId].ports
+        if frameId of @tabState[tabId].hintDescriptors
+          hintDescriptors = extend {}, @tabState[tabId].hintDescriptors
+          # We do not send back the frame's own hint descriptors.  This is faster (approx. speedup 3/2) for
+          # link-busy sites like reddit.
+          delete hintDescriptors[frameId]
+          @postMessage tabId, parseInt(frameId), "activateMode", port,
+            originatingFrameId: @tabState[tabId].originatingFrameId
+            hintDescriptors: hintDescriptors
+            modeIndex: @tabState[tabId].modeIndex
+    return
 
   # If an unregistering frame is participating in link-hints mode, then we need to tidy up after it.
   unregisterFrame: (tabId, frameId) ->
-    if @tabState[tabId]?
-      if @tabState[tabId].ports?[frameId]?
-        delete @tabState[tabId].ports[frameId]
-      if @tabState[tabId].frameIds? and frameId in @tabState[tabId].frameIds
-        # We fake an empty "postHintDescriptors" because the frame has gone away.
-        @postHintDescriptors tabId, frameId, hintDescriptors: []
+    if !@tabState[tabId]
+      return
+    if @tabState[tabId].ports?[frameId]?
+      delete @tabState[tabId].ports[frameId]
+    if @tabState[tabId].frameIds? and frameId in @tabState[tabId].frameIds
+      # We fake an empty "postHintDescriptors" because the frame has gone away.
+      @postHintDescriptors tabId, frameId, hintDescriptors: []
 
 # Port handler mapping
 portHandlers =

# This is exported for use by "marks.coffee".
root.tabLoadedHandlers = {} # tabId -> function()

# A secret, available only within the current instantiation of Vimium.  The secret is big, likely unguessable
# in practice, but less than 2^31.
chrome.storage.local.set
  vimiumSecret: Math.floor Math.random() * 2000000000

  #     map X createTab http://www.bbc.com/news
  # create a new tab with the given URL.
  createTab: mkRepeatCommand (request, callback) ->
    if !request.urls # null check
      if request.url
        # If the request contains a URL, then use it.
        request.urls = [request.url]
    # request.urls ?=
    #   if request.url
    #     [request.url]
      else
        # Otherwise, if we have a registryEntry containing URLs, then use them.
        # urlList = (opt for opt in request.registryEntry.optionList when Utils.isUrl opt)
        urlList = request.registryEntry.optionList.filter((opt) => Utils.isUrl(opt))
        if urlList.length >= 0
          urlList
        else
          # Otherwise, just create a new tab.
