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

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

Issue 6595500853690368: Issue 2172 - Parse URLs lazily on Safari to fix initlization on Safari <=6 (Closed)
Patch Set: Created March 19, 2015, 11:37 a.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-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;
kzar 2015/03/19 15:35:10 Nit: Shouldn't we do `delete this._urlString` here
Sebastian Noack 2015/03/19 16:45:12 I try to be careful not to mess with the optimizer
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
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 tab.activate(); 712 tab.activate();
690 if (callback) 713 if (callback)
691 callback(page); 714 callback(page);
692 return; 715 return;
693 } 716 }
694 } 717 }
695 718
696 ext.pages.open(optionsUrl, callback); 719 ext.pages.open(optionsUrl, callback);
697 }; 720 };
698 })(); 721 })();
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