Index: content/browser/devtools/devtools_http_handler.cc |
diff --git a/content/browser/devtools/devtools_http_handler.cc b/content/browser/devtools/devtools_http_handler.cc |
index 7f06067c4027bdfad4d5cb598bc4dbb44db21958..81eda4cf756bd4c9c2d6edacfd51e1f19d3ec09f 100644 |
--- a/content/browser/devtools/devtools_http_handler.cc |
+++ b/content/browser/devtools/devtools_http_handler.cc |
@@ -14,6 +14,7 @@ |
#include "base/json/json_writer.h" |
#include "base/location.h" |
#include "base/logging.h" |
+#include "base/memory/ref_counted_memory.h" |
#include "base/single_thread_task_runner.h" |
#include "base/strings/string_number_conversions.h" |
#include "base/strings/string_util.h" |
@@ -23,10 +24,12 @@ |
#include "build/build_config.h" |
#include "content/browser/devtools/devtools_http_handler.h" |
#include "content/browser/devtools/devtools_manager.h" |
+#include "content/browser/devtools/grit/devtools_resources.h" |
#include "content/public/browser/browser_thread.h" |
#include "content/public/browser/devtools_external_agent_proxy_delegate.h" |
#include "content/public/browser/devtools_manager_delegate.h" |
#include "content/public/browser/devtools_socket_factory.h" |
+#include "content/public/common/content_client.h" |
#include "content/public/common/url_constants.h" |
#include "content/public/common/user_agent.h" |
#include "net/base/escape.h" |
@@ -37,6 +40,7 @@ |
#include "net/server/http_server_request_info.h" |
#include "net/server/http_server_response_info.h" |
#include "net/socket/server_socket.h" |
+#include "third_party/brotli/include/brotli/decode.h" |
#include "v8/include/v8-version-string.h" |
#if defined(OS_ANDROID) |
@@ -534,6 +538,11 @@ void DevToolsHttpHandler::OnJsonRequest( |
return; |
} |
+ if (command == "protocol") { |
+ DecompressAndSendJsonProtocol(connection_id); |
+ return; |
+ } |
+ |
if (command == "list") { |
DevToolsManager* manager = DevToolsManager::GetInstance(); |
DevToolsAgentHost::List list = |
@@ -607,6 +616,47 @@ void DevToolsHttpHandler::OnJsonRequest( |
return; |
} |
+void DevToolsHttpHandler::DecompressAndSendJsonProtocol(int connection_id) { |
+ scoped_refptr<base::RefCountedMemory> raw_bytes = |
+ GetContentClient()->GetDataResourceBytes(COMPRESSED_PROTOCOL_JSON); |
+ const uint8_t* next_encoded_byte = raw_bytes->front(); |
+ size_t input_size_remaining = raw_bytes->size(); |
+ BrotliDecoderState* decoder = BrotliDecoderCreateInstance( |
+ nullptr /* no custom allocator */, nullptr /* no custom deallocator */, |
+ nullptr /* no custom memory handle */); |
+ CHECK(!!decoder); |
+ std::vector<std::string> decoded_parts; |
+ size_t decompressed_size = 0; |
+ while (!BrotliDecoderIsFinished(decoder)) { |
+ size_t output_size_remaining = 0; |
+ CHECK(BrotliDecoderDecompressStream( |
+ decoder, &input_size_remaining, &next_encoded_byte, |
+ &output_size_remaining, nullptr, |
+ nullptr) != BROTLI_DECODER_RESULT_ERROR); |
+ const uint8_t* output_buffer = |
+ BrotliDecoderTakeOutput(decoder, &output_size_remaining); |
+ decoded_parts.emplace_back(reinterpret_cast<const char*>(output_buffer), |
+ output_size_remaining); |
+ decompressed_size += output_size_remaining; |
+ } |
+ BrotliDecoderDestroyInstance(decoder); |
+ |
+ // Ideally we'd use a StringBuilder here but there isn't one in base/. |
+ std::string json_protocol; |
+ json_protocol.reserve(decompressed_size); |
+ for (const std::string& part : decoded_parts) { |
+ json_protocol.append(part); |
+ } |
+ |
+ net::HttpServerResponseInfo response(net::HTTP_OK); |
+ response.SetBody(json_protocol, "application/json; charset=UTF-8"); |
+ |
+ thread_->task_runner()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ServerWrapper::SendResponse, |
+ base::Unretained(server_wrapper_), connection_id, response)); |
+} |
+ |
void DevToolsHttpHandler::RespondToJsonList( |
int connection_id, |
const std::string& host, |