Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: safari/ext/background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Patch Set: Rebased and used map func for migration code Created March 13, 2015, 10:30 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « metadata.chrome ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: safari/ext/background.js
===================================================================
--- a/safari/ext/background.js
+++ b/safari/ext/background.js
@@ -670,7 +670,67 @@
/* Storage */
- ext.storage = safari.extension.settings;
+ ext.storage = {
+ get: function(keys, callback)
+ {
+ var items = {};
+ var settings = safari.extension.settings;
+
+ for (var i = 0; i < keys.length; i++)
+ {
+ var key = keys[i];
+ if (key in settings)
+ items[key] = settings[key];
+ }
+
+ setTimeout(callback, 0, items);
+ },
+ set: function(key, value, callback)
+ {
+ safari.extension.settings[key] = value;
+
+ if (callback)
+ setTimeout(callback, 0);
+ },
+ remove: function(key, callback)
+ {
+ delete safari.extension.settings[key];
+
+ if (callback)
+ setTimeout(callback, 0);
+ },
+ onChanged: new ext._EventTarget(),
+
+ // Preferences were previously encoded as JSON for compatibility
+ // with localStorage, which has been used on Chrome.
+ migratePrefs: function(mapFunc)
+ {
+ var settings = safari.extension.settings;
+
+ for (var key in settings)
+ {
+ var item = mapFunc(key, settings[key]);
+ if (item)
Wladimir Palant 2015/03/16 12:20:26 Add |&& item.key != key| here? I think we will kee
Sebastian Noack 2015/03/16 12:54:34 Done.
+ {
+ delete settings[key];
+ settings[item.key] = item.value;
+ }
+ }
+ }
+ };
+
+ safari.extension.settings.addEventListener("change", function(event)
+ {
+ var changes = {};
+ var change = changes[event.key] = {};
+
+ if (event.oldValue != null)
+ change.oldValue = event.oldValue;
+ if (event.newValue != null)
+ change.newValue = event.newValue;
+
+ ext.storage.onChanged._dispatch(changes);
+ });
/* Options */
« no previous file with comments | « metadata.chrome ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld