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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 })(); |
LEFT | RIGHT |