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: Fixed typo in variable name Created March 20, 2015, 3:36 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 | « 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 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(hooks)
707 {
708 var settings = safari.extension.settings;
709
710 for (var key in settings)
711 {
712 var item = hooks.map(key, settings[key]);
713
714 if (item)
715 {
716 delete settings[key];
717 settings[item.key] = item.value;
718 }
719 }
720
721 hooks.done();
722 }
723 };
724
725 safari.extension.settings.addEventListener("change", function(event)
726 {
727 var changes = {};
728 var change = changes[event.key] = {};
729
730 if (event.oldValue != null)
731 change.oldValue = event.oldValue;
732 if (event.newValue != null)
733 change.newValue = event.newValue;
734
735 ext.storage.onChanged._dispatch(changes);
736 });
674 737
675 738
676 /* Options */ 739 /* Options */
677 740
678 ext.showOptions = function(callback) 741 ext.showOptions = function(callback)
679 { 742 {
680 var optionsUrl = safari.extension.baseURI + "options.html"; 743 var optionsUrl = safari.extension.baseURI + "options.html";
681 744
682 for (var id in pages) 745 for (var id in pages)
683 { 746 {
684 var page = pages[id]; 747 var page = pages[id];
685 var tab = page._tab; 748 var tab = page._tab;
686 749
687 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow) 750 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow)
688 { 751 {
689 tab.activate(); 752 tab.activate();
690 if (callback) 753 if (callback)
691 callback(page); 754 callback(page);
692 return; 755 return;
693 } 756 }
694 } 757 }
695 758
696 ext.pages.open(optionsUrl, callback); 759 ext.pages.open(optionsUrl, callback);
697 }; 760 };
698 })(); 761 })();
OLDNEW
« no previous file with comments | « qunit/common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld