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

Side by Side Diff: lib/prefs.js

Issue 5732725684174848: Use safari.extension.settings instead of localStorage and WebSQL (Closed)
Patch Set: Created March 12, 2014, 2:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/filesystem/io.js ('k') | lib/storage/io.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2013 Eyeo GmbH 3 * Copyright (C) 2006-2013 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 43
44 let listeners = []; 44 let listeners = [];
45 45
46 function defineProperty(key) 46 function defineProperty(key)
47 { 47 {
48 let value = null; 48 let value = null;
49 Prefs.__defineGetter__(key, function() 49 Prefs.__defineGetter__(key, function()
50 { 50 {
51 if (value === null) 51 if (value === null)
52 { 52 {
53 if (key in localStorage) 53 if (key in ext.storage)
54 { 54 {
55 try 55 try
56 { 56 {
57 value = JSON.parse(localStorage[key]); 57 value = JSON.parse(ext.storage[key]);
58 } 58 }
59 catch(e) 59 catch(e)
60 { 60 {
61 Cu.reportError(e); 61 Cu.reportError(e);
62 } 62 }
63 } 63 }
64 64
65 if (value === null) 65 if (value === null)
66 value = JSON.parse(JSON.stringify(defaults[key])); 66 value = JSON.parse(JSON.stringify(defaults[key]));
67 } 67 }
68 return value; 68 return value;
69 }); 69 });
70 Prefs.__defineSetter__(key, function(newValue) 70 Prefs.__defineSetter__(key, function(newValue)
71 { 71 {
72 if (typeof newValue != typeof defaults[key]) 72 if (typeof newValue != typeof defaults[key])
73 throw new Error("Attempt to change preference type"); 73 throw new Error("Attempt to change preference type");
74 74
75 let stringified = JSON.stringify(newValue); 75 let stringified = JSON.stringify(newValue);
76 if (stringified != JSON.stringify(defaults[key])) 76 if (stringified != JSON.stringify(defaults[key]))
77 localStorage[key] = stringified; 77 ext.storage[key] = stringified;
78 else 78 else
79 delete localStorage[key]; 79 delete ext.storage[key];
80 80
81 value = newValue; 81 value = newValue;
82 82
83 for each (let listener in listeners) 83 for each (let listener in listeners)
84 listener(key); 84 listener(key);
85 85
86 return value; 86 return value;
87 }); 87 });
88 } 88 }
89 89
90 90
91 let Prefs = exports.Prefs = { 91 let Prefs = exports.Prefs = {
92 addListener: function(listener) 92 addListener: function(listener)
93 { 93 {
94 if (listeners.indexOf(listener) < 0) 94 if (listeners.indexOf(listener) < 0)
95 listeners.push(listener); 95 listeners.push(listener);
96 }, 96 },
97 97
98 removeListener: function(listener) 98 removeListener: function(listener)
99 { 99 {
100 let index = listeners.indexOf(listener); 100 let index = listeners.indexOf(listener);
101 if (index >= 0) 101 if (index >= 0)
102 listeners.splice(index, 1); 102 listeners.splice(index, 1);
103 }, 103 },
104 }; 104 };
105 105
106 for (let key in defaults) 106 for (let key in defaults)
107 defineProperty(key); 107 defineProperty(key);
OLDNEW
« no previous file with comments | « lib/filesystem/io.js ('k') | lib/storage/io.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld