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/core/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
43namespace blink {
44
45class LocalFrame;
46class DocumentLoader;
47class InjectedScriptCanvasModule;
48class InjectedScriptManager;
49class InspectorPageAgent;
50class InstrumentingAgents;
51class ScriptValue;
52
53typedef String ErrorString;
54
55class InspectorCanvasAgent FINAL : public InspectorBaseAgent<InspectorCanvasAgent>, public InspectorBackendDispatcher::CanvasCommandHandler {
56public:
57    static PassOwnPtrWillBeRawPtr<InspectorCanvasAgent> create(InspectorPageAgent* pageAgent, InjectedScriptManager* injectedScriptManager)
58    {
59        return adoptPtrWillBeNoop(new InspectorCanvasAgent(pageAgent, injectedScriptManager));
60    }
61    virtual ~InspectorCanvasAgent();
62    virtual void trace(Visitor*) OVERRIDE;
63
64    virtual void setFrontend(InspectorFrontend*) OVERRIDE;
65    virtual void clearFrontend() OVERRIDE;
66    virtual void restore() OVERRIDE;
67
68    void didCommitLoad(LocalFrame*, DocumentLoader*);
69    void frameDetachedFromParent(LocalFrame*);
70    void didBeginFrame();
71
72    // Called from InspectorCanvasInstrumentation.
73    ScriptValue wrapCanvas2DRenderingContextForInstrumentation(const ScriptValue&);
74    ScriptValue wrapWebGLRenderingContextForInstrumentation(const ScriptValue&);
75
76    // Called from the front-end.
77    virtual void enable(ErrorString*) OVERRIDE;
78    virtual void disable(ErrorString*) OVERRIDE;
79    virtual void dropTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&) OVERRIDE;
80    virtual void hasUninstrumentedCanvases(ErrorString*, bool*) OVERRIDE;
81    virtual void captureFrame(ErrorString*, const TypeBuilder::Page::FrameId*, TypeBuilder::Canvas::TraceLogId*) OVERRIDE;
82    virtual void startCapturing(ErrorString*, const TypeBuilder::Page::FrameId*, TypeBuilder::Canvas::TraceLogId*) OVERRIDE;
83    virtual void stopCapturing(ErrorString*, const TypeBuilder::Canvas::TraceLogId&) OVERRIDE;
84    virtual void getTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const int*, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>&) OVERRIDE;
85    virtual void replayTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, int, RefPtr<TypeBuilder::Canvas::ResourceState>&, double*) OVERRIDE;
86    virtual void getResourceState(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const TypeBuilder::Canvas::ResourceId&, RefPtr<TypeBuilder::Canvas::ResourceState>&) OVERRIDE;
87    virtual void evaluateTraceLogCallArgument(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, int, int, const String*, RefPtr<TypeBuilder::Runtime::RemoteObject>&, RefPtr<TypeBuilder::Canvas::ResourceState>&) OVERRIDE;
88
89private:
90    InspectorCanvasAgent(InspectorPageAgent*, InjectedScriptManager*);
91
92    InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, ScriptState*);
93    InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const ScriptValue&);
94    InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const String&);
95
96    void findFramesWithUninstrumentedCanvases();
97    bool checkIsEnabled(ErrorString*) const;
98    ScriptValue notifyRenderingContextWasWrapped(const ScriptValue&);
99
100    RawPtrWillBeMember<InspectorPageAgent> m_pageAgent;
101    RawPtrWillBeMember<InjectedScriptManager> m_injectedScriptManager;
102    InspectorFrontend::Canvas* m_frontend;
103    bool m_enabled;
104    // Contains all frames with canvases, value is true only for frames that have an uninstrumented canvas.
105    typedef HashMap<LocalFrame*, bool> FramesWithUninstrumentedCanvases;
106    FramesWithUninstrumentedCanvases m_framesWithUninstrumentedCanvases;
107};
108
109} // namespace blink
110
111
112#endif // !defined(InspectorCanvasAgent_h)
113