1/*
2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2015 Apple Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the
14 * distribution.
15 * * Neither the name of Google Inc. nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#pragma once
33
34#include "InspectorOverlay.h"
35#include "PageScriptDebugServer.h"
36#include <JavaScriptCore/InspectorAgentRegistry.h>
37#include <JavaScriptCore/InspectorEnvironment.h>
38#include <wtf/Forward.h>
39#include <wtf/Noncopyable.h>
40#include <wtf/text/WTFString.h>
41
42namespace Inspector {
43class BackendDispatcher;
44class FrontendChannel;
45class FrontendRouter;
46class InspectorAgent;
47}
48
49namespace WebCore {
50
51class DOMWrapperWorld;
52class Frame;
53class GraphicsContext;
54class InspectorClient;
55class InspectorDOMAgent;
56class InspectorFrontendClient;
57class InspectorInstrumentation;
58class InspectorPageAgent;
59class InstrumentingAgents;
60class Node;
61class Page;
62class WebInjectedScriptManager;
63struct PageAgentContext;
64
65class InspectorController final : public Inspector::InspectorEnvironment {
66 WTF_MAKE_NONCOPYABLE(InspectorController);
67 WTF_MAKE_FAST_ALLOCATED;
68public:
69 InspectorController(Page&, InspectorClient*);
70 virtual ~InspectorController();
71
72 void inspectedPageDestroyed();
73
74 bool enabled() const;
75 Page& inspectedPage() const;
76
77 WEBCORE_EXPORT void show();
78
79 WEBCORE_EXPORT void setInspectorFrontendClient(InspectorFrontendClient*);
80 unsigned inspectionLevel() const;
81 void didClearWindowObjectInWorld(Frame&, DOMWrapperWorld&);
82
83 WEBCORE_EXPORT void dispatchMessageFromFrontend(const String& message);
84
85 bool hasLocalFrontend() const;
86 bool hasRemoteFrontend() const;
87
88 WEBCORE_EXPORT void connectFrontend(Inspector::FrontendChannel&, bool isAutomaticInspection = false, bool immediatelyPause = false);
89 WEBCORE_EXPORT void disconnectFrontend(Inspector::FrontendChannel&);
90 WEBCORE_EXPORT void disconnectAllFrontends();
91
92 void inspect(Node*);
93 WEBCORE_EXPORT void drawHighlight(GraphicsContext&) const;
94 WEBCORE_EXPORT void getHighlight(Highlight&, InspectorOverlay::CoordinateSystem) const;
95 void hideHighlight();
96 Node* highlightedNode() const;
97
98 WEBCORE_EXPORT void setIndicating(bool);
99
100 WEBCORE_EXPORT void willComposite(Frame&);
101 WEBCORE_EXPORT void didComposite(Frame&);
102
103 bool isUnderTest() const { return m_isUnderTest; }
104 WEBCORE_EXPORT void setIsUnderTest(bool);
105 WEBCORE_EXPORT void evaluateForTestInFrontend(const String& script);
106
107 InspectorClient* inspectorClient() const { return m_inspectorClient; }
108 InspectorFrontendClient* inspectorFrontendClient() const { return m_inspectorFrontendClient; }
109
110 Inspector::InspectorAgent& ensureInspectorAgent();
111 InspectorDOMAgent& ensureDOMAgent();
112 WEBCORE_EXPORT InspectorPageAgent& ensurePageAgent();
113
114 // InspectorEnvironment
115 bool developerExtrasEnabled() const override;
116 bool canAccessInspectedScriptState(JSC::ExecState*) const override;
117 Inspector::InspectorFunctionCallHandler functionCallHandler() const override;
118 Inspector::InspectorEvaluateHandler evaluateHandler() const override;
119 void frontendInitialized() override;
120 Ref<WTF::Stopwatch> executionStopwatch() override;
121 PageScriptDebugServer& scriptDebugServer() override;
122 JSC::VM& vm() override;
123
124private:
125 friend class InspectorInstrumentation;
126
127 PageAgentContext pageAgentContext();
128 void createLazyAgents();
129
130 Ref<InstrumentingAgents> m_instrumentingAgents;
131 std::unique_ptr<WebInjectedScriptManager> m_injectedScriptManager;
132 Ref<Inspector::FrontendRouter> m_frontendRouter;
133 Ref<Inspector::BackendDispatcher> m_backendDispatcher;
134 std::unique_ptr<InspectorOverlay> m_overlay;
135 Ref<WTF::Stopwatch> m_executionStopwatch;
136 PageScriptDebugServer m_scriptDebugServer;
137 Inspector::AgentRegistry m_agents;
138
139 Page& m_page;
140 InspectorClient* m_inspectorClient;
141 InspectorFrontendClient* m_inspectorFrontendClient { nullptr };
142
143 // Lazy, but also on-demand agents.
144 Inspector::InspectorAgent* m_inspectorAgent { nullptr };
145 InspectorDOMAgent* m_inspectorDOMAgent { nullptr };
146 InspectorPageAgent* m_inspectorPageAgent { nullptr };
147
148 bool m_isUnderTest { false };
149 bool m_isAutomaticInspection { false };
150 bool m_pauseAfterInitialization = { false };
151 bool m_didCreateLazyAgents { false };
152};
153
154} // namespace WebCore
155