Title: [140157] trunk/Source/WebCore
Revision
140157
Author
aand...@chromium.org
Date
2013-01-18 08:49:41 -0800 (Fri, 18 Jan 2013)

Log Message

Web Inspector: [Canvas] add getResourceInfo and getResourceState methods to the protocol
https://bugs.webkit.org/show_bug.cgi?id=107280

Reviewed by Pavel Feldman.

We need to expose replayable resource info and replay state via the protocol.
The ResourceInfo describes a replayable resource, i.e. the info about a resource that was stored to replay it later.
The ResourceState describes a current state of a resource being replayed on the back-end.

* inspector/CodeGeneratorInspector.py:
* inspector/InjectedScriptCanvasModule.cpp:
(WebCore::InjectedScriptCanvasModule::replayTraceLog):
(WebCore):
(WebCore::InjectedScriptCanvasModule::resourceInfo):
(WebCore::InjectedScriptCanvasModule::resourceState):
* inspector/InjectedScriptCanvasModule.h:
(InjectedScriptCanvasModule):
* inspector/InjectedScriptCanvasModuleSource.js:
(.):
* inspector/Inspector.json:
* inspector/InspectorCanvasAgent.cpp:
(WebCore::InspectorCanvasAgent::replayTraceLog):
(WebCore):
(WebCore::InspectorCanvasAgent::getResourceInfo):
(WebCore::InspectorCanvasAgent::getResourceState):
* inspector/InspectorCanvasAgent.h:
(InspectorCanvasAgent):
* inspector/front-end/CanvasProfileView.js:
(WebInspector.CanvasProfileView.prototype._replayTraceLog.didReplayTraceLog):
(WebInspector.CanvasProfileView.prototype._replayTraceLog):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (140156 => 140157)


--- trunk/Source/WebCore/ChangeLog	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/ChangeLog	2013-01-18 16:49:41 UTC (rev 140157)
@@ -1,3 +1,36 @@
+2013-01-18  Andrey Adaikin  <aand...@chromium.org>
+
+        Web Inspector: [Canvas] add getResourceInfo and getResourceState methods to the protocol
+        https://bugs.webkit.org/show_bug.cgi?id=107280
+
+        Reviewed by Pavel Feldman.
+
+        We need to expose replayable resource info and replay state via the protocol.
+        The ResourceInfo describes a replayable resource, i.e. the info about a resource that was stored to replay it later.
+        The ResourceState describes a current state of a resource being replayed on the back-end.
+
+        * inspector/CodeGeneratorInspector.py:
+        * inspector/InjectedScriptCanvasModule.cpp:
+        (WebCore::InjectedScriptCanvasModule::replayTraceLog):
+        (WebCore):
+        (WebCore::InjectedScriptCanvasModule::resourceInfo):
+        (WebCore::InjectedScriptCanvasModule::resourceState):
+        * inspector/InjectedScriptCanvasModule.h:
+        (InjectedScriptCanvasModule):
+        * inspector/InjectedScriptCanvasModuleSource.js:
+        (.):
+        * inspector/Inspector.json:
+        * inspector/InspectorCanvasAgent.cpp:
+        (WebCore::InspectorCanvasAgent::replayTraceLog):
+        (WebCore):
+        (WebCore::InspectorCanvasAgent::getResourceInfo):
+        (WebCore::InspectorCanvasAgent::getResourceState):
+        * inspector/InspectorCanvasAgent.h:
+        (InspectorCanvasAgent):
+        * inspector/front-end/CanvasProfileView.js:
+        (WebInspector.CanvasProfileView.prototype._replayTraceLog.didReplayTraceLog):
+        (WebInspector.CanvasProfileView.prototype._replayTraceLog):
+
 2013-01-18  Sergio Villar Senin  <svil...@igalia.com>
 
         [Soup] Frequent crashes on redirections

Modified: trunk/Source/WebCore/inspector/CodeGeneratorInspector.py (140156 => 140157)


--- trunk/Source/WebCore/inspector/CodeGeneratorInspector.py	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/CodeGeneratorInspector.py	2013-01-18 16:49:41 UTC (rev 140157)
@@ -57,7 +57,8 @@
 
 
 TYPES_WITH_RUNTIME_CAST_SET = frozenset(["Runtime.RemoteObject", "Runtime.PropertyDescriptor", "Runtime.InternalPropertyDescriptor",
-                                         "Debugger.FunctionDetails", "Debugger.CallFrame", "Canvas.TraceLog",
+                                         "Debugger.FunctionDetails", "Debugger.CallFrame",
+                                         "Canvas.TraceLog", "Canvas.ResourceInfo", "Canvas.ResourceState",
                                          # This should be a temporary hack. TimelineEvent should be created via generated C++ API.
                                          "Timeline.TimelineEvent"])
 

Modified: trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.cpp (140156 => 140157)


--- trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.cpp	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.cpp	2013-01-18 16:49:41 UTC (rev 140157)
@@ -140,17 +140,50 @@
     *traceLog = TypeBuilder::Canvas::TraceLog::runtimeCast(resultValue);
 }
 
-void InjectedScriptCanvasModule::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, String* result)
+void InjectedScriptCanvasModule::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, RefPtr<TypeBuilder::Canvas::ResourceState>* result)
 {
     ScriptFunctionCall function(injectedScriptObject(), "replayTraceLog");
     function.appendArgument(traceLogId);
     function.appendArgument(stepNo);
     RefPtr<InspectorValue> resultValue;
     makeCall(function, &resultValue);
-    if (!resultValue || resultValue->type() != InspectorValue::TypeString || !resultValue->asString(result))
-        *errorString = "Internal error: replayTraceLog";
+    if (!resultValue || resultValue->type() != InspectorValue::TypeObject) {
+        if (!resultValue->asString(errorString))
+            *errorString = "Internal error: replayTraceLog";
+        return;
+    }
+    *result = TypeBuilder::Canvas::ResourceState::runtimeCast(resultValue);
 }
 
+void InjectedScriptCanvasModule::resourceInfo(ErrorString* errorString, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceInfo>* result)
+{
+    ScriptFunctionCall function(injectedScriptObject(), "resourceInfo");
+    function.appendArgument(resourceId);
+    RefPtr<InspectorValue> resultValue;
+    makeCall(function, &resultValue);
+    if (!resultValue || resultValue->type() != InspectorValue::TypeObject) {
+        if (!resultValue->asString(errorString))
+            *errorString = "Internal error: resourceInfo";
+        return;
+    }
+    *result = TypeBuilder::Canvas::ResourceInfo::runtimeCast(resultValue);
+}
+
+void InjectedScriptCanvasModule::resourceState(ErrorString* errorString, const String& traceLogId, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceState>* result)
+{
+    ScriptFunctionCall function(injectedScriptObject(), "resourceState");
+    function.appendArgument(traceLogId);
+    function.appendArgument(resourceId);
+    RefPtr<InspectorValue> resultValue;
+    makeCall(function, &resultValue);
+    if (!resultValue || resultValue->type() != InspectorValue::TypeObject) {
+        if (!resultValue->asString(errorString))
+            *errorString = "Internal error: resourceState";
+        return;
+    }
+    *result = TypeBuilder::Canvas::ResourceState::runtimeCast(resultValue);
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(INSPECTOR)

Modified: trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.h (140156 => 140157)


--- trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.h	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.h	2013-01-18 16:49:41 UTC (rev 140157)
@@ -60,7 +60,9 @@
     void stopCapturing(ErrorString*, const String&);
     void dropTraceLog(ErrorString*, const String&);
     void traceLog(ErrorString*, const String&, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>*);
-    void replayTraceLog(ErrorString*, const String&, int, String*);
+    void replayTraceLog(ErrorString*, const String&, int, RefPtr<TypeBuilder::Canvas::ResourceState>*);
+    void resourceInfo(ErrorString*, const String&, RefPtr<TypeBuilder::Canvas::ResourceInfo>*);
+    void resourceState(ErrorString*, const String&, const String&, RefPtr<TypeBuilder::Canvas::ResourceState>*);
 
 private:
     ScriptObject callWrapContextFunction(const String&, const ScriptObject&);

Modified: trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js (140156 => 140157)


--- trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js	2013-01-18 16:49:41 UTC (rev 140157)
@@ -741,8 +741,7 @@
      */
     toDataURL: function()
     {
-        var contextResource = this.contextResource();
-        return contextResource === this ? "" : contextResource.toDataURL();
+        return "";
     },
 
     /**
@@ -2607,6 +2606,15 @@
     },
 
     /**
+     * @param {number} id
+     * @return {ReplayableResource}
+     */
+    replayableResource: function(id)
+    {
+        return /** @type {ReplayableResource} */ (this._replayablesCache.get(id));
+    },
+
+    /**
      * @param {!Resource} resource
      */
     captureResource: function(resource)
@@ -2647,6 +2655,15 @@
     },
 
     /**
+     * @param {number} id
+     * @return {Resource}
+     */
+    replayWorldResource: function(id)
+    {
+        return /** @type {Resource} */ (this._replayWorldCache.get(id));
+    },
+
+    /**
      * @return {number}
      */
     nextReplayStep: function()
@@ -2897,13 +2914,13 @@
     /**
      * @param {string} id
      * @param {number=} startOffset
-     * @return {Object|string}
+     * @return {!Object|string}
      */
     traceLog: function(id, startOffset)
     {
         var traceLog = this._traceLogs[id];
         if (!traceLog)
-            return "Error: Trace log with this ID not found.";
+            return "Error: Trace log with the given ID not found.";
         startOffset = Math.max(0, startOffset || 0);
         var alive = this._manager.capturing() && this._manager.lastTraceLog() === traceLog;
         var result = {
@@ -2919,7 +2936,7 @@
             var stackTrace = call.stackTrace();
             var callFrame = stackTrace ? stackTrace.callFrame(0) || {} : {};
             var traceLogItem = {
-                contextId: this._makeContextId(contextResource.id()),
+                contextId: this._makeStringResourceId(contextResource.id()),
                 sourceURL: callFrame.sourceURL,
                 lineNumber: callFrame.lineNumber,
                 columnNumber: callFrame.columnNumber
@@ -2952,21 +2969,80 @@
     },
 
     /**
-     * @param {string} id
+     * @param {string} traceLogId
      * @param {number} stepNo
-     * @return {string}
+     * @return {!Object|string}
      */
-    replayTraceLog: function(id, stepNo)
+    replayTraceLog: function(traceLogId, stepNo)
     {
-        var traceLog = this._traceLogs[id];
+        var traceLog = this._traceLogs[traceLogId];
         if (!traceLog)
-            return "";
-        this._traceLogPlayers[id] = this._traceLogPlayers[id] || new TraceLogPlayer(traceLog);
-        var lastCall = this._traceLogPlayers[id].stepTo(stepNo);
-        return lastCall.resource().toDataURL();
+            return "Error: Trace log with the given ID not found.";
+        this._traceLogPlayers[traceLogId] = this._traceLogPlayers[traceLogId] || new TraceLogPlayer(traceLog);
+        var lastCall = this._traceLogPlayers[traceLogId].stepTo(stepNo);
+        var resource = lastCall.resource();
+        var dataURL = resource.toDataURL();
+        if (!dataURL) {
+            resource = resource.contextResource();
+            dataURL = resource.toDataURL();
+        }
+        return this._makeResourceState(this._makeStringResourceId(resource.id()), traceLogId, dataURL);
     },
 
     /**
+     * @param {string} stringResourceId
+     * @return {!Object|string}
+     */
+    resourceInfo: function(stringResourceId)
+    {
+        var resourceId = this._parseStringId(stringResourceId).resourceId;
+        if (!resourceId)
+            return "Error: Wrong resource ID: " + stringResourceId;
+
+        var replayableResource = null;
+        for (var id in this._traceLogs) {
+            replayableResource = this._traceLogs[id].replayableResource(resourceId);
+            if (replayableResource)
+                break;
+        }
+        if (!replayableResource)
+            return "Error: Resource with the given ID not found.";
+
+        return this._makeResourceInfo(stringResourceId, replayableResource.description());
+    },
+
+    /**
+     * @param {string} traceLogId
+     * @param {string} stringResourceId
+     * @return {!Object|string}
+     */
+    resourceState: function(traceLogId, stringResourceId)
+    {
+        var traceLog = this._traceLogs[traceLogId];
+        if (!traceLog)
+            return "Error: Trace log with the given ID not found.";
+
+        var traceLogPlayer = this._traceLogPlayers[traceLogId];
+        if (!traceLogPlayer)
+            return "Error: Trace log replay has not started yet.";
+
+        var parsedStringId1 = this._parseStringId(traceLogId);
+        var parsedStringId2 = this._parseStringId(stringResourceId);
+        if (parsedStringId1.injectedScriptId !== parsedStringId2.injectedScriptId)
+            return "Error: Both IDs must point to the same injected script.";
+
+        var resourceId = parsedStringId2.resourceId;
+        if (!resourceId)
+            return "Error: Wrong resource ID: " + stringResourceId;
+
+        var resource = traceLogPlayer.replayWorldResource(resourceId);
+        if (!resource)
+            return "Error: Resource with the given ID has not been replayed yet.";
+
+        return this._makeResourceState(stringResourceId, traceLogId, resource.toDataURL());
+    },
+
+    /**
      * @return {string}
      */
     _makeTraceLogId: function()
@@ -2978,9 +3054,46 @@
      * @param {number} resourceId
      * @return {string}
      */
-    _makeContextId: function(resourceId)
+    _makeStringResourceId: function(resourceId)
     {
-        return "{\"injectedScriptId\":" + injectedScriptId + ",\"canvasContextId\":" + resourceId + "}";
+        return "{\"injectedScriptId\":" + injectedScriptId + ",\"resourceId\":" + resourceId + "}";
+    },
+
+    /**
+     * @param {string} stringResourceId
+     * @param {string} description
+     * @return {!Object}
+     */
+    _makeResourceInfo: function(stringResourceId, description)
+    {
+        return {
+            id: stringResourceId,
+            description: description
+        };
+    },
+
+    /**
+     * @param {string} stringResourceId
+     * @param {string} traceLogId
+     * @param {string} imageURL
+     * @return {!Object}
+     */
+    _makeResourceState: function(stringResourceId, traceLogId, imageURL)
+    {
+        return {
+            id: stringResourceId,
+            traceLogId: traceLogId,
+            imageURL: imageURL
+        };
+    },
+
+    /**
+     * @param {string} stringId
+     * @return {{injectedScriptId: number, traceLogId: ?number, resourceId: ?number}}
+     */
+    _parseStringId: function(stringId)
+    {
+        return InjectedScriptHost.evaluate("(" + stringId + ")");
     }
 }
 

Modified: trunk/Source/WebCore/inspector/Inspector.json (140156 => 140157)


--- trunk/Source/WebCore/inspector/Inspector.json	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/Inspector.json	2013-01-18 16:49:41 UTC (rev 140157)
@@ -3194,11 +3194,28 @@
         "hidden": true,
         "types": [
             {
-                "id": "ContextId",
+                "id": "ResourceId",
                 "type": "string",
-                "description": "Unique context identifier."
+                "description": "Unique resource identifier."
             },
             {
+                "id": "ResourceInfo",
+                "type": "object",
+                "properties": [
+                    { "name": "id", "$ref": "ResourceId" },
+                    { "name": "description", "type": "string" }
+                ]
+            },
+            {
+                "id": "ResourceState",
+                "type": "object",
+                "properties": [
+                    { "name": "id", "$ref": "ResourceId" },
+                    { "name": "traceLogId", "$ref": "TraceLogId" },
+                    { "name": "imageURL", "type": "string", "optional": true, "description": "Screenshot image data URL." }
+                ]
+            },
+            {
                 "id": "CallArgument",
                 "type": "object",
                 "properties": [
@@ -3209,7 +3226,7 @@
                 "id": "Call",
                 "type": "object",
                 "properties": [
-                    { "name": "contextId", "$ref": "ContextId" },
+                    { "name": "contextId", "$ref": "ResourceId" },
                     { "name": "functionName", "type": "string", "optional": true },
                     { "name": "arguments", "type": "array", "items": { "$ref": "CallArgument" }, "optional": true },
                     { "name": "result", "$ref": "CallArgument", "optional": true },
@@ -3293,8 +3310,27 @@
                     { "name": "stepNo", "type": "integer" }
                 ],
                 "returns": [
-                    { "name": "screenshotDataUrl", "type": "string" }
+                    { "name": "resourceState", "$ref": "ResourceState" }
                 ]
+            },
+            {
+                "name": "getResourceInfo",
+                "parameters": [
+                    { "name": "resourceId", "$ref": "ResourceId" }
+                ],
+                "returns": [
+                    { "name": "resourceInfo", "$ref": "ResourceInfo" }
+                ]
+            },
+            {
+                "name": "getResourceState",
+                "parameters": [
+                    { "name": "traceLogId", "$ref": "TraceLogId" },
+                    { "name": "resourceId", "$ref": "ResourceId" }
+                ],
+                "returns": [
+                    { "name": "resourceState", "$ref": "ResourceState" }
+                ]
             }
         ],
         "events": []

Modified: trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp (140156 => 140157)


--- trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp	2013-01-18 16:49:41 UTC (rev 140157)
@@ -164,15 +164,33 @@
         module.traceLog(errorString, traceLogId, startOffset, &traceLog);
 }
 
-void InspectorCanvasAgent::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, String* result)
+void InspectorCanvasAgent::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, RefPtr<TypeBuilder::Canvas::ResourceState>& result)
 {
     if (!checkIsEnabled(errorString))
         return;
     InjectedScriptCanvasModule module = injectedScriptCanvasModuleForTraceLogId(errorString, traceLogId);
     if (!module.hasNoValue())
-        module.replayTraceLog(errorString, traceLogId, stepNo, result);
+        module.replayTraceLog(errorString, traceLogId, stepNo, &result);
 }
 
+void InspectorCanvasAgent::getResourceInfo(ErrorString* errorString, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceInfo>& result)
+{
+    if (!checkIsEnabled(errorString))
+        return;
+    InjectedScriptCanvasModule module = injectedScriptCanvasModuleForTraceLogId(errorString, resourceId);
+    if (!module.hasNoValue())
+        module.resourceInfo(errorString, resourceId, &result);
+}
+
+void InspectorCanvasAgent::getResourceState(ErrorString* errorString, const String& traceLogId, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceState>& result)
+{
+    if (!checkIsEnabled(errorString))
+        return;
+    InjectedScriptCanvasModule module = injectedScriptCanvasModuleForTraceLogId(errorString, traceLogId);
+    if (!module.hasNoValue())
+        module.resourceState(errorString, traceLogId, resourceId, &result);
+}
+
 ScriptObject InspectorCanvasAgent::wrapCanvas2DRenderingContextForInstrumentation(const ScriptObject& context)
 {
     if (context.hasNoValue()) {

Modified: trunk/Source/WebCore/inspector/InspectorCanvasAgent.h (140156 => 140157)


--- trunk/Source/WebCore/inspector/InspectorCanvasAgent.h	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/InspectorCanvasAgent.h	2013-01-18 16:49:41 UTC (rev 140157)
@@ -84,7 +84,9 @@
     virtual void startCapturing(ErrorString*, String*);
     virtual void stopCapturing(ErrorString*, const String&);
     virtual void getTraceLog(ErrorString*, const String&, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>&);
-    virtual void replayTraceLog(ErrorString*, const String&, int, String*);
+    virtual void replayTraceLog(ErrorString*, const String&, int, RefPtr<TypeBuilder::Canvas::ResourceState>&);
+    virtual void getResourceInfo(ErrorString*, const String&, RefPtr<TypeBuilder::Canvas::ResourceInfo>&);
+    virtual void getResourceState(ErrorString*, const String&, const String&, RefPtr<TypeBuilder::Canvas::ResourceState>&);
 
 private:
     InspectorCanvasAgent(InstrumentingAgents*, InspectorCompositeState*, Page*, InjectedScriptManager*);

Modified: trunk/Source/WebCore/inspector/front-end/CanvasProfileView.js (140156 => 140157)


--- trunk/Source/WebCore/inspector/front-end/CanvasProfileView.js	2013-01-18 16:46:38 UTC (rev 140156)
+++ trunk/Source/WebCore/inspector/front-end/CanvasProfileView.js	2013-01-18 16:49:41 UTC (rev 140157)
@@ -183,7 +183,7 @@
         if (!callNode)
             return;
         var time = Date.now();
-        function didReplayTraceLog(error, dataURL)
+        function didReplayTraceLog(error, resourceState)
         {
             if (callNode !== this._logGrid.selectedNode)
                 return;
@@ -191,7 +191,7 @@
             if (error)
                 return;
             this._debugInfoElement.textContent = "Replay time: " + (Date.now() - time) + "ms";
-            this._replayImageElement.src = ""
+            this._replayImageElement.src = ""
         }
         this._enableWaitIcon(true);
         CanvasAgent.replayTraceLog(this._traceLogId, callNode.index, didReplayTraceLog.bind(this));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to