aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--background_scripts/settings.coffee28
-rw-r--r--lib/utils.coffee7
-rw-r--r--tests/unit_tests/test_chrome_stubs.coffee3
3 files changed, 25 insertions, 13 deletions
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
index 6b33d239..607264a2 100644
--- a/background_scripts/settings.coffee
+++ b/background_scripts/settings.coffee
@@ -175,16 +175,18 @@ root.Settings = Settings =
# Export Sync via Settings for tests.
root.Settings.Sync = Sync
-
-# 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"))
-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 [])
+# Perform migration from old settings versions, if this is the background page.
+if Utils.isBackgroundPage()
+
+ # 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"))
+ 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/lib/utils.coffee b/lib/utils.coffee
index 65e26b7a..835b0359 100644
--- a/lib/utils.coffee
+++ b/lib/utils.coffee
@@ -2,6 +2,13 @@ Utils =
getCurrentVersion: ->
chrome.runtime.getManifest().version
+ # Returns true whenever the current page is from the extension's origin (and thus can access the
+ # extension's localStorage).
+ isExtensionPage: -> document.location?.origin + "/" == chrome.extension.getURL ""
+
+ # Returns true whenever the current page is the extension's background page.
+ isBackgroundPage: -> @isExtensionPage() and chrome.extension.getBackgroundPage() == window
+
# Takes a dot-notation object string and call the function
# that it points to with the correct value for 'this'.
invokeCommandString: (str, argArray) ->
diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee
index 60f3a890..16f0e144 100644
--- a/tests/unit_tests/test_chrome_stubs.coffee
+++ b/tests/unit_tests/test_chrome_stubs.coffee
@@ -19,6 +19,9 @@ exports.chrome =
onInstalled:
addListener: ->
+ extension:
+ getURL: (path) -> path
+
tabs:
onSelectionChanged:
addListener: () -> true