| 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 <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "android_webview/common/devtools_instrumentation.h" | 10 #include "android_webview/common/devtools_instrumentation.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 AwContentsIoThreadClientImpl::~AwContentsIoThreadClientImpl() { | 217 AwContentsIoThreadClientImpl::~AwContentsIoThreadClientImpl() { |
| 218 // explict, out-of-line destructor. | 218 // explict, out-of-line destructor. |
| 219 } | 219 } |
| 220 | 220 |
| 221 bool AwContentsIoThreadClientImpl::PendingAssociation() const { | 221 bool AwContentsIoThreadClientImpl::PendingAssociation() const { |
| 222 return pending_association_; | 222 return pending_association_; |
| 223 } | 223 } |
| 224 | 224 |
| 225 AwContentsIoThreadClient::CacheMode | 225 AwContentsIoThreadClient::CacheMode |
| 226 AwContentsIoThreadClientImpl::GetCacheMode() const { | 226 AwContentsIoThreadClientImpl::GetCacheMode() const { |
| 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 227 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 228 if (java_object_.is_null()) | 228 if (java_object_.is_null()) |
| 229 return AwContentsIoThreadClient::LOAD_DEFAULT; | 229 return AwContentsIoThreadClient::LOAD_DEFAULT; |
| 230 | 230 |
| 231 JNIEnv* env = AttachCurrentThread(); | 231 JNIEnv* env = AttachCurrentThread(); |
| 232 return static_cast<AwContentsIoThreadClient::CacheMode>( | 232 return static_cast<AwContentsIoThreadClient::CacheMode>( |
| 233 Java_AwContentsIoThreadClient_getCacheMode( | 233 Java_AwContentsIoThreadClient_getCacheMode( |
| 234 env, java_object_.obj())); | 234 env, java_object_.obj())); |
| 235 } | 235 } |
| 236 | 236 |
| 237 scoped_ptr<AwWebResourceResponse> | 237 scoped_ptr<AwWebResourceResponse> |
| 238 AwContentsIoThreadClientImpl::ShouldInterceptRequest( | 238 AwContentsIoThreadClientImpl::ShouldInterceptRequest( |
| 239 const GURL& location, | 239 const GURL& location, |
| 240 const net::URLRequest* request) { | 240 const net::URLRequest* request) { |
| 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 241 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 242 if (java_object_.is_null()) | 242 if (java_object_.is_null()) |
| 243 return scoped_ptr<AwWebResourceResponse>(); | 243 return scoped_ptr<AwWebResourceResponse>(); |
| 244 const content::ResourceRequestInfo* info = | 244 const content::ResourceRequestInfo* info = |
| 245 content::ResourceRequestInfo::ForRequest(request); | 245 content::ResourceRequestInfo::ForRequest(request); |
| 246 bool is_main_frame = info && | 246 bool is_main_frame = info && |
| 247 info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME; | 247 info->GetResourceType() == content::RESOURCE_TYPE_MAIN_FRAME; |
| 248 bool has_user_gesture = info && info->HasUserGesture(); | 248 bool has_user_gesture = info && info->HasUserGesture(); |
| 249 | 249 |
| 250 vector<string> headers_names; | 250 vector<string> headers_names; |
| 251 vector<string> headers_values; | 251 vector<string> headers_values; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 281 jstring_method.obj(), | 281 jstring_method.obj(), |
| 282 jstringArray_headers_names.obj(), | 282 jstringArray_headers_names.obj(), |
| 283 jstringArray_headers_values.obj()); | 283 jstringArray_headers_values.obj()); |
| 284 if (ret.is_null()) | 284 if (ret.is_null()) |
| 285 return scoped_ptr<AwWebResourceResponse>(); | 285 return scoped_ptr<AwWebResourceResponse>(); |
| 286 return scoped_ptr<AwWebResourceResponse>( | 286 return scoped_ptr<AwWebResourceResponse>( |
| 287 new AwWebResourceResponseImpl(ret)); | 287 new AwWebResourceResponseImpl(ret)); |
| 288 } | 288 } |
| 289 | 289 |
| 290 bool AwContentsIoThreadClientImpl::ShouldBlockContentUrls() const { | 290 bool AwContentsIoThreadClientImpl::ShouldBlockContentUrls() const { |
| 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 291 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 292 if (java_object_.is_null()) | 292 if (java_object_.is_null()) |
| 293 return false; | 293 return false; |
| 294 | 294 |
| 295 JNIEnv* env = AttachCurrentThread(); | 295 JNIEnv* env = AttachCurrentThread(); |
| 296 return Java_AwContentsIoThreadClient_shouldBlockContentUrls( | 296 return Java_AwContentsIoThreadClient_shouldBlockContentUrls( |
| 297 env, java_object_.obj()); | 297 env, java_object_.obj()); |
| 298 } | 298 } |
| 299 | 299 |
| 300 bool AwContentsIoThreadClientImpl::ShouldBlockFileUrls() const { | 300 bool AwContentsIoThreadClientImpl::ShouldBlockFileUrls() const { |
| 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 301 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 302 if (java_object_.is_null()) | 302 if (java_object_.is_null()) |
| 303 return false; | 303 return false; |
| 304 | 304 |
| 305 JNIEnv* env = AttachCurrentThread(); | 305 JNIEnv* env = AttachCurrentThread(); |
| 306 return Java_AwContentsIoThreadClient_shouldBlockFileUrls( | 306 return Java_AwContentsIoThreadClient_shouldBlockFileUrls( |
| 307 env, java_object_.obj()); | 307 env, java_object_.obj()); |
| 308 } | 308 } |
| 309 | 309 |
| 310 bool AwContentsIoThreadClientImpl::ShouldAcceptThirdPartyCookies() const { | 310 bool AwContentsIoThreadClientImpl::ShouldAcceptThirdPartyCookies() const { |
| 311 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 311 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 312 if (java_object_.is_null()) | 312 if (java_object_.is_null()) |
| 313 return false; | 313 return false; |
| 314 | 314 |
| 315 JNIEnv* env = AttachCurrentThread(); | 315 JNIEnv* env = AttachCurrentThread(); |
| 316 return Java_AwContentsIoThreadClient_shouldAcceptThirdPartyCookies( | 316 return Java_AwContentsIoThreadClient_shouldAcceptThirdPartyCookies( |
| 317 env, java_object_.obj()); | 317 env, java_object_.obj()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 bool AwContentsIoThreadClientImpl::ShouldBlockNetworkLoads() const { | 320 bool AwContentsIoThreadClientImpl::ShouldBlockNetworkLoads() const { |
| 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 321 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 322 if (java_object_.is_null()) | 322 if (java_object_.is_null()) |
| 323 return false; | 323 return false; |
| 324 | 324 |
| 325 JNIEnv* env = AttachCurrentThread(); | 325 JNIEnv* env = AttachCurrentThread(); |
| 326 return Java_AwContentsIoThreadClient_shouldBlockNetworkLoads( | 326 return Java_AwContentsIoThreadClient_shouldBlockNetworkLoads( |
| 327 env, java_object_.obj()); | 327 env, java_object_.obj()); |
| 328 } | 328 } |
| 329 | 329 |
| 330 void AwContentsIoThreadClientImpl::NewDownload( | 330 void AwContentsIoThreadClientImpl::NewDownload( |
| 331 const GURL& url, | 331 const GURL& url, |
| 332 const string& user_agent, | 332 const string& user_agent, |
| 333 const string& content_disposition, | 333 const string& content_disposition, |
| 334 const string& mime_type, | 334 const string& mime_type, |
| 335 int64 content_length) { | 335 int64 content_length) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 336 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 337 if (java_object_.is_null()) | 337 if (java_object_.is_null()) |
| 338 return; | 338 return; |
| 339 | 339 |
| 340 JNIEnv* env = AttachCurrentThread(); | 340 JNIEnv* env = AttachCurrentThread(); |
| 341 ScopedJavaLocalRef<jstring> jstring_url = | 341 ScopedJavaLocalRef<jstring> jstring_url = |
| 342 ConvertUTF8ToJavaString(env, url.spec()); | 342 ConvertUTF8ToJavaString(env, url.spec()); |
| 343 ScopedJavaLocalRef<jstring> jstring_user_agent = | 343 ScopedJavaLocalRef<jstring> jstring_user_agent = |
| 344 ConvertUTF8ToJavaString(env, user_agent); | 344 ConvertUTF8ToJavaString(env, user_agent); |
| 345 ScopedJavaLocalRef<jstring> jstring_content_disposition = | 345 ScopedJavaLocalRef<jstring> jstring_content_disposition = |
| 346 ConvertUTF8ToJavaString(env, content_disposition); | 346 ConvertUTF8ToJavaString(env, content_disposition); |
| 347 ScopedJavaLocalRef<jstring> jstring_mime_type = | 347 ScopedJavaLocalRef<jstring> jstring_mime_type = |
| 348 ConvertUTF8ToJavaString(env, mime_type); | 348 ConvertUTF8ToJavaString(env, mime_type); |
| 349 | 349 |
| 350 Java_AwContentsIoThreadClient_onDownloadStart( | 350 Java_AwContentsIoThreadClient_onDownloadStart( |
| 351 env, | 351 env, |
| 352 java_object_.obj(), | 352 java_object_.obj(), |
| 353 jstring_url.obj(), | 353 jstring_url.obj(), |
| 354 jstring_user_agent.obj(), | 354 jstring_user_agent.obj(), |
| 355 jstring_content_disposition.obj(), | 355 jstring_content_disposition.obj(), |
| 356 jstring_mime_type.obj(), | 356 jstring_mime_type.obj(), |
| 357 content_length); | 357 content_length); |
| 358 } | 358 } |
| 359 | 359 |
| 360 void AwContentsIoThreadClientImpl::NewLoginRequest(const string& realm, | 360 void AwContentsIoThreadClientImpl::NewLoginRequest(const string& realm, |
| 361 const string& account, | 361 const string& account, |
| 362 const string& args) { | 362 const string& args) { |
| 363 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 363 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 364 if (java_object_.is_null()) | 364 if (java_object_.is_null()) |
| 365 return; | 365 return; |
| 366 | 366 |
| 367 JNIEnv* env = AttachCurrentThread(); | 367 JNIEnv* env = AttachCurrentThread(); |
| 368 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); | 368 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); |
| 369 ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args); | 369 ScopedJavaLocalRef<jstring> jargs = ConvertUTF8ToJavaString(env, args); |
| 370 | 370 |
| 371 ScopedJavaLocalRef<jstring> jaccount; | 371 ScopedJavaLocalRef<jstring> jaccount; |
| 372 if (!account.empty()) | 372 if (!account.empty()) |
| 373 jaccount = ConvertUTF8ToJavaString(env, account); | 373 jaccount = ConvertUTF8ToJavaString(env, account); |
| 374 | 374 |
| 375 Java_AwContentsIoThreadClient_newLoginRequest( | 375 Java_AwContentsIoThreadClient_newLoginRequest( |
| 376 env, java_object_.obj(), jrealm.obj(), jaccount.obj(), jargs.obj()); | 376 env, java_object_.obj(), jrealm.obj(), jaccount.obj(), jargs.obj()); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void AwContentsIoThreadClientImpl::OnReceivedHttpError( | 379 void AwContentsIoThreadClientImpl::OnReceivedHttpError( |
| 380 const net::URLRequest* request, | 380 const net::URLRequest* request, |
| 381 const net::HttpResponseHeaders* response_headers) { | 381 const net::HttpResponseHeaders* response_headers) { |
| 382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 382 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 383 if (java_object_.is_null()) | 383 if (java_object_.is_null()) |
| 384 return; | 384 return; |
| 385 | 385 |
| 386 vector<string> request_header_names; | 386 vector<string> request_header_names; |
| 387 vector<string> request_header_values; | 387 vector<string> request_header_values; |
| 388 { | 388 { |
| 389 net::HttpRequestHeaders headers; | 389 net::HttpRequestHeaders headers; |
| 390 if (!request->GetFullRequestHeaders(&headers)) | 390 if (!request->GetFullRequestHeaders(&headers)) |
| 391 headers = request->extra_request_headers(); | 391 headers = request->extra_request_headers(); |
| 392 net::HttpRequestHeaders::Iterator headers_iterator(headers); | 392 net::HttpRequestHeaders::Iterator headers_iterator(headers); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 jstring_reason.obj(), | 453 jstring_reason.obj(), |
| 454 jstringArray_response_header_names.obj(), | 454 jstringArray_response_header_names.obj(), |
| 455 jstringArray_response_header_values.obj()); | 455 jstringArray_response_header_values.obj()); |
| 456 } | 456 } |
| 457 | 457 |
| 458 bool RegisterAwContentsIoThreadClientImpl(JNIEnv* env) { | 458 bool RegisterAwContentsIoThreadClientImpl(JNIEnv* env) { |
| 459 return RegisterNativesImpl(env); | 459 return RegisterNativesImpl(env); |
| 460 } | 460 } |
| 461 | 461 |
| 462 } // namespace android_webview | 462 } // namespace android_webview |
| OLD | NEW |