Skip to content

Commit

Permalink
[DevTools] Track URL through the target
Browse files Browse the repository at this point in the history
BUG=624494
R=dgozman

Review-Url: https://codereview.chromium.org/2186753002
Cr-Commit-Position: refs/heads/master@{#408267}
  • Loading branch information
eugeneo authored and Commit bot committed Jul 27, 2016
1 parent 294dc0b commit ef35b33
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 77 deletions.
2 changes: 1 addition & 1 deletion front_end/audits/AuditController.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ WebInspector.AuditController.prototype = {
}

var results = [];
var mainResourceURL = target.resourceTreeModel.inspectedPageURL();
var mainResourceURL = target.inspectedURL();
var categoriesDone = 0;

function categoryDoneCallback()
Expand Down
2 changes: 1 addition & 1 deletion front_end/bindings/CompilerScriptMapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ WebInspector.CompilerScriptMapping.prototype = {
{
// script.sourceURL can be a random string, but is generally an absolute path -> complete it to inspected page url for
// relative links.
var scriptURL = WebInspector.ParsedURL.completeURL(this._target.resourceTreeModel.inspectedPageURL(), script.sourceURL);
var scriptURL = WebInspector.ParsedURL.completeURL(this._target.inspectedURL(), script.sourceURL);
if (!scriptURL)
return Promise.resolve(/** @type {?WebInspector.TextSourceMap} */(null));

Expand Down
12 changes: 7 additions & 5 deletions front_end/bindings/ResourceUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ WebInspector.displayNameForURL = function(url)
if (uiSourceCode)
return uiSourceCode.displayName();

if (!WebInspector.targetManager.inspectedPageURL())
var mainTarget = WebInspector.targetManager.mainTarget();
var inspectedURL = mainTarget && mainTarget.inspectedURL();
if (!inspectedURL)
return url.trimURL("");

var parsedURL = WebInspector.targetManager.inspectedPageURL().asParsedURL();
var parsedURL = inspectedURL.asParsedURL();
var lastPathComponent = parsedURL ? parsedURL.lastPathComponent : parsedURL;
var index = WebInspector.targetManager.inspectedPageURL().indexOf(lastPathComponent);
if (index !== -1 && index + lastPathComponent.length === WebInspector.targetManager.inspectedPageURL().length) {
var baseURL = WebInspector.targetManager.inspectedPageURL().substring(0, index);
var index = inspectedURL.indexOf(lastPathComponent);
if (index !== -1 && index + lastPathComponent.length === inspectedURL.length) {
var baseURL = inspectedURL.substring(0, index);
if (url.startsWith(baseURL))
return url.substring(index);
}
Expand Down
6 changes: 4 additions & 2 deletions front_end/components/DOMBreakpointsSidebarPane.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ WebInspector.DOMBreakpointsSidebarPane.Marker = "breakpoint-marker";
WebInspector.DOMBreakpointsSidebarPane.prototype = {
_inspectedURLChanged: function(event)
{
var target = /** @type {!WebInspector.Target} */ (event.data);
if (target !== WebInspector.targetManager.mainTarget())
return;
this._breakpointElements = {};
this.reset();
var url = /** @type {string} */ (event.data);
this._inspectedURL = url.removeURLFragment();
this._inspectedURL = target.inspectedURL().removeURLFragment();
},

/**
Expand Down
3 changes: 2 additions & 1 deletion front_end/console/ConsoleView.js
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,8 @@ WebInspector.ConsoleView.prototype = {

_saveConsole: function()
{
var filename = String.sprintf("%s-%d.log", WebInspector.targetManager.inspectedPageDomain(), Date.now());
var url = WebInspector.targetManager.mainTarget().inspectedURL();
var filename = String.sprintf("%s-%d.log", url.asParsedURL().host, Date.now());
var stream = new WebInspector.FileOutputStream();

var progressIndicator = new WebInspector.ProgressIndicator();
Expand Down
4 changes: 3 additions & 1 deletion front_end/extensions/ExtensionServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,10 @@ WebInspector.ExtensionServer.prototype = {

_inspectedURLChanged: function(event)
{
if (event.data !== WebInspector.targetManager.mainTarget())
return;
this._requests = {};
var url = event.data;
var url = event.data.inspectedURL();
this._postNotification(WebInspector.extensionAPI.Events.InspectedURLChanged, url);
},

Expand Down
5 changes: 3 additions & 2 deletions front_end/network/NetworkLogView.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ WebInspector.NetworkLogView.prototype = {
selectedRequestsNumber++;
selectedTransferSize += requestTransferSize;
}
if (request.url === request.target().resourceTreeModel.inspectedPageURL() && request.resourceType() === WebInspector.resourceTypes.Document)
if (request.url === request.target().inspectedURL() && request.resourceType() === WebInspector.resourceTypes.Document)
baseTime = request.startTime;
if (request.endTime > maxTime)
maxTime = request.endTime;
Expand Down Expand Up @@ -979,7 +979,8 @@ WebInspector.NetworkLogView.prototype = {

_exportAll: function()
{
var filename = WebInspector.targetManager.inspectedPageDomain() + ".har";
var url = WebInspector.targetManager.mainTarget().inspectedURL();
var filename = url.asParsedURL().host + ".har";
var stream = new WebInspector.FileOutputStream();
stream.open(filename, openCallback.bind(this));

Expand Down
3 changes: 2 additions & 1 deletion front_end/sdk/NetworkRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ WebInspector.NetworkRequest.prototype = {
this._path = "";
} else {
this._path = this._parsedURL.host + this._parsedURL.folderPathComponents;
this._path = this._path.trimURL(this.target().resourceTreeModel.inspectedPageDomain());

this._path = this._path.trimURL(this.target().inspectedURL().asParsedURL().host);
if (this._parsedURL.lastPathComponent || this._parsedURL.queryParams)
this._name = this._parsedURL.lastPathComponent + (this._parsedURL.queryParams ? "?" + this._parsedURL.queryParams : "");
else if (this._parsedURL.folderPathComponents) {
Expand Down
35 changes: 2 additions & 33 deletions front_end/sdk/ResourceTreeModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ WebInspector.ResourceTreeModel = function(target, networkManager, securityOrigin

target.registerPageDispatcher(new WebInspector.PageDispatcher(this));

this._inspectedPageURL = "";
this._pendingReloadOptions = null;
this._reloadSuspensionCount = 0;

Expand All @@ -74,7 +73,6 @@ WebInspector.ResourceTreeModel.EventTypes = {
Load: "Load",
PageReloadRequested: "PageReloadRequested",
WillReloadPage: "WillReloadPage",
InspectedURLChanged: "InspectedURLChanged",
ScreencastFrame: "ScreencastFrame",
ScreencastVisibilityChanged: "ScreencastVisibilityChanged",
ColorPicked: "ColorPicked"
Expand Down Expand Up @@ -128,31 +126,13 @@ WebInspector.ResourceTreeModel.prototype = {
{
if (!error) {
this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.WillLoadCachedResources);
this._inspectedPageURL = mainFramePayload.frame.url;
this._addFramesRecursively(null, mainFramePayload);
this._dispatchInspectedURLChanged();
this.target().setInspectedURL(mainFramePayload.frame.url);
}
this._cachedResourcesProcessed = true;
this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded);
},

/**
* @return {string}
*/
inspectedPageURL: function()
{
return this._inspectedPageURL;
},

/**
* @return {string}
*/
inspectedPageDomain: function()
{
var parsedURL = this._inspectedPageURL ? this._inspectedPageURL.asParsedURL() : null;
return parsedURL ? parsedURL.host : "";
},

/**
* @return {boolean}
*/
Expand All @@ -161,12 +141,6 @@ WebInspector.ResourceTreeModel.prototype = {
return this._cachedResourcesProcessed;
},

_dispatchInspectedURLChanged: function()
{
InspectorFrontendHost.inspectedURLChanged(this._inspectedPageURL);
this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, this._inspectedPageURL);
},

/**
* @param {!WebInspector.ResourceTreeFrame} frame
* @param {boolean=} aboutToNavigate
Expand Down Expand Up @@ -248,9 +222,6 @@ WebInspector.ResourceTreeModel.prototype = {
frame._navigate(framePayload);
var addedOrigin = frame.securityOrigin;

if (frame.isMainFrame())
this._inspectedPageURL = frame.url;

this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, frame);
if (frame.isMainFrame()) {
this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, frame);
Expand All @@ -268,7 +239,7 @@ WebInspector.ResourceTreeModel.prototype = {
this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resources[i]);

if (frame.isMainFrame())
this._dispatchInspectedURLChanged();
this.target().setInspectedURL(frame.url);
},

/**
Expand Down Expand Up @@ -378,8 +349,6 @@ WebInspector.ResourceTreeModel.prototype = {
this._addFrame(frame);

var frameResource = this._createResourceFromFramePayload(framePayload, framePayload.url, WebInspector.resourceTypes.Document, framePayload.mimeType);
if (frame.isMainFrame())
this._inspectedPageURL = frameResource.url;
frame.addResource(frameResource);

for (var i = 0; frameTreePayload.childFrames && i < frameTreePayload.childFrames.length; ++i)
Expand Down
19 changes: 19 additions & 0 deletions front_end/sdk/Target.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ WebInspector.Target = function(targetManager, name, capabilitiesMask, connection
Protocol.Agents.call(this, connection.agentsMap());
this._targetManager = targetManager;
this._name = name;
this._inspectedURL = "";
this._capabilitiesMask = capabilitiesMask;
this._connection = connection;
this._parentTarget = parentTarget;
Expand Down Expand Up @@ -189,6 +190,24 @@ WebInspector.Target.prototype = {
return this._modelByConstructor.valuesArray();
},

/**
* @return {string}
*/
inspectedURL: function()
{
return this._inspectedURL;
},

/**
* @param {string} inspectedURL
*/
setInspectedURL: function(inspectedURL)
{
this._inspectedURL = inspectedURL;
InspectorFrontendHost.inspectedURLChanged(inspectedURL || "");
this._targetManager.dispatchEventToListeners(WebInspector.TargetManager.Events.InspectedURLChanged, this);
},

__proto__: Protocol.Agents.prototype
}

Expand Down
24 changes: 0 additions & 24 deletions front_end/sdk/TargetManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,6 @@ WebInspector.TargetManager.prototype = {
return this._isSuspended;
},

/**
* @return {string}
*/
inspectedPageURL: function()
{
if (!this._targets.length)
return "";

return this._targets[0].resourceTreeModel.inspectedPageURL();
},

/**
* @return {string}
*/
inspectedPageDomain: function()
{
if (!this._targets.length)
return "";

return this._targets[0].resourceTreeModel.inspectedPageDomain();
},

/**
* @param {!WebInspector.Event} event
*/
Expand Down Expand Up @@ -250,7 +228,6 @@ WebInspector.TargetManager.prototype = {
{
this._targets.push(target);
if (this._targets.length === 1) {
target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, this._redispatchEvent, this);
target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._redispatchEvent, this);
target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.Load, this._redispatchEvent, this);
target.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.PageReloadRequested, this._redispatchEvent, this);
Expand All @@ -277,7 +254,6 @@ WebInspector.TargetManager.prototype = {
{
this._targets.remove(target);
if (this._targets.length === 0) {
target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, this._redispatchEvent, this);
target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._redispatchEvent, this);
target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel.EventTypes.Load, this._redispatchEvent, this);
target.resourceTreeModel.removeEventListener(WebInspector.ResourceTreeModel.EventTypes.WillReloadPage, this._redispatchEvent, this);
Expand Down
16 changes: 10 additions & 6 deletions front_end/sources/SourcesNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,15 @@ WebInspector.SourcesNavigatorView.prototype = {
*/
_inspectedURLChanged: function(event)
{
var nodes = this._uiSourceCodeNodes.valuesArray();
for (var i = 0; i < nodes.length; ++i) {
var uiSourceCode = nodes[i].uiSourceCode();
var inspectedPageURL = WebInspector.targetManager.inspectedPageURL();
if (inspectedPageURL && WebInspector.networkMapping.networkURL(uiSourceCode) === inspectedPageURL)
var mainTarget = WebInspector.targetManager.mainTarget();
if (event.data !== mainTarget)
return;
var inspectedURL = mainTarget && mainTarget.inspectedURL();
if (!inspectedURL)
return
for (var node of this._uiSourceCodeNodes.valuesArray()) {
var uiSourceCode = node.uiSourceCode();
if (WebInspector.networkMapping.networkURL(uiSourceCode) === inspectedURL)
this.revealUISourceCode(uiSourceCode, true);
}
},
Expand All @@ -178,7 +182,7 @@ WebInspector.SourcesNavigatorView.prototype = {
*/
uiSourceCodeAdded: function(uiSourceCode)
{
var inspectedPageURL = WebInspector.targetManager.inspectedPageURL();
var inspectedPageURL = WebInspector.targetManager.mainTarget().inspectedURL();
if (inspectedPageURL && WebInspector.networkMapping.networkURL(uiSourceCode) === inspectedPageURL)
this.revealUISourceCode(uiSourceCode, true);
},
Expand Down

0 comments on commit ef35b33

Please sign in to comment.