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 used map func for migration code Created March 13, 2015, 10:30 a.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 | « metadata.chrome ('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 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 // only when reloading the page or following links, but not when 663 // only when reloading the page or following links, but not when
664 // the current page is replaced with a prerendered page. 664 // the current page is replaced with a prerendered page.
665 replacePage(pages[event.message.pageId]); 665 replacePage(pages[event.message.pageId]);
666 break; 666 break;
667 } 667 }
668 }); 668 });
669 669
670 670
671 /* Storage */ 671 /* Storage */
672 672
673 ext.storage = safari.extension.settings; 673 ext.storage = {
674 get: function(keys, callback)
675 {
676 var items = {};
677 var settings = safari.extension.settings;
678
679 for (var i = 0; i < keys.length; i++)
680 {
681 var key = keys[i];
682 if (key in settings)
683 items[key] = settings[key];
684 }
685
686 setTimeout(callback, 0, items);
687 },
688 set: function(key, value, callback)
689 {
690 safari.extension.settings[key] = value;
691
692 if (callback)
693 setTimeout(callback, 0);
694 },
695 remove: function(key, callback)
696 {
697 delete safari.extension.settings[key];
698
699 if (callback)
700 setTimeout(callback, 0);
701 },
702 onChanged: new ext._EventTarget(),
703
704 // Preferences were previously encoded as JSON for compatibility
705 // with localStorage, which has been used on Chrome.
706 migratePrefs: function(mapFunc)
707 {
708 var settings = safari.extension.settings;
709
710 for (var key in settings)
711 {
712 var item = mapFunc(key, settings[key]);
713 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.
714 {
715 delete settings[key];
716 settings[item.key] = item.value;
717 }
718 }
719 }
720 };
721
722 safari.extension.settings.addEventListener("change", function(event)
723 {
724 var changes = {};
725 var change = changes[event.key] = {};
726
727 if (event.oldValue != null)
728 change.oldValue = event.oldValue;
729 if (event.newValue != null)
730 change.newValue = event.newValue;
731
732 ext.storage.onChanged._dispatch(changes);
733 });
674 734
675 735
676 /* Options */ 736 /* Options */
677 737
678 ext.showOptions = function(callback) 738 ext.showOptions = function(callback)
679 { 739 {
680 var optionsUrl = safari.extension.baseURI + "options.html"; 740 var optionsUrl = safari.extension.baseURI + "options.html";
681 741
682 for (var id in pages) 742 for (var id in pages)
683 { 743 {
684 var page = pages[id]; 744 var page = pages[id];
685 var tab = page._tab; 745 var tab = page._tab;
686 746
687 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow) 747 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow)
688 { 748 {
689 tab.activate(); 749 tab.activate();
690 if (callback) 750 if (callback)
691 callback(page); 751 callback(page);
692 return; 752 return;
693 } 753 }
694 } 754 }
695 755
696 ext.pages.open(optionsUrl, callback); 756 ext.pages.open(optionsUrl, callback);
697 }; 757 };
698 })(); 758 })();
OLDNEW
« no previous file with comments | « metadata.chrome ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld