From 6653fa0e588d9fb777b627c947b377fa0518bfc8 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 14 Mar 2016 09:20:27 +0000 Subject: Use ports to track frames. Use `onConnect()`, the `domReady` port and `onDisconnect()` to track the frames within a tab. --- content_scripts/vimium_frontend.coffee | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) (limited to 'content_scripts') diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 037d01d3..c948f843 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -214,26 +214,14 @@ window.addEventListener "hashchange", onFocus # initializeOnDomReady = -> # Tell the background page we're in the dom ready state. - chrome.runtime.connect(name: "domReady").onDisconnect.addListener -> + port = chrome.runtime.connect name: "domReady" + port.postMessage handler: "registerFrame", frameId: frameId, isTopFrame: DomUtils.isTopFrame() + port.onDisconnect.addListener -> # We disable content scripts when we lose contact with the background page. isEnabledForUrl = false chrome.runtime.sendMessage = -> window.removeEventListener "focus", onFocus -registerFrame = -> - # Don't register frameset containers; focusing them is no use. - unless document.body?.tagName.toLowerCase() == "frameset" - chrome.runtime.sendMessage - handler: "registerFrame" - frameId: frameId - -# Unregister the frame if we're going to exit. -unregisterFrame = -> - chrome.runtime.sendMessage - handler: "unregisterFrame" - frameId: frameId - tab_is_closing: DomUtils.isTopFrame() - handleShowHUDforDuration = ({ text, duration }) -> if DomUtils.isTopFrame() DomUtils.documentReady -> HUD.showForDuration text, duration @@ -271,12 +259,12 @@ DomUtils.documentReady -> # Called from the backend in order to change frame focus. # focusThisFrame = (request) -> - if window.innerWidth < 3 or window.innerHeight < 3 - # This frame is too small to focus. Cancel and tell the background frame to focus the next one instead. - # This affects sites like Google Inbox, which have many tiny iframes. See #1317. - # Here we're assuming that there is at least one frame large enough to focus. - chrome.runtime.sendMessage({ handler: "nextFrame", frameId: frameId }) - return + unless request.forceFocusThisFrame + if window.innerWidth < 3 or window.innerHeight < 3 or document.body?.tagName.toLowerCase() == "frameset" + # This frame is too small to focus or its a frameset. Cancel and tell the background page to focus the + # next frame instead. This affects sites like Google Inbox, which have many tiny iframes. See 1317. + chrome.runtime.sendMessage handler: "nextFrame", frameId: frameId + return window.focus() flashFrame() if request.highlight @@ -317,7 +305,7 @@ extend window, goToRoot: -> window.location.href = window.location.origin - mainFrame: -> focusThisFrame highlight: true + mainFrame: -> focusThisFrame highlight: true, forceFocusThisFrame: true toggleViewSource: -> chrome.runtime.sendMessage { handler: "getCurrentTabUrl" }, (url) -> @@ -662,8 +650,6 @@ window.HelpDialog ?= initializePreDomReady() DomUtils.documentReady initializeOnDomReady -DomUtils.documentReady registerFrame -window.addEventListener "unload", unregisterFrame root = exports ? window root.handlerStack = handlerStack -- cgit v1.2.3