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

Delta Between Two Patch Sets: chrome/ext/background.js

Issue 5564089086509056: Issue 1801 - Use URL objects to process URLs in the background page (Closed)
Left Patch Set: Rebased and addressed comments Created Feb. 11, 2015, 10:54 a.m.
Right Patch Set: Rebased and addressed comments Created Feb. 11, 2015, 5:06 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « background.js ('k') | lib/basedomain.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 12 matching lines...) Expand all
23 { 23 {
24 this._id = tab.id; 24 this._id = tab.id;
25 this._url = tab.url && new URL(tab.url); 25 this._url = tab.url && new URL(tab.url);
26 26
27 this.browserAction = new BrowserAction(tab.id); 27 this.browserAction = new BrowserAction(tab.id);
28 this.contextMenus = new ContextMenus(this); 28 this.contextMenus = new ContextMenus(this);
29 }; 29 };
30 Page.prototype = { 30 Page.prototype = {
31 get url() 31 get url()
32 { 32 {
33 // usually our Page objects are created from Chrome's Tab objects, which 33 // usually our Page objects are created from Chrome's Tab objects, which
Wladimir Palant 2015/02/11 13:45:45 Nit: A sentence is usually started by a capital le
Sebastian Noack 2015/02/11 17:07:06 Note that I just reverted those lines including th
34 // provide the url. So we can return the url given in the constructor. 34 // provide the url. So we can return the url given in the constructor.
35 if (this._url) 35 if (this._url)
36 return this._url; 36 return this._url;
37 37
38 // but sometimes we only have the tab id when we create a Page object. 38 // but sometimes we only have the tab id when we create a Page object.
Sebastian Noack 2015/02/11 10:55:51 All changes below are due to rebase.
39 // In that case we get the url from top frame of the tab, recorded by 39 // In that case we get the url from top frame of the tab, recorded by
40 // the onBeforeRequest handler. 40 // the onBeforeRequest handler.
41 var frames = framesOfTabs[this._id]; 41 var frames = framesOfTabs[this._id];
42 if (frames) 42 if (frames)
43 { 43 {
44 var frame = frames[0]; 44 var frame = frames[0];
45 if (frame) 45 if (frame)
46 return frame.url; 46 return frame.url;
47 } 47 }
48 }, 48 },
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 312
313 chrome.windows.onFocusChanged.addListener(function(windowId) 313 chrome.windows.onFocusChanged.addListener(function(windowId)
314 { 314 {
315 if (windowId != chrome.windows.WINDOW_ID_NONE) 315 if (windowId != chrome.windows.WINDOW_ID_NONE)
316 updateContextMenu(); 316 updateContextMenu();
317 }); 317 });
318 318
319 319
320 /* Web requests */ 320 /* Web requests */
321 321
322 var framesOfTabs = {__proto__: null}; 322 var framesOfTabs = Object.create(null);
323 323
324 ext.getFrame = function(tabId, frameId) 324 ext.getFrame = function(tabId, frameId)
325 { 325 {
326 return (framesOfTabs[tabId] || {})[frameId]; 326 return (framesOfTabs[tabId] || {})[frameId];
327 }; 327 };
328 328
329 ext.webRequest = { 329 ext.webRequest = {
330 onBeforeRequest: new ext._EventTarget(), 330 onBeforeRequest: new ext._EventTarget(),
331 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged 331 handlerBehaviorChanged: chrome.webRequest.handlerBehaviorChanged
332 }; 332 };
333 333
334 chrome.tabs.query({}, function(tabs) 334 chrome.tabs.query({}, function(tabs)
335 { 335 {
336 tabs.forEach(function(tab) 336 tabs.forEach(function(tab)
337 { 337 {
338 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details) 338 chrome.webNavigation.getAllFrames({tabId: tab.id}, function(details)
339 { 339 {
340 if (details && details.length > 0) 340 if (details && details.length > 0)
341 { 341 {
342 var frames = framesOfTabs[tab.id] = {__proto__: null}; 342 var frames = framesOfTabs[tab.id] = Object.create(null);
343 343
344 for (var i = 0; i < details.length; i++) 344 for (var i = 0; i < details.length; i++)
345 frames[details[i].frameId] = {url: new URL(details[i].url), parent: null}; 345 frames[details[i].frameId] = {url: new URL(details[i].url), parent: null};
346 346
347 for (var i = 0; i < details.length; i++) 347 for (var i = 0; i < details.length; i++)
348 { 348 {
349 var parentFrameId = details[i].parentFrameId; 349 var parentFrameId = details[i].parentFrameId;
350 350
351 if (parentFrameId != -1) 351 if (parentFrameId != -1)
352 frames[details[i].frameId].parent = frames[parentFrameId]; 352 frames[details[i].frameId].parent = frames[parentFrameId];
(...skipping 19 matching lines...) Expand all
372 // assume that the first request belongs to the top frame. Chrome 372 // assume that the first request belongs to the top frame. Chrome
373 // may give the top frame the type "object" instead of "main_frame". 373 // may give the top frame the type "object" instead of "main_frame".
374 // https://code.google.com/p/chromium/issues/detail?id=281711 374 // https://code.google.com/p/chromium/issues/detail?id=281711
375 details.frameId == 0 && !(details.tabId in framesOfTabs) 375 details.frameId == 0 && !(details.tabId in framesOfTabs)
376 ); 376 );
377 377
378 var frames = null; 378 var frames = null;
379 if (!isMainFrame) 379 if (!isMainFrame)
380 frames = framesOfTabs[details.tabId]; 380 frames = framesOfTabs[details.tabId];
381 if (!frames) 381 if (!frames)
382 frames = framesOfTabs[details.tabId] = {__proto__: null}; 382 frames = framesOfTabs[details.tabId] = Object.create(null);
383 383
384 var frame = null; 384 var frame = null;
385 var url = new URL(details.url); 385 var url = new URL(details.url);
386 if (!isMainFrame) 386 if (!isMainFrame)
387 { 387 {
388 // we are looking for the frame that contains the element that 388 // we are looking for the frame that contains the element that
389 // is about to load, however if a frame is loading the surrounding 389 // is about to load, however if a frame is loading the surrounding
390 // frame is indicated by parentFrameId instead of frameId 390 // frame is indicated by parentFrameId instead of frameId
391 var frameId; 391 var frameId;
392 if (requestType == "sub_frame") 392 if (requestType == "sub_frame")
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 callback(new Page(tab)); 514 callback(new Page(tab));
515 } 515 }
516 else 516 else
517 { 517 {
518 ext.pages.open(optionsUrl, callback); 518 ext.pages.open(optionsUrl, callback);
519 } 519 }
520 }); 520 });
521 }); 521 });
522 }; 522 };
523 })(); 523 })();
LEFTRIGHT

Powered by Google App Engine
This is Rietveld