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 25 #ifndef InspectorConsoleAgent_h 26 #define InspectorConsoleAgent_h 27 28 #include "InspectorFrontend.h" 29 #include "bindings/v8/ScriptState.h" 30 #include "bindings/v8/ScriptString.h" 31 #include "core/inspector/ConsoleAPITypes.h" 32 #include "core/inspector/InspectorBaseAgent.h" 33 #include "core/page/ConsoleTypes.h" 34 #include "wtf/Forward.h" 35 #include "wtf/HashMap.h" 36 #include "wtf/Noncopyable.h" 37 #include "wtf/Vector.h" 38 #include "wtf/text/StringHash.h" 39 40 namespace WebCore { 41 42 class ConsoleMessage; 43 class DocumentLoader; 44 class DOMWindow; 45 class Frame; 46 class InspectorFrontend; 47 class InjectedScriptManager; 48 class InstrumentingAgents; 49 class ResourceError; 50 class ResourceLoader; 51 class ResourceResponse; 52 class ScriptArguments; 53 class ScriptCallStack; 54 class ScriptProfile; 55 class ThreadableLoaderClient; 56 57 typedef String ErrorString; 58 59 class InspectorConsoleAgent : public InspectorBaseAgent<InspectorConsoleAgent>, public InspectorBackendDispatcher::ConsoleCommandHandler { 60 WTF_MAKE_NONCOPYABLE(InspectorConsoleAgent); 61 public: 62 InspectorConsoleAgent(InstrumentingAgents*, InspectorCompositeState*, InjectedScriptManager*); 63 virtual ~InspectorConsoleAgent(); 64 65 virtual void enable(ErrorString*); 66 virtual void disable(ErrorString*); 67 virtual void clearMessages(ErrorString*); 68 bool enabled() { return m_enabled; } 69 void reset(); 70 71 virtual void setFrontend(InspectorFrontend*); 72 virtual void clearFrontend(); 73 virtual void restore(); 74 75 void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, ScriptState*, PassRefPtr<ScriptArguments>, unsigned long requestIdentifier = 0); 76 void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, const String& scriptId, unsigned lineNumber, unsigned columnNumber = 0, ScriptState* = 0, unsigned long requestIdentifier = 0); 77 78 // FIXME: Remove once we no longer generate stacks outside of Inspector. 79 void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, PassRefPtr<ScriptCallStack>, unsigned long requestIdentifier = 0); 80 81 Vector<unsigned> consoleMessageArgumentCounts(); 82 83 void startConsoleTiming(Frame*, const String& title); 84 void stopConsoleTiming(Frame*, const String& title, PassRefPtr<ScriptCallStack>); 85 void consoleCount(ScriptState*, PassRefPtr<ScriptArguments>); 86 87 void frameWindowDiscarded(DOMWindow*); 88 void didCommitLoad(Frame*, DocumentLoader*); 89 90 void didFinishXHRLoading(ThreadableLoaderClient*, unsigned long requestIdentifier, ScriptString, const String& url, const String& sendURL, unsigned sendLineNumber); 91 void didReceiveResourceResponse(unsigned long requestIdentifier, DocumentLoader*, const ResourceResponse& response, ResourceLoader*); 92 void didFailLoading(unsigned long requestIdentifier, DocumentLoader*, const ResourceError&); 93 void addProfileFinishedMessageToConsole(PassRefPtr<ScriptProfile>, unsigned lineNumber, const String& sourceURL); 94 void addStartProfilingMessageToConsole(const String& title, unsigned lineNumber, const String& sourceURL); 95 virtual void setMonitoringXHREnabled(ErrorString*, bool enabled); 96 virtual void addInspectedNode(ErrorString*, int nodeId) = 0; 97 virtual void addInspectedHeapObject(ErrorString*, int inspectedHeapObjectId); 98 99 virtual bool isWorkerAgent() = 0; 100 101 protected: 102 void addConsoleMessage(PassOwnPtr<ConsoleMessage>); 103 104 InjectedScriptManager* m_injectedScriptManager; 105 InspectorFrontend::Console* m_frontend; 106 ConsoleMessage* m_previousMessage; 107 Vector<OwnPtr<ConsoleMessage> > m_consoleMessages; 108 int m_expiredConsoleMessageCount; 109 HashMap<String, unsigned> m_counts; 110 HashMap<String, double> m_times; 111 bool m_enabled; 112 private: 113 static int s_enabledAgentCount; 114 }; 115 116 } // namespace WebCore 117 118 119 #endif // !defined(InspectorConsoleAgent_h) 120