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

Unified Diff: chrome/ext/background.js

Issue 5564089086509056: Issue 1801 - Use URL objects to process URLs in the background page (Closed)
Patch Set: Created Jan. 25, 2015, 1:18 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « background.js ('k') | lib/basedomain.js » ('j') | lib/url.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/ext/background.js
===================================================================
--- a/chrome/ext/background.js
+++ b/chrome/ext/background.js
@@ -22,22 +22,21 @@
var Page = ext.Page = function(tab)
{
this._id = tab.id;
- this._url = tab.url;
this.browserAction = new BrowserAction(tab.id);
this.contextMenus = new ContextMenus(this);
+
+ // Usually Page objects are created from Chrome's Tab objects, which
+ // provide the url. So we can override the fallback implemented below.
+ if (tab.url)
+ Object.defineProperty(this, "url", {value: new URL(tab.url), enumerable: true});
Wladimir Palant 2015/02/09 12:54:29 Code that belongs together should really be togeth
Sebastian Noack 2015/02/11 10:55:51 Whatever.
};
Page.prototype = {
get url()
{
- // usually our Page objects are created from Chrome's Tab objects, which
- // provide the url. So we can return the url given in the constructor.
- if (this._url != null)
- return this._url;
-
- // but sometimes we only have the tab id when we create a Page object.
- // In that case we get the url from top frame of the tab, recorded by
- // the onBeforeRequest handler.
+ // Sometimes we only have the tab id when we create a Page object.
+ // In that case we get the url from top frame of the tab, recorded
+ // by the onBeforeRequest handler.
var frames = framesOfTabs[this._id];
if (frames)
{
@@ -265,7 +264,7 @@
var frames = framesOfTabs[tab.id] = {__proto__: null};
for (var i = 0; i < details.length; i++)
- frames[details[i].frameId] = {url: details[i].url, parent: null};
+ frames[details[i].frameId] = {url: new URL(details[i].url), parent: null};
for (var i = 0; i < details.length; i++)
{
@@ -305,6 +304,7 @@
frames = framesOfTabs[details.tabId] = {__proto__: null};
var frame = null;
+ var url = new URL(details.url);
if (!isMainFrame)
{
// we are looking for the frame that contains the element that
@@ -327,7 +327,7 @@
requestType = "object";
var results = ext.webRequest.onBeforeRequest._dispatch(
- details.url,
+ url,
requestType,
new Page({id: details.tabId}),
frame
@@ -339,7 +339,7 @@
}
if (isMainFrame || details.type == "sub_frame")
- frames[details.frameId] = {url: details.url, parent: frame};
+ frames[details.frameId] = {url: url, parent: frame};
}
catch (e)
{
@@ -358,7 +358,7 @@
var sender = {
page: new Page(rawSender.tab),
frame: {
- url: rawSender.url,
+ url: new URL(rawSender.url),
get parent()
{
var frames = framesOfTabs[rawSender.tab.id];
@@ -378,7 +378,7 @@
// Chrome 28-40
for (var frameId in frames)
{
- if (frames[frameId].url == rawSender.url)
+ if (frames[frameId].url.href == this.url.href)
return frames[frameId].parent;
}
}
« no previous file with comments | « background.js ('k') | lib/basedomain.js » ('j') | lib/url.js » ('J')

Powered by Google App Engine
This is Rietveld