Changeset 140157 in webkit


Ignore:
Timestamp:
Jan 18, 2013 8:49:41 AM (11 years ago)
Author:
aandrey@chromium.org
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):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r140154 r140157  
     12013-01-18  Andrey Adaikin  <aandrey@chromium.org>
     2
     3        Web Inspector: [Canvas] add getResourceInfo and getResourceState methods to the protocol
     4        https://bugs.webkit.org/show_bug.cgi?id=107280
     5
     6        Reviewed by Pavel Feldman.
     7
     8        We need to expose replayable resource info and replay state via the protocol.
     9        The ResourceInfo describes a replayable resource, i.e. the info about a resource that was stored to replay it later.
     10        The ResourceState describes a current state of a resource being replayed on the back-end.
     11
     12        * inspector/CodeGeneratorInspector.py:
     13        * inspector/InjectedScriptCanvasModule.cpp:
     14        (WebCore::InjectedScriptCanvasModule::replayTraceLog):
     15        (WebCore):
     16        (WebCore::InjectedScriptCanvasModule::resourceInfo):
     17        (WebCore::InjectedScriptCanvasModule::resourceState):
     18        * inspector/InjectedScriptCanvasModule.h:
     19        (InjectedScriptCanvasModule):
     20        * inspector/InjectedScriptCanvasModuleSource.js:
     21        (.):
     22        * inspector/Inspector.json:
     23        * inspector/InspectorCanvasAgent.cpp:
     24        (WebCore::InspectorCanvasAgent::replayTraceLog):
     25        (WebCore):
     26        (WebCore::InspectorCanvasAgent::getResourceInfo):
     27        (WebCore::InspectorCanvasAgent::getResourceState):
     28        * inspector/InspectorCanvasAgent.h:
     29        (InspectorCanvasAgent):
     30        * inspector/front-end/CanvasProfileView.js:
     31        (WebInspector.CanvasProfileView.prototype._replayTraceLog.didReplayTraceLog):
     32        (WebInspector.CanvasProfileView.prototype._replayTraceLog):
     33
    1342013-01-18  Sergio Villar Senin  <svillar@igalia.com>
    235
  • trunk/Source/WebCore/inspector/CodeGeneratorInspector.py

    r136431 r140157  
    5858
    5959TYPES_WITH_RUNTIME_CAST_SET = frozenset(["Runtime.RemoteObject", "Runtime.PropertyDescriptor", "Runtime.InternalPropertyDescriptor",
    60                                          "Debugger.FunctionDetails", "Debugger.CallFrame", "Canvas.TraceLog",
     60                                         "Debugger.FunctionDetails", "Debugger.CallFrame",
     61                                         "Canvas.TraceLog", "Canvas.ResourceInfo", "Canvas.ResourceState",
    6162                                         # This should be a temporary hack. TimelineEvent should be created via generated C++ API.
    6263                                         "Timeline.TimelineEvent"])
  • trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.cpp

    r135591 r140157  
    141141}
    142142
    143 void InjectedScriptCanvasModule::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, String* result)
     143void InjectedScriptCanvasModule::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, RefPtr<TypeBuilder::Canvas::ResourceState>* result)
    144144{
    145145    ScriptFunctionCall function(injectedScriptObject(), "replayTraceLog");
     
    148148    RefPtr<InspectorValue> resultValue;
    149149    makeCall(function, &resultValue);
    150     if (!resultValue || resultValue->type() != InspectorValue::TypeString || !resultValue->asString(result))
    151         *errorString = "Internal error: replayTraceLog";
     150    if (!resultValue || resultValue->type() != InspectorValue::TypeObject) {
     151        if (!resultValue->asString(errorString))
     152            *errorString = "Internal error: replayTraceLog";
     153        return;
     154    }
     155    *result = TypeBuilder::Canvas::ResourceState::runtimeCast(resultValue);
     156}
     157
     158void InjectedScriptCanvasModule::resourceInfo(ErrorString* errorString, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceInfo>* result)
     159{
     160    ScriptFunctionCall function(injectedScriptObject(), "resourceInfo");
     161    function.appendArgument(resourceId);
     162    RefPtr<InspectorValue> resultValue;
     163    makeCall(function, &resultValue);
     164    if (!resultValue || resultValue->type() != InspectorValue::TypeObject) {
     165        if (!resultValue->asString(errorString))
     166            *errorString = "Internal error: resourceInfo";
     167        return;
     168    }
     169    *result = TypeBuilder::Canvas::ResourceInfo::runtimeCast(resultValue);
     170}
     171
     172void InjectedScriptCanvasModule::resourceState(ErrorString* errorString, const String& traceLogId, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceState>* result)
     173{
     174    ScriptFunctionCall function(injectedScriptObject(), "resourceState");
     175    function.appendArgument(traceLogId);
     176    function.appendArgument(resourceId);
     177    RefPtr<InspectorValue> resultValue;
     178    makeCall(function, &resultValue);
     179    if (!resultValue || resultValue->type() != InspectorValue::TypeObject) {
     180        if (!resultValue->asString(errorString))
     181            *errorString = "Internal error: resourceState";
     182        return;
     183    }
     184    *result = TypeBuilder::Canvas::ResourceState::runtimeCast(resultValue);
    152185}
    153186
  • trunk/Source/WebCore/inspector/InjectedScriptCanvasModule.h

    r135591 r140157  
    6161    void dropTraceLog(ErrorString*, const String&);
    6262    void traceLog(ErrorString*, const String&, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>*);
    63     void replayTraceLog(ErrorString*, const String&, int, String*);
     63    void replayTraceLog(ErrorString*, const String&, int, RefPtr<TypeBuilder::Canvas::ResourceState>*);
     64    void resourceInfo(ErrorString*, const String&, RefPtr<TypeBuilder::Canvas::ResourceInfo>*);
     65    void resourceState(ErrorString*, const String&, const String&, RefPtr<TypeBuilder::Canvas::ResourceState>*);
    6466
    6567private:
  • trunk/Source/WebCore/inspector/InjectedScriptCanvasModuleSource.js

    r140142 r140157  
    742742    toDataURL: function()
    743743    {
    744         var contextResource = this.contextResource();
    745         return contextResource === this ? "" : contextResource.toDataURL();
     744        return "";
    746745    },
    747746
     
    26082607
    26092608    /**
     2609     * @param {number} id
     2610     * @return {ReplayableResource}
     2611     */
     2612    replayableResource: function(id)
     2613    {
     2614        return /** @type {ReplayableResource} */ (this._replayablesCache.get(id));
     2615    },
     2616
     2617    /**
    26102618     * @param {!Resource} resource
    26112619     */
     
    26452653    {
    26462654        return this._traceLog;
     2655    },
     2656
     2657    /**
     2658     * @param {number} id
     2659     * @return {Resource}
     2660     */
     2661    replayWorldResource: function(id)
     2662    {
     2663        return /** @type {Resource} */ (this._replayWorldCache.get(id));
    26472664    },
    26482665
     
    28982915     * @param {string} id
    28992916     * @param {number=} startOffset
    2900      * @return {Object|string}
     2917     * @return {!Object|string}
    29012918     */
    29022919    traceLog: function(id, startOffset)
     
    29042921        var traceLog = this._traceLogs[id];
    29052922        if (!traceLog)
    2906             return "Error: Trace log with this ID not found.";
     2923            return "Error: Trace log with the given ID not found.";
    29072924        startOffset = Math.max(0, startOffset || 0);
    29082925        var alive = this._manager.capturing() && this._manager.lastTraceLog() === traceLog;
     
    29202937            var callFrame = stackTrace ? stackTrace.callFrame(0) || {} : {};
    29212938            var traceLogItem = {
    2922                 contextId: this._makeContextId(contextResource.id()),
     2939                contextId: this._makeStringResourceId(contextResource.id()),
    29232940                sourceURL: callFrame.sourceURL,
    29242941                lineNumber: callFrame.lineNumber,
     
    29532970
    29542971    /**
    2955      * @param {string} id
     2972     * @param {string} traceLogId
    29562973     * @param {number} stepNo
    2957      * @return {string}
    2958      */
    2959     replayTraceLog: function(id, stepNo)
    2960     {
    2961         var traceLog = this._traceLogs[id];
     2974     * @return {!Object|string}
     2975     */
     2976    replayTraceLog: function(traceLogId, stepNo)
     2977    {
     2978        var traceLog = this._traceLogs[traceLogId];
    29622979        if (!traceLog)
    2963             return "";
    2964         this._traceLogPlayers[id] = this._traceLogPlayers[id] || new TraceLogPlayer(traceLog);
    2965         var lastCall = this._traceLogPlayers[id].stepTo(stepNo);
    2966         return lastCall.resource().toDataURL();
     2980            return "Error: Trace log with the given ID not found.";
     2981        this._traceLogPlayers[traceLogId] = this._traceLogPlayers[traceLogId] || new TraceLogPlayer(traceLog);
     2982        var lastCall = this._traceLogPlayers[traceLogId].stepTo(stepNo);
     2983        var resource = lastCall.resource();
     2984        var dataURL = resource.toDataURL();
     2985        if (!dataURL) {
     2986            resource = resource.contextResource();
     2987            dataURL = resource.toDataURL();
     2988        }
     2989        return this._makeResourceState(this._makeStringResourceId(resource.id()), traceLogId, dataURL);
     2990    },
     2991
     2992    /**
     2993     * @param {string} stringResourceId
     2994     * @return {!Object|string}
     2995     */
     2996    resourceInfo: function(stringResourceId)
     2997    {
     2998        var resourceId = this._parseStringId(stringResourceId).resourceId;
     2999        if (!resourceId)
     3000            return "Error: Wrong resource ID: " + stringResourceId;
     3001
     3002        var replayableResource = null;
     3003        for (var id in this._traceLogs) {
     3004            replayableResource = this._traceLogs[id].replayableResource(resourceId);
     3005            if (replayableResource)
     3006                break;
     3007        }
     3008        if (!replayableResource)
     3009            return "Error: Resource with the given ID not found.";
     3010
     3011        return this._makeResourceInfo(stringResourceId, replayableResource.description());
     3012    },
     3013
     3014    /**
     3015     * @param {string} traceLogId
     3016     * @param {string} stringResourceId
     3017     * @return {!Object|string}
     3018     */
     3019    resourceState: function(traceLogId, stringResourceId)
     3020    {
     3021        var traceLog = this._traceLogs[traceLogId];
     3022        if (!traceLog)
     3023            return "Error: Trace log with the given ID not found.";
     3024
     3025        var traceLogPlayer = this._traceLogPlayers[traceLogId];
     3026        if (!traceLogPlayer)
     3027            return "Error: Trace log replay has not started yet.";
     3028
     3029        var parsedStringId1 = this._parseStringId(traceLogId);
     3030        var parsedStringId2 = this._parseStringId(stringResourceId);
     3031        if (parsedStringId1.injectedScriptId !== parsedStringId2.injectedScriptId)
     3032            return "Error: Both IDs must point to the same injected script.";
     3033
     3034        var resourceId = parsedStringId2.resourceId;
     3035        if (!resourceId)
     3036            return "Error: Wrong resource ID: " + stringResourceId;
     3037
     3038        var resource = traceLogPlayer.replayWorldResource(resourceId);
     3039        if (!resource)
     3040            return "Error: Resource with the given ID has not been replayed yet.";
     3041
     3042        return this._makeResourceState(stringResourceId, traceLogId, resource.toDataURL());
    29673043    },
    29683044
     
    29793055     * @return {string}
    29803056     */
    2981     _makeContextId: function(resourceId)
    2982     {
    2983         return "{\"injectedScriptId\":" + injectedScriptId + ",\"canvasContextId\":" + resourceId + "}";
     3057    _makeStringResourceId: function(resourceId)
     3058    {
     3059        return "{\"injectedScriptId\":" + injectedScriptId + ",\"resourceId\":" + resourceId + "}";
     3060    },
     3061
     3062    /**
     3063     * @param {string} stringResourceId
     3064     * @param {string} description
     3065     * @return {!Object}
     3066     */
     3067    _makeResourceInfo: function(stringResourceId, description)
     3068    {
     3069        return {
     3070            id: stringResourceId,
     3071            description: description
     3072        };
     3073    },
     3074
     3075    /**
     3076     * @param {string} stringResourceId
     3077     * @param {string} traceLogId
     3078     * @param {string} imageURL
     3079     * @return {!Object}
     3080     */
     3081    _makeResourceState: function(stringResourceId, traceLogId, imageURL)
     3082    {
     3083        return {
     3084            id: stringResourceId,
     3085            traceLogId: traceLogId,
     3086            imageURL: imageURL
     3087        };
     3088    },
     3089
     3090    /**
     3091     * @param {string} stringId
     3092     * @return {{injectedScriptId: number, traceLogId: ?number, resourceId: ?number}}
     3093     */
     3094    _parseStringId: function(stringId)
     3095    {
     3096        return InjectedScriptHost.evaluate("(" + stringId + ")");
    29843097    }
    29853098}
  • trunk/Source/WebCore/inspector/Inspector.json

    r139998 r140157  
    31953195        "types": [
    31963196            {
    3197                 "id": "ContextId",
     3197                "id": "ResourceId",
    31983198                "type": "string",
    3199                 "description": "Unique context identifier."
     3199                "description": "Unique resource identifier."
     3200            },
     3201            {
     3202                "id": "ResourceInfo",
     3203                "type": "object",
     3204                "properties": [
     3205                    { "name": "id", "$ref": "ResourceId" },
     3206                    { "name": "description", "type": "string" }
     3207                ]
     3208            },
     3209            {
     3210                "id": "ResourceState",
     3211                "type": "object",
     3212                "properties": [
     3213                    { "name": "id", "$ref": "ResourceId" },
     3214                    { "name": "traceLogId", "$ref": "TraceLogId" },
     3215                    { "name": "imageURL", "type": "string", "optional": true, "description": "Screenshot image data URL." }
     3216                ]
    32003217            },
    32013218            {
     
    32103227                "type": "object",
    32113228                "properties": [
    3212                     { "name": "contextId", "$ref": "ContextId" },
     3229                    { "name": "contextId", "$ref": "ResourceId" },
    32133230                    { "name": "functionName", "type": "string", "optional": true },
    32143231                    { "name": "arguments", "type": "array", "items": { "$ref": "CallArgument" }, "optional": true },
     
    32943311                ],
    32953312                "returns": [
    3296                     { "name": "screenshotDataUrl", "type": "string" }
     3313                    { "name": "resourceState", "$ref": "ResourceState" }
     3314                ]
     3315            },
     3316            {
     3317                "name": "getResourceInfo",
     3318                "parameters": [
     3319                    { "name": "resourceId", "$ref": "ResourceId" }
     3320                ],
     3321                "returns": [
     3322                    { "name": "resourceInfo", "$ref": "ResourceInfo" }
     3323                ]
     3324            },
     3325            {
     3326                "name": "getResourceState",
     3327                "parameters": [
     3328                    { "name": "traceLogId", "$ref": "TraceLogId" },
     3329                    { "name": "resourceId", "$ref": "ResourceId" }
     3330                ],
     3331                "returns": [
     3332                    { "name": "resourceState", "$ref": "ResourceState" }
    32973333                ]
    32983334            }
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp

    r138497 r140157  
    165165}
    166166
    167 void InspectorCanvasAgent::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, String* result)
    168 {
    169     if (!checkIsEnabled(errorString))
    170         return;
    171     InjectedScriptCanvasModule module = injectedScriptCanvasModuleForTraceLogId(errorString, traceLogId);
    172     if (!module.hasNoValue())
    173         module.replayTraceLog(errorString, traceLogId, stepNo, result);
     167void InspectorCanvasAgent::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, RefPtr<TypeBuilder::Canvas::ResourceState>& result)
     168{
     169    if (!checkIsEnabled(errorString))
     170        return;
     171    InjectedScriptCanvasModule module = injectedScriptCanvasModuleForTraceLogId(errorString, traceLogId);
     172    if (!module.hasNoValue())
     173        module.replayTraceLog(errorString, traceLogId, stepNo, &result);
     174}
     175
     176void InspectorCanvasAgent::getResourceInfo(ErrorString* errorString, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceInfo>& result)
     177{
     178    if (!checkIsEnabled(errorString))
     179        return;
     180    InjectedScriptCanvasModule module = injectedScriptCanvasModuleForTraceLogId(errorString, resourceId);
     181    if (!module.hasNoValue())
     182        module.resourceInfo(errorString, resourceId, &result);
     183}
     184
     185void InspectorCanvasAgent::getResourceState(ErrorString* errorString, const String& traceLogId, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceState>& result)
     186{
     187    if (!checkIsEnabled(errorString))
     188        return;
     189    InjectedScriptCanvasModule module = injectedScriptCanvasModuleForTraceLogId(errorString, traceLogId);
     190    if (!module.hasNoValue())
     191        module.resourceState(errorString, traceLogId, resourceId, &result);
    174192}
    175193
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.h

    r138497 r140157  
    8585    virtual void stopCapturing(ErrorString*, const String&);
    8686    virtual void getTraceLog(ErrorString*, const String&, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>&);
    87     virtual void replayTraceLog(ErrorString*, const String&, int, String*);
     87    virtual void replayTraceLog(ErrorString*, const String&, int, RefPtr<TypeBuilder::Canvas::ResourceState>&);
     88    virtual void getResourceInfo(ErrorString*, const String&, RefPtr<TypeBuilder::Canvas::ResourceInfo>&);
     89    virtual void getResourceState(ErrorString*, const String&, const String&, RefPtr<TypeBuilder::Canvas::ResourceState>&);
    8890
    8991private:
  • trunk/Source/WebCore/inspector/front-end/CanvasProfileView.js

    r139729 r140157  
    184184            return;
    185185        var time = Date.now();
    186         function didReplayTraceLog(error, dataURL)
     186        function didReplayTraceLog(error, resourceState)
    187187        {
    188188            if (callNode !== this._logGrid.selectedNode)
     
    192192                return;
    193193            this._debugInfoElement.textContent = "Replay time: " + (Date.now() - time) + "ms";
    194             this._replayImageElement.src = dataURL;
     194            this._replayImageElement.src = resourceState.imageURL;
    195195        }
    196196        this._enableWaitIcon(true);
Note: See TracChangeset for help on using the changeset viewer.