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