From c7ada0369f5f49180246eec655249a85643d5df2 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 8 Feb 2015 08:54:12 +0000 Subject: Refactor migration code for find-mode history. Doing the migration in a content script is dumb. Now we do it on the background page. --- background_scripts/settings.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index 2fc3b43d..70b94429 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -121,3 +121,11 @@ root.Settings = Settings = if Utils.compareVersions("1.42", Settings.get("settingsVersion")) != -1 Settings.set("scrollStepSize", parseFloat Settings.get("scrollStepSize")) Settings.set("settingsVersion", Utils.getCurrentVersion()) + +# Migration (after 1.49, 2015/2/1). +# Legacy setting: findModeRawQuery (a string). +# New setting: findModeRawQueryList (a list of strings). +unless Settings.has "findModeRawQueryList" + rawQuery = Settings.get "findModeRawQuery" + Settings.set "findModeRawQueryList", (if rawQuery then [ rawQuery ] else []) + -- cgit v1.2.3 From 534e460f437ade1016ddff6d7ffa2c2e6b254b17 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 8 Feb 2015 09:18:50 +0000 Subject: Incognito mode for find history. - This commit is incomplete because, to progress, we need bc7db7473456713c8c84f324e71da93145ffa2a0. --- background_scripts/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index c1c8dfc8..07127af9 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -382,7 +382,7 @@ root.updateActiveState = updateActiveState = (tabId) -> setBrowserActionIcon(tabId,disabledIcon) # Propagate the new state only if it has changed. if (isCurrentlyEnabled != enabled || currentPasskeys != passKeys) - chrome.tabs.sendMessage(tabId, { name: "setState", enabled: enabled, passKeys: passKeys }) + chrome.tabs.sendMessage(tabId, { name: "setState", enabled: enabled, passKeys: passKeys, incognito: tab.incognito }) else # We didn't get a response from the front end, so Vimium isn't running. setBrowserActionIcon(tabId,disabledIcon) -- cgit v1.2.3 From 1df1b9bdcd7155631d048a3645541db525cd4443 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 8 Feb 2015 12:17:42 +0000 Subject: Fix background-page error on "yy". The return value from copyToClipboard is passed to sendResponse by the chrome.runtime.onMessage.addListener listener. This was using the (somewhat arbitrary) value returned by Clipboard.copy, which turns out to be circular, causing an error. This fixes that. --- background_scripts/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 07127af9..06df8988 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -170,7 +170,7 @@ upgradeNotificationClosed = (request) -> # # Copies some data (request.data) to the clipboard. # -copyToClipboard = (request) -> Clipboard.copy(request.data) +copyToClipboard = (request) -> Clipboard.copy(request.data); null # # Selects the tab with the ID specified in request.id -- cgit v1.2.3 From 3af220b4b26d10e87db2a3caf734dd3a4139a378 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 8 Feb 2015 12:39:16 +0000 Subject: Find-mode history now incorporates ingognito mode. --- background_scripts/main.coffee | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 06df8988..65b97aff 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -189,6 +189,10 @@ handleSettings = (args, port) -> port.postMessage({ key: args.key, value: value }) else # operation == "set" Settings.set(args.key, args.value) + # For some settings, we propagate changes to all tabs immediately. + # In the case of findModeRawQueryList, this allows each tab to accurately track the find-mode history. + if args.key in [ "findModeRawQueryList" ] + sendRequestToAllTabs extend args, name: "updateSettings" refreshCompleter = (request) -> completers[request.name].refresh() -- cgit v1.2.3 From 7b451aaca8d8c84aab77ac262753c6239b466791 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 8 Feb 2015 14:13:38 +0000 Subject: Push fond-mode queries from incognito-mode tabs to other incognito tabs. --- background_scripts/main.coffee | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 65b97aff..54e0491b 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -188,7 +188,7 @@ handleSettings = (args, port) -> value = Settings.get(args.key) port.postMessage({ key: args.key, value: value }) else # operation == "set" - Settings.set(args.key, args.value) + Settings.set(args.key, args.value) unless args.incognito and args.key in [ "findModeRawQueryList" ] # For some settings, we propagate changes to all tabs immediately. # In the case of findModeRawQueryList, this allows each tab to accurately track the find-mode history. if args.key in [ "findModeRawQueryList" ] @@ -593,12 +593,15 @@ checkKeyQueue = (keysToCheck, tabId, frameId) -> # # Message all tabs. Args should be the arguments hash used by the Chrome sendRequest API. +# Normally, the request is sent to all tabs. However, if args.incognito is set, then the request is only sent +# to incognito tabs. # sendRequestToAllTabs = (args) -> chrome.windows.getAll({ populate: true }, (windows) -> for window in windows for tab in window.tabs - chrome.tabs.sendMessage(tab.id, args, null)) + if not args.incognito or tab.incognito + chrome.tabs.sendMessage(tab.id, args, null)) # # Returns true if the current extension version is greater than the previously recorded version in -- cgit v1.2.3 From 11609b918485ee4c3a659bee9dc0c420fb04ddcc Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 8 Feb 2015 15:30:04 +0000 Subject: Proper find-mode history for incognito mode. Approach: - We never save the find mode history from an incognito tab in the settings, instead they are saved in the tabMapInfo for each currently-active incognito tab. - When a new incognito tab (or page, after navigation) starts, we scan the tabMapInfo looking for the find-mode history of any active tab. In this way, the history is shared between incognito tabs, but discarded once the last incognito tab closes. --- background_scripts/main.coffee | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 54e0491b..b4eac4f1 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -193,6 +193,15 @@ handleSettings = (args, port) -> # In the case of findModeRawQueryList, this allows each tab to accurately track the find-mode history. if args.key in [ "findModeRawQueryList" ] sendRequestToAllTabs extend args, name: "updateSettings" + # We also track the incognito find-mode history setting in the tabInfoMap for all incognito tabs. + if args.incognito and args.key == "findModeRawQueryList" + for own _, map of tabInfoMap + map.findModeRawQueryList = args.value if map.incognito + +# Search through the active tab map for an up-to-date find-mode history for an incognito-mode tab. +getIncognitoRawQueryList = -> + for own id, map of tabInfoMap + return map.findModeRawQueryList if map.findModeRawQueryList refreshCompleter = (request) -> completers[request.name].refresh() @@ -337,6 +346,8 @@ updateOpenTabs = (tab) -> scrollX: null scrollY: null deletor: null + incognito: tab.incognito + findModeRawQueryList: null # Frames are recreated on refresh delete frameIdsForTab[tab.id] @@ -661,6 +672,7 @@ sendRequestHandlers = createMark: Marks.create.bind(Marks) gotoMark: Marks.goto.bind(Marks) setBadge: setBadge + getIncognitoRawQueryList: getIncognitoRawQueryList # Convenience function for development use. window.runTests = -> open(chrome.runtime.getURL('tests/dom_tests/dom_tests.html')) -- cgit v1.2.3 From b4f0645075ca79f8b2eb5ad942fb51f5076c6a40 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 9 Feb 2015 08:29:10 +0000 Subject: Initial find-mode history via chrome.storage. --- background_scripts/main.coffee | 38 +++++++++++++++++--------------------- background_scripts/settings.coffee | 10 +++++----- background_scripts/sync.coffee | 2 +- 3 files changed, 23 insertions(+), 27 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index b4eac4f1..286781b4 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -188,20 +188,7 @@ handleSettings = (args, port) -> value = Settings.get(args.key) port.postMessage({ key: args.key, value: value }) else # operation == "set" - Settings.set(args.key, args.value) unless args.incognito and args.key in [ "findModeRawQueryList" ] - # For some settings, we propagate changes to all tabs immediately. - # In the case of findModeRawQueryList, this allows each tab to accurately track the find-mode history. - if args.key in [ "findModeRawQueryList" ] - sendRequestToAllTabs extend args, name: "updateSettings" - # We also track the incognito find-mode history setting in the tabInfoMap for all incognito tabs. - if args.incognito and args.key == "findModeRawQueryList" - for own _, map of tabInfoMap - map.findModeRawQueryList = args.value if map.incognito - -# Search through the active tab map for an up-to-date find-mode history for an incognito-mode tab. -getIncognitoRawQueryList = -> - for own id, map of tabInfoMap - return map.findModeRawQueryList if map.findModeRawQueryList + Settings.set(args.key, args.value) refreshCompleter = (request) -> completers[request.name].refresh() @@ -346,8 +333,6 @@ updateOpenTabs = (tab) -> scrollX: null scrollY: null deletor: null - incognito: tab.incognito - findModeRawQueryList: null # Frames are recreated on refresh delete frameIdsForTab[tab.id] @@ -604,15 +589,12 @@ checkKeyQueue = (keysToCheck, tabId, frameId) -> # # Message all tabs. Args should be the arguments hash used by the Chrome sendRequest API. -# Normally, the request is sent to all tabs. However, if args.incognito is set, then the request is only sent -# to incognito tabs. # sendRequestToAllTabs = (args) -> chrome.windows.getAll({ populate: true }, (windows) -> for window in windows for tab in window.tabs - if not args.incognito or tab.incognito - chrome.tabs.sendMessage(tab.id, args, null)) + chrome.tabs.sendMessage(tab.id, args, null)) # # Returns true if the current extension version is greater than the previously recorded version in @@ -672,7 +654,21 @@ sendRequestHandlers = createMark: Marks.create.bind(Marks) gotoMark: Marks.goto.bind(Marks) setBadge: setBadge - getIncognitoRawQueryList: getIncognitoRawQueryList + +# We always remove chrome.storage.local/findModeRawQueryListIncognito on startup. +chrome.storage.local.remove "findModeRawQueryListIncognito" + +# Remove chrome.storage.local/findModeRawQueryListIncognito if there are no remaining incognito-mode tabs. +# 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) -> + chrome.storage.local.get "findModeRawQueryListIncognito", (items) -> + if items.findModeRawQueryListIncognito + chrome.windows.getAll { populate: true }, (windows) -> + for window in windows + for tab in window.tabs + return if tab.incognito and tab.id != tabId + # There are no remaining incognito-mode tabs, and findModeRawQueryListIncognito is set. + chrome.storage.local.remove "findModeRawQueryListIncognito" # Convenience function for development use. window.runTests = -> open(chrome.runtime.getURL('tests/dom_tests/dom_tests.html')) diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index 70b94429..7430145c 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -116,7 +116,6 @@ root.Settings = Settings = settingsVersion: Utils.getCurrentVersion() - # We use settingsVersion to coordinate any necessary schema changes. if Utils.compareVersions("1.42", Settings.get("settingsVersion")) != -1 Settings.set("scrollStepSize", parseFloat Settings.get("scrollStepSize")) @@ -124,8 +123,9 @@ Settings.set("settingsVersion", Utils.getCurrentVersion()) # Migration (after 1.49, 2015/2/1). # Legacy setting: findModeRawQuery (a string). -# New setting: findModeRawQueryList (a list of strings). -unless Settings.has "findModeRawQueryList" - rawQuery = Settings.get "findModeRawQuery" - Settings.set "findModeRawQueryList", (if rawQuery then [ rawQuery ] else []) +# New setting: findModeRawQueryList (a list of strings), now stored in chrome.storage.local (not localStorage). +chrome.storage.local.get "findModeRawQueryList", (items) -> + unless chrome.runtime.lastError or items.findModeRawQueryList + rawQuery = Settings.get "findModeRawQuery" + chrome.storage.local.set findModeRawQueryList: (if rawQuery then [ rawQuery ] else []) diff --git a/background_scripts/sync.coffee b/background_scripts/sync.coffee index f1850438..866faca1 100644 --- a/background_scripts/sync.coffee +++ b/background_scripts/sync.coffee @@ -42,7 +42,7 @@ root.Sync = Sync = # Only ever called from asynchronous synced-storage callbacks (fetchAsync and handleStorageUpdate). storeAndPropagate: (key, value) -> - return if not key of Settings.defaults + return unless key of Settings.defaults return if not @shouldSyncKey key return if value and key of localStorage and localStorage[key] is value defaultValue = Settings.defaults[key] -- cgit v1.2.3 From 88f6eab0908ee05e67f4883ca3419681e7de39ef Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Mon, 9 Feb 2015 08:55:47 +0000 Subject: Propagate queries to incognito-mode tabs. --- background_scripts/settings.coffee | 1 + 1 file changed, 1 insertion(+) (limited to 'background_scripts') diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee index 7430145c..f43bd4bc 100644 --- a/background_scripts/settings.coffee +++ b/background_scripts/settings.coffee @@ -116,6 +116,7 @@ root.Settings = Settings = settingsVersion: Utils.getCurrentVersion() + # We use settingsVersion to coordinate any necessary schema changes. if Utils.compareVersions("1.42", Settings.get("settingsVersion")) != -1 Settings.set("scrollStepSize", parseFloat Settings.get("scrollStepSize")) -- cgit v1.2.3