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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« background.js ('K') | « qunit/common.js ('k') | no next file » | 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 <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 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 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 // only when reloading the page or following links, but not when 686 // only when reloading the page or following links, but not when
687 // the current page is replaced with a prerendered page. 687 // the current page is replaced with a prerendered page.
688 replacePage(pages[event.message.pageId]); 688 replacePage(pages[event.message.pageId]);
689 break; 689 break;
690 } 690 }
691 }); 691 });
692 692
693 693
694 /* Storage */ 694 /* Storage */
695 695
696 ext.storage = safari.extension.settings; 696 ext.storage = {
697 get: function(keys, callback)
698 {
699 var items = {};
700 var settings = safari.extension.settings;
701
702 for (var i = 0; i < keys.length; i++)
703 {
704 var key = keys[i];
705 if (key in settings)
706 items[key] = settings[key];
707 }
708
709 setTimeout(callback, 0, items);
710 },
711 set: function(key, value, callback)
712 {
713 safari.extension.settings[key] = value;
714
715 if (callback)
716 setTimeout(callback, 0);
717 },
718 remove: function(key, callback)
719 {
720 delete safari.extension.settings[key];
721
722 if (callback)
723 setTimeout(callback, 0);
724 },
725 onChanged: new ext._EventTarget(),
726
727 // Preferences were previously encoded as JSON for compatibility
728 // with localStorage, which has been used on Chrome.
729 migratePrefs: function(hooks)
730 {
731 var settings = safari.extension.settings;
732
733 for (var key in settings)
734 {
735 var item = hooks.map(key, settings[key]);
736
737 if (item)
738 {
739 delete settings[key];
740 settings[item.key] = item.value;
741 }
742 }
743
744 hooks.done();
745 }
746 };
747
748 safari.extension.settings.addEventListener("change", function(event)
749 {
750 var changes = {};
751 var change = changes[event.key] = {};
752
753 if (event.oldValue != null)
754 change.oldValue = event.oldValue;
755 if (event.newValue != null)
756 change.newValue = event.newValue;
757
758 ext.storage.onChanged._dispatch(changes);
759 });
697 760
698 761
699 /* Options */ 762 /* Options */
700 763
701 ext.showOptions = function(callback) 764 ext.showOptions = function(callback)
702 { 765 {
703 var optionsUrl = safari.extension.baseURI + "options.html"; 766 var optionsUrl = safari.extension.baseURI + "options.html";
704 767
705 for (var id in pages) 768 for (var id in pages)
706 { 769 {
707 var page = pages[id]; 770 var page = pages[id];
708 var tab = page._tab; 771 var tab = page._tab;
709 772
710 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow) 773 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow)
711 { 774 {
712 tab.activate(); 775 tab.activate();
713 if (callback) 776 if (callback)
714 callback(page); 777 callback(page);
715 return; 778 return;
716 } 779 }
717 } 780 }
718 781
719 ext.pages.open(optionsUrl, callback); 782 ext.pages.open(optionsUrl, callback);
720 }; 783 };
721 })(); 784 })();
OLDNEW
« background.js ('K') | « qunit/common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld