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
Родитель 91c9f590dd 15a648a879
Коммит 64f9f7e906
7 изменённых файлов: 49 добавлений и 0 удалений

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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'

Просмотреть файл

@ -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']

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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"