Skip to content

Commit

Permalink
Revert "DevTools: roll third_party/inspector_protocol"
Browse files Browse the repository at this point in the history
This reverts commit 84b0216.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> DevTools: roll third_party/inspector_protocol
> 
> Bug: 929862
> 
> Change-Id: I3c12584095a1d2a45a3b6181bece071a2cd34dae
> Reviewed-on: https://chromium-review.googlesource.com/c/1460186
> Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
> Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#630185}

TBR=dgozman@chromium.org,pfeldman@chromium.org

Change-Id: I250784ec2a83b539b640a14188e17980c7a9e9ad
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 929862
Reviewed-on: https://chromium-review.googlesource.com/c/1460485
Reviewed-by: Pavel Feldman <pfeldman@chromium.org>
Commit-Queue: Pavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630188}
  • Loading branch information
pavelfeldman authored and Commit Bot committed Feb 8, 2019
1 parent 6f36ec2 commit 1832865
Show file tree
Hide file tree
Showing 27 changed files with 782 additions and 195 deletions.
4 changes: 2 additions & 2 deletions chrome/browser/devtools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ if (!is_android) {
import("$_inspector_protocol/inspector_protocol.gni")

_protocol_generated = [
"protocol/base_string_adapter.cc",
"protocol/base_string_adapter.h",
"protocol/browser.cc",
"protocol/browser.h",
"protocol/cast.cc",
Expand Down Expand Up @@ -208,6 +206,8 @@ static_library("devtools") {
"protocol/page_handler.h",
"protocol/target_handler.cc",
"protocol/target_handler.h",
"protocol_string.cc",
"protocol_string.h",
]
if (is_chromeos) {
sources += [
Expand Down
2 changes: 1 addition & 1 deletion chrome/browser/devtools/inspector_protocol_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"lib": {
"package": "chrome/browser/devtools/protocol",
"output": "protocol",
"string_header": "chrome/browser/devtools/protocol/base_string_adapter.h"
"string_header": "chrome/browser/devtools/protocol_string.h"
}
}
205 changes: 205 additions & 0 deletions chrome/browser/devtools/protocol_string.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/devtools/protocol_string.h"

#include <utility>
#include "base/base64.h"
#include "base/json/json_reader.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/devtools/protocol/protocol.h"

namespace protocol {

std::unique_ptr<protocol::Value> toProtocolValue(const base::Value* value,
int depth) {
if (!value || !depth)
return nullptr;
if (value->is_none())
return protocol::Value::null();
if (value->is_bool()) {
bool inner;
value->GetAsBoolean(&inner);
return protocol::FundamentalValue::create(inner);
}
if (value->is_int()) {
int inner;
value->GetAsInteger(&inner);
return protocol::FundamentalValue::create(inner);
}
if (value->is_double()) {
double inner;
value->GetAsDouble(&inner);
return protocol::FundamentalValue::create(inner);
}
if (value->is_string()) {
std::string inner;
value->GetAsString(&inner);
return protocol::StringValue::create(inner);
}
if (value->is_list()) {
const base::ListValue* list = nullptr;
value->GetAsList(&list);
std::unique_ptr<protocol::ListValue> result = protocol::ListValue::create();
for (size_t i = 0; i < list->GetSize(); i++) {
const base::Value* item = nullptr;
list->Get(i, &item);
std::unique_ptr<protocol::Value> converted =
toProtocolValue(item, depth - 1);
if (converted)
result->pushValue(std::move(converted));
}
return std::move(result);
}
if (value->is_dict()) {
const base::DictionaryValue* dictionary = nullptr;
value->GetAsDictionary(&dictionary);
std::unique_ptr<protocol::DictionaryValue> result =
protocol::DictionaryValue::create();
for (base::DictionaryValue::Iterator it(*dictionary); !it.IsAtEnd();
it.Advance()) {
std::unique_ptr<protocol::Value> converted =
toProtocolValue(&it.value(), depth - 1);
if (converted)
result->setValue(it.key(), std::move(converted));
}
return std::move(result);
}
return nullptr;
}

std::unique_ptr<base::Value> toBaseValue(protocol::Value* value, int depth) {
if (!value || !depth)
return nullptr;
if (value->type() == protocol::Value::TypeNull)
return std::make_unique<base::Value>();
if (value->type() == protocol::Value::TypeBoolean) {
bool inner;
value->asBoolean(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == protocol::Value::TypeInteger) {
int inner;
value->asInteger(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == protocol::Value::TypeDouble) {
double inner;
value->asDouble(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == protocol::Value::TypeString) {
std::string inner;
value->asString(&inner);
return base::WrapUnique(new base::Value(inner));
}
if (value->type() == protocol::Value::TypeArray) {
protocol::ListValue* list = protocol::ListValue::cast(value);
std::unique_ptr<base::ListValue> result(new base::ListValue());
for (size_t i = 0; i < list->size(); i++) {
std::unique_ptr<base::Value> converted =
toBaseValue(list->at(i), depth - 1);
if (converted)
result->Append(std::move(converted));
}
return std::move(result);
}
if (value->type() == protocol::Value::TypeObject) {
protocol::DictionaryValue* dict = protocol::DictionaryValue::cast(value);
std::unique_ptr<base::DictionaryValue> result(new base::DictionaryValue());
for (size_t i = 0; i < dict->size(); i++) {
protocol::DictionaryValue::Entry entry = dict->at(i);
std::unique_ptr<base::Value> converted =
toBaseValue(entry.second, depth - 1);
if (converted)
result->SetWithoutPathExpansion(entry.first, std::move(converted));
}
return std::move(result);
}
return nullptr;
}

// static
std::unique_ptr<protocol::Value> StringUtil::parseJSON(
const std::string& json) {
std::unique_ptr<base::Value> value = base::JSONReader::Read(json);
return toProtocolValue(value.get(), 1000);
}

StringBuilder::StringBuilder() {}

StringBuilder::~StringBuilder() {}

void StringBuilder::append(const std::string& s) {
string_ += s;
}

void StringBuilder::append(char c) {
string_ += c;
}

void StringBuilder::append(const char* characters, size_t length) {
string_.append(characters, length);
}

// static
void StringUtil::builderAppendQuotedString(StringBuilder& builder,
const String& str) {
builder.append('"');
base::string16 str16 = base::UTF8ToUTF16(str);
escapeWideStringForJSON(reinterpret_cast<const uint16_t*>(&str16[0]),
str16.length(), &builder);
builder.append('"');
}

std::string StringBuilder::toString() {
return string_;
}

void StringBuilder::reserveCapacity(size_t capacity) {
string_.reserve(capacity);
}

Binary::Binary() : bytes_(new base::RefCountedBytes) {}
Binary::Binary(const Binary& binary) : bytes_(binary.bytes_) {}
Binary::Binary(scoped_refptr<base::RefCountedMemory> bytes) : bytes_(bytes) {}
Binary::~Binary() {}

String Binary::toBase64() const {
std::string encoded;
base::Base64Encode(
base::StringPiece(reinterpret_cast<const char*>(bytes_->front()),
bytes_->size()),
&encoded);
return encoded;
}

// static
Binary Binary::fromBase64(const String& base64, bool* success) {
std::string decoded;
*success = base::Base64Decode(base::StringPiece(base64), &decoded);
if (*success) {
return Binary::fromString(std::move(decoded));
}
return Binary();
}

// static
Binary Binary::fromRefCounted(scoped_refptr<base::RefCountedMemory> memory) {
return Binary(memory);
}

// static
Binary Binary::fromVector(std::vector<uint8_t> data) {
return Binary(base::RefCountedBytes::TakeVector(&data));
}

// static
Binary Binary::fromString(std::string data) {
return Binary(base::RefCountedString::TakeString(&data));
}
} // namespace protocol
115 changes: 115 additions & 0 deletions chrome/browser/devtools/protocol_string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_DEVTOOLS_PROTOCOL_STRING_H_
#define CHROME_BROWSER_DEVTOOLS_PROTOCOL_STRING_H_

#include <memory>
#include <string>
#include <vector>

#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ref_counted_memory.h"
#include "base/strings/string_number_conversions.h"

namespace base {
class Value;
}

namespace protocol {

class Value;

using String = std::string;

class StringBuilder {
public:
StringBuilder();
~StringBuilder();
void append(const String&);
void append(char);
void append(const char*, size_t);
String toString();
void reserveCapacity(size_t);

private:
std::string string_;
};

class StringUtil {
public:
static String substring(const String& s, unsigned pos, unsigned len) {
return s.substr(pos, len);
}
static String fromInteger(int number) { return base::NumberToString(number); }
static String fromDouble(double number) {
String s = base::NumberToString(number);
if (!s.empty() && s[0] == '.')
s = "0" + s;
return s;
}
static double toDouble(const char* s, size_t len, bool* ok) {
double v = 0.0;
*ok = base::StringToDouble(std::string(s, len), &v);
return *ok ? v : 0.0;
}
static size_t find(const String& s, const char* needle) {
return s.find(needle);
}
static size_t find(const String& s, const String& needle) {
return s.find(needle);
}
static const size_t kNotFound = static_cast<size_t>(-1);
static void builderAppend(StringBuilder& builder, const String& s) {
builder.append(s);
}
static void builderAppend(StringBuilder& builder, char c) {
builder.append(c);
}
static void builderAppend(StringBuilder& builder, const char* s, size_t len) {
builder.append(s, len);
}
static void builderAppendQuotedString(StringBuilder& builder,
const String& str);
static void builderReserve(StringBuilder& builder, unsigned capacity) {
builder.reserveCapacity(capacity);
}
static String builderToString(StringBuilder& builder) {
return builder.toString();
}

static std::unique_ptr<protocol::Value> parseJSON(const String&);
};

// A read-only sequence of uninterpreted bytes with reference-counted storage.
class Binary {
public:
Binary(const Binary&);
Binary();
~Binary();

const uint8_t* data() const { return bytes_->front(); }
size_t size() const { return bytes_->size(); }
scoped_refptr<base::RefCountedMemory> bytes() const { return bytes_; }

String toBase64() const;

static Binary fromBase64(const String& base64, bool* success);
static Binary fromRefCounted(scoped_refptr<base::RefCountedMemory> memory);
static Binary fromVector(std::vector<uint8_t> data);
static Binary fromString(std::string data);

private:
explicit Binary(scoped_refptr<base::RefCountedMemory> bytes);
scoped_refptr<base::RefCountedMemory> bytes_;
};

std::unique_ptr<protocol::Value> toProtocolValue(const base::Value* value,
int depth);
std::unique_ptr<base::Value> toBaseValue(protocol::Value* value, int depth);

} // namespace protocol

#endif // CHROME_BROWSER_DEVTOOLS_PROTOCOL_STRING_H_
4 changes: 2 additions & 2 deletions content/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,6 @@ jumbo_source_set("browser") {
]

sources = [
"$target_gen_dir/devtools/protocol/base_string_adapter.cc",
"$target_gen_dir/devtools/protocol/base_string_adapter.h",
"$target_gen_dir/devtools/protocol/browser.cc",
"$target_gen_dir/devtools/protocol/browser.h",
"$target_gen_dir/devtools/protocol/dom.cc",
Expand Down Expand Up @@ -722,6 +720,8 @@ jumbo_source_set("browser") {
"devtools/protocol/tethering_handler.h",
"devtools/protocol/tracing_handler.cc",
"devtools/protocol/tracing_handler.h",
"devtools/protocol_string.cc",
"devtools/protocol_string.h",
"devtools/render_frame_devtools_agent_host.cc",
"devtools/render_frame_devtools_agent_host.h",
"devtools/service_worker_devtools_agent_host.cc",
Expand Down
4 changes: 1 addition & 3 deletions content/browser/devtools/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//tools/grit/grit_rule.gni")
import("//third_party/brotli/brotli.gni")
import("//third_party/inspector_protocol/inspector_protocol.gni")
import("//tools/grit/grit_rule.gni")

group("resources") {
if (!is_android) {
Expand Down Expand Up @@ -75,8 +75,6 @@ inspector_protocol_generate("protocol_sources") {

# These are relative to $target_gen_dir.
outputs = [
"protocol/base_string_adapter.cc",
"protocol/base_string_adapter.h",
"protocol/browser.cc",
"protocol/browser.h",
"protocol/dom.cc",
Expand Down
2 changes: 1 addition & 1 deletion content/browser/devtools/protocol_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"lib": {
"package": "content/browser/devtools/protocol",
"output": "protocol",
"string_header": "content/browser/devtools/protocol/base_string_adapter.h",
"string_header": "content/browser/devtools/protocol_string.h",
"export_macro": "CONTENT_EXPORT",
"export_header": "content/common/content_export.h"
}
Expand Down
Loading

0 comments on commit 1832865

Please sign in to comment.