• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "Console.h"
29 #include "InspectorFrontend.h"
30 #include <wtf/Forward.h>
31 #include <wtf/HashMap.h>
32 #include <wtf/Noncopyable.h>
33 #include <wtf/text/StringHash.h>
34 #include <wtf/Vector.h>
35 
36 namespace WebCore {
37 
38 #if ENABLE(INSPECTOR)
39 
40 class ConsoleMessage;
41 class InspectorAgent;
42 class InspectorDOMAgent;
43 class InspectorFrontend;
44 class InspectorState;
45 class InjectedScriptManager;
46 class InstrumentingAgents;
47 class ResourceError;
48 class ResourceResponse;
49 class ScriptArguments;
50 class ScriptCallStack;
51 class ScriptProfile;
52 
53 typedef String ErrorString;
54 
55 class InspectorConsoleAgent {
56     WTF_MAKE_NONCOPYABLE(InspectorConsoleAgent);
57 public:
58     InspectorConsoleAgent(InstrumentingAgents*, InspectorAgent*, InspectorState*, InjectedScriptManager*, InspectorDOMAgent*);
59     ~InspectorConsoleAgent();
60 
61     void enable(ErrorString*, int* consoleMessageExpireCount);
62     void disable(ErrorString*);
63     void clearConsoleMessages(ErrorString* error);
64     void reset();
65     void setFrontend(InspectorFrontend*);
66     void clearFrontend();
67 
68     void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>);
69     void addMessageToConsole(MessageSource, MessageType, MessageLevel, const String& message, unsigned lineNumber, const String& sourceID);
70 
71     void startTiming(const String& title);
72     void stopTiming(const String& title, PassRefPtr<ScriptCallStack>);
73     void count(PassRefPtr<ScriptArguments>, PassRefPtr<ScriptCallStack>);
74 
75     void resourceRetrievedByXMLHttpRequest(const String& url, const String& sendURL, unsigned sendLineNumber);
76     void didReceiveResponse(unsigned long identifier, const ResourceResponse&);
77     void didFailLoading(unsigned long identifier, const ResourceError&);
78 #if ENABLE(JAVASCRIPT_DEBUGGER)
79     void addProfileFinishedMessageToConsole(PassRefPtr<ScriptProfile>, unsigned lineNumber, const String& sourceURL);
80     void addStartProfilingMessageToConsole(const String& title, unsigned lineNumber, const String& sourceURL);
81 #endif
82     void setMonitoringXHREnabled(ErrorString* error, bool enabled);
83     void addInspectedNode(ErrorString*, int nodeId);
84 
85 private:
86     void addConsoleMessage(PassOwnPtr<ConsoleMessage>);
87 
88     InstrumentingAgents* m_instrumentingAgents;
89     InspectorAgent* m_inspectorAgent;
90     InspectorState* m_inspectorState;
91     InjectedScriptManager* m_injectedScriptManager;
92     InspectorDOMAgent* m_inspectorDOMAgent;
93     InspectorFrontend::Console* m_frontend;
94     ConsoleMessage* m_previousMessage;
95     Vector<OwnPtr<ConsoleMessage> > m_consoleMessages;
96     int m_expiredConsoleMessageCount;
97     HashMap<String, unsigned> m_counts;
98     HashMap<String, double> m_times;
99 };
100 
101 #endif
102 
103 } // namespace WebCore
104 
105 #endif // !defined(InspectorConsoleAgent_h)
106