[DevTools] Generate public versions of protocol classes to be exposed in v8_inspector/public.

This includes RemoteObject, StackTrace and SearchMatch. Each API class has toJSONString() and fromJSONString() methods.
On embedder side, we also generate ValueConversions for public types, which allow opaque interoperability
between classes of two dependent protocols.

Added SerializedValue to store opaque string as is.

This patch allows to remove protocol::Value from public API of v8_inspector.

BUG=580337

Review-Url: https://codereview.chromium.org/2159633002
Cr-Original-Commit-Position: refs/heads/master@{#407375}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 4e19044900929958a03fc2d5c07cb2cc5aab47ff
diff --git a/InjectedScript.cpp b/InjectedScript.cpp
index 302b635..e1e825c 100644
--- a/InjectedScript.cpp
+++ b/InjectedScript.cpp
@@ -315,7 +315,7 @@
 
     v8::Local<v8::StackTrace> stackTrace = message->GetStackTrace();
     if (!stackTrace.IsEmpty() && stackTrace->GetFrameCount() > 0)
-        exceptionDetailsObject->setStackTrace(m_context->debugger()->createStackTrace(stackTrace)->buildInspectorObject());
+        exceptionDetailsObject->setStackTrace(m_context->debugger()->createStackTraceImpl(stackTrace)->buildInspectorObjectImpl());
     return exceptionDetailsObject;
 }
 
diff --git a/V8Console.cpp b/V8Console.cpp
index f7e142d..2440748 100644
--- a/V8Console.cpp
+++ b/V8Console.cpp
@@ -108,7 +108,7 @@
         if (!inspectedContext)
             return;
         V8DebuggerImpl* debugger = inspectedContext->debugger();
-        std::unique_ptr<V8ConsoleMessage> message = V8ConsoleMessage::createForConsoleAPI(debugger->client()->currentTimeMS(), type, arguments, debugger->captureStackTrace(false), inspectedContext);
+        std::unique_ptr<V8ConsoleMessage> message = V8ConsoleMessage::createForConsoleAPI(debugger->client()->currentTimeMS(), type, arguments, debugger->captureStackTraceImpl(false), inspectedContext);
         debugger->ensureConsoleMessageStorage(inspectedContext->contextGroupId())->addMessage(std::move(message));
     }
 
diff --git a/V8ConsoleMessage.cpp b/V8ConsoleMessage.cpp
index 42fe95b..6a57261 100644
--- a/V8ConsoleMessage.cpp
+++ b/V8ConsoleMessage.cpp
@@ -191,7 +191,7 @@
 {
 }
 
-void V8ConsoleMessage::setLocation(const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
+void V8ConsoleMessage::setLocation(const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTraceImpl> stackTrace, int scriptId)
 {
     m_url = url;
     m_lineNumber = lineNumber;
@@ -262,7 +262,7 @@
         if (!m_url.isEmpty())
             details->setUrl(m_url);
         if (m_stackTrace)
-            details->setStackTrace(m_stackTrace->buildInspectorObject());
+            details->setStackTrace(m_stackTrace->buildInspectorObjectImpl());
 
         std::unique_ptr<protocol::Runtime::RemoteObject> exception = wrapException(session, generatePreview);
 
@@ -286,7 +286,7 @@
                 arguments->addItem(std::move(messageArg));
             }
         }
-        frontend->consoleAPICalled(consoleAPITypeValue(m_type), std::move(arguments), m_contextId, m_timestamp, m_stackTrace ? m_stackTrace->buildInspectorObject() : nullptr);
+        frontend->consoleAPICalled(consoleAPITypeValue(m_type), std::move(arguments), m_contextId, m_timestamp, m_stackTrace ? m_stackTrace->buildInspectorObjectImpl() : nullptr);
         return;
     }
     NOTREACHED();
@@ -318,7 +318,7 @@
 }
 
 // static
-std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(double timestamp, ConsoleAPIType type, const std::vector<v8::Local<v8::Value>>& arguments, std::unique_ptr<V8StackTrace> stackTrace, InspectedContext* context)
+std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForConsoleAPI(double timestamp, ConsoleAPIType type, const std::vector<v8::Local<v8::Value>>& arguments, std::unique_ptr<V8StackTraceImpl> stackTrace, InspectedContext* context)
 {
     std::unique_ptr<V8ConsoleMessage> message = wrapUnique(new V8ConsoleMessage(V8MessageOrigin::kConsole, timestamp, String16()));
     if (stackTrace && !stackTrace->isEmpty()) {
@@ -349,7 +349,7 @@
 }
 
 // static
-std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(double timestamp, const String16& messageText, const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId, v8::Isolate* isolate, int contextId, v8::Local<v8::Value> exception, unsigned exceptionId)
+std::unique_ptr<V8ConsoleMessage> V8ConsoleMessage::createForException(double timestamp, const String16& messageText, const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTraceImpl> stackTrace, int scriptId, v8::Isolate* isolate, int contextId, v8::Local<v8::Value> exception, unsigned exceptionId)
 {
     std::unique_ptr<V8ConsoleMessage> message = wrapUnique(new V8ConsoleMessage(V8MessageOrigin::kException, timestamp, messageText));
     message->setLocation(url, lineNumber, columnNumber, std::move(stackTrace), scriptId);
diff --git a/V8ConsoleMessage.h b/V8ConsoleMessage.h
index 923a84e..9662ba9 100644
--- a/V8ConsoleMessage.h
+++ b/V8ConsoleMessage.h
@@ -10,7 +10,6 @@
 #include "platform/v8_inspector/protocol/Console.h"
 #include "platform/v8_inspector/protocol/Runtime.h"
 #include "platform/v8_inspector/public/V8ConsoleTypes.h"
-#include "platform/v8_inspector/public/V8StackTrace.h"
 #include <deque>
 #include <v8.h>
 
@@ -19,7 +18,7 @@
 class InspectedContext;
 class V8DebuggerImpl;
 class V8InspectorSessionImpl;
-class V8StackTrace;
+class V8StackTraceImpl;
 
 enum class V8MessageOrigin { kConsole, kException, kRevokedException };
 
@@ -33,7 +32,7 @@
         double timestamp,
         ConsoleAPIType,
         const std::vector<v8::Local<v8::Value>>& arguments,
-        std::unique_ptr<V8StackTrace>,
+        std::unique_ptr<V8StackTraceImpl>,
         InspectedContext*);
 
     static std::unique_ptr<V8ConsoleMessage> createForException(
@@ -42,7 +41,7 @@
         const String16& url,
         unsigned lineNumber,
         unsigned columnNumber,
-        std::unique_ptr<V8StackTrace>,
+        std::unique_ptr<V8StackTraceImpl>,
         int scriptId,
         v8::Isolate*,
         int contextId,
@@ -66,7 +65,7 @@
     using Arguments = std::vector<std::unique_ptr<v8::Global<v8::Value>>>;
     std::unique_ptr<protocol::Array<protocol::Runtime::RemoteObject>> wrapArguments(V8InspectorSessionImpl*, bool generatePreview) const;
     std::unique_ptr<protocol::Runtime::RemoteObject> wrapException(V8InspectorSessionImpl*, bool generatePreview) const;
-    void setLocation(const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace>, int scriptId);
+    void setLocation(const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTraceImpl>, int scriptId);
 
     V8MessageOrigin m_origin;
     double m_timestamp;
@@ -74,7 +73,7 @@
     String16 m_url;
     unsigned m_lineNumber;
     unsigned m_columnNumber;
-    std::unique_ptr<V8StackTrace> m_stackTrace;
+    std::unique_ptr<V8StackTraceImpl> m_stackTrace;
     int m_scriptId;
     int m_contextId;
     ConsoleAPIType m_type;
diff --git a/V8DebuggerAgentImpl.cpp b/V8DebuggerAgentImpl.cpp
index 2b232ef..7af2a5e 100644
--- a/V8DebuggerAgentImpl.cpp
+++ b/V8DebuggerAgentImpl.cpp
@@ -516,10 +516,15 @@
 {
     v8::HandleScope handles(m_isolate);
     ScriptsMap::iterator it = m_scripts.find(scriptId);
-    if (it != m_scripts.end())
-        *results = V8ContentSearchUtil::searchInTextByLines(m_session, toProtocolString(it->second->source(m_isolate)), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.fromMaybe(false));
-    else
+    if (it == m_scripts.end()) {
         *error = String16("No script for id: " + scriptId);
+        return;
+    }
+
+    std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = searchInTextByLinesImpl(m_session, toProtocolString(it->second->source(m_isolate)), query, optionalCaseSensitive.fromMaybe(false), optionalIsRegex.fromMaybe(false));
+    *results = protocol::Array<protocol::Debugger::SearchMatch>::create();
+    for (size_t i = 0; i < matches.size(); ++i)
+        (*results)->addItem(std::move(matches[i]));
 }
 
 void V8DebuggerAgentImpl::setScriptSource(ErrorString* errorString,
diff --git a/V8DebuggerImpl.cpp b/V8DebuggerImpl.cpp
index 4d84b32..d9db1a3 100644
--- a/V8DebuggerImpl.cpp
+++ b/V8DebuggerImpl.cpp
@@ -859,6 +859,11 @@
 
 std::unique_ptr<V8StackTrace> V8DebuggerImpl::createStackTrace(v8::Local<v8::StackTrace> stackTrace)
 {
+    return createStackTraceImpl(stackTrace);
+}
+
+std::unique_ptr<V8StackTraceImpl> V8DebuggerImpl::createStackTraceImpl(v8::Local<v8::StackTrace> stackTrace)
+{
     int contextGroupId = m_isolate->InContext() ? getGroupId(m_isolate->GetCurrentContext()) : 0;
     return V8StackTraceImpl::create(this, contextGroupId, stackTrace, V8StackTraceImpl::maxCallStackSizeToCapture);
 }
@@ -1069,13 +1074,14 @@
         arguments.push_back(arg1);
     if (!arg2.IsEmpty())
         arguments.push_back(arg2);
-    ensureConsoleMessageStorage(contextGroupId)->addMessage(V8ConsoleMessage::createForConsoleAPI(m_client->currentTimeMS(), ConsoleAPIType::kLog, arguments, captureStackTrace(false), inspectedContext));
+    ensureConsoleMessageStorage(contextGroupId)->addMessage(V8ConsoleMessage::createForConsoleAPI(m_client->currentTimeMS(), ConsoleAPIType::kLog, arguments, captureStackTraceImpl(false), inspectedContext));
 }
 
 void V8DebuggerImpl::exceptionThrown(int contextGroupId, const String16& errorMessage, const String16& url, unsigned lineNumber, unsigned columnNumber, std::unique_ptr<V8StackTrace> stackTrace, int scriptId)
 {
+    std::unique_ptr<V8StackTraceImpl> stackTraceImpl = wrapUnique(static_cast<V8StackTraceImpl*>(stackTrace.release()));
     unsigned exceptionId = ++m_lastExceptionId;
-    std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createForException(m_client->currentTimeMS(), errorMessage, url, lineNumber, columnNumber, std::move(stackTrace), scriptId, m_isolate, 0, v8::Local<v8::Value>(), exceptionId);
+    std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createForException(m_client->currentTimeMS(), errorMessage, url, lineNumber, columnNumber, std::move(stackTraceImpl), scriptId, m_isolate, 0, v8::Local<v8::Value>(), exceptionId);
     ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMessage));
 }
 
@@ -1084,8 +1090,9 @@
     int contextGroupId = getGroupId(context);
     if (!contextGroupId)
         return 0;
+    std::unique_ptr<V8StackTraceImpl> stackTraceImpl = wrapUnique(static_cast<V8StackTraceImpl*>(stackTrace.release()));
     unsigned exceptionId = ++m_lastExceptionId;
-    std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createForException(m_client->currentTimeMS(), errorMessage, url, lineNumber, columnNumber, std::move(stackTrace), scriptId, m_isolate, contextId(context), exception, exceptionId);
+    std::unique_ptr<V8ConsoleMessage> consoleMessage = V8ConsoleMessage::createForException(m_client->currentTimeMS(), errorMessage, url, lineNumber, columnNumber, std::move(stackTraceImpl), scriptId, m_isolate, contextId(context), exception, exceptionId);
     ensureConsoleMessageStorage(contextGroupId)->addMessage(std::move(consoleMessage));
     return exceptionId;
 }
@@ -1102,6 +1109,11 @@
 
 std::unique_ptr<V8StackTrace> V8DebuggerImpl::captureStackTrace(bool fullStack)
 {
+    return captureStackTraceImpl(fullStack);
+}
+
+std::unique_ptr<V8StackTraceImpl> V8DebuggerImpl::captureStackTraceImpl(bool fullStack)
+{
     if (!m_isolate->InContext())
         return nullptr;
 
diff --git a/V8DebuggerImpl.h b/V8DebuggerImpl.h
index 0be86bf..7994685 100644
--- a/V8DebuggerImpl.h
+++ b/V8DebuggerImpl.h
@@ -120,6 +120,8 @@
     void enableStackCapturingIfNeeded();
     void disableStackCapturingIfNeeded();
     V8ConsoleMessageStorage* ensureConsoleMessageStorage(int contextGroupId);
+    std::unique_ptr<V8StackTraceImpl> createStackTraceImpl(v8::Local<v8::StackTrace>);
+    std::unique_ptr<V8StackTraceImpl> captureStackTraceImpl(bool fullStack);
 
     // V8Debugger implementation
     std::unique_ptr<V8InspectorSession> connect(int contextGroupId, protocol::FrontendChannel*, V8InspectorSessionClient*, const String16* state) override;
diff --git a/V8InspectorSessionImpl.cpp b/V8InspectorSessionImpl.cpp
index fc13b3d..db89ba4 100644
--- a/V8InspectorSessionImpl.cpp
+++ b/V8InspectorSessionImpl.cpp
@@ -209,6 +209,11 @@
     return objectValue;
 }
 
+std::unique_ptr<protocol::Runtime::API::RemoteObject> V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16& groupName)
+{
+    return wrapObject(context, value, groupName, false);
+}
+
 std::unique_ptr<protocol::Runtime::RemoteObject> V8InspectorSessionImpl::wrapObject(v8::Local<v8::Context> context, v8::Local<v8::Value> value, const String16& groupName, bool generatePreview)
 {
     ErrorString errorString;
diff --git a/V8InspectorSessionImpl.h b/V8InspectorSessionImpl.h
index 21753da..888c3d7 100644
--- a/V8InspectorSessionImpl.h
+++ b/V8InspectorSessionImpl.h
@@ -48,6 +48,8 @@
     void discardInjectedScripts();
     void reportAllContexts(V8RuntimeAgentImpl*);
     void setCustomObjectFormatterEnabled(bool);
+    std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName, bool generatePreview);
+    std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable(v8::Local<v8::Context>, v8::Local<v8::Value> table, v8::Local<v8::Value> columns);
 
     // V8InspectorSession implementation.
     void dispatchProtocolMessage(const String16& message) override;
@@ -61,8 +63,7 @@
     void stepOver() override;
     void releaseObjectGroup(const String16& objectGroup) override;
     v8::Local<v8::Value> findObject(ErrorString*, const String16& objectId, v8::Local<v8::Context>* = nullptr, String16* groupName = nullptr) override;
-    std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName, bool generatePreview) override;
-    std::unique_ptr<protocol::Runtime::RemoteObject> wrapTable(v8::Local<v8::Context>, v8::Local<v8::Value> table, v8::Local<v8::Value> columns);
+    std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName) override;
 
     V8InspectorSession::Inspectable* inspectedObject(unsigned num);
     static const unsigned kInspectedObjectBufferSize = 5;
diff --git a/V8StackTraceImpl.cpp b/V8StackTraceImpl.cpp
index 343234c..8221c3a 100644
--- a/V8StackTraceImpl.cpp
+++ b/V8StackTraceImpl.cpp
@@ -227,7 +227,7 @@
     return m_frames[0].m_scriptId;
 }
 
-std::unique_ptr<protocol::Runtime::StackTrace> V8StackTraceImpl::buildInspectorObject() const
+std::unique_ptr<protocol::Runtime::StackTrace> V8StackTraceImpl::buildInspectorObjectImpl() const
 {
     std::unique_ptr<protocol::Array<protocol::Runtime::CallFrame>> frames = protocol::Array<protocol::Runtime::CallFrame>::create();
     for (size_t i = 0; i < m_frames.size(); i++)
@@ -238,7 +238,7 @@
     if (!m_description.isEmpty())
         stackTrace->setDescription(m_description);
     if (m_parent)
-        stackTrace->setParent(m_parent->buildInspectorObject());
+        stackTrace->setParent(m_parent->buildInspectorObjectImpl());
     return stackTrace;
 }
 
@@ -249,7 +249,12 @@
     std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create(debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), V8StackTraceImpl::maxCallStackSizeToCapture);
     if (!fullChain || !fullChain->m_parent)
         return nullptr;
-    return fullChain->m_parent->buildInspectorObject();
+    return fullChain->m_parent->buildInspectorObjectImpl();
+}
+
+std::unique_ptr<protocol::Runtime::API::StackTrace> V8StackTraceImpl::buildInspectorObject() const
+{
+    return buildInspectorObjectImpl();
 }
 
 String16 V8StackTraceImpl::toString() const
diff --git a/V8StackTraceImpl.h b/V8StackTraceImpl.h
index 63b59e8..c9f3137 100644
--- a/V8StackTraceImpl.h
+++ b/V8StackTraceImpl.h
@@ -5,7 +5,9 @@
 #ifndef V8StackTraceImpl_h
 #define V8StackTraceImpl_h
 
+#include "platform/inspector_protocol/Allocator.h"
 #include "platform/inspector_protocol/Platform.h"
+#include "platform/v8_inspector/protocol/Runtime.h"
 #include "platform/v8_inspector/public/V8StackTrace.h"
 
 #include <vector>
@@ -57,6 +59,7 @@
     std::unique_ptr<V8StackTrace> isolatedCopy() override;
     std::unique_ptr<V8StackTraceImpl> isolatedCopyImpl();
     std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectForTail(V8DebuggerImpl*) const;
+    std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl() const;
     ~V8StackTraceImpl() override;
 
     // V8StackTrace implementation.
@@ -66,7 +69,7 @@
     int topColumnNumber() const override;
     String16 topScriptId() const override;
     String16 topFunctionName() const override;
-    std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject() const override;
+    std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject() const override;
     String16 toString() const override;
 
 private:
diff --git a/V8StringUtil.cpp b/V8StringUtil.cpp
index 4ba7898..843c7c0 100644
--- a/V8StringUtil.cpp
+++ b/V8StringUtil.cpp
@@ -182,6 +182,17 @@
     return toProtocolString(value.As<v8::String>());
 }
 
+std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> searchInTextByLinesImpl(V8InspectorSession* session, const String16& text, const String16& query, const bool caseSensitive, const bool isRegex)
+{
+    std::unique_ptr<V8Regex> regex = createSearchRegex(static_cast<V8InspectorSessionImpl*>(session)->debugger(), query, caseSensitive, isRegex);
+    std::vector<std::pair<int, String16>> matches = scriptRegexpMatchesByLines(*regex.get(), text);
+
+    std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> result;
+    for (const auto& match : matches)
+        result.push_back(buildObjectForSearchMatch(match.first, match.second));
+    return result;
+}
+
 namespace V8ContentSearchUtil {
 
 String16 findSourceURL(const String16& content, bool multiline, bool* deprecated)
@@ -194,15 +205,12 @@
     return findMagicComment(content, "sourceMappingURL", multiline, deprecated);
 }
 
-std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextByLines(V8InspectorSession* session, const String16& text, const String16& query, const bool caseSensitive, const bool isRegex)
+std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> searchInTextByLines(V8InspectorSession* session, const String16& text, const String16& query, const bool caseSensitive, const bool isRegex)
 {
-    std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>> result = protocol::Array<protocol::Debugger::SearchMatch>::create();
-    std::unique_ptr<V8Regex> regex = createSearchRegex(static_cast<V8InspectorSessionImpl*>(session)->debugger(), query, caseSensitive, isRegex);
-    std::vector<std::pair<int, String16>> matches = scriptRegexpMatchesByLines(*regex.get(), text);
-
-    for (const auto& match : matches)
-        result->addItem(buildObjectForSearchMatch(match.first, match.second));
-
+    std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = searchInTextByLinesImpl(session, text, query, caseSensitive, isRegex);
+    std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> result = protocol::Array<protocol::Debugger::API::SearchMatch>::create();
+    for (size_t i = 0; i < matches.size(); ++i)
+        result->addItem(std::move(matches[i]));
     return result;
 }
 
diff --git a/V8StringUtil.h b/V8StringUtil.h
index 2d42613..47e5018 100644
--- a/V8StringUtil.h
+++ b/V8StringUtil.h
@@ -7,10 +7,13 @@
 
 #include "platform/inspector_protocol/String16.h"
 #include "platform/inspector_protocol/Values.h"
+#include "platform/v8_inspector/protocol/Debugger.h"
 #include <v8.h>
 
 namespace blink {
 
+class V8InspectorSession;
+
 std::unique_ptr<protocol::Value> toProtocolValue(v8::Local<v8::Context>, v8::Local<v8::Value>, int maxDepth = protocol::Value::maxDepth);
 
 v8::Local<v8::String> toV8String(v8::Isolate*, const String16&);
@@ -19,6 +22,8 @@
 String16 toProtocolString(v8::Local<v8::String>);
 String16 toProtocolStringWithTypeCheck(v8::Local<v8::Value>);
 
+std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> searchInTextByLinesImpl(V8InspectorSession*, const String16& text, const String16& query, const bool caseSensitive, const bool isRegex);
+
 } //  namespace blink
 
 
diff --git a/js_protocol.json b/js_protocol.json
index 78548bc..387ef9a 100644
--- a/js_protocol.json
+++ b/js_protocol.json
@@ -18,6 +18,7 @@
                 "id": "RemoteObject",
                 "type": "object",
                 "description": "Mirror object referencing original JavaScript object.",
+                "exported": true,
                 "properties": [
                     { "name": "type", "type": "string", "enum": ["object", "function", "undefined", "string", "number", "boolean", "symbol"], "description": "Object type." },
                     { "name": "subtype", "type": "string", "optional": true, "enum": ["array", "null", "node", "regexp", "date", "map", "set", "iterator", "generator", "error"], "description": "Object subtype hint. Specified for <code>object</code> type values only." },
@@ -166,6 +167,7 @@
                 "id": "StackTrace",
                 "type": "object",
                 "description": "Call frames for assertions or error messages.",
+                "exported": true,
                 "properties": [
                     { "name": "description", "type": "string", "optional": true, "description": "String label of this stack trace. For async traces this may be a name of the function that initiated the async call." },
                     { "name": "callFrames", "type": "array", "items": { "$ref": "CallFrame" }, "description": "JavaScript function name." },
@@ -427,6 +429,7 @@
                 "id": "SearchMatch",
                 "type": "object",
                 "description": "Search match for resource.",
+                "exported": true,
                 "properties": [
                     { "name": "lineNumber", "type": "number", "description": "Line number in resource content." },
                     { "name": "lineContent", "type": "string", "description": "Line with match content." }
@@ -700,7 +703,7 @@
                 "name": "paused",
                 "parameters": [
                     { "name": "callFrames", "type": "array", "items": { "$ref": "CallFrame" }, "description": "Call stack the virtual machine stopped on." },
-                    { "name": "reason", "type": "string", "enum": [ "XHR", "DOM", "EventListener", "exception", "assert", "debugCommand", "promiseRejection", "other" ], "description": "Pause reason." },
+                    { "name": "reason", "type": "string", "enum": [ "XHR", "DOM", "EventListener", "exception", "assert", "debugCommand", "promiseRejection", "other" ], "description": "Pause reason.", "exported": true },
                     { "name": "data", "type": "object", "optional": true, "description": "Object containing break-specific auxiliary properties." },
                     { "name": "hitBreakpoints", "type": "array", "optional": true, "items": { "type": "string" }, "description": "Hit breakpoints IDs", "hidden": true },
                     { "name": "asyncStackTrace", "$ref": "Runtime.StackTrace", "optional": true, "description": "Async stack trace, if any.", "hidden": true }
diff --git a/public/V8ContentSearchUtil.h b/public/V8ContentSearchUtil.h
index a932b7a..0faaf78 100644
--- a/public/V8ContentSearchUtil.h
+++ b/public/V8ContentSearchUtil.h
@@ -7,7 +7,7 @@
 
 #include "platform/inspector_protocol/Platform.h"
 #include "platform/inspector_protocol/String16.h"
-#include "platform/v8_inspector/protocol/Debugger.h"
+#include "platform/v8_inspector/public/protocol/Debugger.h"
 
 namespace blink {
 
@@ -17,7 +17,7 @@
 
 PLATFORM_EXPORT String16 findSourceURL(const String16& content, bool multiline, bool* deprecated = nullptr);
 PLATFORM_EXPORT String16 findSourceMapURL(const String16& content, bool multiline, bool* deprecated = nullptr);
-PLATFORM_EXPORT std::unique_ptr<protocol::Array<protocol::Debugger::SearchMatch>> searchInTextByLines(V8InspectorSession*, const String16& text, const String16& query, const bool caseSensitive, const bool isRegex);
+PLATFORM_EXPORT std::unique_ptr<protocol::Array<protocol::Debugger::API::SearchMatch>> searchInTextByLines(V8InspectorSession*, const String16& text, const String16& query, const bool caseSensitive, const bool isRegex);
 
 }
 
diff --git a/public/V8InspectorSession.h b/public/V8InspectorSession.h
index 2103467..6d3caae 100644
--- a/public/V8InspectorSession.h
+++ b/public/V8InspectorSession.h
@@ -6,7 +6,7 @@
 #define V8InspectorSession_h
 
 #include "platform/inspector_protocol/Platform.h"
-#include "platform/v8_inspector/protocol/Runtime.h"
+#include "platform/v8_inspector/public/protocol/Runtime.h"
 
 #include <v8.h>
 
@@ -40,7 +40,7 @@
 
     // Remote objects.
     static const char backtraceObjectGroup[];
-    virtual std::unique_ptr<protocol::Runtime::RemoteObject> wrapObject(v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName, bool generatePreview) = 0;
+    virtual std::unique_ptr<protocol::Runtime::API::RemoteObject> wrapObject(v8::Local<v8::Context>, v8::Local<v8::Value>, const String16& groupName) = 0;
     virtual v8::Local<v8::Value> findObject(ErrorString*, const String16& objectId, v8::Local<v8::Context>* = nullptr, String16* objectGroup = nullptr) = 0;
     virtual void releaseObjectGroup(const String16&) = 0;
 };
diff --git a/public/V8StackTrace.h b/public/V8StackTrace.h
index beee115..2935eef 100644
--- a/public/V8StackTrace.h
+++ b/public/V8StackTrace.h
@@ -7,7 +7,7 @@
 
 #include "platform/inspector_protocol/Platform.h"
 #include "platform/inspector_protocol/String16.h"
-#include "platform/v8_inspector/protocol/Runtime.h"
+#include "platform/v8_inspector/public/protocol/Runtime.h"
 
 #include <v8.h>
 
@@ -24,7 +24,7 @@
     virtual String16 topFunctionName() const = 0;
 
     virtual ~V8StackTrace() { }
-    virtual std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject() const = 0;
+    virtual std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject() const = 0;
     virtual String16 toString() const = 0;
     virtual std::unique_ptr<V8StackTrace> clone() = 0;
     virtual std::unique_ptr<V8StackTrace> isolatedCopy() = 0; // Safe to pass between threads.
diff --git a/v8_inspector.gyp b/v8_inspector.gyp
index 48e7ee1..60ac3c0 100644
--- a/v8_inspector.gyp
+++ b/v8_inspector.gyp
@@ -79,6 +79,8 @@
             # Source code templates.
             '../inspector_protocol/TypeBuilder_h.template',
             '../inspector_protocol/TypeBuilder_cpp.template',
+            '../inspector_protocol/Exported_h.template',
+            '../inspector_protocol/Imported_h.template',
             # Protocol definitions
             'js_protocol.json',
           ],
@@ -93,6 +95,8 @@
             '<(blink_platform_output_dir)/v8_inspector/protocol/Profiler.h',
             '<(blink_platform_output_dir)/v8_inspector/protocol/Runtime.cpp',
             '<(blink_platform_output_dir)/v8_inspector/protocol/Runtime.h',
+            '<(blink_platform_output_dir)/v8_inspector/public/protocol/Runtime.h',
+            '<(blink_platform_output_dir)/v8_inspector/public/protocol/Debugger.h',
           ],
           'action': [
             'python',
@@ -102,6 +106,8 @@
             '--export_macro', 'PLATFORM_EXPORT',
             '--output_dir', '<(blink_platform_output_dir)/v8_inspector/protocol',
             '--output_package', 'platform/v8_inspector/protocol',
+            '--exported_dir', '<(blink_platform_output_dir)/v8_inspector/public/protocol',
+            '--exported_package', 'platform/v8_inspector/public/protocol',
           ],
           'message': 'Generating protocol backend sources from json definitions.',
         },