diff options
| author | Stephen Blott | 2015-06-01 11:35:51 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-06-01 11:35:53 +0100 | 
| commit | 0f90453d269c5f8ab700123aa356a3d41026d925 (patch) | |
| tree | 07fbf1e236211552eda8befb822ca336a32bf03b | |
| parent | 5f0400ebac5867df74225b987ea1238bdaeb40b2 (diff) | |
| download | vimium-0f90453d269c5f8ab700123aa356a3d41026d925.tar.bz2 | |
Eliminate possibility of race condition.
See newly-added long comment for details.
| -rw-r--r-- | pages/options.coffee | 13 | ||||
| -rw-r--r-- | pages/options.html | 1 | 
2 files changed, 10 insertions, 4 deletions
| diff --git a/pages/options.coffee b/pages/options.coffee index ddab2bf4..99492291 100644 --- a/pages/options.coffee +++ b/pages/options.coffee @@ -2,6 +2,12 @@  $ = (id) -> document.getElementById id  bgExclusions = chrome.extension.getBackgroundPage().Exclusions +# We have to use Settings from the background page here (not Settings, directly) to avoid a race condition for +# the page popup.  Specifically, we must ensure that the settings have been updated on the background page +# *before* the popup closes.  This ensures that any exclusion-rule changes are in place before the page +# regains the focus. +bgSettings = chrome.extension.getBackgroundPage().Settings +  #  # Class hierarchy for various types of option.  class Option @@ -20,20 +26,21 @@ class Option    # Fetch a setting from localStorage, remember the @previous value and populate the DOM element.    # Return the fetched value.    fetch: -> -    @populateElement @previous = Settings.get @field +    @populateElement @previous = bgSettings.get @field      @previous    # Write this option's new value back to localStorage, if necessary.    save: ->      value = @readValueFromElement()      if not @areEqual value, @previous -      Settings.set @field, @previous = value +      bgSettings.set @field, @previous = value +      bgSettings.performPostUpdateHook @field, value    # Compare values; this is overridden by sub-classes.    areEqual: (a,b) -> a == b    restoreToDefault: -> -    Settings.clear @field +    bgSettings.clear @field      @fetch()    # Static method. diff --git a/pages/options.html b/pages/options.html index b14c454f..441bd9da 100644 --- a/pages/options.html +++ b/pages/options.html @@ -3,7 +3,6 @@      <title>Vimium Options</title>      <link rel="stylesheet" type="text/css" href="options.css">      <script src="content_script_loader.js"></script> -    <script type="text/javascript" src="../lib/settings.js"></script>      <script type="text/javascript" src="options.js"></script>    </head> | 
