| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "android_webview/native/aw_contents_io_thread_client_impl.h" | 5 #include "android_webview/native/aw_contents_io_thread_client_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 } | 300 } |
| 301 | 301 |
| 302 AwContentsIoThreadClient::CacheMode | 302 AwContentsIoThreadClient::CacheMode |
| 303 AwContentsIoThreadClientImpl::GetCacheMode() const { | 303 AwContentsIoThreadClientImpl::GetCacheMode() const { |
| 304 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 304 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 305 if (java_object_.is_null()) | 305 if (java_object_.is_null()) |
| 306 return AwContentsIoThreadClient::LOAD_DEFAULT; | 306 return AwContentsIoThreadClient::LOAD_DEFAULT; |
| 307 | 307 |
| 308 JNIEnv* env = AttachCurrentThread(); | 308 JNIEnv* env = AttachCurrentThread(); |
| 309 return static_cast<AwContentsIoThreadClient::CacheMode>( | 309 return static_cast<AwContentsIoThreadClient::CacheMode>( |
| 310 Java_AwContentsIoThreadClient_getCacheMode( | 310 Java_AwContentsIoThreadClient_getCacheMode(env, java_object_)); |
| 311 env, java_object_.obj())); | |
| 312 } | 311 } |
| 313 | 312 |
| 314 | 313 |
| 315 namespace { | 314 namespace { |
| 316 | 315 |
| 317 std::unique_ptr<AwWebResourceResponse> RunShouldInterceptRequest( | 316 std::unique_ptr<AwWebResourceResponse> RunShouldInterceptRequest( |
| 318 WebResourceRequest web_request, | 317 WebResourceRequest web_request, |
| 319 JavaObjectWeakGlobalRef ref) { | 318 JavaObjectWeakGlobalRef ref) { |
| 320 DCHECK_CURRENTLY_ON(BrowserThread::FILE); | 319 DCHECK_CURRENTLY_ON(BrowserThread::FILE); |
| 321 JNIEnv* env = AttachCurrentThread(); | 320 JNIEnv* env = AttachCurrentThread(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 349 | 348 |
| 350 void AwContentsIoThreadClientImpl::ShouldInterceptRequestAsync( | 349 void AwContentsIoThreadClientImpl::ShouldInterceptRequestAsync( |
| 351 const net::URLRequest* request, | 350 const net::URLRequest* request, |
| 352 const ShouldInterceptRequestResultCallback callback) { | 351 const ShouldInterceptRequestResultCallback callback) { |
| 353 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 352 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 354 base::Callback<std::unique_ptr<AwWebResourceResponse>()> get_response = | 353 base::Callback<std::unique_ptr<AwWebResourceResponse>()> get_response = |
| 355 base::Bind(&ReturnNull); | 354 base::Bind(&ReturnNull); |
| 356 JNIEnv* env = AttachCurrentThread(); | 355 JNIEnv* env = AttachCurrentThread(); |
| 357 if (bg_thread_client_object_.is_null() && !java_object_.is_null()) { | 356 if (bg_thread_client_object_.is_null() && !java_object_.is_null()) { |
| 358 bg_thread_client_object_.Reset( | 357 bg_thread_client_object_.Reset( |
| 359 Java_AwContentsIoThreadClient_getBackgroundThreadClient( | 358 Java_AwContentsIoThreadClient_getBackgroundThreadClient(env, |
| 360 env, java_object_.obj())); | 359 java_object_)); |
| 361 } | 360 } |
| 362 if (!bg_thread_client_object_.is_null()) { | 361 if (!bg_thread_client_object_.is_null()) { |
| 363 get_response = base::Bind( | 362 get_response = base::Bind( |
| 364 &RunShouldInterceptRequest, WebResourceRequest(request), | 363 &RunShouldInterceptRequest, WebResourceRequest(request), |
| 365 JavaObjectWeakGlobalRef(env, bg_thread_client_object_.obj())); | 364 JavaObjectWeakGlobalRef(env, bg_thread_client_object_.obj())); |
| 366 } | 365 } |
| 367 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::FILE, FROM_HERE, | 366 BrowserThread::PostTaskAndReplyWithResult(BrowserThread::FILE, FROM_HERE, |
| 368 get_response, callback); | 367 get_response, callback); |
| 369 } | 368 } |
| 370 | 369 |
| 371 bool AwContentsIoThreadClientImpl::ShouldBlockContentUrls() const { | 370 bool AwContentsIoThreadClientImpl::ShouldBlockContentUrls() const { |
| 372 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 371 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 373 if (java_object_.is_null()) | 372 if (java_object_.is_null()) |
| 374 return false; | 373 return false; |
| 375 | 374 |
| 376 JNIEnv* env = AttachCurrentThread(); | 375 JNIEnv* env = AttachCurrentThread(); |
| 377 return Java_AwContentsIoThreadClient_shouldBlockContentUrls( | 376 return Java_AwContentsIoThreadClient_shouldBlockContentUrls(env, |
| 378 env, java_object_.obj()); | 377 java_object_); |
| 379 } | 378 } |
| 380 | 379 |
| 381 bool AwContentsIoThreadClientImpl::ShouldBlockFileUrls() const { | 380 bool AwContentsIoThreadClientImpl::ShouldBlockFileUrls() const { |
| 382 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 381 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 383 if (java_object_.is_null()) | 382 if (java_object_.is_null()) |
| 384 return false; | 383 return false; |
| 385 | 384 |
| 386 JNIEnv* env = AttachCurrentThread(); | 385 JNIEnv* env = AttachCurrentThread(); |
| 387 return Java_AwContentsIoThreadClient_shouldBlockFileUrls( | 386 return Java_AwContentsIoThreadClient_shouldBlockFileUrls(env, java_object_); |
| 388 env, java_object_.obj()); | |
| 389 } | 387 } |
| 390 | 388 |
| 391 bool AwContentsIoThreadClientImpl::ShouldAcceptThirdPartyCookies() const { | 389 bool AwContentsIoThreadClientImpl::ShouldAcceptThirdPartyCookies() const { |
| 392 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 390 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 393 if (java_object_.is_null()) | 391 if (java_object_.is_null()) |
| 394 return false; | 392 return false; |
| 395 | 393 |
| 396 JNIEnv* env = AttachCurrentThread(); | 394 JNIEnv* env = AttachCurrentThread(); |
| 397 return Java_AwContentsIoThreadClient_shouldAcceptThirdPartyCookies( | 395 return Java_AwContentsIoThreadClient_shouldAcceptThirdPartyCookies( |
| 398 env, java_object_.obj()); | 396 env, java_object_); |
| 399 } | 397 } |
| 400 | 398 |
| 401 bool AwContentsIoThreadClientImpl::ShouldBlockNetworkLoads() const { | 399 bool AwContentsIoThreadClientImpl::ShouldBlockNetworkLoads() const { |
| 402 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 400 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 403 if (java_object_.is_null()) | 401 if (java_object_.is_null()) |
| 404 return false; | 402 return false; |
| 405 | 403 |
| 406 JNIEnv* env = AttachCurrentThread(); | 404 JNIEnv* env = AttachCurrentThread(); |
| 407 return Java_AwContentsIoThreadClient_shouldBlockNetworkLoads( | 405 return Java_AwContentsIoThreadClient_shouldBlockNetworkLoads(env, |
| 408 env, java_object_.obj()); | 406 java_object_); |
| 409 } | 407 } |
| 410 | 408 |
| 411 void AwContentsIoThreadClientImpl::NewDownload( | 409 void AwContentsIoThreadClientImpl::NewDownload( |
| 412 const GURL& url, | 410 const GURL& url, |
| 413 const string& user_agent, | 411 const string& user_agent, |
| 414 const string& content_disposition, | 412 const string& content_disposition, |
| 415 const string& mime_type, | 413 const string& mime_type, |
| 416 int64_t content_length) { | 414 int64_t content_length) { |
| 417 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 415 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 418 if (java_object_.is_null()) | 416 if (java_object_.is_null()) |
| 419 return; | 417 return; |
| 420 | 418 |
| 421 JNIEnv* env = AttachCurrentThread(); | 419 JNIEnv* env = AttachCurrentThread(); |
| 422 ScopedJavaLocalRef<jstring> jstring_url = | 420 ScopedJavaLocalRef<jstring> jstring_url = |
| 423 ConvertUTF8ToJavaString(env, url.spec()); | 421 ConvertUTF8ToJavaString(env, url.spec()); |
| 424 ScopedJavaLocalRef<jstring> jstring_user_agent = | 422 ScopedJavaLocalRef<jstring> jstring_user_agent = |
| 425 ConvertUTF8ToJavaString(env, user_agent); | 423 ConvertUTF8ToJavaString(env, user_agent); |
| 426 ScopedJavaLocalRef<jstring> jstring_content_disposition = | 424 ScopedJavaLocalRef<jstring> jstring_content_disposition = |
| 427 ConvertUTF8ToJavaString(env, content_disposition); | 425 ConvertUTF8ToJavaString(env, content_disposition); |
| 428 ScopedJavaLocalRef<jstring> jstring_mime_type = | 426 ScopedJavaLocalRef<jstring> jstring_mime_type = |
| 429 ConvertUTF8ToJavaString(env, mime_type); | 427 ConvertUTF8ToJavaString(env, mime_type); |
| 430 | 428 |
| 431 Java_AwContentsIoThreadClient_onDownloadStart( | 429 Java_AwContentsIoThreadClient_onDownloadStart( |
| 432 env, | 430 env, java_object_, jstring_url, jstring_user_agent, |
| 433 java_object_.obj(), | 431 jstring_content_disposition, jstring_mime_type, content_length); |
| 434 jstring_url.obj(), | |
| 435 jstring_user_agent.obj(), | |
| 436 jstring_content_disposition.obj(), | |
| 437 jstring_mime_type.obj(), | |
| 438 content_length); | |
| 439 } | 432 } |
| 440 | 433 |
| 441 void AwContentsIoThreadClientImpl::NewLoginRequest(const string& realm, | 434 void AwContentsIoThreadClientImpl::NewLoginRequest(const string& realm, |
| 442 const string& account, | 435 const string& account, |
| 443 const string& args) { | 436 const string& args) { |
| 444 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 437 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 445 if (java_object_.is_null()) | 438 if (java_object_.is_null()) |
| 446 return; | 439 return; |
| 447 | 440 |
| 448 JNIEnv* env = AttachCurrentThread(); | 441 JNIEnv* env = AttachCurrentThread(); |
| 449 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); | 442 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); |
| 450 ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args); | 443 ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args); |
| 451 | 444 |
| 452 ScopedJavaLocalRef<jstring> jaccount; | 445 ScopedJavaLocalRef<jstring> jaccount; |
| 453 if (!account.empty()) | 446 if (!account.empty()) |
| 454 jaccount = ConvertUTF8ToJavaString(env, account); | 447 jaccount = ConvertUTF8ToJavaString(env, account); |
| 455 | 448 |
| 456 Java_AwContentsIoThreadClient_newLoginRequest( | 449 Java_AwContentsIoThreadClient_newLoginRequest(env, java_object_, jrealm, |
| 457 env, java_object_.obj(), jrealm.obj(), jaccount.obj(), jargs.obj()); | 450 jaccount, jargs); |
| 458 } | 451 } |
| 459 | 452 |
| 460 void AwContentsIoThreadClientImpl::OnReceivedError( | 453 void AwContentsIoThreadClientImpl::OnReceivedError( |
| 461 const net::URLRequest* request) { | 454 const net::URLRequest* request) { |
| 462 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 455 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 463 if (java_object_.is_null()) | 456 if (java_object_.is_null()) |
| 464 return; | 457 return; |
| 465 | 458 |
| 466 JNIEnv* env = AttachCurrentThread(); | 459 JNIEnv* env = AttachCurrentThread(); |
| 467 WebResourceRequest web_request(env, request); | 460 WebResourceRequest web_request(env, request); |
| 468 | 461 |
| 469 int error_code = request->status().error(); | 462 int error_code = request->status().error(); |
| 470 ScopedJavaLocalRef<jstring> jstring_description = ConvertUTF8ToJavaString( | 463 ScopedJavaLocalRef<jstring> jstring_description = ConvertUTF8ToJavaString( |
| 471 env, net::ErrorToString(request->status().error())); | 464 env, net::ErrorToString(request->status().error())); |
| 472 | 465 |
| 473 Java_AwContentsIoThreadClient_onReceivedError( | 466 Java_AwContentsIoThreadClient_onReceivedError( |
| 474 env, | 467 env, java_object_, web_request.jstring_url, web_request.is_main_frame, |
| 475 java_object_.obj(), | 468 web_request.has_user_gesture, web_request.jstring_method, |
| 476 web_request.jstring_url.obj(), | 469 web_request.jstringArray_header_names, |
| 477 web_request.is_main_frame, | 470 web_request.jstringArray_header_values, error_code, jstring_description); |
| 478 web_request.has_user_gesture, | |
| 479 web_request.jstring_method.obj(), | |
| 480 web_request.jstringArray_header_names.obj(), | |
| 481 web_request.jstringArray_header_values.obj(), | |
| 482 error_code, | |
| 483 jstring_description.obj()); | |
| 484 } | 471 } |
| 485 | 472 |
| 486 void AwContentsIoThreadClientImpl::OnReceivedHttpError( | 473 void AwContentsIoThreadClientImpl::OnReceivedHttpError( |
| 487 const net::URLRequest* request, | 474 const net::URLRequest* request, |
| 488 const net::HttpResponseHeaders* response_headers) { | 475 const net::HttpResponseHeaders* response_headers) { |
| 489 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 476 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 490 if (java_object_.is_null()) | 477 if (java_object_.is_null()) |
| 491 return; | 478 return; |
| 492 | 479 |
| 493 JNIEnv* env = AttachCurrentThread(); | 480 JNIEnv* env = AttachCurrentThread(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 513 ConvertUTF8ToJavaString(env, encoding); | 500 ConvertUTF8ToJavaString(env, encoding); |
| 514 int status_code = response_headers->response_code(); | 501 int status_code = response_headers->response_code(); |
| 515 ScopedJavaLocalRef<jstring> jstring_reason = | 502 ScopedJavaLocalRef<jstring> jstring_reason = |
| 516 ConvertUTF8ToJavaString(env, response_headers->GetStatusText()); | 503 ConvertUTF8ToJavaString(env, response_headers->GetStatusText()); |
| 517 ScopedJavaLocalRef<jobjectArray> jstringArray_response_header_names = | 504 ScopedJavaLocalRef<jobjectArray> jstringArray_response_header_names = |
| 518 ToJavaArrayOfStrings(env, response_header_names); | 505 ToJavaArrayOfStrings(env, response_header_names); |
| 519 ScopedJavaLocalRef<jobjectArray> jstringArray_response_header_values = | 506 ScopedJavaLocalRef<jobjectArray> jstringArray_response_header_values = |
| 520 ToJavaArrayOfStrings(env, response_header_values); | 507 ToJavaArrayOfStrings(env, response_header_values); |
| 521 | 508 |
| 522 Java_AwContentsIoThreadClient_onReceivedHttpError( | 509 Java_AwContentsIoThreadClient_onReceivedHttpError( |
| 523 env, | 510 env, java_object_, web_request.jstring_url, web_request.is_main_frame, |
| 524 java_object_.obj(), | 511 web_request.has_user_gesture, web_request.jstring_method, |
| 525 web_request.jstring_url.obj(), | 512 web_request.jstringArray_header_names, |
| 526 web_request.is_main_frame, | 513 web_request.jstringArray_header_values, jstring_mime_type, |
| 527 web_request.has_user_gesture, | 514 jstring_encoding, status_code, jstring_reason, |
| 528 web_request.jstring_method.obj(), | 515 jstringArray_response_header_names, jstringArray_response_header_values); |
| 529 web_request.jstringArray_header_names.obj(), | |
| 530 web_request.jstringArray_header_values.obj(), | |
| 531 jstring_mime_type.obj(), | |
| 532 jstring_encoding.obj(), | |
| 533 status_code, | |
| 534 jstring_reason.obj(), | |
| 535 jstringArray_response_header_names.obj(), | |
| 536 jstringArray_response_header_values.obj()); | |
| 537 } | 516 } |
| 538 | 517 |
| 539 } // namespace android_webview | 518 } // namespace android_webview |
| OLD | NEW |