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 "bindings/core/v8/ScriptState.h"
     29 #include "bindings/core/v8/ScriptString.h"
     30 #include "core/InspectorFrontend.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 blink {
     42 
     43 class ConsoleMessage;
     44 class ConsoleMessageStorage;
     45 class DocumentLoader;
     46 class LocalDOMWindow;
     47 class LocalFrame;
     48 class InspectorConsoleMessage;
     49 class InspectorFrontend;
     50 class InjectedScriptManager;
     51 class InspectorTimelineAgent;
     52 class InstrumentingAgents;
     53 class ResourceError;
     54 class ResourceLoader;
     55 class ResourceResponse;
     56 class ScriptArguments;
     57 class ScriptCallStack;
     58 class ScriptProfile;
     59 class ThreadableLoaderClient;
     60 class WorkerGlobalScopeProxy;
     61 class XMLHttpRequest;
     62 
     63 typedef String ErrorString;
     64 
     65 class InspectorConsoleAgent : public InspectorBaseAgent<InspectorConsoleAgent>, public InspectorBackendDispatcher::ConsoleCommandHandler {
     66     WTF_MAKE_NONCOPYABLE(InspectorConsoleAgent);
     67 public:
     68     InspectorConsoleAgent(InspectorTimelineAgent*, InjectedScriptManager*);
     69     virtual ~InspectorConsoleAgent();
     70     virtual void trace(Visitor*) OVERRIDE;
     71 
     72     virtual void init() OVERRIDE;
     73     virtual void enable(ErrorString*) OVERRIDE FINAL;
     74     virtual void disable(ErrorString*) OVERRIDE FINAL;
     75     virtual void clearMessages(ErrorString*) OVERRIDE;
     76     bool enabled() { return m_enabled; }
     77 
     78     virtual void setFrontend(InspectorFrontend*) OVERRIDE FINAL;
     79     virtual void clearFrontend() OVERRIDE FINAL;
     80     virtual void restore() OVERRIDE FINAL;
     81 
     82     void addMessageToConsole(ConsoleMessage*);
     83     void consoleMessagesCleared();
     84 
     85     void setTracingBasedTimeline(ErrorString*, bool enabled);
     86     void consoleTimeline(ExecutionContext*, const String& title, ScriptState*);
     87     void consoleTimelineEnd(ExecutionContext*, const String& title, ScriptState*);
     88 
     89     void frameWindowDiscarded(LocalDOMWindow*);
     90     void didCommitLoad(LocalFrame*, DocumentLoader*);
     91 
     92     void didFinishXHRLoading(XMLHttpRequest*, ThreadableLoaderClient*, unsigned long requestIdentifier, ScriptString, const AtomicString& method, const String& url, const String& sendURL, unsigned sendLineNumber);
     93     void didFailLoading(unsigned long requestIdentifier, const ResourceError&);
     94     void addProfileFinishedMessageToConsole(PassRefPtrWillBeRawPtr<ScriptProfile>, unsigned lineNumber, const String& sourceURL);
     95     void addStartProfilingMessageToConsole(const String& title, unsigned lineNumber, const String& sourceURL);
     96     virtual void setMonitoringXHREnabled(ErrorString*, bool enabled) OVERRIDE;
     97     virtual void addInspectedNode(ErrorString*, int nodeId) = 0;
     98     virtual void addInspectedHeapObject(ErrorString*, int inspectedHeapObjectId) OVERRIDE;
     99 
    100     virtual bool isWorkerAgent() = 0;
    101 
    102 protected:
    103     void sendConsoleMessageToFrontend(ConsoleMessage*, bool generatePreview);
    104     virtual ConsoleMessageStorage* messageStorage() = 0;
    105 
    106     RawPtrWillBeMember<InspectorTimelineAgent> m_timelineAgent;
    107     RawPtrWillBeMember<InjectedScriptManager> m_injectedScriptManager;
    108     InspectorFrontend::Console* m_frontend;
    109     bool m_enabled;
    110 private:
    111     static int s_enabledAgentCount;
    112 };
    113 
    114 } // namespace blink
    115 
    116 
    117 #endif // !defined(InspectorConsoleAgent_h)
    118