diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 9791a94bb77..79f359ae8d7 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -120,6 +120,33 @@ struct Converter { } }; +template<> +struct Converter { + static v8::Local ToV8(v8::Isolate* isolate, + net::HttpResponseHeaders* headers) { + base::DictionaryValue response_headers; + if (headers) { + void* iter = nullptr; + std::string key; + std::string 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()); + } + } + } + return ConvertToV8(isolate, response_headers); + } +}; + } // namespace mate @@ -131,7 +158,7 @@ namespace { v8::Persistent template_; -// The wrapWebContents funtion which is implemented in JavaScript +// The wrapWebContents function which is implemented in JavaScript using WrapWebContentsCallback = base::Callback)>; WrapWebContentsCallback g_wrap_web_contents; @@ -414,30 +441,6 @@ void WebContents::DidStopLoading() { void WebContents::DidGetResourceResponseStart( const content::ResourceRequestDetails& details) { - v8::Locker locker(isolate()); - v8::HandleScope handle_scope(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->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(), details.url, @@ -445,7 +448,7 @@ void WebContents::DidGetResourceResponseStart( details.http_response_code, details.method, details.referrer, - response_headers); + details.headers.get()); } void WebContents::DidGetRedirectForResourceRequest( @@ -454,7 +457,11 @@ void WebContents::DidGetRedirectForResourceRequest( Emit("did-get-redirect-request", details.url, details.new_url, - (details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME)); + (details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME), + details.http_response_code, + details.method, + details.referrer, + details.headers.get()); } void WebContents::DidNavigateMainFrame( diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index e8f72cd24bf..f971c569eee 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -78,6 +78,10 @@ Returns: * `oldUrl` String * `newUrl` String * `isMainFrame` Boolean +* `httpResponseCode` Integer +* `requestMethod` String +* `referrer` String +* `headers` Object Emitted when a redirect is received while requesting a resource.