From 64e84b8f6ab125549fd00f5d015233da1e9493b9 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Fri, 5 Jun 2015 13:24:47 +0800 Subject: [PATCH] Support multiple-line headers in web-contents `did-get-response-details' event. --- atom/browser/api/atom_api_web_contents.cc | 20 ++++++++++++++++---- .../common/native_mate_converters/value_converter.cc | 7 +++++++ atom/common/native_mate_converters/value_converter.h | 4 +++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index e06d2b2..8664822 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -345,15 +345,27 @@ void WebContents::DidGetResourceResponseStart( v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::Locker locker(isolate); v8::HandleScope handle_scope(isolate); - mate::Dictionary response_headers(isolate, v8::Object::New(isolate)); + base::DictionaryValue response_headers; net::HttpResponseHeaders* headers = details.headers.get(); + if (!headers) + return; void* iter = nullptr; std::string key; std::string value; - while (headers && headers->EnumerateHeaderLines(&iter, &key, &value)) - response_headers.Set(base::StringToLowerASCII(key), - base::StringToLowerASCII(value)); + while (headers->EnumerateHeaderLines(&iter, &key, &value)) { + key = base::StringToLowerASCII(key); + value = base::StringToLowerASCII(value); + if (response_headers.HasKey(key)) { + base::ListValue* values = nullptr; + if (response_headers.GetList(key, &values)) + values->AppendString(value); + } else { + scoped_ptr values(new base::ListValue()); + values->AppendString(value); + response_headers.Set(key, values.Pass()); + } + } Emit("did-get-response-details", details.socket_address.IsEmpty(), diff --git a/atom/common/native_mate_converters/value_converter.cc b/atom/common/native_mate_converters/value_converter.cc index 815ba0e..c9c1a86 100644 --- a/atom/common/native_mate_converters/value_converter.cc +++ b/atom/common/native_mate_converters/value_converter.cc @@ -23,6 +23,13 @@ bool Converter::FromV8(v8::Isolate* isolate, } } +v8::Local Converter::ToV8( + v8::Isolate* isolate, + const base::DictionaryValue& val) { + scoped_ptr converter(new atom::V8ValueConverter); + return converter->ToV8Value(&val, isolate->GetCurrentContext()); +} + bool Converter::FromV8(v8::Isolate* isolate, v8::Local val, base::ListValue* out) { diff --git a/atom/common/native_mate_converters/value_converter.h b/atom/common/native_mate_converters/value_converter.h index bb0ef66..013dd99 100644 --- a/atom/common/native_mate_converters/value_converter.h +++ b/atom/common/native_mate_converters/value_converter.h @@ -19,6 +19,8 @@ struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Local val, base::DictionaryValue* out); + static v8::Local ToV8(v8::Isolate* isolate, + const base::DictionaryValue& val); }; template<> @@ -27,7 +29,7 @@ struct Converter { v8::Local val, base::ListValue* out); static v8::Local ToV8(v8::Isolate* isolate, - const base::ListValue& val); + const base::ListValue& val); }; } // namespace mate -- 2.7.4