| 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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 if (!frames) | 116 if (!frames) |
| 117 frames = framesOfTabs[tabId] = Object.create(null); | 117 frames = framesOfTabs[tabId] = Object.create(null); |
| 118 | 118 |
| 119 var frame = frames[frameId]; | 119 var frame = frames[frameId]; |
| 120 if (!frame) | 120 if (!frame) |
| 121 frame = frames[frameId] = {}; | 121 frame = frames[frameId] = {}; |
| 122 | 122 |
| 123 return frame; | 123 return frame; |
| 124 } | 124 } |
| 125 | 125 |
| 126 chrome.webNavigation.onBeforeNavigate.addListener(function(details) | |
| 127 { | |
| 128 // Capture parent frame here because onCommitted doesn't get this info. | |
| 129 var frame = createFrame(details.tabId, details.frameId); | |
| 130 frame.parent = framesOfTabs[details.tabId][details.parentFrameId] || null; | |
| 131 }); | |
| 132 | |
| 133 var eagerlyUpdatedPages = new ext.PageMap(); | 126 var eagerlyUpdatedPages = new ext.PageMap(); |
| 134 | 127 |
| 135 ext._updatePageFrameStructure = function(frameId, tabId, url, eager) | 128 ext._updatePageFrameStructure = function(frameId, tabId, url, eager, |
| 129 parentFrameId) |
| 136 { | 130 { |
| 137 if (frameId == 0) | 131 if (frameId == 0) |
| 138 { | 132 { |
| 139 let page = new Page({id: tabId, url: url}); | 133 let page = new Page({id: tabId, url: url}); |
| 140 | 134 |
| 141 if (eagerlyUpdatedPages.get(page) != url) | 135 if (eagerlyUpdatedPages.get(page) != url) |
| 142 { | 136 { |
| 143 ext._removeFromAllPageMaps(tabId); | 137 ext._removeFromAllPageMaps(tabId); |
| 144 | 138 |
| 145 // When a sitekey header is received we must immediately update the page | 139 // When a sitekey header is received we must immediately update the page |
| (...skipping 13 matching lines...) Expand all Loading... |
| 159 // when Chrome automatically resets them on navigation. | 153 // when Chrome automatically resets them on navigation. |
| 160 if (chrome.runtime.lastError) | 154 if (chrome.runtime.lastError) |
| 161 ext.pages.onLoading._dispatch(page); | 155 ext.pages.onLoading._dispatch(page); |
| 162 }); | 156 }); |
| 163 } | 157 } |
| 164 } | 158 } |
| 165 | 159 |
| 166 // Update frame URL in frame structure | 160 // Update frame URL in frame structure |
| 167 var frame = createFrame(tabId, frameId); | 161 var frame = createFrame(tabId, frameId); |
| 168 frame.url = new URL(url); | 162 frame.url = new URL(url); |
| 163 |
| 164 // We only get the parentFrameId for onBeforeNavigate, not for onCommitted |
| 165 if (typeof parentFrameId != "undefined") |
| 166 frame.parent = framesOfTabs[tabId][parentFrameId] || null; |
| 169 }; | 167 }; |
| 170 | 168 |
| 169 chrome.webNavigation.onBeforeNavigate.addListener(function(details) |
| 170 { |
| 171 // Since requests are sometimes made by a page before its onCommitted event |
| 172 // fires we also need to update the page structure here. Otherwise those |
| 173 // requests will be considered third party since a URL for the page wasn't |
| 174 // yet determined. |
| 175 ext._updatePageFrameStructure(details.frameId, details.tabId, |
| 176 details.url, false, details.parentFrameId); |
| 177 }); |
| 178 |
| 171 chrome.webNavigation.onCommitted.addListener(function(details) | 179 chrome.webNavigation.onCommitted.addListener(function(details) |
| 172 { | 180 { |
| 173 ext._updatePageFrameStructure(details.frameId, details.tabId, details.url); | 181 ext._updatePageFrameStructure(details.frameId, details.tabId, |
| 182 details.url, false); |
| 174 }); | 183 }); |
| 175 | 184 |
| 176 function forgetTab(tabId) | 185 function forgetTab(tabId) |
| 177 { | 186 { |
| 178 ext.pages.onRemoved._dispatch(tabId); | 187 ext.pages.onRemoved._dispatch(tabId); |
| 179 | 188 |
| 180 ext._removeFromAllPageMaps(tabId); | 189 ext._removeFromAllPageMaps(tabId); |
| 181 delete framesOfTabs[tabId]; | 190 delete framesOfTabs[tabId]; |
| 182 } | 191 } |
| 183 | 192 |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 ext.windows = { | 648 ext.windows = { |
| 640 create: function(createData, callback) | 649 create: function(createData, callback) |
| 641 { | 650 { |
| 642 chrome.windows.create(createData, function(createdWindow) | 651 chrome.windows.create(createData, function(createdWindow) |
| 643 { | 652 { |
| 644 afterTabLoaded(callback)(createdWindow.tabs[0]); | 653 afterTabLoaded(callback)(createdWindow.tabs[0]); |
| 645 }); | 654 }); |
| 646 } | 655 } |
| 647 }; | 656 }; |
| 648 })(); | 657 })(); |
| OLD | NEW |