1 | /* |
2 | * Copyright (C) 2014, 2015 Apple 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. ``AS IS'' AND ANY |
14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "InspectorAgentRegistry.h" |
29 | #include "InspectorEnvironment.h" |
30 | #include "InspectorFrontendRouter.h" |
31 | #include "JSGlobalObjectScriptDebugServer.h" |
32 | #include <wtf/Forward.h> |
33 | #include <wtf/Noncopyable.h> |
34 | #include <wtf/text/WTFString.h> |
35 | |
36 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
37 | #include "AugmentableInspectorController.h" |
38 | #endif |
39 | |
40 | namespace JSC { |
41 | class ConsoleClient; |
42 | class Exception; |
43 | class ExecState; |
44 | class JSGlobalObject; |
45 | } |
46 | |
47 | namespace Inspector { |
48 | |
49 | class BackendDispatcher; |
50 | class FrontendChannel; |
51 | class InjectedScriptManager; |
52 | class InspectorAgent; |
53 | class InspectorConsoleAgent; |
54 | class InspectorDebuggerAgent; |
55 | class InspectorScriptProfilerAgent; |
56 | class JSGlobalObjectConsoleClient; |
57 | class ScriptCallStack; |
58 | struct JSAgentContext; |
59 | |
60 | class JSGlobalObjectInspectorController final |
61 | : public InspectorEnvironment |
62 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
63 | , public AugmentableInspectorController |
64 | #endif |
65 | { |
66 | WTF_MAKE_NONCOPYABLE(JSGlobalObjectInspectorController); |
67 | WTF_MAKE_FAST_ALLOCATED; |
68 | public: |
69 | JSGlobalObjectInspectorController(JSC::JSGlobalObject&); |
70 | ~JSGlobalObjectInspectorController(); |
71 | |
72 | void connectFrontend(FrontendChannel&, bool isAutomaticInspection, bool immediatelyPause); |
73 | void disconnectFrontend(FrontendChannel&); |
74 | |
75 | void dispatchMessageFromFrontend(const String&); |
76 | |
77 | void globalObjectDestroyed(); |
78 | |
79 | bool includesNativeCallStackWhenReportingExceptions() const { return m_includeNativeCallStackWithExceptions; } |
80 | void setIncludesNativeCallStackWhenReportingExceptions(bool includesNativeCallStack) { m_includeNativeCallStackWithExceptions = includesNativeCallStack; } |
81 | |
82 | void reportAPIException(JSC::ExecState*, JSC::Exception*); |
83 | |
84 | JSC::ConsoleClient* consoleClient() const; |
85 | |
86 | bool () const override; |
87 | bool canAccessInspectedScriptState(JSC::ExecState*) const override { return true; } |
88 | InspectorFunctionCallHandler functionCallHandler() const override; |
89 | InspectorEvaluateHandler evaluateHandler() const override; |
90 | void frontendInitialized() override; |
91 | Ref<WTF::Stopwatch> executionStopwatch() override; |
92 | JSGlobalObjectScriptDebugServer& scriptDebugServer() override; |
93 | JSC::VM& vm() override; |
94 | |
95 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
96 | AugmentableInspectorControllerClient* augmentableInspectorControllerClient() const override { return m_augmentingClient; } |
97 | void setAugmentableInspectorControllerClient(AugmentableInspectorControllerClient* client) override { m_augmentingClient = client; } |
98 | |
99 | const FrontendRouter& frontendRouter() const override { return m_frontendRouter.get(); } |
100 | BackendDispatcher& backendDispatcher() override { return m_backendDispatcher.get(); } |
101 | void appendExtraAgent(std::unique_ptr<InspectorAgentBase>) override; |
102 | #endif |
103 | |
104 | private: |
105 | void appendAPIBacktrace(ScriptCallStack&); |
106 | |
107 | InspectorAgent& ensureInspectorAgent(); |
108 | InspectorDebuggerAgent& ensureDebuggerAgent(); |
109 | |
110 | JSAgentContext jsAgentContext(); |
111 | void createLazyAgents(); |
112 | |
113 | JSC::JSGlobalObject& m_globalObject; |
114 | std::unique_ptr<InjectedScriptManager> m_injectedScriptManager; |
115 | std::unique_ptr<JSGlobalObjectConsoleClient> m_consoleClient; |
116 | Ref<WTF::Stopwatch> m_executionStopwatch; |
117 | JSGlobalObjectScriptDebugServer m_scriptDebugServer; |
118 | |
119 | AgentRegistry m_agents; |
120 | InspectorConsoleAgent* m_consoleAgent { nullptr }; |
121 | |
122 | // Lazy, but also on-demand agents. |
123 | InspectorAgent* m_inspectorAgent { nullptr }; |
124 | InspectorDebuggerAgent* m_debuggerAgent { nullptr }; |
125 | |
126 | Ref<FrontendRouter> m_frontendRouter; |
127 | Ref<BackendDispatcher> m_backendDispatcher; |
128 | |
129 | // Used to keep the JSGlobalObject and VM alive while we are debugging it. |
130 | JSC::Strong<JSC::JSGlobalObject> m_strongGlobalObject; |
131 | RefPtr<JSC::VM> m_strongVM; |
132 | |
133 | bool m_includeNativeCallStackWithExceptions { true }; |
134 | bool m_isAutomaticInspection { false }; |
135 | bool m_pauseAfterInitialization { false }; |
136 | bool m_didCreateLazyAgents { false }; |
137 | |
138 | #if ENABLE(INSPECTOR_ALTERNATE_DISPATCHERS) |
139 | AugmentableInspectorControllerClient* m_augmentingClient { nullptr }; |
140 | #endif |
141 | }; |
142 | |
143 | } // namespace Inspector |
144 | |