| OLD | NEW |
| 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 |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 (function() | 18 (function() |
| 19 { | 19 { |
| 20 /* Pages */ | 20 /* Pages */ |
| 21 | 21 |
| 22 var pages = {__proto__: null}; | 22 var pages = {__proto__: null}; |
| 23 var pageCounter = 0; | 23 var pageCounter = 0; |
| 24 | 24 |
| 25 var Page = function(id, tab, url) | 25 var Page = function(id, tab, url) |
| 26 { | 26 { |
| 27 this._id = id; | 27 this._id = id; |
| 28 this._tab = tab; | 28 this._tab = tab; |
| 29 this._frames = [{url: url, parent: null}]; | 29 this._frames = [{url: new URL(url), parent: null}]; |
| 30 | 30 |
| 31 if (tab.page) | 31 if (tab.page) |
| 32 this._messageProxy = new ext._MessageProxy(tab.page); | 32 this._messageProxy = new ext._MessageProxy(tab.page); |
| 33 else | 33 else |
| 34 // while the new tab page is shown on Safari 7, the 'page' property | 34 // while the new tab page is shown on Safari 7, the 'page' property |
| 35 // of the tab is undefined, and we can't send messages to that page | 35 // of the tab is undefined, and we can't send messages to that page |
| 36 this._messageProxy = { | 36 this._messageProxy = { |
| 37 handleRequest: function() {}, | 37 handleRequest: function() {}, |
| 38 handleResponse: function() {}, | 38 handleResponse: function() {}, |
| 39 sendMessage: function() {} | 39 sendMessage: function() {} |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 // loaded in the same tab. If there is more than one match, | 567 // loaded in the same tab. If there is more than one match, |
| 568 // the most recent loaded page and frame is preferred. | 568 // the most recent loaded page and frame is preferred. |
| 569 for (var curPageId in tab._pages) | 569 for (var curPageId in tab._pages) |
| 570 { | 570 { |
| 571 var curPage = pages[curPageId]; | 571 var curPage = pages[curPageId]; |
| 572 | 572 |
| 573 for (var i = 0; i < curPage._frames.length; i++) | 573 for (var i = 0; i < curPage._frames.length; i++) |
| 574 { | 574 { |
| 575 var curFrame = curPage._frames[i]; | 575 var curFrame = curPage._frames[i]; |
| 576 | 576 |
| 577 if (curFrame.url == message.referrer) | 577 if (curFrame.url.href == message.referrer) |
| 578 { | 578 { |
| 579 pageId = curPageId; | 579 pageId = curPageId; |
| 580 page = curPage; | 580 page = curPage; |
| 581 parentFrame = curFrame; | 581 parentFrame = curFrame; |
| 582 } | 582 } |
| 583 | 583 |
| 584 if (i == 0) | 584 if (i == 0) |
| 585 { | 585 { |
| 586 lastPageId = curPageId; | 586 lastPageId = curPageId; |
| 587 lastPage = curPage; | 587 lastPage = curPage; |
| 588 lastPageTopLevelFrame = curFrame; | 588 lastPageTopLevelFrame = curFrame; |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 // if we can't find the parent frame and its page, fall back to | 593 // if we can't find the parent frame and its page, fall back to |
| 594 // the page most recently loaded in the tab and its top level fram
e | 594 // the page most recently loaded in the tab and its top level fram
e |
| 595 if (!page) | 595 if (!page) |
| 596 { | 596 { |
| 597 pageId = lastPageId; | 597 pageId = lastPageId; |
| 598 page = lastPage; | 598 page = lastPage; |
| 599 parentFrame = lastPageTopLevelFrame; | 599 parentFrame = lastPageTopLevelFrame; |
| 600 } | 600 } |
| 601 | 601 |
| 602 frameId = page._frames.length; | 602 frameId = page._frames.length; |
| 603 page._frames.push({url: message.url, parent: parentFrame}); | 603 page._frames.push({url: new URL(message.url), parent: parentFrame}
); |
| 604 } | 604 } |
| 605 | 605 |
| 606 event.message = {pageId: pageId, frameId: frameId}; | 606 event.message = {pageId: pageId, frameId: frameId}; |
| 607 break; | 607 break; |
| 608 case "webRequest": | 608 case "webRequest": |
| 609 var page = pages[event.message.pageId]; | 609 var page = pages[event.message.pageId]; |
| 610 var frame = page._frames[event.message.frameId]; |
| 611 |
| 610 var results = ext.webRequest.onBeforeRequest._dispatch( | 612 var results = ext.webRequest.onBeforeRequest._dispatch( |
| 611 event.message.url, | 613 new URL(event.message.url, frame.url), |
| 612 event.message.type, | 614 event.message.type, page, frame |
| 613 page, | |
| 614 page._frames[event.message.frameId] | |
| 615 ); | 615 ); |
| 616 | 616 |
| 617 event.message = (results.indexOf(false) == -1); | 617 event.message = (results.indexOf(false) == -1); |
| 618 break; | 618 break; |
| 619 case "proxy": | 619 case "proxy": |
| 620 event.message = backgroundPageProxy.handleMessage(event.message); | 620 event.message = backgroundPageProxy.handleMessage(event.message); |
| 621 break; | 621 break; |
| 622 case "request": | 622 case "request": |
| 623 var page = pages[event.message.pageId]; | 623 var page = pages[event.message.pageId]; |
| 624 var sender = {page: page, frame: page._frames[event.message.frameId]
}; | 624 var sender = {page: page, frame: page._frames[event.message.frameId]
}; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 662 |
| 663 ext.showOptions = function(callback) | 663 ext.showOptions = function(callback) |
| 664 { | 664 { |
| 665 var optionsUrl = safari.extension.baseURI + "options.html"; | 665 var optionsUrl = safari.extension.baseURI + "options.html"; |
| 666 | 666 |
| 667 for (var id in pages) | 667 for (var id in pages) |
| 668 { | 668 { |
| 669 var page = pages[id]; | 669 var page = pages[id]; |
| 670 var tab = page._tab; | 670 var tab = page._tab; |
| 671 | 671 |
| 672 if (page.url == optionsUrl && tab.browserWindow == safari.application.acti
veBrowserWindow) | 672 if (page.url.href == optionsUrl && tab.browserWindow == safari.application
.activeBrowserWindow) |
| 673 { | 673 { |
| 674 tab.activate(); | 674 tab.activate(); |
| 675 if (callback) | 675 if (callback) |
| 676 callback(page); | 676 callback(page); |
| 677 return; | 677 return; |
| 678 } | 678 } |
| 679 } | 679 } |
| 680 | 680 |
| 681 ext.pages.open(optionsUrl, callback); | 681 ext.pages.open(optionsUrl, callback); |
| 682 }; | 682 }; |
| 683 })(); | 683 })(); |
| OLD | NEW |