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

Side by Side Diff: safari/ext/background.js

Issue 29333522: Issue 3515 - Adapted polyfill for URL class for consistency (Closed)
Patch Set: Rebased and addressed comments Created Jan. 19, 2016, 2:11 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 | « metadata.common ('k') | 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-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
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
193 var Page = function(id, tab, url) 170 var Page = function(id, tab, url)
194 { 171 {
195 this._id = id; 172 this._id = id;
196 this._tab = tab; 173 this._tab = tab;
197 this._frames = [new Frame(url, null)]; 174 this._frames = [{url: new URL(url), parent: null}];
198 175
199 if (tab.page) 176 if (tab.page)
200 this._messageProxy = new ext._MessageProxy(tab.page); 177 this._messageProxy = new ext._MessageProxy(tab.page);
201 else 178 else
202 // while the new tab page is shown on Safari 7, the 'page' property 179 // while the new tab page is shown on Safari 7, the 'page' property
203 // of the tab is undefined, and we can't send messages to that page 180 // of the tab is undefined, and we can't send messages to that page
204 this._messageProxy = { 181 this._messageProxy = {
205 handleRequest: function() {}, 182 handleRequest: function() {},
206 handleResponse: function() {}, 183 handleResponse: function() {},
207 sendMessage: function() {} 184 sendMessage: function() {}
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 // if we can't find the parent frame and its page, fall back to 614 // if we can't find the parent frame and its page, fall back to
638 // the page most recently loaded in the tab and its top level fram e 615 // the page most recently loaded in the tab and its top level fram e
639 if (!page) 616 if (!page)
640 { 617 {
641 pageId = lastPageId; 618 pageId = lastPageId;
642 page = lastPage; 619 page = lastPage;
643 parentFrame = lastPageTopLevelFrame; 620 parentFrame = lastPageTopLevelFrame;
644 } 621 }
645 622
646 frameId = page._frames.length; 623 frameId = page._frames.length;
647 page._frames.push(new Frame(message.url, parentFrame)); 624 page._frames.push({url: new URL(message.url), parent: parentFrame} );
648 } 625 }
649 event.message = {pageId: pageId, frameId: frameId}; 626 event.message = {pageId: pageId, frameId: frameId};
650 break; 627 break;
651 case "webRequest": 628 case "webRequest":
652 var page = pages[event.message.pageId]; 629 var page = pages[event.message.pageId];
653 var frame = page._frames[event.message.frameId]; 630 var frame = page._frames[event.message.frameId];
654 631
655 var results = ext.webRequest.onBeforeRequest._dispatch( 632 var results = ext.webRequest.onBeforeRequest._dispatch(
656 new URL(event.message.url, frame.url), 633 new URL(event.message.url, frame.url),
657 event.message.type, page, frame 634 event.message.type, page, frame
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 tab.activate(); 737 tab.activate();
761 if (callback) 738 if (callback)
762 callback(page); 739 callback(page);
763 return; 740 return;
764 } 741 }
765 } 742 }
766 743
767 ext.pages.open(optionsUrl, callback); 744 ext.pages.open(optionsUrl, callback);
768 }; 745 };
769 })(); 746 })();
OLDNEW
« no previous file with comments | « metadata.common ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld