diff options
author | mnaganov <mnaganov@chromium.org> | 2015-03-10 03:01:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-10 10:02:08 +0000 |
commit | 8a4a31d0494d4b19d9c5cf60da890106ea1da518 (patch) | |
tree | 45f654cde76606232f0ae9c72cbc4fc1ff244d51 /android_webview/native | |
parent | b6a7008789ce4a144669fa906a21f7f5722f8448 (diff) | |
download | chromium_src-8a4a31d0494d4b19d9c5cf60da890106ea1da518.zip chromium_src-8a4a31d0494d4b19d9c5cf60da890106ea1da518.tar.gz chromium_src-8a4a31d0494d4b19d9c5cf60da890106ea1da518.tar.bz2 |
[Android WebView] Implement OnReceivedHttpError callback
Implement OnReceivedHttpError via NetworkDelegate::OnHeadersReceived
for status codes >= 400.
BUG=456782
Review URL: https://codereview.chromium.org/976393002
Cr-Commit-Position: refs/heads/master@{#319856}
Diffstat (limited to 'android_webview/native')
-rw-r--r-- | android_webview/native/aw_contents_io_thread_client_impl.cc | 80 | ||||
-rw-r--r-- | android_webview/native/aw_contents_io_thread_client_impl.h | 3 |
2 files changed, 83 insertions, 0 deletions
diff --git a/android_webview/native/aw_contents_io_thread_client_impl.cc b/android_webview/native/aw_contents_io_thread_client_impl.cc index 69003ae..0cadc94 100644 --- a/android_webview/native/aw_contents_io_thread_client_impl.cc +++ b/android_webview/native/aw_contents_io_thread_client_impl.cc @@ -25,6 +25,7 @@ #include "content/public/browser/web_contents_observer.h" #include "jni/AwContentsIoThreadClient_jni.h" #include "net/http/http_request_headers.h" +#include "net/http/http_response_headers.h" #include "net/url_request/url_request.h" #include "url/gurl.h" @@ -375,6 +376,85 @@ void AwContentsIoThreadClientImpl::NewLoginRequest(const string& realm, env, java_object_.obj(), jrealm.obj(), jaccount.obj(), jargs.obj()); } +void AwContentsIoThreadClientImpl::OnReceivedHttpError( + const net::URLRequest* request, + const net::HttpResponseHeaders* response_headers) { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + if (java_object_.is_null()) + return; + + vector<string> request_header_names; + vector<string> request_header_values; + { + net::HttpRequestHeaders headers; + if (!request->GetFullRequestHeaders(&headers)) + headers = request->extra_request_headers(); + net::HttpRequestHeaders::Iterator headers_iterator(headers); + while (headers_iterator.GetNext()) { + request_header_names.push_back(headers_iterator.name()); + request_header_values.push_back(headers_iterator.value()); + } + } + + vector<string> response_header_names; + vector<string> response_header_values; + { + void* headers_iterator = NULL; + string header_name, header_value; + while (response_headers->EnumerateHeaderLines( + &headers_iterator, &header_name, &header_value)) { + response_header_names.push_back(header_name); + response_header_values.push_back(header_value); + } + } + + JNIEnv* env = AttachCurrentThread(); + ScopedJavaLocalRef<jstring> jstring_url = + ConvertUTF8ToJavaString(env, request->url().spec()); + ScopedJavaLocalRef<jstring> jstring_method = + ConvertUTF8ToJavaString(env, request->method()); + ScopedJavaLocalRef<jobjectArray> jstringArray_request_header_names = + ToJavaArrayOfStrings(env, request_header_names); + ScopedJavaLocalRef<jobjectArray> jstringArray_request_header_values = + ToJavaArrayOfStrings(env, request_header_values); + + const content::ResourceRequestInfo* info = + content::ResourceRequestInfo::ForRequest(request); + bool is_main_frame = info && + info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME; + bool has_user_gesture = info && info->HasUserGesture(); + + string mime_type, encoding; + response_headers->GetMimeTypeAndCharset(&mime_type, &encoding); + ScopedJavaLocalRef<jstring> jstring_mime_type = + ConvertUTF8ToJavaString(env, mime_type); + ScopedJavaLocalRef<jstring> jstring_encoding = + ConvertUTF8ToJavaString(env, encoding); + int status_code = response_headers->response_code(); + ScopedJavaLocalRef<jstring> jstring_reason = + ConvertUTF8ToJavaString(env, response_headers->GetStatusText()); + ScopedJavaLocalRef<jobjectArray> jstringArray_response_header_names = + ToJavaArrayOfStrings(env, response_header_names); + ScopedJavaLocalRef<jobjectArray> jstringArray_response_header_values = + ToJavaArrayOfStrings(env, response_header_values); + + Java_AwContentsIoThreadClient_onReceivedHttpError( + env, + java_object_.obj(), + jstring_url.obj(), + is_main_frame, + has_user_gesture, + jstring_method.obj(), + jstringArray_request_header_names.obj(), + jstringArray_request_header_values.obj(), + jstring_mime_type.obj(), + jstring_encoding.obj(), + status_code, + jstring_reason.obj(), + jstringArray_response_header_names.obj(), + jstringArray_response_header_values.obj()); +} + bool RegisterAwContentsIoThreadClientImpl(JNIEnv* env) { return RegisterNativesImpl(env); } diff --git a/android_webview/native/aw_contents_io_thread_client_impl.h b/android_webview/native/aw_contents_io_thread_client_impl.h index 320d35b..41c7b8a 100644 --- a/android_webview/native/aw_contents_io_thread_client_impl.h +++ b/android_webview/native/aw_contents_io_thread_client_impl.h @@ -62,6 +62,9 @@ class AwContentsIoThreadClientImpl : public AwContentsIoThreadClient { void NewLoginRequest(const std::string& realm, const std::string& account, const std::string& args) override; + void OnReceivedHttpError( + const net::URLRequest* request, + const net::HttpResponseHeaders* response_headers) override; private: bool pending_association_; |