Changeset 141098 in webkit


Ignore:
Timestamp:
Jan 29, 2013 4:43:45 AM (11 years ago)
Author:
aandrey@chromium.org
Message:

Web Inspector: [Canvas] support instrumenting canvases in iframes (backend side)
https://bugs.webkit.org/show_bug.cgi?id=107951

Reviewed by Pavel Feldman.

Source/WebCore:

Accept optional FrameId argument for captureFrame and startCapturing commands.
Add event to the protocol to inform about instrumented canvas context creation.

  • inspector/Inspector.json:
  • inspector/InspectorCanvasAgent.cpp:

(WebCore::InspectorCanvasAgent::InspectorCanvasAgent):
(WebCore::InspectorCanvasAgent::hasUninstrumentedCanvases):
(WebCore::InspectorCanvasAgent::captureFrame):
(WebCore::InspectorCanvasAgent::startCapturing):
(WebCore::InspectorCanvasAgent::getTraceLog):
(WebCore::InspectorCanvasAgent::replayTraceLog):
(WebCore::InspectorCanvasAgent::getResourceInfo):
(WebCore::InspectorCanvasAgent::getResourceState):
(WebCore::InspectorCanvasAgent::wrapCanvas2DRenderingContextForInstrumentation):
(WebCore::InspectorCanvasAgent::wrapWebGLRenderingContextForInstrumentation):
(WebCore::InspectorCanvasAgent::notifyRenderingContextWasWrapped):
(WebCore):
(WebCore::InspectorCanvasAgent::findFramesWithUninstrumentedCanvases):
(WebCore::InspectorCanvasAgent::frameNavigated):
(WebCore::InspectorCanvasAgent::frameDetached):

  • inspector/InspectorCanvasAgent.h:

(WebCore):
(WebCore::InspectorCanvasAgent::create):
(InspectorCanvasAgent):

  • inspector/InspectorController.cpp:

(WebCore::InspectorController::InspectorController):

  • inspector/InspectorInstrumentation.cpp:

(WebCore):
(WebCore::InspectorInstrumentation::frameDetachedFromParentImpl):
(WebCore::InspectorInstrumentation::didCommitLoadImpl):

LayoutTests:

Stub Canvas dispatcher for now to silence alerts in tests.

  • inspector/profiler/canvas-profiler-test.js:

(initialize_CanvasWebGLProfilerTest.InspectorTest.enableCanvasAgent.InspectorBackend.registerCanvasDispatcher):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r141094 r141098  
     12013-01-29  Andrey Adaikin  <aandrey@chromium.org>
     2
     3        Web Inspector: [Canvas] support instrumenting canvases in iframes (backend side)
     4        https://bugs.webkit.org/show_bug.cgi?id=107951
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Stub Canvas dispatcher for now to silence alerts in tests.
     9
     10        * inspector/profiler/canvas-profiler-test.js:
     11        (initialize_CanvasWebGLProfilerTest.InspectorTest.enableCanvasAgent.InspectorBackend.registerCanvasDispatcher):
     12
    1132013-01-29  Eugene Klyuchnikov  <eustas@chromium.org>
    214
  • trunk/LayoutTests/inspector/profiler/canvas-profiler-test.js

    r140679 r141098  
    33InspectorTest.enableCanvasAgent = function(callback)
    44{
     5    var dispatcher = InspectorBackend._domainDispatchers["Canvas"];
     6    if (!dispatcher) {
     7        InspectorBackend.registerCanvasDispatcher({
     8            contextCreated: function() {}
     9        });
     10    }
     11
    512    function canvasAgentEnabled(error)
    613    {
  • trunk/Source/WebCore/ChangeLog

    r141094 r141098  
     12013-01-29  Andrey Adaikin  <aandrey@chromium.org>
     2
     3        Web Inspector: [Canvas] support instrumenting canvases in iframes (backend side)
     4        https://bugs.webkit.org/show_bug.cgi?id=107951
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Accept optional FrameId argument for captureFrame and startCapturing commands.
     9        Add event to the protocol to inform about instrumented canvas context creation.
     10
     11        * inspector/Inspector.json:
     12        * inspector/InspectorCanvasAgent.cpp:
     13        (WebCore::InspectorCanvasAgent::InspectorCanvasAgent):
     14        (WebCore::InspectorCanvasAgent::hasUninstrumentedCanvases):
     15        (WebCore::InspectorCanvasAgent::captureFrame):
     16        (WebCore::InspectorCanvasAgent::startCapturing):
     17        (WebCore::InspectorCanvasAgent::getTraceLog):
     18        (WebCore::InspectorCanvasAgent::replayTraceLog):
     19        (WebCore::InspectorCanvasAgent::getResourceInfo):
     20        (WebCore::InspectorCanvasAgent::getResourceState):
     21        (WebCore::InspectorCanvasAgent::wrapCanvas2DRenderingContextForInstrumentation):
     22        (WebCore::InspectorCanvasAgent::wrapWebGLRenderingContextForInstrumentation):
     23        (WebCore::InspectorCanvasAgent::notifyRenderingContextWasWrapped):
     24        (WebCore):
     25        (WebCore::InspectorCanvasAgent::findFramesWithUninstrumentedCanvases):
     26        (WebCore::InspectorCanvasAgent::frameNavigated):
     27        (WebCore::InspectorCanvasAgent::frameDetached):
     28        * inspector/InspectorCanvasAgent.h:
     29        (WebCore):
     30        (WebCore::InspectorCanvasAgent::create):
     31        (InspectorCanvasAgent):
     32        * inspector/InspectorController.cpp:
     33        (WebCore::InspectorController::InspectorController):
     34        * inspector/InspectorInstrumentation.cpp:
     35        (WebCore):
     36        (WebCore::InspectorInstrumentation::frameDetachedFromParentImpl):
     37        (WebCore::InspectorInstrumentation::didCommitLoadImpl):
     38
    1392013-01-29  Eugene Klyuchnikov  <eustas@chromium.org>
    240
  • trunk/Source/WebCore/inspector/Inspector.json

    r140818 r141098  
    33293329            {
    33303330                "name": "captureFrame",
    3331                 "returns": [
    3332                     { "name": "traceLogId", "$ref": "TraceLogId" }
    3333                 ]
     3331                "parameters": [
     3332                    { "name": "frameId", "$ref": "Network.FrameId", "optional": true, "description": "Identifier of the frame containing document whose canvases are to be captured. If omitted, main frame is assumed." }
     3333                ],
     3334                "returns": [
     3335                    { "name": "traceLogId", "$ref": "TraceLogId", "description": "Identifier of the trace log containing captured canvas calls." }
     3336                ],
     3337                "description": "Starts (or continues) a canvas frame capturing which will be stopped automatically after the next frame is prepared."
    33343338            },
    33353339            {
    33363340                "name": "startCapturing",
    3337                 "returns": [
    3338                     { "name": "traceLogId", "$ref": "TraceLogId" }
    3339                 ]
     3341                "parameters": [
     3342                    { "name": "frameId", "$ref": "Network.FrameId", "optional": true, "description": "Identifier of the frame containing document whose canvases are to be captured. If omitted, main frame is assumed." }
     3343                ],
     3344                "returns": [
     3345                    { "name": "traceLogId", "$ref": "TraceLogId", "description": "Identifier of the trace log containing captured canvas calls." }
     3346                ],
     3347                "description": "Starts (or continues) consecutive canvas frames capturing. The capturing is stopped by the corresponding stopCapturing command."
    33403348            },
    33413349            {
     
    33863394            }
    33873395        ],
    3388         "events": []
     3396        "events": [
     3397            {
     3398                "name": "contextCreated",
     3399                "parameters": [
     3400                    { "name": "frameId", "$ref": "Network.FrameId", "description": "Identifier of the frame containing a canvas with a context." }
     3401                ],
     3402                "description": "Fired when a canvas context has been created in the given frame. The context may not be instrumented (see hasUninstrumentedCanvases command)."
     3403            }
     3404        ]
    33893405    },
    33903406    {
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.cpp

    r140963 r141098  
    3636
    3737#include "BindingVisitors.h"
     38#include "DOMWindow.h"
    3839#include "Frame.h"
    3940#include "HTMLCanvasElement.h"
     
    4344#include "InjectedScriptManager.h"
    4445#include "InspectorFrontend.h"
     46#include "InspectorPageAgent.h"
    4547#include "InspectorState.h"
    4648#include "InstrumentingAgents.h"
     
    5052#include "ScriptState.h"
    5153
     54using WebCore::TypeBuilder::Canvas::ResourceInfo;
     55using WebCore::TypeBuilder::Canvas::ResourceState;
     56using WebCore::TypeBuilder::Canvas::TraceLog;
     57using WebCore::TypeBuilder::Canvas::TraceLogId;
     58using WebCore::TypeBuilder::Network::FrameId;
     59
    5260namespace WebCore {
    5361
     
    5664};
    5765
    58 InspectorCanvasAgent::InspectorCanvasAgent(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state, Page* page, InjectedScriptManager* injectedScriptManager)
     66InspectorCanvasAgent::InspectorCanvasAgent(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state, InspectorPageAgent* pageAgent, InjectedScriptManager* injectedScriptManager)
    5967    : InspectorBaseAgent<InspectorCanvasAgent>("Canvas", instrumentingAgents, state)
    60     , m_inspectedPage(page)
     68    , m_pageAgent(pageAgent)
    6169    , m_injectedScriptManager(injectedScriptManager)
    6270    , m_frontend(0)
     
    118126    if (!checkIsEnabled(errorString))
    119127        return;
    120     *result = m_framesWithUninstrumentedCanvases.contains(m_inspectedPage->mainFrame());
    121 }
    122 
    123 void InspectorCanvasAgent::captureFrame(ErrorString* errorString, String* traceLogId)
    124 {
    125     InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, mainWorldScriptState(m_inspectedPage->mainFrame()));
     128    *result = !m_framesWithUninstrumentedCanvases.isEmpty();
     129}
     130
     131void InspectorCanvasAgent::captureFrame(ErrorString* errorString, const FrameId* frameId, TraceLogId* traceLogId)
     132{
     133    Frame* frame = frameId ? m_pageAgent->assertFrame(errorString, *frameId) : m_pageAgent->mainFrame();
     134    if (!frame)
     135        return;
     136    InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, mainWorldScriptState(frame));
    126137    if (!module.hasNoValue())
    127138        module.captureFrame(errorString, traceLogId);
    128139}
    129140
    130 void InspectorCanvasAgent::startCapturing(ErrorString* errorString, String* traceLogId)
    131 {
    132     InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, mainWorldScriptState(m_inspectedPage->mainFrame()));
     141void InspectorCanvasAgent::startCapturing(ErrorString* errorString, const FrameId* frameId, TraceLogId* traceLogId)
     142{
     143    Frame* frame = frameId ? m_pageAgent->assertFrame(errorString, *frameId) : m_pageAgent->mainFrame();
     144    if (!frame)
     145        return;
     146    InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, mainWorldScriptState(frame));
    133147    if (!module.hasNoValue())
    134148        module.startCapturing(errorString, traceLogId);
     
    142156}
    143157
    144 void InspectorCanvasAgent::getTraceLog(ErrorString* errorString, const String& traceLogId, const int* startOffset, const int* maxLength, RefPtr<TypeBuilder::Canvas::TraceLog>& traceLog)
     158void InspectorCanvasAgent::getTraceLog(ErrorString* errorString, const String& traceLogId, const int* startOffset, const int* maxLength, RefPtr<TraceLog>& traceLog)
    145159{
    146160    InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, traceLogId);
     
    149163}
    150164
    151 void InspectorCanvasAgent::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, RefPtr<TypeBuilder::Canvas::ResourceState>& result)
     165void InspectorCanvasAgent::replayTraceLog(ErrorString* errorString, const String& traceLogId, int stepNo, RefPtr<ResourceState>& result)
    152166{
    153167    InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, traceLogId);
     
    156170}
    157171
    158 void InspectorCanvasAgent::getResourceInfo(ErrorString* errorString, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceInfo>& result)
     172void InspectorCanvasAgent::getResourceInfo(ErrorString* errorString, const String& resourceId, RefPtr<ResourceInfo>& result)
    159173{
    160174    InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, resourceId);
     
    163177}
    164178
    165 void InspectorCanvasAgent::getResourceState(ErrorString* errorString, const String& traceLogId, const String& resourceId, RefPtr<TypeBuilder::Canvas::ResourceState>& result)
     179void InspectorCanvasAgent::getResourceState(ErrorString* errorString, const String& traceLogId, const String& resourceId, RefPtr<ResourceState>& result)
    166180{
    167181    InjectedScriptCanvasModule module = injectedScriptCanvasModule(errorString, traceLogId);
     
    176190    if (module.hasNoValue())
    177191        return ScriptObject();
    178     return module.wrapCanvas2DContext(context);
     192    return notifyRenderingContextWasWrapped(module.wrapCanvas2DContext(context));
    179193}
    180194
     
    186200    if (module.hasNoValue())
    187201        return ScriptObject();
    188     return module.wrapWebGLContext(glContext);
     202    return notifyRenderingContextWasWrapped(module.wrapWebGLContext(glContext));
    189203}
    190204#endif
     205
     206ScriptObject InspectorCanvasAgent::notifyRenderingContextWasWrapped(const ScriptObject& wrappedContext)
     207{
     208    ASSERT(m_frontend);
     209    ScriptState* scriptState = wrappedContext.scriptState();
     210    DOMWindow* domWindow = scriptState ? domWindowFromScriptState(scriptState) : 0;
     211    Frame* frame = domWindow ? domWindow->frame() : 0;
     212    String frameId = m_pageAgent->frameId(frame);
     213    if (!frameId.isEmpty())
     214        m_frontend->contextCreated(frameId);
     215    return wrappedContext;
     216}
    191217
    192218InjectedScriptCanvasModule InspectorCanvasAgent::injectedScriptCanvasModule(ErrorString* errorString, ScriptState* scriptState)
     
    253279        Page* m_page;
    254280        HashSet<Frame*>& m_framesWithUninstrumentedCanvases;
    255     } nodeVisitor(m_inspectedPage, m_framesWithUninstrumentedCanvases);
    256 
     281    } nodeVisitor(m_pageAgent->page(), m_framesWithUninstrumentedCanvases);
     282
     283    m_framesWithUninstrumentedCanvases.clear();
    257284    ScriptProfiler::visitNodeWrappers(&nodeVisitor);
     285
     286    for (HashSet<Frame*>::iterator it = m_framesWithUninstrumentedCanvases.begin(); it != m_framesWithUninstrumentedCanvases.end(); ++it) {
     287        String frameId = m_pageAgent->frameId(*it);
     288        if (!frameId.isEmpty())
     289            m_frontend->contextCreated(frameId);
     290    }
    258291}
    259292
     
    266299}
    267300
    268 void InspectorCanvasAgent::reset()
    269 {
    270     m_framesWithUninstrumentedCanvases.clear();
     301void InspectorCanvasAgent::frameNavigated(Frame* frame)
     302{
     303    if (!m_enabled)
     304        return;
     305    if (frame == m_pageAgent->mainFrame())
     306        m_framesWithUninstrumentedCanvases.clear();
     307    else {
     308        while (frame) {
     309            m_framesWithUninstrumentedCanvases.remove(frame);
     310            frame = frame->tree()->traverseNext();
     311        }
     312    }
     313}
     314
     315void InspectorCanvasAgent::frameDetached(Frame* frame)
     316{
    271317    if (m_enabled)
    272         findFramesWithUninstrumentedCanvases();
     318        m_framesWithUninstrumentedCanvases.remove(frame);
    273319}
    274320
  • trunk/Source/WebCore/inspector/InspectorCanvasAgent.h

    r140963 r141098  
    4848class InjectedScriptCanvasModule;
    4949class InjectedScriptManager;
     50class InspectorPageAgent;
    5051class InspectorState;
    5152class InstrumentingAgents;
    52 class Page;
    5353class ScriptObject;
    5454
     
    5757class InspectorCanvasAgent : public InspectorBaseAgent<InspectorCanvasAgent>, public InspectorBackendDispatcher::CanvasCommandHandler {
    5858public:
    59     static PassOwnPtr<InspectorCanvasAgent> create(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state, Page* page, InjectedScriptManager* injectedScriptManager)
     59    static PassOwnPtr<InspectorCanvasAgent> create(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state, InspectorPageAgent* pageAgent, InjectedScriptManager* injectedScriptManager)
    6060    {
    61         return adoptPtr(new InspectorCanvasAgent(instrumentingAgents, state, page, injectedScriptManager));
     61        return adoptPtr(new InspectorCanvasAgent(instrumentingAgents, state, pageAgent, injectedScriptManager));
    6262    }
    6363    ~InspectorCanvasAgent();
     
    6868
    6969    // Called from InspectorInstrumentation
    70     void reset();
     70    void frameNavigated(Frame*);
     71    void frameDetached(Frame*);
    7172
    7273    // Called from InspectorCanvasInstrumentation
     
    8182    virtual void dropTraceLog(ErrorString*, const String&);
    8283    virtual void hasUninstrumentedCanvases(ErrorString*, bool*);
    83     virtual void captureFrame(ErrorString*, String*);
    84     virtual void startCapturing(ErrorString*, String*);
     84    virtual void captureFrame(ErrorString*, const TypeBuilder::Network::FrameId*, TypeBuilder::Canvas::TraceLogId*);
     85    virtual void startCapturing(ErrorString*, const TypeBuilder::Network::FrameId*, TypeBuilder::Canvas::TraceLogId*);
    8586    virtual void stopCapturing(ErrorString*, const String&);
    8687    virtual void getTraceLog(ErrorString*, const String&, const int*, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>&);
     
    9091
    9192private:
    92     InspectorCanvasAgent(InstrumentingAgents*, InspectorCompositeState*, Page*, InjectedScriptManager*);
     93    InspectorCanvasAgent(InstrumentingAgents*, InspectorCompositeState*, InspectorPageAgent*, InjectedScriptManager*);
    9394
    9495    InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, ScriptState*);
     
    9899    void findFramesWithUninstrumentedCanvases();
    99100    bool checkIsEnabled(ErrorString*) const;
     101    ScriptObject notifyRenderingContextWasWrapped(const ScriptObject&);
    100102
    101     Page* m_inspectedPage;
     103    InspectorPageAgent* m_pageAgent;
    102104    InjectedScriptManager* m_injectedScriptManager;
    103105    InspectorFrontend::Canvas* m_frontend;
  • trunk/Source/WebCore/inspector/InspectorController.cpp

    r140823 r141098  
    159159#endif
    160160
    161     m_agents.append(InspectorCanvasAgent::create(m_instrumentingAgents.get(), m_state.get(), page, m_injectedScriptManager.get()));
     161    m_agents.append(InspectorCanvasAgent::create(m_instrumentingAgents.get(), m_state.get(), pageAgent, m_injectedScriptManager.get()));
    162162
    163163    m_agents.append(InspectorInputAgent::create(m_instrumentingAgents.get(), m_state.get(), page));
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r140649 r141098  
    903903void InspectorInstrumentation::frameDetachedFromParentImpl(InstrumentingAgents* instrumentingAgents, Frame* frame)
    904904{
     905    if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
     906        canvasAgent->frameDetached(frame);
    905907    if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
    906908        pageAgent->frameDetached(frame);
     
    938940            layerTreeAgent->reset();
    939941#endif
    940         if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
    941             canvasAgent->reset();
    942942        inspectorAgent->didCommitLoad();
    943943    }
     944    if (InspectorCanvasAgent* canvasAgent = instrumentingAgents->inspectorCanvasAgent())
     945        canvasAgent->frameNavigated(loader->frame());
    944946    if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
    945947        pageAgent->frameNavigated(loader);
Note: See TracChangeset for help on using the changeset viewer.