Skip to content

Commit

Permalink
Merge pull request electron#1386 from deepak1556/web_contents_patch
Browse files Browse the repository at this point in the history
webContents: event to detect status of requested resource
  • Loading branch information
zcbenz committed Apr 13, 2015
2 parents 91c9f59 + 15a648a commit 64f9f7e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 0 deletions.
11 changes: 11 additions & 0 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions atom/browser/api/atom_api_web_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions atom/browser/lib/guest-view-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 2 additions & 0 deletions atom/renderer/lib/web-view/guest-view-internal.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
13 changes: 13 additions & 0 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions docs/api/web-view-tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/api-browser-window-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 64f9f7e

Please sign in to comment.