Fixing code review issues: function call formatting, renaming JS member variables, refactoring response headers conversion.

This commit is contained in:
ali.ibrahim 2016-10-13 17:14:23 +02:00
commit 6f5b0a28c5
9 changed files with 272 additions and 185 deletions

View file

@ -41,7 +41,7 @@ v8::Local<v8::Value> Net::URLRequest(v8::Isolate* isolate) {
void Net::RequestGarbageCollectionForTesting() {
isolate()->RequestGarbageCollectionForTesting(
v8::Isolate::GarbageCollectionType::kFullGarbageCollection);
v8::Isolate::GarbageCollectionType::kFullGarbageCollection);
}

View file

@ -16,38 +16,20 @@
namespace mate {
template<>
struct Converter<scoped_refptr<const net::HttpResponseHeaders>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
scoped_refptr<const net::HttpResponseHeaders> val) {
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
if (val) {
size_t iter = 0;
std::string name;
std::string value;
while (val->EnumerateHeaderLines(&iter, &name, &value)) {
dict.Set(name, value);
}
}
return dict.GetHandle();
}
};
template<>
struct Converter<scoped_refptr<const net::IOBufferWithSize>> {
static v8::Local<v8::Value> ToV8(
v8::Isolate* isolate,
scoped_refptr<const net::IOBufferWithSize> buffer) {
v8::Isolate* isolate,
scoped_refptr<const net::IOBufferWithSize> buffer) {
return node::Buffer::Copy(isolate,
buffer->data(),
buffer->size()).ToLocalChecked();
buffer->data(),
buffer->size()).ToLocalChecked();
}
static bool FromV8(
v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<const net::IOBufferWithSize>* out) {
v8::Isolate* isolate,
v8::Local<v8::Value> val,
scoped_refptr<const net::IOBufferWithSize>* out) {
auto size = node::Buffer::Length(val);
if (size == 0) {
@ -179,11 +161,8 @@ mate::WrappableBase* URLRequest::New(mate::Arguments* args) {
auto browser_context = session->browser_context();
auto api_url_request = new URLRequest(args->isolate(), args->GetThis());
auto weak_ptr = api_url_request->weak_ptr_factory_.GetWeakPtr();
auto atom_url_request = AtomURLRequest::Create(
browser_context,
method,
url,
weak_ptr);
auto atom_url_request = AtomURLRequest::Create(browser_context, method, url,
weak_ptr);
api_url_request->atom_request_ = atom_url_request;
@ -228,9 +207,9 @@ bool URLRequest::Write(
scoped_refptr<const net::IOBufferWithSize> buffer,
bool is_last) {
if (request_state_.Canceled() ||
request_state_.Failed() ||
request_state_.Finished() ||
request_state_.Closed()) {
request_state_.Failed() ||
request_state_.Finished() ||
request_state_.Closed()) {
return false;
}
@ -326,7 +305,7 @@ void URLRequest::SetChunkedUpload(bool is_chunked_upload) {
void URLRequest::OnAuthenticationRequired(
scoped_refptr<const net::AuthChallengeInfo> auth_info) {
if (request_state_.Canceled() ||
request_state_.Closed()) {
request_state_.Closed()) {
return;
}
@ -336,10 +315,10 @@ void URLRequest::OnAuthenticationRequired(
}
EmitRequestEvent(
false,
"login",
auth_info.get(),
base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_));
false,
"login",
auth_info.get(),
base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_));
}
void URLRequest::OnResponseStarted(
@ -373,9 +352,9 @@ void URLRequest::OnResponseData(
void URLRequest::OnResponseCompleted() {
if (request_state_.Canceled() ||
request_state_.Closed() ||
request_state_.Failed() ||
response_state_.Failed()) {
request_state_.Closed() ||
request_state_.Failed() ||
response_state_.Failed()) {
// In case we received an unexpected event from Chromium net,
// don't emit any data event after request cancel/error/close.
return;

View file

@ -35,10 +35,10 @@
#include "atom/common/native_mate_converters/gfx_converter.h"
#include "atom/common/native_mate_converters/gurl_converter.h"
#include "atom/common/native_mate_converters/image_converter.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "atom/common/options_switches.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "brightray/browser/inspectable_web_contents.h"
#include "brightray/browser/inspectable_web_contents_view.h"
@ -66,7 +66,6 @@
#include "content/public/common/context_menu_params.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request_context.h"
#include "third_party/WebKit/public/web/WebFindOptions.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
@ -141,32 +140,6 @@ struct Converter<WindowOpenDisposition> {
}
};
template<>
struct Converter<net::HttpResponseHeaders*> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
net::HttpResponseHeaders* headers) {
base::DictionaryValue response_headers;
if (headers) {
size_t iter = 0;
std::string key;
std::string value;
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
key = base::ToLowerASCII(key);
if (response_headers.HasKey(key)) {
base::ListValue* values = nullptr;
if (response_headers.GetList(key, &values))
values->AppendString(value);
} else {
std::unique_ptr<base::ListValue> values(new base::ListValue());
values->AppendString(value);
response_headers.Set(key, std::move(values));
}
}
}
return ConvertToV8(isolate, response_headers);
}
};
template<>
struct Converter<content::SavePageType> {
static bool FromV8(v8::Isolate* isolate, v8::Local<v8::Value> val,
@ -691,7 +664,7 @@ void WebContents::DidGetResourceResponseStart(
details.http_response_code,
details.method,
details.referrer,
details.headers.get(),
details.headers,
ResourceTypeToString(details.resource_type));
}
@ -705,7 +678,7 @@ void WebContents::DidGetRedirectForResourceRequest(
details.http_response_code,
details.method,
details.referrer,
details.headers.get());
details.headers);
}
void WebContents::DidFinishNavigation(