forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "DevTools: roll third_party/inspector_protocol"
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
1 parent
6f36ec2
commit 1832865
Showing
27 changed files
with
782 additions
and
195 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.