InspectorConsoleAgent.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2011 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
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
  14. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  16. * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  18. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  19. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  20. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  21. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  22. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. #ifndef InspectorConsoleAgent_h
  25. #define InspectorConsoleAgent_h
  26. #if ENABLE(INSPECTOR)
  27. #include "ConsoleAPITypes.h"
  28. #include "ConsoleTypes.h"
  29. #include "InspectorBaseAgent.h"
  30. #include "InspectorFrontend.h"
  31. #include "ScriptState.h"
  32. #include <wtf/Forward.h>
  33. #include <wtf/HashMap.h>
  34. #include <wtf/Noncopyable.h>
  35. #include <wtf/text/StringHash.h>
  36. #include <wtf/Vector.h>
  37. namespace WebCore {
  38. class ConsoleMessage;
  39. class DOMWindow;
  40. class InspectorFrontend;
  41. class InspectorState;
  42. class InjectedScriptManager;
  43. class InstrumentingAgents;
  44. class ResourceError;
  45. class ResourceResponse;
  46. class ScriptArguments;
  47. class ScriptCallStack;
  48. class ScriptProfile;
  49. typedef String ErrorString;
  50. class InspectorConsoleAgent : public InspectorBaseAgent<InspectorConsoleAgent>, public InspectorBackendDispatcher::ConsoleCommandHandler {
  51. WTF_MAKE_NONCOPYABLE(InspectorConsoleAgent);
  52. public:
  53. InspectorConsoleAgent(InstrumentingAgents*, InspectorCompositeState*, InjectedScriptManager*);
  54. virtual ~InspectorConsoleAgent();
  55. virtual void enable(ErrorString*);
  56. virtual void disable(ErrorString*);
  57. virtual void clearMessages(ErrorString*);
  58. bool enabled() { return m_enabled; }
  59. void reset();
  60. virtual void setFrontend(InspectorFrontend*);
  61. virtual void clearFrontend();
  62. virtual void restore();
  63. void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, ScriptState*, PassRefPtr<ScriptArguments>, unsigned long requestIdentifier = 0);
  64. void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, const String& scriptId, unsigned lineNumber, unsigned columnNumber, ScriptState* = 0, unsigned long requestIdentifier = 0);
  65. // FIXME: Remove once we no longer generate stacks outside of Inspector.
  66. void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, PassRefPtr<ScriptCallStack>, unsigned long requestIdentifier = 0);
  67. Vector<unsigned> consoleMessageArgumentCounts();
  68. void startTiming(const String& title);
  69. void stopTiming(const String& title, PassRefPtr<ScriptCallStack>);
  70. void count(ScriptState*, PassRefPtr<ScriptArguments>);
  71. void frameWindowDiscarded(DOMWindow*);
  72. void didFinishXHRLoading(unsigned long requestIdentifier, const String& url, const String& sendURL, unsigned sendLineNumber);
  73. void didReceiveResponse(unsigned long requestIdentifier, const ResourceResponse&);
  74. void didFailLoading(unsigned long requestIdentifier, const ResourceError&);
  75. #if ENABLE(JAVASCRIPT_DEBUGGER)
  76. void addProfileFinishedMessageToConsole(PassRefPtr<ScriptProfile>, unsigned lineNumber, unsigned columnNumber, const String& sourceURL);
  77. void addStartProfilingMessageToConsole(const String& title, unsigned lineNumber, unsigned columnNumber, const String& sourceURL);
  78. #endif
  79. virtual void setMonitoringXHREnabled(ErrorString*, bool enabled);
  80. virtual void addInspectedNode(ErrorString*, int nodeId) = 0;
  81. virtual void addInspectedHeapObject(ErrorString*, int inspectedHeapObjectId);
  82. virtual bool isWorkerAgent() = 0;
  83. protected:
  84. void addConsoleMessage(PassOwnPtr<ConsoleMessage>);
  85. virtual bool developerExtrasEnabled() = 0;
  86. InjectedScriptManager* m_injectedScriptManager;
  87. InspectorFrontend::Console* m_frontend;
  88. ConsoleMessage* m_previousMessage;
  89. Vector<OwnPtr<ConsoleMessage> > m_consoleMessages;
  90. int m_expiredConsoleMessageCount;
  91. HashMap<String, unsigned> m_counts;
  92. HashMap<String, double> m_times;
  93. bool m_enabled;
  94. private:
  95. static int s_enabledAgentCount;
  96. };
  97. } // namespace WebCore
  98. #endif // ENABLE(INSPECTOR)
  99. #endif // !defined(InspectorConsoleAgent_h)