Web Inspector: sourceMappingURL not used when sourceURL is set
https://bugs.webkit.org/show_bug.cgi?id=156021
<rdar://problem/25438417>

Patch by Joseph Pecoraro <pecoraro@apple.com> on 2016-04-15
Reviewed by Timothy Hatcher.

Source/JavaScriptCore:

Clean up Debugger.sourceParsed to separately include:

    - url ("resource URL", "source url" in JSC APIs)
    - sourceURL - //# sourceURL directive

By always having the resource URL the Web Inspector frontend
can better match this Script to a Resource of the same URL,
and decide to use the sourceURL if it is available when
appropriate.

* inspector/protocol/Debugger.json:
* inspector/agents/InspectorDebuggerAgent.cpp:
(Inspector::InspectorDebuggerAgent::setBreakpointByUrl):
(Inspector::InspectorDebuggerAgent::didParseSource):
Send the new sourceParsed parameters.

Source/WebInspectorUI:

Previously Debugger.sourceParsed only providing the sourceURL, and
wiping out the resourceURL, meant that a Script from a Resource that
set a sourceURL directive would fail to be associated with its Resource.

This would result in duplicated tree elements in the Resources Sidebar,
one for the Resource, and one for the Script. With the Script getting
ultimately getting the SourceMap resources. However, since the frontend
prefers Resources over Scripts when possible, an error that generated
from the script would point to a location in the Resource, not following
source maps.

By always providing the resource URL in Debugger.sourceParsed, a Script
can better be associated with its Resource. The result is now a single
shared tree element in the Resources Sidebar, and the Resource getting
the SourceMap resources. Now the script error goes through the Resource
to its SourceMap resources as we would expect.

* UserInterface/Protocol/DebuggerObserver.js:
(WebInspector.DebuggerObserver):
(WebInspector.DebuggerObserver.prototype.scriptParsed):
We now have to handle two different signatures of scriptParsed. One
for legacy, and one for non-legacy. Cache that value early on, since
scriptParsed happens a lot.

* UserInterface/Protocol/InspectorBackend.js:
(InspectorBackend.Agent.prototype.hasEventParameter):
Runtime check a protocol event to see if it has a parameter. This
is used to check if Debugger.sourceParsed is legacy or not based
on if it has the legacy "hasSourceURL" parameter.

* UserInterface/Models/Script.js:
(WebInspector.Script):
(WebInspector.Script.prototype.get sourceURL):
Treat sourceURL and url separately.

(WebInspector.Script.prototype.get displayName):
Handle both the url and sourceURL in displayName.

* UserInterface/Controllers/DebuggerManager.js:
(WebInspector.DebuggerManager.prototype.get knownNonResourceScripts):
(WebInspector.DebuggerManager.prototype.debuggerDidPause):
(WebInspector.DebuggerManager.prototype.scriptDidParse):
* UserInterface/Protocol/RemoteObject.js:
(WebInspector.RemoteObject.prototype.findFunctionSourceCodeLocation):
Update code that checks the sourceURL to explicitly use sourceURL.

* UserInterface/Controllers/SourceMapManager.js:
(WebInspector.SourceMapManager.prototype.downloadSourceMap):
For legacy backends, or in case we get a resource that has an incomplete
baseURL, attempt to get an absolute URL based on the main resource.

* UserInterface/Views/DebuggerSidebarPanel.js:
(WebInspector.DebuggerSidebarPanel.prototype._addScript):
* UserInterface/Views/ResourceSidebarPanel.js:
(WebInspector.ResourceSidebarPanel.prototype._scriptWasAdded):
Ignore scripts without a url or sourceURL.

LayoutTests:

* inspector/debugger/scriptParsed.html:
* inspector/debugger/search-scripts.html:
* inspector/debugger/setBreakpointByUrl-sourceURL.html:
* inspector/debugger/sourceURLs.html:
Update tests that need to handle sourceURL separately.

* inspector/model/resources/relationship-named.js: Added.
* inspector/model/resources/relationship-normal.js: Added.
* inspector/model/script-resource-relationship-expected.txt: Added.
* inspector/model/script-resource-relationship.html: Added.
Tests for Script and Resource relationships.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@199602 268f45cc-cd09-0410-ab3c-d52691b4dbfc
21 files changed