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 are
6 * met:
7 *
8 *     * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *     * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 *     * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef InspectorController_h
32#define InspectorController_h
33
34#if ENABLE(INSPECTOR)
35
36#include "InspectorBaseAgent.h"
37#include <wtf/Forward.h>
38#include <wtf/HashMap.h>
39#include <wtf/Noncopyable.h>
40#include <wtf/text/WTFString.h>
41
42namespace WebCore {
43
44class DOMWrapperWorld;
45class Frame;
46class GraphicsContext;
47class InjectedScriptManager;
48class InspectorAgent;
49class InspectorApplicationCacheAgent;
50class InspectorBackendDispatcher;
51class InspectorBaseAgentInterface;
52class InspectorClient;
53class InspectorDOMAgent;
54class InspectorDOMDebuggerAgent;
55class InspectorDebuggerAgent;
56class InspectorFrontend;
57class InspectorFrontendChannel;
58class InspectorFrontendClient;
59class InspectorMemoryAgent;
60class InspectorOverlay;
61class InspectorPageAgent;
62class InspectorProfilerAgent;
63class InspectorResourceAgent;
64class InspectorState;
65class InstrumentingAgents;
66class IntSize;
67class Page;
68class PostWorkerNotificationToFrontendTask;
69class Node;
70
71struct Highlight;
72
73class InspectorController {
74    WTF_MAKE_NONCOPYABLE(InspectorController);
75    WTF_MAKE_FAST_ALLOCATED;
76public:
77    ~InspectorController();
78
79    static PassOwnPtr<InspectorController> create(Page*, InspectorClient*);
80    void inspectedPageDestroyed();
81
82    bool enabled() const;
83    Page* inspectedPage() const;
84
85    void show();
86    void close();
87
88    void setInspectorFrontendClient(PassOwnPtr<InspectorFrontendClient>);
89    bool hasInspectorFrontendClient() const;
90    void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld*);
91    void setInjectedScriptForOrigin(const String& origin, const String& source);
92
93    void dispatchMessageFromFrontend(const String& message);
94
95    bool hasFrontend() const { return m_inspectorFrontend; }
96    void connectFrontend(InspectorFrontendChannel*);
97    void disconnectFrontend();
98    void reconnectFrontend(InspectorFrontendChannel*, const String& inspectorStateCookie);
99    void setProcessId(long);
100    void webViewResized(const IntSize&);
101
102    void inspect(Node*);
103    void drawHighlight(GraphicsContext&) const;
104    void getHighlight(Highlight*) const;
105    void hideHighlight();
106    Node* highlightedNode() const;
107
108    bool isUnderTest();
109    void evaluateForTestInFrontend(long callId, const String& script);
110
111#if ENABLE(JAVASCRIPT_DEBUGGER)
112    bool profilerEnabled();
113    void setProfilerEnabled(bool);
114
115    void resume();
116#endif
117
118    void setResourcesDataSizeLimitsFromInternals(int maximumResourcesContentSize, int maximumSingleResourceContentSize);
119
120    InspectorClient* inspectorClient() const { return m_inspectorClient; }
121    InspectorPageAgent* pageAgent() const { return m_pageAgent; }
122
123    void willProcessTask();
124    void didProcessTask();
125
126    void didBeginFrame();
127    void didCancelFrame();
128    void willComposite();
129    void didComposite();
130
131private:
132    InspectorController(Page*, InspectorClient*);
133
134    friend class PostWorkerNotificationToFrontendTask;
135    friend InstrumentingAgents* instrumentationForPage(Page*);
136
137    RefPtr<InstrumentingAgents> m_instrumentingAgents;
138    OwnPtr<InjectedScriptManager> m_injectedScriptManager;
139    OwnPtr<InspectorCompositeState> m_state;
140    OwnPtr<InspectorOverlay> m_overlay;
141
142    InspectorAgent* m_inspectorAgent;
143    InspectorDOMAgent* m_domAgent;
144    InspectorResourceAgent* m_resourceAgent;
145    InspectorPageAgent* m_pageAgent;
146    InspectorMemoryAgent* m_memoryAgent;
147#if ENABLE(JAVASCRIPT_DEBUGGER)
148    InspectorDebuggerAgent* m_debuggerAgent;
149    InspectorDOMDebuggerAgent* m_domDebuggerAgent;
150    InspectorProfilerAgent* m_profilerAgent;
151#endif
152
153    RefPtr<InspectorBackendDispatcher> m_inspectorBackendDispatcher;
154    OwnPtr<InspectorFrontendClient> m_inspectorFrontendClient;
155    OwnPtr<InspectorFrontend> m_inspectorFrontend;
156    Page* m_page;
157    InspectorClient* m_inspectorClient;
158    InspectorAgentRegistry m_agents;
159    bool m_isUnderTest;
160};
161
162}
163
164#endif // ENABLE(INSPECTOR)
165
166#endif // !defined(InspectorController_h)
167