InspectorCanvasAgent.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef InspectorCanvasAgent_h
  31. #define InspectorCanvasAgent_h
  32. #if ENABLE(INSPECTOR)
  33. #include "InspectorBaseAgent.h"
  34. #include "InspectorFrontend.h"
  35. #include "InspectorTypeBuilder.h"
  36. #include "ScriptState.h"
  37. #include <wtf/HashMap.h>
  38. #include <wtf/PassOwnPtr.h>
  39. #include <wtf/PassRefPtr.h>
  40. #include <wtf/text/WTFString.h>
  41. namespace WebCore {
  42. class Frame;
  43. class InjectedScriptCanvasModule;
  44. class InjectedScriptManager;
  45. class InspectorPageAgent;
  46. class InspectorState;
  47. class InstrumentingAgents;
  48. class ScriptObject;
  49. typedef String ErrorString;
  50. class InspectorCanvasAgent : public InspectorBaseAgent<InspectorCanvasAgent>, public InspectorBackendDispatcher::CanvasCommandHandler {
  51. public:
  52. static PassOwnPtr<InspectorCanvasAgent> create(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state, InspectorPageAgent* pageAgent, InjectedScriptManager* injectedScriptManager)
  53. {
  54. return adoptPtr(new InspectorCanvasAgent(instrumentingAgents, state, pageAgent, injectedScriptManager));
  55. }
  56. ~InspectorCanvasAgent();
  57. virtual void setFrontend(InspectorFrontend*);
  58. virtual void clearFrontend();
  59. virtual void restore();
  60. void frameNavigated(Frame*);
  61. void frameDetached(Frame*);
  62. void didBeginFrame();
  63. // Called from InspectorCanvasInstrumentation.
  64. ScriptObject wrapCanvas2DRenderingContextForInstrumentation(const ScriptObject&);
  65. #if ENABLE(WEBGL)
  66. ScriptObject wrapWebGLRenderingContextForInstrumentation(const ScriptObject&);
  67. #endif
  68. // Called from the front-end.
  69. virtual void enable(ErrorString*);
  70. virtual void disable(ErrorString*);
  71. virtual void dropTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&);
  72. virtual void hasUninstrumentedCanvases(ErrorString*, bool*);
  73. virtual void captureFrame(ErrorString*, const TypeBuilder::Network::FrameId*, TypeBuilder::Canvas::TraceLogId*);
  74. virtual void startCapturing(ErrorString*, const TypeBuilder::Network::FrameId*, TypeBuilder::Canvas::TraceLogId*);
  75. virtual void stopCapturing(ErrorString*, const TypeBuilder::Canvas::TraceLogId&);
  76. virtual void getTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const int*, const int*, RefPtr<TypeBuilder::Canvas::TraceLog>&);
  77. virtual void replayTraceLog(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, int, RefPtr<TypeBuilder::Canvas::ResourceState>&);
  78. virtual void getResourceInfo(ErrorString*, const TypeBuilder::Canvas::ResourceId&, RefPtr<TypeBuilder::Canvas::ResourceInfo>&);
  79. virtual void getResourceState(ErrorString*, const TypeBuilder::Canvas::TraceLogId&, const TypeBuilder::Canvas::ResourceId&, RefPtr<TypeBuilder::Canvas::ResourceState>&);
  80. private:
  81. InspectorCanvasAgent(InstrumentingAgents*, InspectorCompositeState*, InspectorPageAgent*, InjectedScriptManager*);
  82. InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, ScriptState*);
  83. InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const ScriptObject&);
  84. InjectedScriptCanvasModule injectedScriptCanvasModule(ErrorString*, const String&);
  85. void findFramesWithUninstrumentedCanvases();
  86. bool checkIsEnabled(ErrorString*) const;
  87. ScriptObject notifyRenderingContextWasWrapped(const ScriptObject&);
  88. InspectorPageAgent* m_pageAgent;
  89. InjectedScriptManager* m_injectedScriptManager;
  90. InspectorFrontend::Canvas* m_frontend;
  91. bool m_enabled;
  92. // Contains all frames with canvases, value is true only for frames that have an uninstrumented canvas.
  93. typedef HashMap<Frame*, bool> FramesWithUninstrumentedCanvases;
  94. FramesWithUninstrumentedCanvases m_framesWithUninstrumentedCanvases;
  95. };
  96. } // namespace WebCore
  97. #endif // ENABLE(INSPECTOR)
  98. #endif // !defined(InspectorCanvasAgent_h)