Home | History | Annotate | Download | only in inspector
      1 /*
      2  * Copyright (C) 2012 Google Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *     * Redistributions of source code must retain the above copyright
      9  * notice, this list of conditions and the following disclaimer.
     10  *     * Redistributions in binary form must reproduce the above
     11  * copyright notice, this list of conditions and the following disclaimer
     12  * in the documentation and/or other materials provided with the
     13  * distribution.
     14  *     * Neither the name of Google Inc. nor the names of its
     15  * contributors may be used to endorse or promote products derived from
     16  * this software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef InspectorCanvasAgent_h
     32 #define InspectorCanvasAgent_h
     33 
     34 
     35 #include "InspectorFrontend.h"
     36 #include "InspectorTypeBuilder.h"
     37 #include "bindings/v8/ScriptState.h"
     38 #include "core/inspector/InspectorBaseAgent.h"
     39 #include "wtf/HashMap.h"
     40 #include "wtf/PassOwnPtr.h"
     41 #include "wtf/text/WTFString.h"
     42 
     43 namespace WebCore {
     44 
     45 class Frame;
     46 class DocumentLoader;
     47 class InjectedScriptCanvasModule;
     48 class InjectedScriptManager;
     49 class InspectorPageAgent;
     50 class InstrumentingAgents;
     51 class ScriptObject;
     52 
     53 typedef String ErrorString;
     54 
     55 class InspectorCanvasAgent : public InspectorBaseAgent<InspectorCanvasAgent>, public InspectorBackendDispatcher::CanvasCommandHandler {
     56 public:
     57     static PassOwnPtr<InspectorCanvasAgent> create(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state, InspectorPageAgent* pageAgent, InjectedScriptManager* injectedScriptManager)
     58     {
     59         return adoptPtr(new InspectorCanvasAgent(instrumentingAgents, state, pageAgent, injectedScriptManager));
     60     }
     61     ~InspectorCanvasAgent();
     62 
     63     virtual void setFrontend(InspectorFrontend*);
     64     virtual void clearFrontend();
     65     virtual void restore();
     66 
     67     void didCommitLoad(Frame*, DocumentLoader*);
     68     void frameDetachedFromParent(Frame*);
     69     void didBeginFrame();
     70 
     71     // Called from InspectorCanvasInstrumentation.
     72     ScriptObject wrapCanvas2DRenderingContextForInstrumentation(const ScriptObject&);
     73     ScriptObject wrapWebGLRenderingContextForInstrumentation(const ScriptObject&);
     74 
     75     // Called from the front-end.
     76     virtual void enable(ErrorString*);
     77     virtual void disable(ErrorString*);
     78     virtual void dropTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&);
     79     virtual void hasUninstrumentedCanvases(ErrorString*, bool*);
     80     virtual void captureFrame(ErrorString*, const TypeBuilder::Network::FrameId*, TypeBuilder::Canvas::TraceLogId*);
     81     virtual void startCapturing(ErrorString*, const TypeBuilder::Network::FrameId*, TypeBuilder::Canvas::TraceLogId*);
     82     virtual void stopCapturing(ErrorString*, const TypeBuilder::Canvas::TraceLogId&);
     83     virtual void getTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const int*, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>&);
     84     virtual void replayTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, int, RefPtr<TypeBuilder::Canvas::ResourceState>&, double*);
     85     virtual void getResourceState(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const TypeBuilder::Canvas::ResourceId&, RefPtr<TypeBuilder::Canvas::ResourceState>&);
     86     virtual void evaluateTraceLogCallArgument(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, int, int, const String*, RefPtr<TypeBuilder::Runtime::RemoteObject>&, RefPtr<TypeBuilder::Canvas::ResourceState>&);
     87 
     88 private:
     89     InspectorCanvasAgent(InstrumentingAgents*, InspectorCompositeState*, InspectorPageAgent*, InjectedScriptManager*);
     90 
     91     InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, ScriptState*);
     92     InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const ScriptObject&);
     93     InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const String&);
     94 
     95     void findFramesWithUninstrumentedCanvases();
     96     bool checkIsEnabled(ErrorString*) const;
     97     ScriptObject notifyRenderingContextWasWrapped(const ScriptObject&);
     98 
     99     InspectorPageAgent* m_pageAgent;
    100     InjectedScriptManager* m_injectedScriptManager;
    101     InspectorFrontend::Canvas* m_frontend;
    102     bool m_enabled;
    103     // Contains all frames with canvases, value is true only for frames that have an uninstrumented canvas.
    104     typedef HashMap<Frame*, bool> FramesWithUninstrumentedCanvases;
    105     FramesWithUninstrumentedCanvases m_framesWithUninstrumentedCanvases;
    106 };
    107 
    108 } // namespace WebCore
    109 
    110 
    111 #endif // !defined(InspectorCanvasAgent_h)
    112