Merge pull request #2829 from nekuz0r/enhanced-redirect-event

More infos on did-get-redirect-request event
This commit is contained in:
Cheng Zhao 2015-09-21 21:15:13 +08:00
commit 62d64e7528
2 changed files with 38 additions and 27 deletions

View file

@ -120,6 +120,33 @@ struct Converter<WindowOpenDisposition> {
} }
}; };
template<>
struct Converter<net::HttpResponseHeaders*> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
net::HttpResponseHeaders* headers) {
base::DictionaryValue response_headers;
if (headers) {
void* iter = nullptr;
std::string key;
std::string value;
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
key = base::StringToLowerASCII(key);
value = base::StringToLowerASCII(value);
if (response_headers.HasKey(key)) {
base::ListValue* values = nullptr;
if (response_headers.GetList(key, &values))
values->AppendString(value);
} else {
scoped_ptr<base::ListValue> values(new base::ListValue());
values->AppendString(value);
response_headers.Set(key, values.Pass());
}
}
}
return ConvertToV8(isolate, response_headers);
}
};
} // namespace mate } // namespace mate
@ -131,7 +158,7 @@ namespace {
v8::Persistent<v8::ObjectTemplate> template_; v8::Persistent<v8::ObjectTemplate> template_;
// The wrapWebContents funtion which is implemented in JavaScript // The wrapWebContents function which is implemented in JavaScript
using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>; using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>;
WrapWebContentsCallback g_wrap_web_contents; WrapWebContentsCallback g_wrap_web_contents;
@ -414,30 +441,6 @@ void WebContents::DidStopLoading() {
void WebContents::DidGetResourceResponseStart( void WebContents::DidGetResourceResponseStart(
const content::ResourceRequestDetails& details) { const content::ResourceRequestDetails& details) {
v8::Locker locker(isolate());
v8::HandleScope handle_scope(isolate());
base::DictionaryValue response_headers;
net::HttpResponseHeaders* headers = details.headers.get();
if (!headers)
return;
void* iter = nullptr;
std::string key;
std::string value;
while (headers->EnumerateHeaderLines(&iter, &key, &value)) {
key = base::StringToLowerASCII(key);
value = base::StringToLowerASCII(value);
if (response_headers.HasKey(key)) {
base::ListValue* values = nullptr;
if (response_headers.GetList(key, &values))
values->AppendString(value);
} else {
scoped_ptr<base::ListValue> values(new base::ListValue());
values->AppendString(value);
response_headers.Set(key, values.Pass());
}
}
Emit("did-get-response-details", Emit("did-get-response-details",
details.socket_address.IsEmpty(), details.socket_address.IsEmpty(),
details.url, details.url,
@ -445,7 +448,7 @@ void WebContents::DidGetResourceResponseStart(
details.http_response_code, details.http_response_code,
details.method, details.method,
details.referrer, details.referrer,
response_headers); details.headers.get());
} }
void WebContents::DidGetRedirectForResourceRequest( void WebContents::DidGetRedirectForResourceRequest(
@ -454,7 +457,11 @@ void WebContents::DidGetRedirectForResourceRequest(
Emit("did-get-redirect-request", Emit("did-get-redirect-request",
details.url, details.url,
details.new_url, details.new_url,
(details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME)); (details.resource_type == content::RESOURCE_TYPE_MAIN_FRAME),
details.http_response_code,
details.method,
details.referrer,
details.headers.get());
} }
void WebContents::DidNavigateMainFrame( void WebContents::DidNavigateMainFrame(

View file

@ -78,6 +78,10 @@ Returns:
* `oldUrl` String * `oldUrl` String
* `newUrl` String * `newUrl` String
* `isMainFrame` Boolean * `isMainFrame` Boolean
* `httpResponseCode` Integer
* `requestMethod` String
* `referrer` String
* `headers` Object
Emitted when a redirect is received while requesting a resource. Emitted when a redirect is received while requesting a resource.