11cb0ef41Sopenharmony_ci/*
21cb0ef41Sopenharmony_ci * Copyright (C) 2011 Google Inc. All rights reserved.
31cb0ef41Sopenharmony_ci *
41cb0ef41Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
51cb0ef41Sopenharmony_ci * modification, are permitted provided that the following conditions are
61cb0ef41Sopenharmony_ci * met:
71cb0ef41Sopenharmony_ci *
81cb0ef41Sopenharmony_ci *     * Redistributions of source code must retain the above copyright
91cb0ef41Sopenharmony_ci * notice, this list of conditions and the following disclaimer.
101cb0ef41Sopenharmony_ci *     * Redistributions in binary form must reproduce the above
111cb0ef41Sopenharmony_ci * copyright notice, this list of conditions and the following disclaimer
121cb0ef41Sopenharmony_ci * in the documentation and/or other materials provided with the
131cb0ef41Sopenharmony_ci * distribution.
141cb0ef41Sopenharmony_ci *     * Neither the name of Google Inc. nor the names of its
151cb0ef41Sopenharmony_ci * contributors may be used to endorse or promote products derived from
161cb0ef41Sopenharmony_ci * this software without specific prior written permission.
171cb0ef41Sopenharmony_ci *
181cb0ef41Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
191cb0ef41Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
201cb0ef41Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
211cb0ef41Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
221cb0ef41Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
231cb0ef41Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
241cb0ef41Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
251cb0ef41Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
261cb0ef41Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
271cb0ef41Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
281cb0ef41Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
291cb0ef41Sopenharmony_ci */
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci#ifndef V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
321cb0ef41Sopenharmony_ci#define V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_ci#include <memory>
351cb0ef41Sopenharmony_ci#include <unordered_map>
361cb0ef41Sopenharmony_ci
371cb0ef41Sopenharmony_ci#include "include/v8-persistent-handle.h"
381cb0ef41Sopenharmony_ci#include "src/base/macros.h"
391cb0ef41Sopenharmony_ci#include "src/inspector/protocol/Forward.h"
401cb0ef41Sopenharmony_ci#include "src/inspector/protocol/Runtime.h"
411cb0ef41Sopenharmony_ci
421cb0ef41Sopenharmony_cinamespace v8 {
431cb0ef41Sopenharmony_ciclass Script;
441cb0ef41Sopenharmony_ci}  // namespace v8
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_cinamespace v8_inspector {
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciclass InjectedScript;
491cb0ef41Sopenharmony_ciclass InspectedContext;
501cb0ef41Sopenharmony_ciclass RemoteObjectIdBase;
511cb0ef41Sopenharmony_ciclass V8ConsoleMessage;
521cb0ef41Sopenharmony_ciclass V8InspectorImpl;
531cb0ef41Sopenharmony_ciclass V8InspectorSessionImpl;
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciusing protocol::Response;
561cb0ef41Sopenharmony_ciusing protocol::Maybe;
571cb0ef41Sopenharmony_ci
581cb0ef41Sopenharmony_ciclass V8RuntimeAgentImpl : public protocol::Runtime::Backend {
591cb0ef41Sopenharmony_ci public:
601cb0ef41Sopenharmony_ci  V8RuntimeAgentImpl(V8InspectorSessionImpl*, protocol::FrontendChannel*,
611cb0ef41Sopenharmony_ci                     protocol::DictionaryValue* state);
621cb0ef41Sopenharmony_ci  ~V8RuntimeAgentImpl() override;
631cb0ef41Sopenharmony_ci  V8RuntimeAgentImpl(const V8RuntimeAgentImpl&) = delete;
641cb0ef41Sopenharmony_ci  V8RuntimeAgentImpl& operator=(const V8RuntimeAgentImpl&) = delete;
651cb0ef41Sopenharmony_ci  void restore();
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ci  // Part of the protocol.
681cb0ef41Sopenharmony_ci  Response enable() override;
691cb0ef41Sopenharmony_ci  Response disable() override;
701cb0ef41Sopenharmony_ci  void evaluate(const String16& expression, Maybe<String16> objectGroup,
711cb0ef41Sopenharmony_ci                Maybe<bool> includeCommandLineAPI, Maybe<bool> silent,
721cb0ef41Sopenharmony_ci                Maybe<int> executionContextId, Maybe<bool> returnByValue,
731cb0ef41Sopenharmony_ci                Maybe<bool> generatePreview, Maybe<bool> userGesture,
741cb0ef41Sopenharmony_ci                Maybe<bool> awaitPromise, Maybe<bool> throwOnSideEffect,
751cb0ef41Sopenharmony_ci                Maybe<double> timeout, Maybe<bool> disableBreaks,
761cb0ef41Sopenharmony_ci                Maybe<bool> replMode, Maybe<bool> allowUnsafeEvalBlockedByCSP,
771cb0ef41Sopenharmony_ci                Maybe<String16> uniqueContextId,
781cb0ef41Sopenharmony_ci                Maybe<bool> generateWebDriverValue,
791cb0ef41Sopenharmony_ci                std::unique_ptr<EvaluateCallback>) override;
801cb0ef41Sopenharmony_ci  void awaitPromise(const String16& promiseObjectId, Maybe<bool> returnByValue,
811cb0ef41Sopenharmony_ci                    Maybe<bool> generatePreview,
821cb0ef41Sopenharmony_ci                    std::unique_ptr<AwaitPromiseCallback>) override;
831cb0ef41Sopenharmony_ci  void callFunctionOn(
841cb0ef41Sopenharmony_ci      const String16& expression, Maybe<String16> objectId,
851cb0ef41Sopenharmony_ci      Maybe<protocol::Array<protocol::Runtime::CallArgument>> optionalArguments,
861cb0ef41Sopenharmony_ci      Maybe<bool> silent, Maybe<bool> returnByValue,
871cb0ef41Sopenharmony_ci      Maybe<bool> generatePreview, Maybe<bool> userGesture,
881cb0ef41Sopenharmony_ci      Maybe<bool> awaitPromise, Maybe<int> executionContextId,
891cb0ef41Sopenharmony_ci      Maybe<String16> objectGroup, Maybe<bool> throwOnSideEffect,
901cb0ef41Sopenharmony_ci      Maybe<bool> generateWebDriverValue,
911cb0ef41Sopenharmony_ci      std::unique_ptr<CallFunctionOnCallback>) override;
921cb0ef41Sopenharmony_ci  Response releaseObject(const String16& objectId) override;
931cb0ef41Sopenharmony_ci  Response getProperties(
941cb0ef41Sopenharmony_ci      const String16& objectId, Maybe<bool> ownProperties,
951cb0ef41Sopenharmony_ci      Maybe<bool> accessorPropertiesOnly, Maybe<bool> generatePreview,
961cb0ef41Sopenharmony_ci      Maybe<bool> nonIndexedPropertiesOnly,
971cb0ef41Sopenharmony_ci      std::unique_ptr<protocol::Array<protocol::Runtime::PropertyDescriptor>>*
981cb0ef41Sopenharmony_ci          result,
991cb0ef41Sopenharmony_ci      Maybe<protocol::Array<protocol::Runtime::InternalPropertyDescriptor>>*
1001cb0ef41Sopenharmony_ci          internalProperties,
1011cb0ef41Sopenharmony_ci      Maybe<protocol::Array<protocol::Runtime::PrivatePropertyDescriptor>>*
1021cb0ef41Sopenharmony_ci          privateProperties,
1031cb0ef41Sopenharmony_ci      Maybe<protocol::Runtime::ExceptionDetails>*) override;
1041cb0ef41Sopenharmony_ci  Response releaseObjectGroup(const String16& objectGroup) override;
1051cb0ef41Sopenharmony_ci  Response runIfWaitingForDebugger() override;
1061cb0ef41Sopenharmony_ci  Response setCustomObjectFormatterEnabled(bool) override;
1071cb0ef41Sopenharmony_ci  Response setMaxCallStackSizeToCapture(int) override;
1081cb0ef41Sopenharmony_ci  Response discardConsoleEntries() override;
1091cb0ef41Sopenharmony_ci  Response compileScript(const String16& expression, const String16& sourceURL,
1101cb0ef41Sopenharmony_ci                         bool persistScript, Maybe<int> executionContextId,
1111cb0ef41Sopenharmony_ci                         Maybe<String16>*,
1121cb0ef41Sopenharmony_ci                         Maybe<protocol::Runtime::ExceptionDetails>*) override;
1131cb0ef41Sopenharmony_ci  void runScript(const String16&, Maybe<int> executionContextId,
1141cb0ef41Sopenharmony_ci                 Maybe<String16> objectGroup, Maybe<bool> silent,
1151cb0ef41Sopenharmony_ci                 Maybe<bool> includeCommandLineAPI, Maybe<bool> returnByValue,
1161cb0ef41Sopenharmony_ci                 Maybe<bool> generatePreview, Maybe<bool> awaitPromise,
1171cb0ef41Sopenharmony_ci                 std::unique_ptr<RunScriptCallback>) override;
1181cb0ef41Sopenharmony_ci  Response queryObjects(
1191cb0ef41Sopenharmony_ci      const String16& prototypeObjectId, Maybe<String16> objectGroup,
1201cb0ef41Sopenharmony_ci      std::unique_ptr<protocol::Runtime::RemoteObject>* objects) override;
1211cb0ef41Sopenharmony_ci  Response globalLexicalScopeNames(
1221cb0ef41Sopenharmony_ci      Maybe<int> executionContextId,
1231cb0ef41Sopenharmony_ci      std::unique_ptr<protocol::Array<String16>>* outNames) override;
1241cb0ef41Sopenharmony_ci  Response getIsolateId(String16* outIsolateId) override;
1251cb0ef41Sopenharmony_ci  Response getHeapUsage(double* out_usedSize, double* out_totalSize) override;
1261cb0ef41Sopenharmony_ci  void terminateExecution(
1271cb0ef41Sopenharmony_ci      std::unique_ptr<TerminateExecutionCallback> callback) override;
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci  Response addBinding(const String16& name, Maybe<int> executionContextId,
1301cb0ef41Sopenharmony_ci                      Maybe<String16> executionContextName) override;
1311cb0ef41Sopenharmony_ci  Response removeBinding(const String16& name) override;
1321cb0ef41Sopenharmony_ci  void addBindings(InspectedContext* context);
1331cb0ef41Sopenharmony_ci  Response getExceptionDetails(const String16& errorObjectId,
1341cb0ef41Sopenharmony_ci                               Maybe<protocol::Runtime::ExceptionDetails>*
1351cb0ef41Sopenharmony_ci                                   out_exceptionDetails) override;
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_ci  void reset();
1381cb0ef41Sopenharmony_ci  void reportExecutionContextCreated(InspectedContext*);
1391cb0ef41Sopenharmony_ci  void reportExecutionContextDestroyed(InspectedContext*);
1401cb0ef41Sopenharmony_ci  void inspect(std::unique_ptr<protocol::Runtime::RemoteObject> objectToInspect,
1411cb0ef41Sopenharmony_ci               std::unique_ptr<protocol::DictionaryValue> hints,
1421cb0ef41Sopenharmony_ci               int executionContextId);
1431cb0ef41Sopenharmony_ci  void messageAdded(V8ConsoleMessage*);
1441cb0ef41Sopenharmony_ci  bool enabled() const { return m_enabled; }
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci private:
1471cb0ef41Sopenharmony_ci  bool reportMessage(V8ConsoleMessage*, bool generatePreview);
1481cb0ef41Sopenharmony_ci
1491cb0ef41Sopenharmony_ci  static void bindingCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
1501cb0ef41Sopenharmony_ci  void bindingCalled(const String16& name, const String16& payload,
1511cb0ef41Sopenharmony_ci                     int executionContextId);
1521cb0ef41Sopenharmony_ci  void addBinding(InspectedContext* context, const String16& name);
1531cb0ef41Sopenharmony_ci
1541cb0ef41Sopenharmony_ci  V8InspectorSessionImpl* m_session;
1551cb0ef41Sopenharmony_ci  protocol::DictionaryValue* m_state;
1561cb0ef41Sopenharmony_ci  protocol::Runtime::Frontend m_frontend;
1571cb0ef41Sopenharmony_ci  V8InspectorImpl* m_inspector;
1581cb0ef41Sopenharmony_ci  bool m_enabled;
1591cb0ef41Sopenharmony_ci  std::unordered_map<String16, std::unique_ptr<v8::Global<v8::Script>>>
1601cb0ef41Sopenharmony_ci      m_compiledScripts;
1611cb0ef41Sopenharmony_ci  // Binding name -> executionContextIds mapping.
1621cb0ef41Sopenharmony_ci  std::unordered_map<String16, std::unordered_set<int>> m_activeBindings;
1631cb0ef41Sopenharmony_ci};
1641cb0ef41Sopenharmony_ci
1651cb0ef41Sopenharmony_ci}  // namespace v8_inspector
1661cb0ef41Sopenharmony_ci
1671cb0ef41Sopenharmony_ci#endif  // V8_INSPECTOR_V8_RUNTIME_AGENT_IMPL_H_
168