feat: migrate webRequest module to NetworkService (Part 4) (#19679)
* chore: use gin in WebRequest * Add stubs for APIs
This commit is contained in:
parent
bc0a2d1b28
commit
2dffc9f6eb
7 changed files with 255 additions and 23 deletions
44
shell/common/gin_converters/callback_converter_gin_adapter.h
Normal file
44
shell/common/gin_converters/callback_converter_gin_adapter.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Copyright (c) 2019 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_COMMON_GIN_CONVERTERS_CALLBACK_CONVERTER_GIN_ADAPTER_H_
|
||||
#define SHELL_COMMON_GIN_CONVERTERS_CALLBACK_CONVERTER_GIN_ADAPTER_H_
|
||||
|
||||
#include "gin/converter.h"
|
||||
#include "shell/common/native_mate_converters/once_callback.h"
|
||||
|
||||
// TODO(zcbenz): Move the implementations from native_mate_converters to here.
|
||||
|
||||
namespace gin {
|
||||
|
||||
template <typename Sig>
|
||||
struct Converter<base::RepeatingCallback<Sig>> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const base::RepeatingCallback<Sig>& in) {
|
||||
return mate::ConvertToV8(isolate, in);
|
||||
}
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::RepeatingCallback<Sig>* out) {
|
||||
return mate::ConvertFromV8(isolate, val, out);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Sig>
|
||||
struct Converter<base::OnceCallback<Sig>> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
base::OnceCallback<Sig> in) {
|
||||
return mate::ConvertToV8(isolate, in);
|
||||
}
|
||||
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::OnceCallback<Sig>* out) {
|
||||
return mate::ConvertFromV8(isolate, val, out);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // SHELL_COMMON_GIN_CONVERTERS_CALLBACK_CONVERTER_GIN_ADAPTER_H_
|
52
shell/common/gin_converters/std_converter.h
Normal file
52
shell/common/gin_converters/std_converter.h
Normal file
|
@ -0,0 +1,52 @@
|
|||
// Copyright (c) 2019 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||
#define SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
||||
|
||||
#include <set>
|
||||
|
||||
#include "gin/converter.h"
|
||||
|
||||
namespace gin {
|
||||
|
||||
template <typename T>
|
||||
struct Converter<std::set<T>> {
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const std::set<T>& val) {
|
||||
v8::Local<v8::Array> result(
|
||||
v8::Array::New(isolate, static_cast<int>(val.size())));
|
||||
auto context = isolate->GetCurrentContext();
|
||||
typename std::set<T>::const_iterator it;
|
||||
int i;
|
||||
for (i = 0, it = val.begin(); it != val.end(); ++it, ++i)
|
||||
result->Set(context, i, Converter<T>::ToV8(isolate, *it)).Check();
|
||||
return result;
|
||||
}
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
std::set<T>* out) {
|
||||
if (!val->IsArray())
|
||||
return false;
|
||||
|
||||
auto context = isolate->GetCurrentContext();
|
||||
std::set<T> result;
|
||||
v8::Local<v8::Array> array(v8::Local<v8::Array>::Cast(val));
|
||||
uint32_t length = array->Length();
|
||||
for (uint32_t i = 0; i < length; ++i) {
|
||||
T item;
|
||||
if (!Converter<T>::FromV8(isolate,
|
||||
array->Get(context, i).ToLocalChecked(), &item))
|
||||
return false;
|
||||
result.insert(item);
|
||||
}
|
||||
|
||||
out->swap(result);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // SHELL_COMMON_GIN_CONVERTERS_STD_CONVERTER_H_
|
30
shell/common/gin_converters/value_converter_gin_adapter.h
Normal file
30
shell/common/gin_converters/value_converter_gin_adapter.h
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright (c) 2019 GitHub, Inc.
|
||||
// Use of this source code is governed by the MIT license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_
|
||||
#define SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_
|
||||
|
||||
#include "gin/converter.h"
|
||||
#include "shell/common/native_mate_converters/value_converter.h"
|
||||
|
||||
// TODO(zcbenz): Move the implementations from native_mate_converters to here.
|
||||
|
||||
namespace gin {
|
||||
|
||||
template <>
|
||||
struct Converter<base::Value> {
|
||||
static bool FromV8(v8::Isolate* isolate,
|
||||
v8::Local<v8::Value> val,
|
||||
base::Value* out) {
|
||||
return mate::ConvertFromV8(isolate, val, out);
|
||||
}
|
||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||
const base::Value& in) {
|
||||
return mate::ConvertToV8(isolate, in);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gin
|
||||
|
||||
#endif // SHELL_COMMON_GIN_CONVERTERS_VALUE_CONVERTER_GIN_ADAPTER_H_
|
Loading…
Add table
Add a link
Reference in a new issue