diff --git a/front_end/audits/AuditController.js b/front_end/audits/AuditController.js index be7afd40c4..d9a72a4cba 100644 --- a/front_end/audits/AuditController.js +++ b/front_end/audits/AuditController.js @@ -61,7 +61,7 @@ WebInspector.AuditController.prototype = { } var results = []; - var mainResourceURL = target.resourceTreeModel.inspectedPageURL(); + var mainResourceURL = target.inspectedURL(); var categoriesDone = 0; function categoryDoneCallback() diff --git a/front_end/bindings/CompilerScriptMapping.js b/front_end/bindings/CompilerScriptMapping.js index 1bcd93290c..049d8acafd 100644 --- a/front_end/bindings/CompilerScriptMapping.js +++ b/front_end/bindings/CompilerScriptMapping.js @@ -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)); diff --git a/front_end/bindings/ResourceUtils.js b/front_end/bindings/ResourceUtils.js index 97de058620..202a35f3f1 100644 --- a/front_end/bindings/ResourceUtils.js +++ b/front_end/bindings/ResourceUtils.js @@ -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); } diff --git a/front_end/components/DOMBreakpointsSidebarPane.js b/front_end/components/DOMBreakpointsSidebarPane.js index 2f7f1aa738..7f7b6ccc1f 100644 --- a/front_end/components/DOMBreakpointsSidebarPane.js +++ b/front_end/components/DOMBreakpointsSidebarPane.js @@ -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(); }, /** diff --git a/front_end/console/ConsoleView.js b/front_end/console/ConsoleView.js index f41672c9b3..10eeee0902 100644 --- a/front_end/console/ConsoleView.js +++ b/front_end/console/ConsoleView.js @@ -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(); diff --git a/front_end/extensions/ExtensionServer.js b/front_end/extensions/ExtensionServer.js index 4ac4041899..3704e9ad0d 100644 --- a/front_end/extensions/ExtensionServer.js +++ b/front_end/extensions/ExtensionServer.js @@ -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); }, diff --git a/front_end/network/NetworkLogView.js b/front_end/network/NetworkLogView.js index cfd70e927a..a79f94391f 100644 --- a/front_end/network/NetworkLogView.js +++ b/front_end/network/NetworkLogView.js @@ -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; @@ -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)); diff --git a/front_end/sdk/NetworkRequest.js b/front_end/sdk/NetworkRequest.js index ffcbb8e3ca..b6d620a7e5 100644 --- a/front_end/sdk/NetworkRequest.js +++ b/front_end/sdk/NetworkRequest.js @@ -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) { diff --git a/front_end/sdk/ResourceTreeModel.js b/front_end/sdk/ResourceTreeModel.js index d70ad805d0..8848923762 100644 --- a/front_end/sdk/ResourceTreeModel.js +++ b/front_end/sdk/ResourceTreeModel.js @@ -53,7 +53,6 @@ WebInspector.ResourceTreeModel = function(target, networkManager, securityOrigin target.registerPageDispatcher(new WebInspector.PageDispatcher(this)); - this._inspectedPageURL = ""; this._pendingReloadOptions = null; this._reloadSuspensionCount = 0; @@ -74,7 +73,6 @@ WebInspector.ResourceTreeModel.EventTypes = { Load: "Load", PageReloadRequested: "PageReloadRequested", WillReloadPage: "WillReloadPage", - InspectedURLChanged: "InspectedURLChanged", ScreencastFrame: "ScreencastFrame", ScreencastVisibilityChanged: "ScreencastVisibilityChanged", ColorPicked: "ColorPicked" @@ -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} */ @@ -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 @@ -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); @@ -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); }, /** @@ -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) diff --git a/front_end/sdk/Target.js b/front_end/sdk/Target.js index d36d8c1089..099b0a06c1 100644 --- a/front_end/sdk/Target.js +++ b/front_end/sdk/Target.js @@ -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; @@ -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 } diff --git a/front_end/sdk/TargetManager.js b/front_end/sdk/TargetManager.js index 84687b4648..e5f085158a 100644 --- a/front_end/sdk/TargetManager.js +++ b/front_end/sdk/TargetManager.js @@ -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 */ @@ -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); @@ -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); diff --git a/front_end/sources/SourcesNavigator.js b/front_end/sources/SourcesNavigator.js index 137a2abff6..d735a3b4de 100644 --- a/front_end/sources/SourcesNavigator.js +++ b/front_end/sources/SourcesNavigator.js @@ -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); } }, @@ -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); },