Merge pull request #1386 from deepak1556/web_contents_patch

webContents: event to detect status of requested resource
This commit is contained in:
Cheng Zhao 2015-04-13 11:59:37 +08:00
commit 64f9f7e906
7 changed files with 49 additions and 0 deletions

View file

@ -224,6 +224,17 @@ void WebContents::DidStopLoading(content::RenderViewHost* render_view_host) {
Emit("did-stop-loading"); 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( void WebContents::DidGetRedirectForResourceRequest(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const content::ResourceRedirectDetails& details) { const content::ResourceRedirectDetails& details) {

View file

@ -161,6 +161,8 @@ class WebContents : public mate::EventEmitter,
const base::string16& error_description) override; const base::string16& error_description) override;
void DidStartLoading(content::RenderViewHost* render_view_host) override; void DidStartLoading(content::RenderViewHost* render_view_host) override;
void DidStopLoading(content::RenderViewHost* render_view_host) override; void DidStopLoading(content::RenderViewHost* render_view_host) override;
void DidGetResourceResponseStart(
const content::ResourceRequestDetails& details) override;
void DidGetRedirectForResourceRequest( void DidGetRedirectForResourceRequest(
content::RenderFrameHost* render_frame_host, content::RenderFrameHost* render_frame_host,
const content::ResourceRedirectDetails& details) override; const content::ResourceRedirectDetails& details) override;

View file

@ -8,6 +8,7 @@ supportedWebViewEvents = [
'did-frame-finish-load' 'did-frame-finish-load'
'did-start-loading' 'did-start-loading'
'did-stop-loading' 'did-stop-loading'
'did-get-response-details'
'did-get-redirect-request' 'did-get-redirect-request'
'console-message' 'console-message'
'new-window' 'new-window'

View file

@ -9,6 +9,8 @@ WEB_VIEW_EVENTS =
'did-frame-finish-load': ['isMainFrame'] 'did-frame-finish-load': ['isMainFrame']
'did-start-loading': [] 'did-start-loading': []
'did-stop-loading': [] 'did-stop-loading': []
'did-get-response-details': ['status', 'newUrl', 'originalUrl',
'httpResponseCode', 'requestMethod', 'referrer']
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame'] 'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
'console-message': ['level', 'message', 'line', 'sourceId'] 'console-message': ['level', 'message', 'line', 'sourceId']
'new-window': ['url', 'frameName', 'disposition'] 'new-window': ['url', 'frameName', 'disposition']

View file

@ -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. 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: 'did-get-redirect-request'
* `event` Event * `event` Event

View file

@ -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. 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 ### did-get-redirect-request
* `oldUrl` String * `oldUrl` String

View file

@ -221,3 +221,11 @@ describe 'browser-window module', ->
assert.equal url, 'https://www.github.com/' assert.equal url, 'https://www.github.com/'
done() done()
w.loadUrl "file://#{fixtures}/pages/will-navigate.html" 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"