aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2015-02-09 14:17:03 +0000
committerStephen Blott2015-02-09 14:17:03 +0000
commit9f20c33adf75e2e78b35e2cd16f2a0925a72c577 (patch)
treef94654449c387b8b94d34051b2557a0ec99ee8bb
parenta2ab96e858ddb5ec0b9f17e47936b2a571e90ab4 (diff)
parentb0ffde36732eee6a6b114927d45ae4d1e7ab0107 (diff)
downloadvimium-9f20c33adf75e2e78b35e2cd16f2a0925a72c577.tar.bz2
Merge branch 'find-mode-history-for-incognito-mode'
Conflicts: background_scripts/main.coffee
-rw-r--r--background_scripts/main.coffee20
-rw-r--r--background_scripts/settings.coffee9
-rw-r--r--content_scripts/vimium_frontend.coffee66
-rw-r--r--tests/unit_tests/test_chrome_stubs.coffee2
4 files changed, 75 insertions, 22 deletions
diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee
index 5a126ceb..8f51b374 100644
--- a/background_scripts/main.coffee
+++ b/background_scripts/main.coffee
@@ -172,7 +172,10 @@ upgradeNotificationClosed = (request) ->
# We return null to avoid the return value from the copy operations being passed to sendResponse.
#
copyToClipboard = (request) -> Clipboard.copy(request.data); null
+<<<<<<< HEAD
pasteFromClipboard = (request) -> Clipboard.paste(); null
+=======
+>>>>>>> @{-1}
#
# Selects the tab with the ID specified in request.id
@@ -384,7 +387,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)
@@ -658,6 +661,21 @@ sendRequestHandlers =
gotoMark: Marks.goto.bind(Marks)
setBadge: setBadge
+# 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 2fc3b43d..f43bd4bc 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -121,3 +121,12 @@ 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), 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/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee
index 4fdf58bd..a0f4b0fe 100644
--- a/content_scripts/vimium_frontend.coffee
+++ b/content_scripts/vimium_frontend.coffee
@@ -12,6 +12,7 @@ findModeInitialRange = null
isShowingHelpDialog = false
keyPort = null
isEnabledForUrl = true
+isIncognitoMode = false
passKeys = null
keyQueue = null
# The user's operating system.
@@ -41,9 +42,9 @@ settings =
port: null
values: {}
loadedValues: 0
- valuesToLoad: ["scrollStepSize", "linkHintCharacters", "linkHintNumbers", "filterLinkHints", "hideHud",
- "previousPatterns", "nextPatterns", "findModeRawQuery", "findModeRawQueryList", "regexFindMode", "userDefinedLinkHintCss",
- "helpDialog_showAdvancedCommands", "smoothScroll"]
+ valuesToLoad: [ "scrollStepSize", "linkHintCharacters", "linkHintNumbers", "filterLinkHints", "hideHud",
+ "previousPatterns", "nextPatterns", "regexFindMode", "userDefinedLinkHintCss",
+ "helpDialog_showAdvancedCommands", "smoothScroll" ]
isLoaded: false
eventListeners: {}
@@ -186,7 +187,9 @@ window.initializeWhenEnabled = ->
setState = (request) ->
isEnabledForUrl = request.enabled
passKeys = request.passKeys
+ isIncognitoMode = request.incognito
initializeWhenEnabled() if isEnabledForUrl
+ FindModeHistory.init()
handlerStack.bubbleEvent "registerStateChange",
enabled: isEnabledForUrl
passKeys: passKeys
@@ -551,27 +554,48 @@ window.refreshCompletionKeys = (response) ->
isValidFirstKey = (keyChar) ->
validFirstKeys[keyChar] || /^[1-9]/.test(keyChar)
-# This implements a find-mode query history (using the "findModeRawQueryList" setting) as a list of raw
-# queries, most recent first.
+# This implements find-mode query history (using the "findModeRawQueryList" setting) as a list of raw queries,
+# most recent first.
FindModeHistory =
+ storage: chrome.storage.local
+ key: "findModeRawQueryList"
+ max: 50
+ rawQueryList: null
+
+ init: ->
+ unless @rawQueryList
+ @rawQueryList = [] # Prevent repeated initialization.
+ @key = "findModeRawQueryListIncognito" if isIncognitoMode
+ @storage.get @key, (items) =>
+ unless chrome.runtime.lastError
+ @rawQueryList = items[@key] if items[@key]
+ if isIncognitoMode and not items[@key]
+ # This is the first incognito tab, so we need to initialize the incognito-mode query history.
+ @storage.get "findModeRawQueryList", (items) =>
+ unless chrome.runtime.lastError
+ @rawQueryList = items.findModeRawQueryList
+ @storage.set findModeRawQueryListIncognito: @rawQueryList
+
+ chrome.storage.onChanged.addListener (changes, area) =>
+ @rawQueryList = changes[@key].newValue if changes[@key]
+
getQuery: (index = 0) ->
- @migration()
- recentQueries = settings.get "findModeRawQueryList"
- if index < recentQueries.length then recentQueries[index] else ""
+ @rawQueryList[index] or ""
- recordQuery: (query) ->
- @migration()
+ saveQuery: (query) ->
if 0 < query.length
- recentQueries = settings.get "findModeRawQueryList"
- settings.set "findModeRawQueryList", ([ query ].concat recentQueries.filter (q) -> q != query)[0..50]
-
- # Migration (from 1.49, 2015/2/1).
- # Legacy setting: findModeRawQuery (a string).
- # New setting: findModeRawQueryList (a list of strings).
- migration: ->
- unless settings.get "findModeRawQueryList"
- rawQuery = settings.get "findModeRawQuery"
- settings.set "findModeRawQueryList", (if rawQuery then [ rawQuery ] else [])
+ @rawQueryList = @refreshRawQueryList query, @rawQueryList
+ newSetting = {}; newSetting[@key] = @rawQueryList
+ @storage.set newSetting
+ # If there are any active incognito-mode tabs, then propagte this query to those tabs too.
+ unless isIncognitoMode
+ @storage.get "findModeRawQueryListIncognito", (items) =>
+ if not chrome.runtime.lastError and items.findModeRawQueryListIncognito
+ @storage.set
+ findModeRawQueryListIncognito: @refreshRawQueryList query, items.findModeRawQueryListIncognito
+
+ refreshRawQueryList: (query, rawQueryList) ->
+ ([ query ].concat rawQueryList.filter (q) => q != query)[0..@max]
# should be called whenever rawQuery is modified.
updateFindModeQuery = ->
@@ -665,7 +689,7 @@ handleEnterForFindMode = ->
exitFindMode()
focusFoundLink()
document.body.classList.add("vimiumFindMode")
- FindModeHistory.recordQuery findModeQuery.rawQuery
+ FindModeHistory.saveQuery findModeQuery.rawQuery
class FindMode extends Mode
constructor: ->
diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee
index 7f666068..c61d7246 100644
--- a/tests/unit_tests/test_chrome_stubs.coffee
+++ b/tests/unit_tests/test_chrome_stubs.coffee
@@ -46,7 +46,9 @@ exports.chrome =
storage:
# chrome.storage.local
local:
+ get: ->
set: ->
+ remove: ->
# chrome.storage.onChanged
onChanged: