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 Created March 3, 2015, 3: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
« chrome/ext/background.js ('K') | « 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 629 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 // only when reloading the page or following links, but not when 640 // only when reloading the page or following links, but not when
641 // the current page is replaced with a prerendered page. 641 // the current page is replaced with a prerendered page.
642 replacePage(pages[event.message.pageId]); 642 replacePage(pages[event.message.pageId]);
643 break; 643 break;
644 } 644 }
645 }); 645 });
646 646
647 647
648 /* Storage */ 648 /* Storage */
649 649
650 ext.storage = safari.extension.settings; 650 ext.storage = {
651 get: function(keys, callback)
652 {
653 var items = {};
654 var settings = safari.extension.settings;
655
656 for (var i = 0; i < keys.length; i++)
657 {
658 var key = keys[i];
659 if (key in settings)
660 items[key] = settings[key];
661 }
662
663 setTimeout(callback, 0, items);
Wladimir Palant 2015/03/12 23:05:37 Did you verify that this works on all Safari versi
Sebastian Noack 2015/03/12 23:35:29 I saw this one coming. I checked MDN and made the
664 },
665 set: function(key, value, callback)
666 {
667 safari.extension.settings[key] = value;
668
669 if (callback)
670 setTimeout(callback, 0);
671 },
672 remove: function(key, callback)
673 {
674 delete safari.extension.settings[key];
675
676 if (callback)
677 setTimeout(callback, 0);
678 },
679 onChanged: new ext._EventTarget(),
680
681 // Preferences were previously encoded as JSON for compatibility
682 // with localStorage, which has been used on Chrome.
683 migratePrefs: function(prefs)
684 {
685 var settings = safari.extension.settings;
686
687 for (var key in settings)
688 {
689 if (key in prefs)
690 {
691 try
692 {
693 settings["pref:" + key] = JSON.parse(settings[key]);
694 }
695 catch (e)
696 {
697 }
698
699 delete settings[key];
700 }
701 }
702 }
703 };
704
705 safari.extension.settings.addEventListener("change", function(event)
706 {
707 var changes = {};
708 var change = changes[event.key] = {};
709
710 if (event.oldValue != null)
711 change.oldValue = event.oldValue;
712 if (event.newValue != null)
713 change.newValue = event.newValue;
714
715 ext.storage.onChanged._dispatch(changes);
716 });
651 717
652 718
653 /* Options */ 719 /* Options */
654 720
655 ext.showOptions = function(callback) 721 ext.showOptions = function(callback)
656 { 722 {
657 var optionsUrl = safari.extension.baseURI + "options.html"; 723 var optionsUrl = safari.extension.baseURI + "options.html";
658 724
659 for (var id in pages) 725 for (var id in pages)
660 { 726 {
661 var page = pages[id]; 727 var page = pages[id];
662 var tab = page._tab; 728 var tab = page._tab;
663 729
664 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow) 730 if (page.url.href == optionsUrl && tab.browserWindow == safari.application .activeBrowserWindow)
665 { 731 {
666 tab.activate(); 732 tab.activate();
667 if (callback) 733 if (callback)
668 callback(page); 734 callback(page);
669 return; 735 return;
670 } 736 }
671 } 737 }
672 738
673 ext.pages.open(optionsUrl, callback); 739 ext.pages.open(optionsUrl, callback);
674 }; 740 };
675 })(); 741 })();
OLDNEW
« chrome/ext/background.js ('K') | « metadata.chrome ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld