diff options
| author | Stephen Blott | 2016-04-02 10:32:53 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2016-04-02 10:35:43 +0100 | 
| commit | 175f4b275c49ba332000ab773061777af820a87f (patch) | |
| tree | fa9701436f1c6a366bbdd3283dad13d4ee7926f8 | |
| parent | 03e010f0aeb835778664438549f168ccae297d7c (diff) | |
| download | vimium-175f4b275c49ba332000ab773061777af820a87f.tar.bz2 | |
Do not register tiny frames.
This affects focusFrame and link hints.
We do not register tiny frames.  The reason for doing this is that link
hints messages all (registered) frames to collect their hint
descriptors.  On some sites (e.g. Google Inbox and other Google
properties), there are many tiny iframes (on the order of 12 or 15 or
so).  Those frames cannot provide useful hints, so -- by not registering
them -- we don't ask them for hints.
The intention is to speed up the link-hints activation sequence.
| -rw-r--r-- | background_scripts/main.coffee | 8 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 29 | 
2 files changed, 24 insertions, 13 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 241c809b..dea436ef 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -291,6 +291,8 @@ Frames =    onConnect: (sender, port) ->      [tabId, frameId] = [sender.tab.id, sender.frameId]      port.postMessage handler: "registerFrameId", chromeFrameId: frameId +    # We only register the top frame automatically; other frames request registration via "registerFrame". +    @registerFrame {tabId, frameId, port} if frameId == 0      port.onDisconnect.addListener listener = ->        # Unregister the frame.  However, we never unregister the main/top frame.  If the tab is navigating to @@ -307,10 +309,8 @@ Frames =        this[request.handler] {request, tabId, frameId, port}    registerFrame: ({tabId, frameId, port}) -> -    frameIdsForTab[tabId] ?= [] -    frameIdsForTab[tabId].push frameId unless frameId in frameIdsForTab[tabId] -    portsForTab[tabId] ?= {} -    portsForTab[tabId][frameId] = port +    frameIdsForTab[tabId].push frameId unless frameId in frameIdsForTab[tabId] ?= [] +    (portsForTab[tabId] ?= {})[frameId] = port    isEnabledForUrl: ({request, tabId, port}) ->      urlForTab[tabId] = request.url if request.frameIsFocused diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index fb8742e0..f14c5d07 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -138,15 +138,12 @@ installModes = ->  initializeOnEnabledStateKnown = Utils.makeIdempotent ->    installModes() -registerFrame = -> -  Frame.postMessage "registerFrame" -  # -# Complete initialization work that sould be done prior to DOMReady. +# Complete initialization work that should be done prior to DOMReady.  #  initializePreDomReady = ->    installListeners() -  Frame.init registerFrame +  Frame.init()    checkIfEnabledForUrl()    requestHandlers = @@ -214,10 +211,26 @@ Frame =    addEventListener: (handler, callback) -> @listeners[handler] = callback    postMessage: (handler, request = {}) -> @port.postMessage extend request, {handler} -  registerFrameId: ({chromeFrameId}) -> frameId = window.frameId = chromeFrameId    linkHintsMessage: (request) -> HintCoordinator[request.messageType] request +  registerFrameId: ({chromeFrameId}) -> +    frameId = window.frameId = chromeFrameId +    unless frameId == 0 +      # The background page registers the top frame automatically.  We register any other frame immediately if +      # it is focused or its window isn't tiny.  We register tiny frames later, when necessary.  This affects +      # focusFrame() and link hints. +      if windowIsFocused() or not DomUtils.windowIsTooSmall() +        Frame.postMessage "registerFrame" +      else +        postRegisterFrame = -> +          window.removeEventListener "focus", focusHandler +          window.removeEventListener "resize", resizeHandler +          Frame.postMessage "registerFrame" +        window.addEventListener "focus", focusHandler = -> +          postRegisterFrame() if event.target == window +        window.addEventListener "resize", resizeHandler = -> +          postRegisterFrame() unless DomUtils.windowIsTooSmall() -  init: (callback = null) -> +  init: ->      @port = chrome.runtime.connect name: "frames"      @port.onMessage.addListener (request) => @@ -228,8 +241,6 @@ Frame =        isEnabledForUrl = false        window.removeEventListener "focus", onFocus -    callback?() -  setScrollPosition = ({ scrollX, scrollY }) ->    if DomUtils.isTopFrame()      DomUtils.documentReady -> | 
