From 15a648a8793d53b9310d563b775421479c7f39d4 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Wed, 8 Apr 2015 19:14:47 +0530 Subject: [PATCH] webContents: event to detect status of requested resource --- atom/browser/api/atom_api_web_contents.cc | 11 +++++++++++ atom/browser/api/atom_api_web_contents.h | 2 ++ atom/browser/lib/guest-view-manager.coffee | 1 + .../lib/web-view/guest-view-internal.coffee | 2 ++ docs/api/browser-window.md | 13 +++++++++++++ docs/api/web-view-tag.md | 12 ++++++++++++ spec/api-browser-window-spec.coffee | 8 ++++++++ 7 files changed, 49 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 4c76f5349eb5..a6fd58674baa 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -224,6 +224,17 @@ void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) { Emit("did-stop-loading"); } +void WebContents::DidGetResourceResponseStart( + const content::ResourceRequestDetails& details) { + Emit("did-get-response-details", + details.socket_address.IsEmpty(), + details.url, + details.original_url, + details.http_response_code, + details.method, + details.referrer); +} + void WebContents::DidGetRedirectForResourceRequest( content::RenderFrameHost* render_frame_host, const content::ResourceRedirectDetails& details) { diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 8e0d12801a9a..9b2a9cd4e3e4 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -161,6 +161,8 @@ class WebContents : public mate::EventEmitter, const base::string16& error_description) override; void DidStartLoading(content::RenderViewHost* render_view_host) override; void DidStopLoading(content::RenderViewHost* render_view_host) override; + void DidGetResourceResponseStart( + const content::ResourceRequestDetails& details) override; void DidGetRedirectForResourceRequest( content::RenderFrameHost* render_frame_host, const content::ResourceRedirectDetails& details) override; diff --git a/atom/browser/lib/guest-view-manager.coffee b/atom/browser/lib/guest-view-manager.coffee index b7caac22ac6d..51fb9424670f 100644 --- a/atom/browser/lib/guest-view-manager.coffee +++ b/atom/browser/lib/guest-view-manager.coffee @@ -8,6 +8,7 @@ supportedWebViewEvents = [ 'did-frame-finish-load' 'did-start-loading' 'did-stop-loading' + 'did-get-response-details' 'did-get-redirect-request' 'console-message' 'new-window' diff --git a/atom/renderer/lib/web-view/guest-view-internal.coffee b/atom/renderer/lib/web-view/guest-view-internal.coffee index f150615b937a..345491030147 100644 --- a/atom/renderer/lib/web-view/guest-view-internal.coffee +++ b/atom/renderer/lib/web-view/guest-view-internal.coffee @@ -9,6 +9,8 @@ WEB_VIEW_EVENTS = 'did-frame-finish-load': ['isMainFrame'] 'did-start-loading': [] 'did-stop-loading': [] + 'did-get-response-details': ['status', 'newUrl', 'originalUrl', + 'httpResponseCode', 'requestMethod', 'referrer'] 'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame'] 'console-message': ['level', 'message', 'line', 'sourceId'] 'new-window': ['url', 'frameName', 'disposition'] diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 5eff0a874c4f..250c63888e1f 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -640,6 +640,19 @@ Corresponds to the points in time when the spinner of the tab starts spinning. Corresponds to the points in time when the spinner of the tab stops spinning. +### Event: 'did-get-response-details' + +* `event` Event +* `status` Boolean +* `newUrl` String +* `originalUrl` String +* `httpResponseCode` Integer +* `requestMethod` String +* `referrer` String + +Emitted when details regarding a requested resource is available. +`status` indicates the socket connection to download the resource. + ### Event: 'did-get-redirect-request' * `event` Event diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index b1fdf6449e90..1c2bc4b2a86f 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -302,6 +302,18 @@ Corresponds to the points in time when the spinner of the tab starts spinning. Corresponds to the points in time when the spinner of the tab stops spinning. +### did-get-response-details + +* `status` Boolean +* `newUrl` String +* `originalUrl` String +* `httpResponseCode` Integer +* `requestMethod` String +* `referrer` String + +Fired when details regarding a requested resource is available. +`status` indicates socket connection to download the resource. + ### did-get-redirect-request * `oldUrl` String diff --git a/spec/api-browser-window-spec.coffee b/spec/api-browser-window-spec.coffee index c723246d94fc..c63816651fad 100644 --- a/spec/api-browser-window-spec.coffee +++ b/spec/api-browser-window-spec.coffee @@ -221,3 +221,11 @@ describe 'browser-window module', -> assert.equal url, 'https://www.github.com/' done() w.loadUrl "file://#{fixtures}/pages/will-navigate.html" + + describe 'did-get-response-details', -> + it 'emits when user requests a resource', (done) -> + w.webContents.on 'did-get-response-details', (event, status, url) -> + assert.notEqual status + assert.equal url, "https://d4hwcs1zqtwzs.cloudfront.net/mac/GitHub%20for%20Mac%20204.zip" + done() + w.loadUrl "https://central.github.com/mac/latest"