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

Side by Side Diff: ext/background.js

Issue 29838555: Issue 6808 - Default to top frame of page if parent can't be found (Closed)
Patch Set: Consistent > 0 Created July 25, 2018, 8:27 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // overridden when Chrome automatically resets them on navigation. 153 // overridden when Chrome automatically resets them on navigation.
154 if (browser.runtime.lastError) 154 if (browser.runtime.lastError)
155 ext.pages.onLoading._dispatch(page); 155 ext.pages.onLoading._dispatch(page);
156 }); 156 });
157 } 157 }
158 158
159 // Update frame URL and parent in frame structure 159 // Update frame URL and parent in frame structure
160 let frame = createFrame(tabId, frameId); 160 let frame = createFrame(tabId, frameId);
161 frame.url = new URL(url); 161 frame.url = new URL(url);
162 162
163 let parentFrame = framesOfTabs.get(tabId).get(parentFrameId); 163 let frames = framesOfTabs.get(tabId);
164 let parentFrame = frames.get(parentFrameId);
165 if (!parentFrame && parentFrameId > 0)
166 parentFrame = frames.get(0);
167
164 if (parentFrame) 168 if (parentFrame)
165 frame.parent = parentFrame; 169 frame.parent = parentFrame;
166 } 170 }
167 171
168 browser.webRequest.onHeadersReceived.addListener(details => 172 browser.webRequest.onHeadersReceived.addListener(details =>
169 { 173 {
170 // We have to update the frame structure when switching to a new 174 // We have to update the frame structure when switching to a new
171 // document, so that we process any further requests made by that 175 // document, so that we process any further requests made by that
172 // document in the right context. Unfortunately, we cannot rely 176 // document in the right context. Unfortunately, we cannot rely
173 // on webNavigation.onCommitted since it isn't guaranteed to fire 177 // on webNavigation.onCommitted since it isn't guaranteed to fire
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 { 525 {
522 let frames = new Map(); 526 let frames = new Map();
523 framesOfTabs.set(tab.id, frames); 527 framesOfTabs.set(tab.id, frames);
524 528
525 for (let detail of details) 529 for (let detail of details)
526 { 530 {
527 let frame = {url: new URL(detail.url)}; 531 let frame = {url: new URL(detail.url)};
528 frames.set(detail.frameId, frame); 532 frames.set(detail.frameId, frame);
529 533
530 if (detail.parentFrameId != -1) 534 if (detail.parentFrameId != -1)
535 {
531 frame.parent = frames.get(detail.parentFrameId); 536 frame.parent = frames.get(detail.parentFrameId);
537
538 if (!frame.parent && detail.parentFrameId > 0)
539 frame.parent = frames.get(0);
540 }
532 } 541 }
533 } 542 }
534 }); 543 });
535 }); 544 });
536 }); 545 });
537 546
538 547
539 /* Message passing */ 548 /* Message passing */
540 549
541 browser.runtime.onMessage.addListener((message, rawSender, sendResponse) => 550 browser.runtime.onMessage.addListener((message, rawSender, sendResponse) =>
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 return frames.get(0) || null; 599 return frames.get(0) || null;
591 } 600 }
592 }; 601 };
593 } 602 }
594 603
595 return ext.onMessage._dispatch( 604 return ext.onMessage._dispatch(
596 message, sender, sendResponse 605 message, sender, sendResponse
597 ).includes(true); 606 ).includes(true);
598 }); 607 });
599 } 608 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld