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

Delta Between Two Patch Sets: safari/ext/background.js

Issue 5693109165883392: Issue 2040 - Replaced localStorage with chrome.storage.local (Closed)
Left Patch Set: Addressed comment Created March 16, 2015, 12:53 p.m.
Right Patch Set: Fixed typo in comment Created April 13, 2015, 10:30 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « qunit/common.js ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 // toolbar item of the window, is reset to its intial configuration. 160 // toolbar item of the window, is reset to its intial configuration.
161 updateToolbarItemForPage(event.target._visiblePage, event.target.browserWind ow); 161 updateToolbarItemForPage(event.target._visiblePage, event.target.browserWind ow);
162 }, true); 162 }, true);
163 163
164 164
165 /* Pages */ 165 /* Pages */
166 166
167 var pages = Object.create(null); 167 var pages = Object.create(null);
168 var pageCounter = 0; 168 var pageCounter = 0;
169 169
170 var Frame = function(url, parent)
171 {
172 this._urlString = url;
173 this._urlObj = null;
174
175 this.parent = parent;
176 }
177 Frame.prototype = {
178 get url()
179 {
180 // On Safari 6 and before, the URL constuctor doesn't exist.
181 // The "urls" module provides a polifill, but it might not
182 // be loaded yet. So we have to lazily parse URLs.
183 if (!this._urlObj)
184 {
185 this._urlObj = new URL(this._urlString);
186 this._urlString = null;
187 }
188
189 return this._urlObj;
190 }
191 };
192
170 var Page = function(id, tab, url) 193 var Page = function(id, tab, url)
171 { 194 {
172 this._id = id; 195 this._id = id;
173 this._tab = tab; 196 this._tab = tab;
174 this._frames = [{url: new URL(url), parent: null}]; 197 this._frames = [new Frame(url, null)];
175 198
176 if (tab.page) 199 if (tab.page)
177 this._messageProxy = new ext._MessageProxy(tab.page); 200 this._messageProxy = new ext._MessageProxy(tab.page);
178 else 201 else
179 // while the new tab page is shown on Safari 7, the 'page' property 202 // while the new tab page is shown on Safari 7, the 'page' property
180 // of the tab is undefined, and we can't send messages to that page 203 // of the tab is undefined, and we can't send messages to that page
181 this._messageProxy = { 204 this._messageProxy = {
182 handleRequest: function() {}, 205 handleRequest: function() {},
183 handleResponse: function() {}, 206 handleResponse: function() {},
184 sendMessage: function() {} 207 sendMessage: function() {}
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 // if we can't find the parent frame and its page, fall back to 632 // if we can't find the parent frame and its page, fall back to
610 // the page most recently loaded in the tab and its top level fram e 633 // the page most recently loaded in the tab and its top level fram e
611 if (!page) 634 if (!page)
612 { 635 {
613 pageId = lastPageId; 636 pageId = lastPageId;
614 page = lastPage; 637 page = lastPage;
615 parentFrame = lastPageTopLevelFrame; 638 parentFrame = lastPageTopLevelFrame;
616 } 639 }
617 640
618 frameId = page._frames.length; 641 frameId = page._frames.length;
619 page._frames.push({url: new URL(message.url), parent: parentFrame} ); 642 page._frames.push(new Frame(message.url, parentFrame));
620 } 643 }
621 event.message = {pageId: pageId, frameId: frameId}; 644 event.message = {pageId: pageId, frameId: frameId};
622 break; 645 break;
623 case "webRequest": 646 case "webRequest":
624 var page = pages[event.message.pageId]; 647 var page = pages[event.message.pageId];
625 var frame = page._frames[event.message.frameId]; 648 var frame = page._frames[event.message.frameId];
626 649
627 var results = ext.webRequest.onBeforeRequest._dispatch( 650 var results = ext.webRequest.onBeforeRequest._dispatch(
628 new URL(event.message.url, frame.url), 651 new URL(event.message.url, frame.url),
629 event.message.type, page, frame 652 event.message.type, page, frame
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 { 719 {
697 delete safari.extension.settings[key]; 720 delete safari.extension.settings[key];
698 721
699 if (callback) 722 if (callback)
700 setTimeout(callback, 0); 723 setTimeout(callback, 0);
701 }, 724 },
702 onChanged: new ext._EventTarget(), 725 onChanged: new ext._EventTarget(),
703 726
704 // Preferences were previously encoded as JSON for compatibility 727 // Preferences were previously encoded as JSON for compatibility
705 // with localStorage, which has been used on Chrome. 728 // with localStorage, which has been used on Chrome.
706 migratePrefs: function(mapFunc) 729 migratePrefs: function(hooks)
707 { 730 {
708 var settings = safari.extension.settings; 731 var settings = safari.extension.settings;
709 732
710 for (var key in settings) 733 for (var key in settings)
711 { 734 {
712 var item = mapFunc(key, settings[key]); 735 var item = hooks.map(key, settings[key]);
713 736
714 // Only touch settings if the key changed. Otherwise we would keep 737 if (item)
715 // migrating "currentVersion" over and over again on every initilization .
716 if (item && item.key != key)
717 { 738 {
718 delete settings[key]; 739 delete settings[key];
719 settings[item.key] = item.value; 740 settings[item.key] = item.value;
720 } 741 }
721 } 742 }
743
744 hooks.done();
722 } 745 }
723 }; 746 };
724 747
725 safari.extension.settings.addEventListener("change", function(event) 748 safari.extension.settings.addEventListener("change", function(event)
726 { 749 {
727 var changes = {}; 750 var changes = {};
728 var change = changes[event.key] = {}; 751 var change = changes[event.key] = {};
729 752
730 if (event.oldValue != null) 753 if (event.oldValue != null)
731 change.oldValue = event.oldValue; 754 change.oldValue = event.oldValue;
(...skipping 20 matching lines...) Expand all
752 tab.activate(); 775 tab.activate();
753 if (callback) 776 if (callback)
754 callback(page); 777 callback(page);
755 return; 778 return;
756 } 779 }
757 } 780 }
758 781
759 ext.pages.open(optionsUrl, callback); 782 ext.pages.open(optionsUrl, callback);
760 }; 783 };
761 })(); 784 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld