Diff
Modified: trunk/LayoutTests/ChangeLog (124590 => 124591)
--- trunk/LayoutTests/ChangeLog 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/LayoutTests/ChangeLog 2012-08-03 10:28:23 UTC (rev 124591)
@@ -1,3 +1,16 @@
+2012-08-03 Eugene Klyuchnikov <[email protected]>
+
+ Web Inspector: Profiles: extract save to file / load from code
+ https://bugs.webkit.org/show_bug.cgi?id=92348
+
+ Reviewed by Yury Semikhatsky.
+
+ Changed test to adopt new API. Replaced FS mock with
+ reader mock.
+
+ * inspector/profiler/heap-snapshot-loader.html:
+ Adopted new API.
+
2012-08-03 Alexander Pavlov <[email protected]>
Web Inspector: Incorrect blob url href when inspecting
Modified: trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html (124590 => 124591)
--- trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/LayoutTests/inspector/profiler/heap-snapshot-loader.html 2012-08-03 10:28:23 UTC (rev 124591)
@@ -19,9 +19,10 @@
function heapSnapshotLoaderTest(next)
{
var loader = new WebInspector.HeapSnapshotLoader();
+ loader.startTransfer();
for (var i = 0, l = sourceStringified.length; i < l; i += partSize)
- loader.pushJSONChunk(sourceStringified.slice(i, i + partSize));
- loader.finishLoading();
+ loader.transferChunk(sourceStringified.slice(i, i + partSize));
+ loader.finishTransfer();
var result = loader.buildSnapshot();
result._nodes = new Uint32Array(result._nodes);
result._containmentEdges = new Uint32Array(result._containmentEdges);
@@ -89,16 +90,33 @@
var fileMock = {
name: "mock.heapsnapshot",
- size: sourceStringified.length,
- slice: function(begin, end) { return this; },
- webkitSlice: function(begin, end) { return this; }
+ size: sourceStringified.length
};
InspectorTest.override(WebInspector.HeapProfileHeader.prototype, '_createFileReader', function(fileMock, delegate) {
return {
- readAsText: function(filePart) {
- var profileHeader = panel._profiles[panel._profiles.length - 1];
- profileHeader._nextChunkLoaded(sourceStringified);
+ start: function(receiver) {
+ receiver.startTransfer();
+ delegate.onTransferStarted(this);
+ receiver.transferChunk(sourceStringified);
+ delegate.onChunkTransferred(this);
+ receiver.finishTransfer();
+ delegate.onTransferFinished(this);
+ },
+
+ loadedSize: function()
+ {
+ return fileMock.size;
+ },
+
+ fileSize: function()
+ {
+ return fileMock.size;
+ },
+
+ fileName: function()
+ {
+ return fileMock.name;
}
};
});
Modified: trunk/Source/WebCore/ChangeLog (124590 => 124591)
--- trunk/Source/WebCore/ChangeLog 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/ChangeLog 2012-08-03 10:28:23 UTC (rev 124591)
@@ -1,3 +1,48 @@
+2012-08-03 Eugene Klyuchnikov <[email protected]>
+
+ Web Inspector: Profiles: extract save to file / load from code
+ https://bugs.webkit.org/show_bug.cgi?id=92348
+
+ Reviewed by Yury Semikhatsky.
+
+ Motivation: extract reusable code for timeline load/save.
+ FileUtils.js will contain common code. Not all code moved to FileUtils
+ to make review easier. This code will be moved in next patch.
+
+ Core abstractions: OutputStream and OutputStreamDelegate.
+
+ OutputStream is interface that is used to transfer entity divded
+ to chunks. Transfer process is explicitly initialized (startTransfer)
+ and finalized (finishTrnsfer).
+
+ OutputStreamDelegate is interface to receive notifications about
+ transfer process: onTransferStarted, onChunkTransferred, onTransferFinished.
+
+ ChunkedFileReader: utility class that loads file by chunks of specified
+ size and notifies given delegate. OutputStream is supplied as a
+ parameter of method "start".
+
+ ChunkedFileWriter: implementation of OutputStream that saves data
+ to file specified by file name and notifies given delegate.
+
+ * WebCore.gypi: Added 'FileUtils.js'.
+ * WebCore.vcproj/WebCore.vcproj: Added 'FileUtils.js'.
+ * inspector/compile-front-end.py: Added 'FileUtils.js'.
+ * inspector/front-end/FileUtils.js: Added.
+ (WebInspector.OutputStreamDelegate): Added.
+ (WebInspector.ChunkedFileReader): Added.
+ (WebInspector.createFileSelectorElement): Added utility method to construct
+ hidden input element to select file.
+ * inspector/front-end/HeapSnapshotLoader.js: Adopted new API.
+ * inspector/front-end/HeapSnapshotProxy.js: Adopted new API.
+ * inspector/front-end/HeapSnapshotView.js: Adopted new API.
+ (WebInspector.HeapSnapshotLoadFromFileDelegate):
+ Extracted from existing code.
+ (WebInspector.ChunkedFileWriter): Renamed and refactored.
+ (WebInspector.HeapSnapshotSaveToFileDelegate):
+ Extracted from existing code.
+ * inspector/front-end/ProfilesPanel.js: Adopted new API.
+
2012-08-03 Alexander Pavlov <[email protected]>
Web Inspector: Incorrect blob url href when inspecting
Modified: trunk/Source/WebCore/WebCore.gypi (124590 => 124591)
--- trunk/Source/WebCore/WebCore.gypi 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/WebCore.gypi 2012-08-03 10:28:23 UTC (rev 124591)
@@ -6302,6 +6302,7 @@
'inspector/front-end/FileContentView.js',
'inspector/front-end/FileSystemModel.js',
'inspector/front-end/FileSystemView.js',
+ 'inspector/front-end/FileUtils.js',
'inspector/front-end/FilteredItemSelectionDialog.js',
'inspector/front-end/FontView.js',
'inspector/front-end/GoToLineDialog.js',
Modified: trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj (124590 => 124591)
--- trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj 2012-08-03 10:28:23 UTC (rev 124591)
@@ -75526,6 +75526,10 @@
>
</File>
<File
+ RelativePath="..\inspector\front-end\FileUtils.js"
+ >
+ </File>
+ <File
RelativePath="..\inspector\front-end\filteredItemSelectionDialog.css"
>
</File>
Modified: trunk/Source/WebCore/inspector/compile-front-end.py (124590 => 124591)
--- trunk/Source/WebCore/inspector/compile-front-end.py 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/inspector/compile-front-end.py 2012-08-03 10:28:23 UTC (rev 124591)
@@ -82,6 +82,7 @@
"DebuggerScriptMapping.js",
"FileManager.js",
"FileSystemModel.js",
+ "FileUtils.js",
"HAREntry.js",
"IndexedDBModel.js",
"Linkifier.js",
Added: trunk/Source/WebCore/inspector/front-end/FileUtils.js (0 => 124591)
--- trunk/Source/WebCore/inspector/front-end/FileUtils.js (rev 0)
+++ trunk/Source/WebCore/inspector/front-end/FileUtils.js 2012-08-03 10:28:23 UTC (rev 124591)
@@ -0,0 +1,149 @@
+/*
+ * Copyright (C) 2012 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @interface
+ */
+WebInspector.OutputStreamDelegate = function()
+{
+}
+
+WebInspector.OutputStreamDelegate.prototype = {
+ onTransferStarted: function(source)
+ {
+ },
+
+ onChunkTransferred: function(source)
+ {
+ },
+
+ onTransferFinished: function(source)
+ {
+ },
+
+ onError: function(source, event)
+ {
+ }
+}
+
+/**
+ * @constructor
+ * @param {!File} file
+ * @param {!number} chunkSize
+ * @param {!WebInspector.OutputStreamDelegate} delegate
+ */
+WebInspector.ChunkedFileReader = function(file, chunkSize, delegate)
+{
+ this._file = file;
+ this._fileSize = file.size;
+ this._loadedSize = 0;
+ this._chunkSize = chunkSize;
+ this._delegate = delegate;
+}
+
+WebInspector.ChunkedFileReader.prototype = {
+ /**
+ * @param {!WebInspector.OutputStream} output
+ */
+ start: function(output)
+ {
+ this._output = output;
+
+ this._reader = new FileReader();
+ this._reader._onload_ = this._onChunkLoaded.bind(this);
+ this._reader._onerror_ = this._delegate.onError.bind(this._delegate, this);
+ this._output.startTransfer();
+ this._delegate.onTransferStarted(this);
+ this._loadChunk();
+ },
+
+ loadedSize: function()
+ {
+ return this._loadedSize;
+ },
+
+ fileSize: function()
+ {
+ return this._fileSize;
+ },
+
+ fileName: function()
+ {
+ return this._file.name;
+ },
+
+ /**
+ * @param {Event} event
+ */
+ _onChunkLoaded: function(event)
+ {
+ if (event.target.readyState !== FileReader.DONE)
+ return;
+
+ var data = ""
+ this._loadedSize += data.length;
+
+ this._output.transferChunk(data);
+ this._delegate.onChunkTransferred(this);
+
+ if (this._loadedSize === this._fileSize) {
+ this._file = null;
+ this._reader = null;
+ this._output.finishTransfer();
+ this._delegate.onTransferFinished(this);
+ return;
+ }
+
+ this._loadChunk();
+ },
+
+ _loadChunk: function()
+ {
+ var chunkStart = this._loadedSize;
+ var chunkEnd = Math.min(this._fileSize, chunkStart + this._chunkSize)
+ var nextPart = this._file.webkitSlice(chunkStart, chunkEnd);
+ this._reader.readAsText(nextPart);
+ }
+}
+
+/**
+ * @param {!function(File)} callback
+ * @return {Node}
+ */
+WebInspector.createFileSelectorElement = function(callback) {
+ var fileSelectorElement = document.createElement("input");
+ fileSelectorElement.type = "file";
+ fileSelectorElement.style.zIndex = -1;
+ fileSelectorElement.style.position = "absolute";
+ fileSelectorElement._onchange_ = function(event) {
+ callback(fileSelectorElement.files[0]);
+ };
+ return fileSelectorElement;
+}
Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshotLoader.js (124590 => 124591)
--- trunk/Source/WebCore/inspector/front-end/HeapSnapshotLoader.js 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshotLoader.js 2012-08-03 10:28:23 UTC (rev 124591)
@@ -30,7 +30,7 @@
/**
* @constructor
- * @implements {WebInspector.HeapSnapshotReceiver}
+ * @implements {WebInspector.OutputStream}
*/
WebInspector.HeapSnapshotLoader = function()
{
@@ -38,7 +38,7 @@
}
WebInspector.HeapSnapshotLoader.prototype = {
- startLoading: function()
+ startTransfer: function()
{
},
@@ -70,7 +70,7 @@
return -1;
},
- finishLoading: function()
+ finishTransfer: function()
{
if (this._json)
this._parseStringsArray();
@@ -133,7 +133,7 @@
/**
* @param {string} chunk
*/
- pushJSONChunk: function(chunk)
+ transferChunk: function(chunk)
{
this._json += chunk;
switch (this._state) {
@@ -144,7 +144,7 @@
throw new Error("Snapshot token not found");
this._json = this._json.slice(snapshotTokenIndex + snapshotToken.length + 1);
this._state = "parse-snapshot-info";
- this.pushJSONChunk("");
+ this.transferChunk("");
break;
}
case "parse-snapshot-info": {
@@ -154,7 +154,7 @@
this._snapshot.snapshot = /** @type {HeapSnapshotHeader} */JSON.parse(this._json.slice(0, closingBracketIndex));
this._json = this._json.slice(closingBracketIndex);
this._state = "find-nodes";
- this.pushJSONChunk("");
+ this.transferChunk("");
break;
}
case "find-nodes": {
@@ -171,7 +171,7 @@
this._array = new Uint32Array(nodes_length);
this._arrayIndex = 0;
this._state = "parse-nodes";
- this.pushJSONChunk("");
+ this.transferChunk("");
break;
}
case "parse-nodes": {
@@ -180,7 +180,7 @@
this._snapshot.nodes = this._array;
this._state = "find-edges";
this._array = null;
- this.pushJSONChunk("");
+ this.transferChunk("");
break;
}
case "find-edges": {
@@ -197,7 +197,7 @@
this._array = new Uint32Array(edges_length);
this._arrayIndex = 0;
this._state = "parse-edges";
- this.pushJSONChunk("");
+ this.transferChunk("");
break;
}
case "parse-edges": {
@@ -206,7 +206,7 @@
this._snapshot.edges = this._array;
this._array = null;
this._state = "find-strings";
- this.pushJSONChunk("");
+ this.transferChunk("");
break;
}
case "find-strings": {
Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js (124590 => 124591)
--- trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshotProxy.js 2012-08-03 10:28:23 UTC (rev 124591)
@@ -355,7 +355,7 @@
/**
* @constructor
* @extends {WebInspector.HeapSnapshotProxyObject}
- * @implements {WebInspector.HeapSnapshotReceiver}
+ * @implements {WebInspector.OutputStream}
*/
WebInspector.HeapSnapshotLoaderProxy = function(worker, objectId)
{
@@ -365,7 +365,7 @@
}
WebInspector.HeapSnapshotLoaderProxy.prototype = {
- startLoading: function()
+ startTransfer: function()
{
this._started = true;
this.callMethod(null, "startTransfer");
@@ -387,12 +387,12 @@
/**
* @param {string} chunk
*/
- pushJSONChunk: function(chunk)
+ transferChunk: function(chunk)
{
- this.callMethod(null, "pushJSONChunk", chunk);
+ this.callMethod(null, "transferChunk", chunk);
},
- finishLoading: function()
+ finishTransfer: function()
{
function buildSnapshot()
{
@@ -411,7 +411,7 @@
this._started = false;
this._pendingSnapshotConsumers = [];
}
- this.callMethod(buildSnapshot.bind(this), "finishLoading");
+ this.callMethod(buildSnapshot.bind(this), "finishTransfer");
}
};
Modified: trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js (124590 => 124591)
--- trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/inspector/front-end/HeapSnapshotView.js 2012-08-03 10:28:23 UTC (rev 124591)
@@ -787,23 +787,23 @@
/**
* @interface
*/
-WebInspector.HeapSnapshotReceiver = function()
+WebInspector.OutputStream = function()
{
}
-WebInspector.HeapSnapshotReceiver.prototype = {
- startLoading: function()
+WebInspector.OutputStream.prototype = {
+ startTransfer: function()
{
},
/**
* @param {string} chunk
*/
- pushJSONChunk: function(chunk)
+ transferChunk: function(chunk)
{
},
- finishLoading: function()
+ finishTransfer: function()
{
},
@@ -825,7 +825,7 @@
WebInspector.ProfileHeader.call(this, type, title, uid);
this.maxJSObjectId = maxJSObjectId;
/**
- * @type {WebInspector.HeapSnapshotReceiver}
+ * @type {WebInspector.OutputStream}
*/
this._receiver = null;
/**
@@ -874,7 +874,7 @@
this._numberOfChunks = 0;
if (!loaderProxy.isStarted()) {
- loaderProxy.startLoading();
+ loaderProxy.startTransfer();
this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
this.sidebarElement.wait = true;
ProfilerAgent.getProfile(this.profileType().id, this.uid);
@@ -917,10 +917,10 @@
/**
* @param {string} chunk
*/
- pushJSONChunk: function(chunk)
+ transferChunk: function(chunk)
{
++this._numberOfChunks;
- this._receiver.pushJSONChunk(chunk);
+ this._receiver.transferChunk(chunk);
},
_snapshotReceived: function(snapshotProxy)
@@ -935,11 +935,12 @@
worker.startCheckingForLongRunningCalls();
},
- finishHeapSnapshot: function()
+ finishHeapSnapshot: function(transferFinished)
{
this._totalNumberOfChunks = this._numberOfChunks;
this.sidebarElement.subtitle = WebInspector.UIString("Parsing\u2026");
- this._receiver.finishLoading();
+ if (!transferFinished)
+ this._receiver.finishTransfer();
},
/**
@@ -957,12 +958,23 @@
saveToFile: function()
{
this._fileName = this._fileName || "Heap-" + new Date().toISO8601Compact() + ".heapsnapshot";
- this._receiver = new WebInspector.HeapSnapshotSaveToFileReceiver(this._fileName, this);
+ var delegate = new WebInspector.HeapSnapshotSaveToFileDelegate(this);
+ this._receiver = this._createFileWriter(this._fileName, delegate);
this._numberOfChunks = 0;
- this._receiver.startLoading();
+ this._receiver.startTransfer();
},
/**
+ * @param {!string} fileName
+ * @param {!WebInspector.OutputStreamDelegate} delegate
+ * @return {WebInspector.OutputStream}
+ */
+ _createFileWriter: function(fileName, delegate)
+ {
+ return new WebInspector.ChunkedFileWriter(fileName, delegate);
+ },
+
+ /**
* @return {boolean}
*/
canLoadFromFile: function()
@@ -976,99 +988,86 @@
*/
loadFromFile: function(file)
{
- function onError(e)
- {
- switch(e.target.error.code) {
- case e.target.error.NOT_FOUND_ERR:
- this.sidebarElement.subtitle = WebInspector.UIString("'%s' not found.", file.name);
- break;
- case e.target.error.NOT_READABLE_ERR:
- this.sidebarElement.subtitle = WebInspector.UIString("'%s' is not readable", file.name);
- break;
- case e.target.error.ABORT_ERR:
- break;
- default:
- this.sidebarElement.subtitle = WebInspector.UIString("'%s' error %d", file.name, e.target.error.code);
- }
- }
-
this.title = file.name;
this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026");
this.sidebarElement.wait = true;
this._setupWorker();
this._numberOfChunks = 0;
- this._receiver.startLoading();
- /**
- * @param {Event} event
- */
- function onLoad(event)
- {
- if (event.target.readyState !== FileReader.DONE)
- return;
- this._nextChunkLoaded(event.target.result);
- }
+ var delegate = new WebInspector.HeapSnapshotLoadFromFileDelegate(this);
+ var fileReader = this._createFileReader(file, delegate);
+ fileReader.start(this._receiver);
+ },
- this._file = file;
- this._expectedSize = file.size;
- this._loadedSize = 0;
- this._reader = this._createFileReader();
- this._reader._onload_ = onLoad.bind(this);
- this._reader._onerror_ = onError;
- this._loadNextChunk();
+ _createFileReader: function(file, delegate)
+ {
+ return new WebInspector.ChunkedFileReader(file, 10000000, delegate);
+ }
+}
+
+WebInspector.HeapProfileHeader.prototype.__proto__ = WebInspector.ProfileHeader.prototype;
+
+/**
+ * @constructor
+ * @implements {WebInspector.OutputStreamDelegate}
+ */
+WebInspector.HeapSnapshotLoadFromFileDelegate = function(snapshotHeader)
+{
+ this._snapshotHeader = snapshotHeader;
+}
+
+WebInspector.HeapSnapshotLoadFromFileDelegate.prototype = {
+ onTransferStarted: function(source)
+ {
},
- _loadNextChunk: function()
+ onChunkTransferred: function(source)
{
- var loadedSize = this._loadedSize;
- var chunkSize = 10000000;
- var size = this._expectedSize < loadedSize + chunkSize ? this._expectedSize - loadedSize : chunkSize;
- var nextPart = this._file.webkitSlice(loadedSize, loadedSize + size);
- this._reader.readAsText(nextPart);
+ this._snapshotHeader.sidebarElement.subtitle = WebInspector.UIString(
+ "Loading\u2026 %d%", (source.loadedSize() * 100 / source.fileSize()).toFixed(2));
},
- _nextChunkLoaded: function(data)
+ onTransferFinished: function(source)
{
- this._loadedSize += data.length;
- this._receiver.pushJSONChunk(data);
- this.sidebarElement.subtitle = WebInspector.UIString("Loading\u2026 %d%", (this._loadedSize * 100 / this._expectedSize).toFixed(2));
-
- if (this._loadedSize === this._expectedSize) {
- this._file = null;
- this._reader = null;
- this.finishHeapSnapshot();
- return;
- }
- this._loadNextChunk();
+ this._snapshotHeader.finishHeapSnapshot(true);
},
- _createFileReader: function()
+ onError: function (source, e)
{
- return new FileReader();
+ switch(e.target.error.code) {
+ case e.target.error.NOT_FOUND_ERR:
+ this._snapshotHeader.sidebarElement.subtitle = WebInspector.UIString("'%s' not found.", source.fileName());
+ break;
+ case e.target.error.NOT_READABLE_ERR:
+ this._snapshotHeader.sidebarElement.subtitle = WebInspector.UIString("'%s' is not readable", source.fileName());
+ break;
+ case e.target.error.ABORT_ERR:
+ break;
+ default:
+ this._snapshotHeader.sidebarElement.subtitle = WebInspector.UIString("'%s' error %d", source.fileName(), e.target.error.code);
+ }
}
}
-WebInspector.HeapProfileHeader.prototype.__proto__ = WebInspector.ProfileHeader.prototype;
-
-
/**
* @constructor
- * @implements {WebInspector.HeapSnapshotReceiver}
+ * @implements {WebInspector.OutputStream}
+ * @param {!string} fileName
+ * @param {!WebInspector.OutputStreamDelegate} delegate
*/
-WebInspector.HeapSnapshotSaveToFileReceiver = function(fileName, snapshotHeader)
+WebInspector.ChunkedFileWriter = function(fileName, delegate)
{
this._fileName = fileName;
- this._snapshotHeader = snapshotHeader;
- this._savedChunks = 0;
+ this._delegate = delegate;
}
-WebInspector.HeapSnapshotSaveToFileReceiver.prototype = {
+WebInspector.ChunkedFileWriter.prototype = {
/**
* @override
*/
- startLoading: function()
+ startTransfer: function()
{
- WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._startSavingSnapshot, this);
+ WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._onTransferStarted, this);
WebInspector.fileManager.save(this._fileName, "", true);
},
@@ -1076,7 +1075,7 @@
* @override
* @param {string} chunk
*/
- pushJSONChunk: function(chunk)
+ transferChunk: function(chunk)
{
WebInspector.fileManager.append(this._fileName, chunk);
},
@@ -1084,10 +1083,10 @@
/**
* @override
*/
- finishLoading: function()
+ finishTransfer: function()
{
- WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
- this._snapshotHeader._snapshotReceived(null);
+ WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._onChunkTransferred, this);
+ this._delegate.onTransferFinished(this);
},
dispose: function()
@@ -1097,26 +1096,54 @@
/**
* @param {WebInspector.Event} event
*/
- _startSavingSnapshot: function(event)
+ _onTransferStarted: function(event)
{
if (event.data !== this._fileName)
return;
- this._snapshotHeader._saveStatusUpdate(0);
- WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._startSavingSnapshot, this);
- WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
- ProfilerAgent.getProfile(this._snapshotHeader.profileType().id, this._snapshotHeader.uid);
+ this._delegate.onTransferStarted(this);
+ WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._onTransferStarted, this);
+ WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._onChunkTransferred, this);
},
/**
* @param {WebInspector.Event} event
*/
- _saveStatusUpdate: function(event)
+ _onChunkTransferred: function(event)
{
if (event.data !== this._fileName)
return;
+ this._delegate.onChunkTransferred(this);
+ }
+}
+
+/**
+ * @constructor
+ * @implements {WebInspector.OutputStreamDelegate}
+ */
+WebInspector.HeapSnapshotSaveToFileDelegate = function(snapshotHeader)
+{
+ this._snapshotHeader = snapshotHeader;
+ this._savedChunks = 0;
+}
+
+WebInspector.HeapSnapshotSaveToFileDelegate.prototype = {
+ onTransferStarted: function(source)
+ {
+ this._snapshotHeader._saveStatusUpdate(0);
+ ProfilerAgent.getProfile(this._snapshotHeader.profileType().id, this._snapshotHeader.uid);
+ },
+
+ onChunkTransferred: function(source)
+ {
this._snapshotHeader._saveStatusUpdate(++this._savedChunks);
- if (this._savedChunks === this._snapshotHeader._totalNumberOfChunks)
- WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._saveStatusUpdate, this);
+ },
+
+ onTransferFinished: function(source)
+ {
+ this._snapshotHeader._snapshotReceived(null);
+ },
+
+ onError: function(source, event)
+ {
}
-};
-
+}
Modified: trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js (124590 => 124591)
--- trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/inspector/front-end/ProfilesPanel.js 2012-08-03 10:28:23 UTC (rev 124591)
@@ -264,17 +264,8 @@
{
if (this._fileSelectorElement)
this.element.removeChild(this._fileSelectorElement);
-
- var fileSelectorElement = document.createElement("input");
- fileSelectorElement.type = "file";
- fileSelectorElement.style.zIndex = -1;
- fileSelectorElement.style.position = "absolute";
- function onChange(event) {
- this._loadFromFile(this._fileSelectorElement.files[0]);
- }
- fileSelectorElement._onchange_ = onChange.bind(this);
- this.element.appendChild(fileSelectorElement);
- this._fileSelectorElement = fileSelectorElement;
+ this._fileSelectorElement = WebInspector.createFileSelectorElement(this._loadFromFile.bind(this));
+ this.element.appendChild(this._fileSelectorElement);
},
_loadFromFile: function(file)
@@ -675,9 +666,9 @@
_addHeapSnapshotChunk: function(uid, chunk)
{
var profile = "" WebInspector.HeapSnapshotProfileType.TypeId)];
- if (!profile )
+ if (!profile)
return;
- profile.pushJSONChunk(chunk);
+ profile.transferChunk(chunk);
},
/**
@@ -688,7 +679,7 @@
var profile = "" WebInspector.HeapSnapshotProfileType.TypeId)];
if (!profile)
return;
- profile.finishHeapSnapshot();
+ profile.finishHeapSnapshot(false);
},
/**
Modified: trunk/Source/WebCore/inspector/front-end/WebKit.qrc (124590 => 124591)
--- trunk/Source/WebCore/inspector/front-end/WebKit.qrc 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/inspector/front-end/WebKit.qrc 2012-08-03 10:28:23 UTC (rev 124591)
@@ -62,6 +62,7 @@
<file>FileManager.js</file>
<file>FileSystemModel.js</file>
<file>FileSystemView.js</file>
+ <file>FileUtils.js</file>
<file>FilteredItemSelectionDialog.js</file>
<file>FontView.js</file>
<file>GoToLineDialog.js</file>
Modified: trunk/Source/WebCore/inspector/front-end/inspector.html (124590 => 124591)
--- trunk/Source/WebCore/inspector/front-end/inspector.html 2012-08-03 10:25:20 UTC (rev 124590)
+++ trunk/Source/WebCore/inspector/front-end/inspector.html 2012-08-03 10:28:23 UTC (rev 124591)
@@ -165,6 +165,7 @@
<script type="text/_javascript_" src=""
<script type="text/_javascript_" src=""
<script type="text/_javascript_" src=""
+ <script type="text/_javascript_" src=""
<script type="text/_javascript_" src=""
<script type="text/_javascript_" src=""
<script type="text/_javascript_" src=""