Web Inspector: Saving HAR, snapshots and timeline data do not work in remote debuggin...
authorcaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2012 08:02:24 +0000 (08:02 +0000)
committercaseq@chromium.org <caseq@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Oct 2012 08:02:24 +0000 (08:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=99179

Patch by Eugene Klyuchnikov <eustas.bug@gmail.com> on 2012-10-19
Reviewed by Yury Semikhatsky.

Added method "close" to InspectorFrontendHost.
Symantically, this method forces to flush all unsaved buffers for
specified file. In native implementation this turns to be no-op.

In stub implementation "close" causes compilation of blob object an
navigating to blob-schema url.

Removed "canAppend", as appending in now suppurted
by all implementations.

Repaced schema "data" with "blob" in InspectorFrontendHostStub "save"
to avoid out-of-memory errors.

* inspector/InspectorFrontendHost.cpp:
(WebCore::InspectorFrontendHost::close): Compiles blob object and
navigates to blob-object url.
(WebCore):
* inspector/InspectorFrontendHost.h: Added "close" method.
* inspector/InspectorFrontendHost.idl: Ditto.
* inspector/front-end/FileManager.js:
(WebInspector.FileManager.prototype.close): Proxy to InspectorFrontend.
* inspector/front-end/FileUtils.js:
(WebInspector.FileOutputStream.prototype.close):
Invoke "close" on FileManager.
(WebInspector.FileOutputStream.prototype._onAppendDone): Ditto.
* inspector/front-end/HandlerRegistry.js: Added mandatory "close" call.
* inspector/front-end/HeapSnapshotView.js:
(WebInspector.HeapProfileHeader.prototype.canSaveToFile): Fixed check.
* inspector/front-end/InspectorFrontendHostStub.js:
(.WebInspector.InspectorFrontendHostStub):
Added "appendable" behaviour emulation.
* inspector/front-end/SourceFrame.js: Added mandatory "close" call.
* inspector/front-end/externs.js: Replaced "canAppend" with "close"

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@131872 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorFrontendHost.cpp
Source/WebCore/inspector/InspectorFrontendHost.h
Source/WebCore/inspector/InspectorFrontendHost.idl
Source/WebCore/inspector/front-end/FileManager.js
Source/WebCore/inspector/front-end/FileUtils.js
Source/WebCore/inspector/front-end/HandlerRegistry.js
Source/WebCore/inspector/front-end/HeapSnapshotView.js
Source/WebCore/inspector/front-end/InspectorFrontendHostStub.js
Source/WebCore/inspector/front-end/UISourceCode.js
Source/WebCore/inspector/front-end/externs.js

index b2f87be..0f570f5 100644 (file)
@@ -1,3 +1,44 @@
+2012-10-19  Eugene Klyuchnikov  <eustas.bug@gmail.com>
+
+        Web Inspector: Saving HAR, snapshots and timeline data do not work in remote debugging mode
+        https://bugs.webkit.org/show_bug.cgi?id=99179
+
+        Reviewed by Yury Semikhatsky.
+
+        Added method "close" to InspectorFrontendHost.
+        Symantically, this method forces to flush all unsaved buffers for
+        specified file. In native implementation this turns to be no-op.
+
+        In stub implementation "close" causes compilation of blob object an
+        navigating to blob-schema url.
+
+        Removed "canAppend", as appending in now suppurted
+        by all implementations.
+
+        Repaced schema "data" with "blob" in InspectorFrontendHostStub "save"
+        to avoid out-of-memory errors.
+
+        * inspector/InspectorFrontendHost.cpp:
+        (WebCore::InspectorFrontendHost::close): Compiles blob object and
+        navigates to blob-object url.
+        (WebCore):
+        * inspector/InspectorFrontendHost.h: Added "close" method.
+        * inspector/InspectorFrontendHost.idl: Ditto.
+        * inspector/front-end/FileManager.js:
+        (WebInspector.FileManager.prototype.close): Proxy to InspectorFrontend.
+        * inspector/front-end/FileUtils.js:
+        (WebInspector.FileOutputStream.prototype.close):
+        Invoke "close" on FileManager.
+        (WebInspector.FileOutputStream.prototype._onAppendDone): Ditto.
+        * inspector/front-end/HandlerRegistry.js: Added mandatory "close" call.
+        * inspector/front-end/HeapSnapshotView.js:
+        (WebInspector.HeapProfileHeader.prototype.canSaveToFile): Fixed check.
+        * inspector/front-end/InspectorFrontendHostStub.js:
+        (.WebInspector.InspectorFrontendHostStub):
+        Added "appendable" behaviour emulation.
+        * inspector/front-end/SourceFrame.js: Added mandatory "close" call.
+        * inspector/front-end/externs.js: Replaced "canAppend" with "close"
+
 2012-10-18  Dominic Mazzoni  <dmazzoni@google.com>
 
         AX: labelForElement is slow when there are a lot of DOM elements
index e7b0220..895ab03 100644 (file)
@@ -250,6 +250,10 @@ void InspectorFrontendHost::append(const String& url, const String& content)
         m_client->append(url, content);
 }
 
+void InspectorFrontendHost::close(const String&)
+{
+}
+
 bool InspectorFrontendHost::canInspectWorkers()
 {
 #if ENABLE(WORKERS)
index d5ae51d..93eb427 100644 (file)
@@ -77,6 +77,7 @@ public:
     bool canSave();
     void save(const String& url, const String& content, bool forceSaveAs);
     void append(const String& url, const String& content);
+    void close(const String& url);
 
     bool canInspectWorkers();
 
index 8ddc9a6..0edd069 100644 (file)
@@ -54,6 +54,7 @@
     boolean canSave();
     void save(in DOMString url, in DOMString content, in boolean forceSaveAs);
     void append(in DOMString url, in DOMString content);
+    void close(in DOMString url);
 
     boolean canInspectWorkers();
 
index 6b108d3..bb88734 100644 (file)
@@ -51,14 +51,6 @@ WebInspector.FileManager.prototype = {
     },
 
     /**
-     * @return {boolean}
-     */
-    canAppend: function()
-    {
-        return InspectorFrontendHost.canSave() && ("append" in InspectorFrontendHost);
-    },
-
-    /**
      * @param {string} url
      * @param {string} content
      * @param {boolean} forceSaveAs
@@ -105,6 +97,14 @@ WebInspector.FileManager.prototype = {
     /**
      * @param {string} url
      */
+    close: function(url)
+    {
+        InspectorFrontendHost.close(url);
+    },
+
+    /**
+     * @param {string} url
+     */
     appendedToURL: function(url)
     {
         this.dispatchEventToListeners(WebInspector.FileManager.EventTypes.AppendedToURL, url);
index 7e95bdf..d6a1dec 100644 (file)
@@ -385,6 +385,7 @@ WebInspector.FileOutputStream.prototype = {
         if (this._writeCallbacks.length)
             return;
         WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._onAppendDone, this);
+        WebInspector.fileManager.close(this._fileName);
     },
 
     /**
@@ -395,8 +396,10 @@ WebInspector.FileOutputStream.prototype = {
         if (event.data !== this._fileName)
             return;
         if (!this._writeCallbacks.length) {
-            if (this._closed)
+            if (this._closed) {
                 WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._onAppendDone, this);
+                WebInspector.fileManager.close(this._fileName);
+            }
             return;
         }
         var callback = this._writeCallbacks.shift();
index 379eb43..99d1bbf 100644 (file)
@@ -132,7 +132,9 @@ WebInspector.HandlerRegistry.prototype = {
 
         function doSave(forceSaveAs, content)
         {
-            WebInspector.fileManager.save(contentProvider.contentURL(), content, forceSaveAs);
+            var url = contentProvider.contentURL();
+            WebInspector.fileManager.save(url, content, forceSaveAs);
+            WebInspector.fileManager.close(url);
         }
 
         function save(forceSaveAs)
index a094b45..ccd3630 100644 (file)
@@ -953,7 +953,7 @@ WebInspector.HeapProfileHeader.prototype = {
      */
     canSaveToFile: function()
     {
-        return !this.fromFile() && this._snapshotProxy && !this._receiver && WebInspector.fileManager.canAppend();
+        return !this.fromFile() && !!this._snapshotProxy && !this._receiver;
     },
 
     /**
index ce3a30a..30494f2 100644 (file)
@@ -38,6 +38,7 @@ WebInspector.InspectorFrontendHostStub = function()
 {
     this._attachedWindowHeight = 0;
     this.isStub = true;
+    this._fileBuffers = {};
     WebInspector.documentCopyEventFired = this.documentCopy.bind(this);
 }
 
@@ -143,23 +144,43 @@ WebInspector.InspectorFrontendHostStub.prototype = {
 
     save: function(url, content, forceSaveAs)
     {
-        var blob = new Blob([content], { type: "application/octet-stream" });
+        if (this._fileBuffers[url])
+            throw new Error("Concurrent file modification denied.");
 
-        var fr = new FileReader();
-        fr.onload = function(e) {
-            // Force download
-            window.location = this.result;
-        }
-        fr.readAsDataURL(blob);
+        this._fileBuffers[url] = [content];
+        setTimeout(WebInspector.fileManager.savedURL.bind(WebInspector.fileManager, url), 0);
     },
 
-    canAppend: function()
+    append: function(url, content)
     {
-        return false;
+        var buffer = this._fileBuffers[url];
+        if (!buffer)
+            throw new Error("File is not open for write yet.");
+
+        buffer.push(content);
+        setTimeout(WebInspector.fileManager.appendedToURL.bind(WebInspector.fileManager, url), 0);
     },
 
-    append: function(url, content)
+    close: function(url)
     {
+        var content = this._fileBuffers[url];
+        delete this._fileBuffers[url];
+
+        if (!content)
+            return;
+
+        var lastSlashIndex = url.lastIndexOf("/");
+        var fileNameSuffix = (lastSlashIndex === -1) ? url : url.substring(lastSlashIndex + 1);
+
+        var blob = new Blob(content, { type: "application/octet-stream" });
+        var objectUrl = window.URL.createObjectURL(blob);
+        window.location = objectUrl + "#" + fileNameSuffix;
+
+        function cleanup()
+        {
+            window.URL.revokeObjectURL(objectUrl);
+        }
+        setTimeout(cleanup, 0);
     },
 
     sendMessageToBackend: function(message)
index 9bfd340..8613dff 100644 (file)
@@ -192,8 +192,10 @@ WebInspector.UISourceCode.prototype = {
         delete this._workingCopy;
         this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyCommitted, {oldWorkingCopy: oldWorkingCopy, workingCopy: this.workingCopy()});
         WebInspector.workspace.dispatchEventToListeners(WebInspector.Workspace.Events.UISourceCodeContentCommitted, { uiSourceCode: this, content: this._content });
-        if (this._url && WebInspector.fileManager.isURLSaved(this._url))
+        if (this._url && WebInspector.fileManager.isURLSaved(this._url)) {
             WebInspector.fileManager.save(this._url, this._content, false);
+            WebInspector.fileManager.close(this._url);
+        }
     },
 
     /**
index ba5bbc9..ab3e5ee 100644 (file)
@@ -138,7 +138,7 @@ InspectorFrontendHostAPI.prototype.copyText = function(text) {}
 InspectorFrontendHostAPI.prototype.openInNewTab = function(url) {}
 InspectorFrontendHostAPI.prototype.canSave = function() {}
 InspectorFrontendHostAPI.prototype.save = function(url, content, forceSaveAs) {}
-InspectorFrontendHostAPI.prototype.canAppend = function() {}
+InspectorFrontendHostAPI.prototype.close = function(url) {}
 InspectorFrontendHostAPI.prototype.append = function(url, content) {}
 InspectorFrontendHostAPI.prototype.sendMessageToBackend = function(message) {}
 InspectorFrontendHostAPI.prototype.recordActionTaken = function(actionCode) {}