diff options
| -rw-r--r-- | background_scripts/main.coffee | 7 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 16 |
2 files changed, 11 insertions, 12 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 5270ef02..4a982594 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -21,6 +21,7 @@ chrome.runtime.onInstalled.addListener ({ reason }) -> currentVersion = Utils.getCurrentVersion() frameIdsForTab = {} root.urlForTab = {} +topFramePortForTab = {} # This is exported for use by "marks.coffee". root.tabLoadedHandlers = {} # tabId -> function() @@ -324,6 +325,7 @@ openOptionsPageInNewTab = -> Frames = onConnect: (sender, port) -> [tabId, frameId] = [sender.tab.id, sender.frameId] + topFramePortForTab[tabId] = port if frameId == 0 frameIdsForTab[tabId] ?= [] frameIdsForTab[tabId].push frameId unless frameId in frameIdsForTab[tabId] port.postMessage handler: "registerFrameId", chromeFrameId: frameId @@ -364,6 +366,9 @@ Frames = tabLoadedHandlers[tabId]?() delete tabLoadedHandlers[tabId] + initializeTopFrameUIComponents: ({tabId}) -> + topFramePortForTab[tabId].postMessage handler: "initializeTopFrameUIComponents" + handleFrameFocused = (request, sender) -> [tabId, frameId] = [sender.tab.id, sender.frameId] frameIdsForTab[tabId] ?= [] @@ -416,7 +421,7 @@ chrome.storage.local.remove "findModeRawQueryListIncognito" # there are no remaining incognito-mode windows. Since the common case is that there are none to begin with, # we first check whether the key is set at all. chrome.tabs.onRemoved.addListener (tabId) -> - delete cache[tabId] for cache in [frameIdsForTab, urlForTab] + delete cache[tabId] for cache in [frameIdsForTab, urlForTab, topFramePortForTab] chrome.storage.local.get "findModeRawQueryListIncognito", (items) -> if items.findModeRawQueryListIncognito chrome.windows.getAll null, (windows) -> diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index a1461622..1b823dbc 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -425,17 +425,11 @@ extend window, indicator: false # Initialize UI components which are only installed in the main/top frame. -initializeTopFrameUIComponents = Utils.makeIdempotent (request = null) -> - DomUtils.documentReady -> - # We only initialize the vomnibar in the tab's top/main frame, because it's only ever opened there. - if DomUtils.isTopFrame() - Vomnibar.init() - else - # Ignore requests from other frames (because we're not the top frame). - unless request? - # Tell the top frame to initialize the Vomnibar. We already have "DOMContentLoaded". This ensures - # that the listener in the main/top frame (which are installed pre-DomReady) is ready. - chrome.runtime.sendMessage handler: "sendMessageToFrames", message: name: "initializeTopFrameUIComponents" +initializeTopFrameUIComponents = do -> + Frame.addEventListener "initializeTopFrameUIComponents", Utils.makeIdempotent Vomnibar.init.bind Vomnibar + + Utils.makeIdempotent -> + DomUtils.documentReady -> Frame.postMessage "initializeTopFrameUIComponents" # Initialize UI components which are only installed in all frames (i.e., the HUD). initializeAllFrameUIComponents = Utils.makeIdempotent -> |
