WebInspector.RawSourceCode = function(id, script, resource, request, formatter, formatted)
{
this.id = id;
this.url = script.sourceURL;
this.isContentScript = script.isContentScript;
this._scripts = [script];
this._formatter = formatter;
this._formatted = formatted;
this._resource = resource;
this._pendingRequest = request;
this._hasNewScripts = true;
if (this._pendingRequest)
this._pendingRequest.addEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, this._finishedLoading, this);
else
this._updateSourceMapping();
}
WebInspector.RawSourceCode.Events = {
UISourceCodeChanged: "us-source-code-changed"
}
WebInspector.RawSourceCode.prototype = {
addScript: function(script)
{
this._scripts.push(script);
this._hasNewScripts = true;
},
rawLocationToUILocation: function(rawLocation)
{
if (this._sourceMapping)
return this._sourceMapping.rawLocationToUILocation(rawLocation);
return null;
},
uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
{
if (this._sourceMapping)
return this._sourceMapping.uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber);
return null;
},
uiSourceCode: function()
{
if (this._sourceMapping)
return this._sourceMapping.uiSourceCode();
return null;
},
setFormatted: function(formatted)
{
if (this._formatted === formatted)
return;
this._formatted = formatted;
this._updateSourceMapping();
},
_finishedLoading: function(event)
{
this._resource = WebInspector.resourceForURL(this._pendingRequest.url);
delete this._pendingRequest;
this._updateSourceMapping();
},
forceUpdateSourceMapping: function(script)
{
if (!this._pendingRequest || !this._hasNewScripts)
return;
this._hasNewScripts = false;
this._updateSourceMapping();
},
_updateSourceMapping: function()
{
if (this._updatingSourceMapping) {
this._updateNeeded = true;
return;
}
this._updatingSourceMapping = true;
this._updateNeeded = false;
this._createSourceMapping(didCreateSourceMapping.bind(this));
function didCreateSourceMapping(sourceMapping)
{
this._updatingSourceMapping = false;
if (sourceMapping && !this._updateNeeded)
this._saveSourceMapping(sourceMapping);
else
this._updateSourceMapping();
}
},
_createContentProvider: function()
{
if (this._resource)
return this._resource;
if (this._scripts.length === 1 && !this._scripts[0].lineOffset && !this._scripts[0].columnOffset)
return this._scripts[0];
return new WebInspector.ConcatenatedScriptsContentProvider(this._scripts);
},
_createSourceMapping: function(callback)
{
var originalContentProvider = this._createContentProvider();
if (!this._formatted) {
var uiSourceCode = this._createUISourceCode(this.url, this.url, originalContentProvider);
var sourceMapping = new WebInspector.RawSourceCode.PlainSourceMapping(this, uiSourceCode);
callback(sourceMapping);
return;
}
function didRequestContent(content, contentEncoded, mimeType)
{
function didFormatContent(formattedContent, mapping)
{
var contentProvider = new WebInspector.StaticContentProvider(mimeType, formattedContent)
var uiSourceCode = this._createUISourceCode("deobfuscated:" + this.url, this.url, contentProvider);
var sourceMapping = new WebInspector.RawSourceCode.FormattedSourceMapping(this, uiSourceCode, mapping);
callback(sourceMapping);
}
this._formatter.formatContent(mimeType, content || "", didFormatContent.bind(this));
}
originalContentProvider.requestContent(didRequestContent.bind(this));
},
_createUISourceCode: function(id, url, contentProvider)
{
var uiSourceCode = new WebInspector.JavaScriptSource(id, url, contentProvider);
uiSourceCode.isContentScript = this.isContentScript;
uiSourceCode.isEditable = this._scripts.length === 1 && !this._scripts[0].lineOffset && !this._scripts[0].columnOffset && !this._formatted;
return uiSourceCode;
},
_saveSourceMapping: function(sourceMapping)
{
var oldUISourceCode;
if (this._sourceMapping)
oldUISourceCode = this._sourceMapping.uiSourceCode();
this._sourceMapping = sourceMapping;
this.dispatchEventToListeners(WebInspector.RawSourceCode.Events.UISourceCodeChanged, { oldUISourceCode: oldUISourceCode });
}
}
WebInspector.RawSourceCode.prototype.__proto__ = WebInspector.Object.prototype;
WebInspector.RawSourceCode.SourceMapping = function()
{
}
WebInspector.RawSourceCode.SourceMapping.prototype = {
uiSourceCode: function() { }
}
WebInspector.RawSourceCode.PlainSourceMapping = function(rawSourceCode, uiSourceCode)
{
this._rawSourceCode = rawSourceCode;
this._uiSourceCode = uiSourceCode;
}
WebInspector.RawSourceCode.PlainSourceMapping.prototype = {
rawLocationToUILocation: function(rawLocation)
{
return new WebInspector.UILocation(this._uiSourceCode, rawLocation.lineNumber, rawLocation.columnNumber || 0);
},
uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
{
console.assert(uiSourceCode === this._uiSourceCode);
return WebInspector.debuggerModel.createRawLocation(this._rawSourceCode._scripts[0], lineNumber, columnNumber);
},
uiSourceCode: function()
{
return this._uiSourceCode;
}
}
WebInspector.RawSourceCode.FormattedSourceMapping = function(rawSourceCode, uiSourceCode, mapping)
{
this._rawSourceCode = rawSourceCode;
this._uiSourceCode = uiSourceCode;
this._mapping = mapping;
}
WebInspector.RawSourceCode.FormattedSourceMapping.prototype = {
rawLocationToUILocation: function(rawLocation)
{
var location = this._mapping.originalToFormatted(rawLocation.lineNumber, rawLocation.columnNumber || 0);
return new WebInspector.UILocation(this._uiSourceCode, location[0], location[1]);
},
uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
{
console.assert(uiSourceCode === this._uiSourceCode);
var location = this._mapping.formattedToOriginal(lineNumber, columnNumber);
return WebInspector.debuggerModel.createRawLocation(this._rawSourceCode._scripts[0], location[0], location[1]);
},
uiSourceCode: function()
{
return this._uiSourceCode;
}
}