• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_V8RUNTIMEAGENTIMPL_H_
32 #define V8_INSPECTOR_V8RUNTIMEAGENTIMPL_H_
33 
34 #include "src/base/macros.h"
35 #include "src/inspector/protocol/Forward.h"
36 #include "src/inspector/protocol/Runtime.h"
37 
38 #include "include/v8.h"
39 
40 namespace v8_inspector {
41 
42 class InjectedScript;
43 class InspectedContext;
44 class RemoteObjectIdBase;
45 class V8ConsoleMessage;
46 class V8InspectorImpl;
47 class V8InspectorSessionImpl;
48 
49 using protocol::Response;
50 using protocol::Maybe;
51 
52 class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
53  public:
54   V8RuntimeAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
55                      protocol::DictionaryValue* state);
56   ~V8RuntimeAgentImpl() override;
57   void restore();
58 
59   // Part of the protocol.
60   Response enable() override;
61   Response disable() override;
62   void evaluate(const String16& expression, Maybe<String16> objectGroup,
63                 Maybe<bool> includeCommandLineAPI, Maybe<bool> silent,
64                 Maybe<int> executionContextId, Maybe<bool> returnByValue,
65                 Maybe<bool> generatePreview, Maybe<bool> userGesture,
66                 Maybe<bool> awaitPromise,
67                 std::unique_ptr<EvaluateCallback>) override;
68   void awaitPromise(const String16& promiseObjectId, Maybe<bool> returnByValue,
69                     Maybe<bool> generatePreview,
70                     std::unique_ptr<AwaitPromiseCallback>) override;
71   void callFunctionOn(
72       const String16& objectId, const String16& expression,
73       Maybe<protocol::Array<protocol::Runtime::CallArgument>> optionalArguments,
74       Maybe<bool> silent, Maybe<bool> returnByValue,
75       Maybe<bool> generatePreview, Maybe<bool> userGesture,
76       Maybe<bool> awaitPromise,
77       std::unique_ptr<CallFunctionOnCallback>) override;
78   Response releaseObject(const String16& objectId) override;
79   Response getProperties(
80       const String16& objectId, Maybe<bool> ownProperties,
81       Maybe<bool> accessorPropertiesOnly, Maybe<bool> generatePreview,
82       std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>*
83           result,
84       Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>*
85           internalProperties,
86       Maybe<protocol::Runtime::ExceptionDetails>*) override;
87   Response releaseObjectGroup(const String16& objectGroup) override;
88   Response runIfWaitingForDebugger() override;
89   Response setCustomObjectFormatterEnabled(bool) override;
90   Response discardConsoleEntries() override;
91   Response compileScript(const String16& expression, const String16& sourceURL,
92                          bool persistScript, Maybe<int> executionContextId,
93                          Maybe<String16>*,
94                          Maybe<protocol::Runtime::ExceptionDetails>*) override;
95   void runScript(const String16&, Maybe<int> executionContextId,
96                  Maybe<String16> objectGroup, Maybe<bool> silent,
97                  Maybe<bool> includeCommandLineAPI, Maybe<bool> returnByValue,
98                  Maybe<bool> generatePreview, Maybe<bool> awaitPromise,
99                  std::unique_ptr<RunScriptCallback>) override;
100 
101   void reset();
102   void reportExecutionContextCreated(InspectedContext*);
103   void reportExecutionContextDestroyed(InspectedContext*);
104   void inspect(std::unique_ptr<protocol::Runtime::RemoteObject> objectToInspect,
105                std::unique_ptr<protocol::DictionaryValue> hints);
106   void messageAdded(V8ConsoleMessage*);
enabled()107   bool enabled() const { return m_enabled; }
108 
109  private:
110   bool reportMessage(V8ConsoleMessage*, bool generatePreview);
111 
112   V8InspectorSessionImpl* m_session;
113   protocol::DictionaryValue* m_state;
114   protocol::Runtime::Frontend m_frontend;
115   V8InspectorImpl* m_inspector;
116   bool m_enabled;
117   protocol::HashMap<String16, std::unique_ptr<v8::Global<v8::Script>>>
118       m_compiledScripts;
119 
120   DISALLOW_COPY_AND_ASSIGN(V8RuntimeAgentImpl);
121 };
122 
123 }  // namespace v8_inspector
124 
125 #endif  // V8_INSPECTOR_V8RUNTIMEAGENTIMPL_H_
126