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 renamed onProgress() to checkLoaded() Created April 8, 2015, 3:12 p.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
« background.js ('K') | « qunit/common.js ('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
@@ -693,7 +693,70 @@
/* 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(hooks)
+ {
+ var settings = safari.extension.settings;
+
+ for (var key in settings)
+ {
+ var item = hooks.map(key, settings[key]);
+
+ if (item)
+ {
+ delete settings[key];
+ settings[item.key] = item.value;
+ }
+ }
+
+ hooks.done();
+ }
+ };
+
+ 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 */
« background.js ('K') | « qunit/common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld