Line data Source code
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 V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
32 : #define V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
33 :
34 : #include <unordered_map>
35 :
36 : #include "src/base/macros.h"
37 : #include "src/inspector/protocol/Forward.h"
38 : #include "src/inspector/protocol/Runtime.h"
39 :
40 : #include "include/v8.h"
41 :
42 : namespace v8_inspector {
43 :
44 : class InjectedScript;
45 : class InspectedContext;
46 : class RemoteObjectIdBase;
47 : class V8ConsoleMessage;
48 : class V8InspectorImpl;
49 : class V8InspectorSessionImpl;
50 :
51 : using protocol::Response;
52 : using protocol::Maybe;
53 :
54 7758 : class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
55 : public:
56 : V8RuntimeAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
57 : protocol::DictionaryValue* state);
58 : ~V8RuntimeAgentImpl() override;
59 : void restore();
60 :
61 : // Part of the protocol.
62 : Response enable() override;
63 : Response disable() override;
64 : void evaluate(const String16& expression, Maybe<String16> objectGroup,
65 : Maybe<bool> includeCommandLineAPI, Maybe<bool> silent,
66 : Maybe<int> executionContextId, Maybe<bool> returnByValue,
67 : Maybe<bool> generatePreview, Maybe<bool> userGesture,
68 : Maybe<bool> awaitPromise, Maybe<bool> throwOnSideEffect,
69 : Maybe<double> timeout,
70 : std::unique_ptr<EvaluateCallback>) override;
71 : void awaitPromise(const String16& promiseObjectId, Maybe<bool> returnByValue,
72 : Maybe<bool> generatePreview,
73 : std::unique_ptr<AwaitPromiseCallback>) override;
74 : void callFunctionOn(
75 : const String16& expression, Maybe<String16> objectId,
76 : Maybe<protocol::Array<protocol::Runtime::CallArgument>> optionalArguments,
77 : Maybe<bool> silent, Maybe<bool> returnByValue,
78 : Maybe<bool> generatePreview, Maybe<bool> userGesture,
79 : Maybe<bool> awaitPromise, Maybe<int> executionContextId,
80 : Maybe<String16> objectGroup,
81 : std::unique_ptr<CallFunctionOnCallback>) override;
82 : Response releaseObject(const String16& objectId) override;
83 : Response getProperties(
84 : const String16& objectId, Maybe<bool> ownProperties,
85 : Maybe<bool> accessorPropertiesOnly, Maybe<bool> generatePreview,
86 : std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>*
87 : result,
88 : Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>*
89 : internalProperties,
90 : Maybe<protocol::Array<protocol::Runtime::PrivatePropertyDescriptor>>*
91 : privateProperties,
92 : Maybe<protocol::Runtime::ExceptionDetails>*) override;
93 : Response releaseObjectGroup(const String16& objectGroup) override;
94 : Response runIfWaitingForDebugger() override;
95 : Response setCustomObjectFormatterEnabled(bool) override;
96 : Response setMaxCallStackSizeToCapture(int) override;
97 : Response discardConsoleEntries() override;
98 : Response compileScript(const String16& expression, const String16& sourceURL,
99 : bool persistScript, Maybe<int> executionContextId,
100 : Maybe<String16>*,
101 : Maybe<protocol::Runtime::ExceptionDetails>*) override;
102 : void runScript(const String16&, Maybe<int> executionContextId,
103 : Maybe<String16> objectGroup, Maybe<bool> silent,
104 : Maybe<bool> includeCommandLineAPI, Maybe<bool> returnByValue,
105 : Maybe<bool> generatePreview, Maybe<bool> awaitPromise,
106 : std::unique_ptr<RunScriptCallback>) override;
107 : Response queryObjects(
108 : const String16& prototypeObjectId, Maybe<String16> objectGroup,
109 : std::unique_ptr<protocol::Runtime::RemoteObject>* objects) override;
110 : Response globalLexicalScopeNames(
111 : Maybe<int> executionContextId,
112 : std::unique_ptr<protocol::Array<String16>>* outNames) override;
113 : Response getIsolateId(String16* outIsolateId) override;
114 : Response getHeapUsage(double* out_usedSize, double* out_totalSize) override;
115 : void terminateExecution(
116 : std::unique_ptr<TerminateExecutionCallback> callback) override;
117 :
118 : Response addBinding(const String16& name,
119 : Maybe<int> executionContextId) override;
120 : Response removeBinding(const String16& name) override;
121 : void addBindings(InspectedContext* context);
122 :
123 : void reset();
124 : void reportExecutionContextCreated(InspectedContext*);
125 : void reportExecutionContextDestroyed(InspectedContext*);
126 : void inspect(std::unique_ptr<protocol::Runtime::RemoteObject> objectToInspect,
127 : std::unique_ptr<protocol::DictionaryValue> hints);
128 : void messageAdded(V8ConsoleMessage*);
129 : bool enabled() const { return m_enabled; }
130 :
131 : private:
132 : bool reportMessage(V8ConsoleMessage*, bool generatePreview);
133 :
134 : static void bindingCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
135 : void bindingCalled(const String16& name, const String16& payload,
136 : int executionContextId);
137 : void addBinding(InspectedContext* context, const String16& name);
138 :
139 : V8InspectorSessionImpl* m_session;
140 : protocol::DictionaryValue* m_state;
141 : protocol::Runtime::Frontend m_frontend;
142 : V8InspectorImpl* m_inspector;
143 : bool m_enabled;
144 : std::unordered_map<String16, std::unique_ptr<v8::Global<v8::Script>>>
145 : m_compiledScripts;
146 :
147 : DISALLOW_COPY_AND_ASSIGN(V8RuntimeAgentImpl);
148 : };
149 :
150 : } // namespace v8_inspector
151 :
152 : #endif // V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
|