| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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]); |
| 736 | |
| 713 if (item) | 737 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 { | 738 { |
| 715 delete settings[key]; | 739 delete settings[key]; |
| 716 settings[item.key] = item.value; | 740 settings[item.key] = item.value; |
| 717 } | 741 } |
| 718 } | 742 } |
| 743 | |
| 744 hooks.done(); | |
| 719 } | 745 } |
| 720 }; | 746 }; |
| 721 | 747 |
| 722 safari.extension.settings.addEventListener("change", function(event) | 748 safari.extension.settings.addEventListener("change", function(event) |
| 723 { | 749 { |
| 724 var changes = {}; | 750 var changes = {}; |
| 725 var change = changes[event.key] = {}; | 751 var change = changes[event.key] = {}; |
| 726 | 752 |
| 727 if (event.oldValue != null) | 753 if (event.oldValue != null) |
| 728 change.oldValue = event.oldValue; | 754 change.oldValue = event.oldValue; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 749 tab.activate(); | 775 tab.activate(); |
| 750 if (callback) | 776 if (callback) |
| 751 callback(page); | 777 callback(page); |
| 752 return; | 778 return; |
| 753 } | 779 } |
| 754 } | 780 } |
| 755 | 781 |
| 756 ext.pages.open(optionsUrl, callback); | 782 ext.pages.open(optionsUrl, callback); |
| 757 }; | 783 }; |
| 758 })(); | 784 })(); |
| LEFT | RIGHT |