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 "InspectorInstrumentationCookie.h"
37#include "InspectorOverlay.h"
38#include <inspector/InspectorAgentRegistry.h>
39#include <inspector/InspectorEnvironment.h>
40#include <wtf/Forward.h>
41#include <wtf/HashMap.h>
42#include <wtf/Noncopyable.h>
43#include <wtf/Vector.h>
44#include <wtf/text/WTFString.h>
45
46namespace Inspector {
47class InspectorAgent;
48class InspectorBackendDispatcher;
49class InspectorFrontendChannel;
50class InspectorProfilerAgent;
51class InspectorObject;
52}
53
54namespace WebCore {
55
56class DOMWrapperWorld;
57class Frame;
58class GraphicsContext;
59class InspectorClient;
60class InspectorDOMAgent;
61class InspectorDOMDebuggerAgent;
62class InspectorFrontendClient;
63class InspectorPageAgent;
64class InspectorResourceAgent;
65class InspectorTimelineAgent;
66class InstrumentingAgents;
67class Node;
68class Page;
69class PageDebuggerAgent;
70class WebInjectedScriptManager;
71
72class InspectorController final : public Inspector::InspectorEnvironment {
73    WTF_MAKE_NONCOPYABLE(InspectorController);
74    WTF_MAKE_FAST_ALLOCATED;
75public:
76    InspectorController(Page&, InspectorClient*);
77    virtual ~InspectorController();
78
79    void inspectedPageDestroyed();
80
81    bool enabled() const;
82    Page& inspectedPage() const;
83
84    void show();
85    void close();
86
87    void setInspectorFrontendClient(std::unique_ptr<InspectorFrontendClient>);
88    bool hasInspectorFrontendClient() const;
89    void didClearWindowObjectInWorld(Frame*, DOMWrapperWorld&);
90
91    void dispatchMessageFromFrontend(const String& message);
92
93    bool hasFrontend() const { return !!m_inspectorFrontendChannel; }
94    bool hasLocalFrontend() const;
95    bool hasRemoteFrontend() const;
96
97    void connectFrontend(Inspector::InspectorFrontendChannel*);
98    void disconnectFrontend(Inspector::InspectorDisconnectReason);
99    void setProcessId(long);
100
101#if ENABLE(REMOTE_INSPECTOR)
102    void setHasRemoteFrontend(bool hasRemote) { m_hasRemoteFrontend = hasRemote; }
103#endif
104
105    void inspect(Node*);
106    void drawHighlight(GraphicsContext&) const;
107    void getHighlight(Highlight*, InspectorOverlay::CoordinateSystem) const;
108    void hideHighlight();
109    Node* highlightedNode() const;
110
111    void setIndicating(bool);
112
113    PassRefPtr<Inspector::InspectorObject> buildObjectForHighlightedNode() const;
114
115    bool isUnderTest() const { return m_isUnderTest; }
116    void setIsUnderTest(bool isUnderTest) { m_isUnderTest = isUnderTest; }
117    void evaluateForTestInFrontend(const String& script);
118
119    bool profilerEnabled() const;
120    void setProfilerEnabled(bool);
121
122    void resume();
123
124    InspectorClient* inspectorClient() const { return m_inspectorClient; }
125    InspectorPageAgent* pageAgent() const { return m_pageAgent; }
126
127    virtual bool developerExtrasEnabled() const override;
128    virtual bool canAccessInspectedScriptState(JSC::ExecState*) const override;
129    virtual Inspector::InspectorFunctionCallHandler functionCallHandler() const override;
130    virtual Inspector::InspectorEvaluateHandler evaluateHandler() const override;
131    virtual void willCallInjectedScriptFunction(JSC::ExecState*, const String& scriptName, int scriptLine) override;
132    virtual void didCallInjectedScriptFunction(JSC::ExecState*) override;
133
134private:
135    friend InstrumentingAgents* instrumentationForPage(Page*);
136
137    RefPtr<InstrumentingAgents> m_instrumentingAgents;
138    std::unique_ptr<WebInjectedScriptManager> m_injectedScriptManager;
139    std::unique_ptr<InspectorOverlay> m_overlay;
140
141    Inspector::InspectorAgent* m_inspectorAgent;
142    InspectorDOMAgent* m_domAgent;
143    InspectorResourceAgent* m_resourceAgent;
144    InspectorPageAgent* m_pageAgent;
145    PageDebuggerAgent* m_debuggerAgent;
146    InspectorDOMDebuggerAgent* m_domDebuggerAgent;
147    Inspector::InspectorProfilerAgent* m_profilerAgent;
148    InspectorTimelineAgent* m_timelineAgent;
149
150    RefPtr<Inspector::InspectorBackendDispatcher> m_inspectorBackendDispatcher;
151    std::unique_ptr<InspectorFrontendClient> m_inspectorFrontendClient;
152    Inspector::InspectorFrontendChannel* m_inspectorFrontendChannel;
153    Page& m_page;
154    InspectorClient* m_inspectorClient;
155    Inspector::InspectorAgentRegistry m_agents;
156    Vector<InspectorInstrumentationCookie, 2> m_injectedScriptInstrumentationCookies;
157    bool m_isUnderTest;
158
159#if ENABLE(REMOTE_INSPECTOR)
160    bool m_hasRemoteFrontend;
161#endif
162};
163
164}
165
166#endif // ENABLE(INSPECTOR)
167
168#endif // !defined(InspectorController_h)
169