Merge branch '5074-did-get-response-details-resource-type' of https://github.com/Mr0grog/electron into Mr0grog-5074-did-get-response-details-resource-type
This commit is contained in:
commit
a07612c1ed
13 changed files with 78 additions and 8 deletions
|
@ -14,6 +14,7 @@
|
|||
#include "atom/browser/atom_browser_context.h"
|
||||
#include "atom/browser/atom_browser_main_parts.h"
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "atom/browser/net/atom_network_delegate.h"
|
||||
#include "atom/browser/web_contents_permission_helper.h"
|
||||
#include "atom/browser/web_contents_preferences.h"
|
||||
#include "atom/browser/web_view_guest_delegate.h"
|
||||
|
@ -587,7 +588,8 @@ void WebContents::DidGetResourceResponseStart(
|
|||
details.http_response_code,
|
||||
details.method,
|
||||
details.referrer,
|
||||
details.headers.get());
|
||||
details.headers.get(),
|
||||
ResourceTypeToString(details.resource_type));
|
||||
}
|
||||
|
||||
void WebContents::DidGetRedirectForResourceRequest(
|
||||
|
|
|
@ -11,18 +11,12 @@
|
|||
#include "base/stl_util.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "content/public/browser/browser_thread.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
#include "net/url_request/url_request.h"
|
||||
|
||||
using content::BrowserThread;
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace {
|
||||
|
||||
using ResponseHeadersContainer =
|
||||
std::pair<scoped_refptr<net::HttpResponseHeaders>*, const std::string&>;
|
||||
|
||||
const char* ResourceTypeToString(content::ResourceType type) {
|
||||
switch (type) {
|
||||
case content::RESOURCE_TYPE_MAIN_FRAME:
|
||||
|
@ -44,6 +38,11 @@ const char* ResourceTypeToString(content::ResourceType type) {
|
|||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
using ResponseHeadersContainer =
|
||||
std::pair<scoped_refptr<net::HttpResponseHeaders>*, const std::string&>;
|
||||
|
||||
void RunSimpleListener(const AtomNetworkDelegate::SimpleListener& listener,
|
||||
scoped_ptr<base::DictionaryValue> details) {
|
||||
return listener.Run(*(details.get()));
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "net/base/net_errors.h"
|
||||
#include "net/http/http_request_headers.h"
|
||||
#include "net/http/http_response_headers.h"
|
||||
#include "content/public/browser/resource_request_info.h"
|
||||
|
||||
namespace extensions {
|
||||
class URLPattern;
|
||||
|
@ -24,6 +25,8 @@ namespace atom {
|
|||
|
||||
using URLPatterns = std::set<extensions::URLPattern>;
|
||||
|
||||
const char* ResourceTypeToString(content::ResourceType type);
|
||||
|
||||
class AtomNetworkDelegate : public brightray::NetworkDelegate {
|
||||
public:
|
||||
using ResponseCallback = base::Callback<void(const base::DictionaryValue&)>;
|
||||
|
|
|
@ -67,6 +67,7 @@ Returns:
|
|||
* `requestMethod` String
|
||||
* `referrer` String
|
||||
* `headers` Object
|
||||
* `resourceType` String
|
||||
|
||||
요청한 리소스에 관련된 자세한 정보를 사용할 수 있을 때 발생하는 이벤트입니다.
|
||||
`status`는 리소스를 다운로드하기 위한 소켓 연결을 나타냅니다.
|
||||
|
|
|
@ -495,6 +495,7 @@ Returns:
|
|||
* `requestMethod` String
|
||||
* `referrer` String
|
||||
* `headers` Object
|
||||
* `resourceType` String
|
||||
|
||||
요청한 리소스에 관해 자세한 내용을 알 수 있을 때 발생하는 이벤트입니다.
|
||||
`status`는 리소스를 다운로드할 소켓 커낵션을 나타냅니다.
|
||||
|
|
|
@ -63,6 +63,7 @@ var webContents = win.webContents;
|
|||
* `requestMethod` String
|
||||
* `referrer` String
|
||||
* `headers` Object
|
||||
* `resourceType` String
|
||||
|
||||
当有关请求资源的详细信息可用的时候发出事件.
|
||||
`status` 标识了 socket链接来下载资源.
|
||||
|
|
|
@ -457,6 +457,7 @@ Returns:
|
|||
* `requestMethod` String
|
||||
* `referrer` String
|
||||
* `headers` Object
|
||||
* `resourceType` String
|
||||
|
||||
当获得返回详情的时候触发.
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ Returns:
|
|||
* `requestMethod` String
|
||||
* `referrer` String
|
||||
* `headers` Object
|
||||
* `resourceType` String
|
||||
|
||||
Emitted when details regarding a requested resource are available.
|
||||
`status` indicates the socket connection to download the resource.
|
||||
|
|
|
@ -510,6 +510,7 @@ Returns:
|
|||
* `requestMethod` String
|
||||
* `referrer` String
|
||||
* `headers` Object
|
||||
* `resourceType` String
|
||||
|
||||
Fired when details regarding a requested resource is available.
|
||||
`status` indicates socket connection to download the resource.
|
||||
|
|
|
@ -12,7 +12,7 @@ var WEB_VIEW_EVENTS = {
|
|||
'did-frame-finish-load': ['isMainFrame'],
|
||||
'did-start-loading': [],
|
||||
'did-stop-loading': [],
|
||||
'did-get-response-details': ['status', 'newURL', 'originalURL', 'httpResponseCode', 'requestMethod', 'referrer', 'headers'],
|
||||
'did-get-response-details': ['status', 'newURL', 'originalURL', 'httpResponseCode', 'requestMethod', 'referrer', 'headers', 'resourceType'],
|
||||
'did-get-redirect-request': ['oldURL', 'newURL', 'isMainFrame'],
|
||||
'dom-ready': [],
|
||||
'console-message': ['level', 'message', 'line', 'sourceId'],
|
||||
|
|
|
@ -101,6 +101,32 @@ describe('browser-window module', function () {
|
|||
w.loadURL('about:blank')
|
||||
})
|
||||
|
||||
it('should emit did-get-response-details event', function (done) {
|
||||
// expected {fileName: resourceType} pairs
|
||||
var expectedResources = {
|
||||
'did-get-response-details.html': 'mainFrame',
|
||||
'logo.png': 'image'
|
||||
}
|
||||
var responses = 0;
|
||||
w.webContents.on('did-get-response-details', function (event, status, newUrl, oldUrl, responseCode, method, referrer, headers, resourceType) {
|
||||
responses++
|
||||
var fileName = newUrl.slice(newUrl.lastIndexOf('/') + 1)
|
||||
var expectedType = expectedResources[fileName]
|
||||
assert(!!expectedType, `Unexpected response details for ${newUrl}`)
|
||||
assert(typeof status === 'boolean', 'status should be boolean')
|
||||
assert.equal(responseCode, 200)
|
||||
assert.equal(method, 'GET')
|
||||
assert(typeof referrer === 'string', 'referrer should be string')
|
||||
assert(!!headers, 'headers should be present')
|
||||
assert(typeof headers === 'object', 'headers should be object')
|
||||
assert.equal(resourceType, expectedType, 'Incorrect resourceType')
|
||||
if (responses === Object.keys(expectedResources).length) {
|
||||
done()
|
||||
}
|
||||
})
|
||||
w.loadURL('file://' + path.join(fixtures, 'pages', 'did-get-response-details.html'))
|
||||
})
|
||||
|
||||
it('should emit did-fail-load event for files that do not exist', function (done) {
|
||||
w.webContents.on('did-fail-load', function (event, code, desc, url, isMainFrame) {
|
||||
assert.equal(code, -6)
|
||||
|
|
5
spec/fixtures/pages/did-get-response-details.html
vendored
Normal file
5
spec/fixtures/pages/did-get-response-details.html
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
<html>
|
||||
<body>
|
||||
<img src="../assets/logo.png" />
|
||||
</body>
|
||||
</html>
|
|
@ -763,4 +763,33 @@ describe('<webview> tag', function () {
|
|||
document.body.appendChild(webview)
|
||||
})
|
||||
})
|
||||
|
||||
describe('did-get-response-details event', function () {
|
||||
it('emits for the page and its resources', function (done) {
|
||||
// expected {fileName: resourceType} pairs
|
||||
var expectedResources = {
|
||||
'did-get-response-details.html': 'mainFrame',
|
||||
'logo.png': 'image'
|
||||
}
|
||||
var responses = 0;
|
||||
webview.addEventListener('did-get-response-details', function (event) {
|
||||
responses++
|
||||
var fileName = event.newURL.slice(event.newURL.lastIndexOf('/') + 1)
|
||||
var expectedType = expectedResources[fileName]
|
||||
assert(!!expectedType, `Unexpected response details for ${event.newURL}`)
|
||||
assert(typeof event.status === 'boolean', 'status should be boolean')
|
||||
assert.equal(event.httpResponseCode, 200)
|
||||
assert.equal(event.requestMethod, 'GET')
|
||||
assert(typeof event.referrer === 'string', 'referrer should be string')
|
||||
assert(!!event.headers, 'headers should be present')
|
||||
assert(typeof event.headers === 'object', 'headers should be object')
|
||||
assert.equal(event.resourceType, expectedType, 'Incorrect resourceType')
|
||||
if (responses === Object.keys(expectedResources).length) {
|
||||
done()
|
||||
}
|
||||
})
|
||||
webview.src = 'file://' + path.join(fixtures, 'pages', 'did-get-response-details.html')
|
||||
document.body.appendChild(webview)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue