From 04b797ff0ceb410255e363295cf284a765acf69e Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Thu, 7 May 2015 17:12:40 +0530 Subject: [PATCH 1/2] webContents: providing response headers in did-get-response-details event --- atom/browser/api/atom_api_web_contents.cc | 8 +++++++- atom/renderer/lib/web-view/guest-view-internal.coffee | 3 ++- docs/api/browser-window.md | 2 ++ docs/api/web-view-tag.md | 2 ++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 5a91062340d..3ccb297514b 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -278,13 +278,19 @@ void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) { void WebContents::DidGetResourceResponseStart( const content::ResourceRequestDetails& details) { + auto context = AtomBrowserContext::Get(); + std::string headers; + if (context) + headers = context->GetNetworkDelegate()->GetResponseHeaders(details.url); + Emit("did-get-response-details", details.socket_address.IsEmpty(), details.url, details.original_url, details.http_response_code, details.method, - details.referrer); + details.referrer, + headers); } void WebContents::DidGetRedirectForResourceRequest( diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index fb1b40d27e1..218108ce377 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -10,7 +10,8 @@ WEB_VIEW_EVENTS = 'did-start-loading': [] 'did-stop-loading': [] 'did-get-response-details': ['status', 'newUrl', 'originalUrl', - 'httpResponseCode', 'requestMethod', 'referrer'] + 'httpResponseCode', 'requestMethod', 'referrer', + 'headers'] 'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame'] 'dom-ready': [] 'console-message': ['level', 'message', 'line', 'sourceId'] diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 9808e3abfd1..14740e929c4 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -666,9 +666,11 @@ Corresponds to the points in time when the spinner of the tab stops spinning. * `httpResponseCode` Integer * `requestMethod` String * `referrer` String +* `headers` String Emitted when details regarding a requested resource is available. `status` indicates the socket connection to download the resource. +`headers` is key-value string separated by new-line character. ### Event: 'did-get-redirect-request' diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 49c16fabae9..55f4ad77bfa 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -325,9 +325,11 @@ Corresponds to the points in time when the spinner of the tab stops spinning. * `httpResponseCode` Integer * `requestMethod` String * `referrer` String +* `headers` String Fired when details regarding a requested resource is available. `status` indicates socket connection to download the resource. +`headers` is key-value string separated by new-line character. ### did-get-redirect-request From e80e4ae02c2cda76cb2e8cdec44687df19c16608 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 20 May 2015 16:14:57 +0530 Subject: [PATCH 2/2] remove usage global browser context --- atom/browser/api/atom_api_web_contents.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 3ccb297514b..002739424f0 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -37,6 +37,7 @@ #include "native_mate/callback.h" #include "native_mate/dictionary.h" #include "native_mate/object_template_builder.h" +#include "net/url_request/url_request_context.h" #include "atom/common/node_includes.h" @@ -278,7 +279,8 @@ void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) { void WebContents::DidGetResourceResponseStart( const content::ResourceRequestDetails& details) { - auto context = AtomBrowserContext::Get(); + auto context = static_cast( + web_contents()->GetBrowserContext()); std::string headers; if (context) headers = context->GetNetworkDelegate()->GetResponseHeaders(details.url);