• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "bindings/v8/ScriptState.h"
36 #include "core/InspectorFrontend.h"
37 #include "core/InspectorTypeBuilder.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 LocalFrame;
46 class DocumentLoader;
47 class InjectedScriptCanvasModule;
48 class InjectedScriptManager;
49 class InspectorPageAgent;
50 class InstrumentingAgents;
51 class ScriptValue;
52 
53 typedef String ErrorString;
54 
55 class InspectorCanvasAgent FINAL : public InspectorBaseAgent<InspectorCanvasAgent>, public InspectorBackendDispatcher::CanvasCommandHandler {
56 public:
create(InspectorPageAgent * pageAgent,InjectedScriptManager * injectedScriptManager)57     static PassOwnPtr<InspectorCanvasAgent> create(InspectorPageAgent* pageAgent, InjectedScriptManager* injectedScriptManager)
58     {
59         return adoptPtr(new InspectorCanvasAgent(pageAgent, injectedScriptManager));
60     }
61     virtual ~InspectorCanvasAgent();
62 
63     virtual void setFrontend(InspectorFrontend*) OVERRIDE;
64     virtual void clearFrontend() OVERRIDE;
65     virtual void restore() OVERRIDE;
66 
67     void didCommitLoad(LocalFrame*, DocumentLoader*);
68     void frameDetachedFromParent(LocalFrame*);
69     void didBeginFrame();
70 
71     // Called from InspectorCanvasInstrumentation.
72     ScriptValue wrapCanvas2DRenderingContextForInstrumentation(const ScriptValue&);
73     ScriptValue wrapWebGLRenderingContextForInstrumentation(const ScriptValue&);
74 
75     // Called from the front-end.
76     virtual void enable(ErrorString*) OVERRIDE;
77     virtual void disable(ErrorString*) OVERRIDE;
78     virtual void dropTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&) OVERRIDE;
79     virtual void hasUninstrumentedCanvases(ErrorString*, bool*) OVERRIDE;
80     virtual void captureFrame(ErrorString*, const TypeBuilder::Page::FrameId*, TypeBuilder::Canvas::TraceLogId*) OVERRIDE;
81     virtual void startCapturing(ErrorString*, const TypeBuilder::Page::FrameId*, TypeBuilder::Canvas::TraceLogId*) OVERRIDE;
82     virtual void stopCapturing(ErrorString*, const TypeBuilder::Canvas::TraceLogId&) OVERRIDE;
83     virtual void getTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const int*, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>&) OVERRIDE;
84     virtual void replayTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, int, RefPtr<TypeBuilder::Canvas::ResourceState>&, double*) OVERRIDE;
85     virtual void getResourceState(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const TypeBuilder::Canvas::ResourceId&, RefPtr<TypeBuilder::Canvas::ResourceState>&) OVERRIDE;
86     virtual void evaluateTraceLogCallArgument(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, int, int, const String*, RefPtr<TypeBuilder::Runtime::RemoteObject>&, RefPtr<TypeBuilder::Canvas::ResourceState>&) OVERRIDE;
87 
88 private:
89     InspectorCanvasAgent(InspectorPageAgent*, InjectedScriptManager*);
90 
91     InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, ScriptState*);
92     InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const ScriptValue&);
93     InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const String&);
94 
95     void findFramesWithUninstrumentedCanvases();
96     bool checkIsEnabled(ErrorString*) const;
97     ScriptValue notifyRenderingContextWasWrapped(const ScriptValue&);
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<LocalFrame*, bool> FramesWithUninstrumentedCanvases;
105     FramesWithUninstrumentedCanvases m_framesWithUninstrumentedCanvases;
106 };
107 
108 } // namespace WebCore
109 
110 
111 #endif // !defined(InspectorCanvasAgent_h)
112