Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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.h" | 5 #include "android_webview/native/aw_contents.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_browser_context.h" | 9 #include "android_webview/browser/aw_browser_context.h" |
| 10 #include "android_webview/browser/aw_browser_main_parts.h" | 10 #include "android_webview/browser/aw_browser_main_parts.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 | 206 |
| 207 AwAutofillClient* autofill_manager_delegate = | 207 AwAutofillClient* autofill_manager_delegate = |
| 208 AwAutofillClient::FromWebContents(web_contents_.get()); | 208 AwAutofillClient::FromWebContents(web_contents_.get()); |
| 209 if (autofill_manager_delegate) | 209 if (autofill_manager_delegate) |
| 210 InitAutofillIfNecessary(autofill_manager_delegate->GetSaveFormData()); | 210 InitAutofillIfNecessary(autofill_manager_delegate->GetSaveFormData()); |
| 211 content::SynchronousCompositor::SetClientForWebContents( | 211 content::SynchronousCompositor::SetClientForWebContents( |
| 212 web_contents_.get(), &browser_view_renderer_); | 212 web_contents_.get(), &browser_view_renderer_); |
| 213 AwContentsLifecycleNotifier::OnWebViewCreated(); | 213 AwContentsLifecycleNotifier::OnWebViewCreated(); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void AwContents::SetJavaPeers(JNIEnv* env, | 216 void AwContents::SetJavaPeers( |
| 217 jobject obj, | 217 JNIEnv* env, |
| 218 jobject aw_contents, | 218 const JavaParamRef<jobject>& obj, |
| 219 jobject web_contents_delegate, | 219 const JavaParamRef<jobject>& aw_contents, |
| 220 jobject contents_client_bridge, | 220 const JavaParamRef<jobject>& web_contents_delegate, |
| 221 jobject io_thread_client, | 221 const JavaParamRef<jobject>& contents_client_bridge, |
| 222 jobject intercept_navigation_delegate) { | 222 const JavaParamRef<jobject>& io_thread_client, |
| 223 const JavaParamRef<jobject>& intercept_navigation_delegate) { | |
| 223 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 224 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 224 // The |aw_content| param is technically spurious as it duplicates |obj| but | 225 // The |aw_content| param is technically spurious as it duplicates |obj| but |
| 225 // is passed over anyway to make the binding more explicit. | 226 // is passed over anyway to make the binding more explicit. |
| 226 java_ref_ = JavaObjectWeakGlobalRef(env, aw_contents); | 227 java_ref_ = JavaObjectWeakGlobalRef(env, aw_contents); |
| 227 | 228 |
| 228 web_contents_delegate_.reset( | 229 web_contents_delegate_.reset( |
| 229 new AwWebContentsDelegate(env, web_contents_delegate)); | 230 new AwWebContentsDelegate(env, web_contents_delegate)); |
| 230 web_contents_->SetDelegate(web_contents_delegate_.get()); | 231 web_contents_->SetDelegate(web_contents_delegate_.get()); |
| 231 | 232 |
| 232 contents_client_bridge_.reset( | 233 contents_client_bridge_.reset( |
| 233 new AwContentsClientBridge(env, contents_client_bridge)); | 234 new AwContentsClientBridge(env, contents_client_bridge)); |
| 234 AwContentsClientBridgeBase::Associate(web_contents_.get(), | 235 AwContentsClientBridgeBase::Associate(web_contents_.get(), |
| 235 contents_client_bridge_.get()); | 236 contents_client_bridge_.get()); |
| 236 | 237 |
| 237 AwContentsIoThreadClientImpl::Associate( | 238 AwContentsIoThreadClientImpl::Associate(web_contents_.get(), |
|
Torne
2015/12/03 14:56:30
manual change here: no need to construct a tempora
sgurun-gerrit only
2015/12/03 22:21:38
yes. Although I did not see any reason for creatin
| |
| 238 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, io_thread_client)); | 239 io_thread_client); |
| 239 | 240 |
| 240 InterceptNavigationDelegate::Associate( | 241 InterceptNavigationDelegate::Associate( |
| 241 web_contents_.get(), | 242 web_contents_.get(), |
| 242 make_scoped_ptr(new InterceptNavigationDelegate( | 243 make_scoped_ptr(new InterceptNavigationDelegate( |
| 243 env, intercept_navigation_delegate))); | 244 env, intercept_navigation_delegate))); |
| 244 | 245 |
| 245 // Finally, having setup the associations, release any deferred requests | 246 // Finally, having setup the associations, release any deferred requests |
| 246 web_contents_->ForEachFrame(base::Bind(&OnIoThreadClientReady)); | 247 web_contents_->ForEachFrame(base::Bind(&OnIoThreadClientReady)); |
| 247 } | 248 } |
| 248 | 249 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 // without ever using another WebView. | 297 // without ever using another WebView. |
| 297 if (instance_count == 0) { | 298 if (instance_count == 0) { |
| 298 // TODO(timvolodine): consider moving NotifyMemoryPressure to | 299 // TODO(timvolodine): consider moving NotifyMemoryPressure to |
| 299 // AwContentsLifecycleNotifier (crbug.com/522988). | 300 // AwContentsLifecycleNotifier (crbug.com/522988). |
| 300 base::MemoryPressureListener::NotifyMemoryPressure( | 301 base::MemoryPressureListener::NotifyMemoryPressure( |
| 301 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); | 302 base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 302 } | 303 } |
| 303 AwContentsLifecycleNotifier::OnWebViewDestroyed(); | 304 AwContentsLifecycleNotifier::OnWebViewDestroyed(); |
| 304 } | 305 } |
| 305 | 306 |
| 306 base::android::ScopedJavaLocalRef<jobject> | 307 base::android::ScopedJavaLocalRef<jobject> AwContents::GetWebContents( |
| 307 AwContents::GetWebContents(JNIEnv* env, jobject obj) { | 308 JNIEnv* env, |
| 309 const JavaParamRef<jobject>& obj) { | |
| 308 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 310 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 309 DCHECK(web_contents_); | 311 DCHECK(web_contents_); |
| 310 if (!web_contents_) | 312 if (!web_contents_) |
| 311 return base::android::ScopedJavaLocalRef<jobject>(); | 313 return base::android::ScopedJavaLocalRef<jobject>(); |
| 312 | 314 |
| 313 return web_contents_->GetJavaWebContents(); | 315 return web_contents_->GetJavaWebContents(); |
| 314 } | 316 } |
| 315 | 317 |
| 316 void AwContents::Destroy(JNIEnv* env, jobject obj) { | 318 void AwContents::Destroy(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 317 java_ref_.reset(); | 319 java_ref_.reset(); |
| 318 delete this; | 320 delete this; |
| 319 } | 321 } |
| 320 | 322 |
| 321 static jlong Init(JNIEnv* env, | 323 static jlong Init(JNIEnv* env, |
| 322 const JavaParamRef<jclass>&, | 324 const JavaParamRef<jclass>&, |
| 323 const JavaParamRef<jobject>& browser_context) { | 325 const JavaParamRef<jobject>& browser_context) { |
| 324 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather | 326 // TODO(joth): Use |browser_context| to get the native BrowserContext, rather |
| 325 // than hard-code the default instance lookup here. | 327 // than hard-code the default instance lookup here. |
| 326 scoped_ptr<WebContents> web_contents(content::WebContents::Create( | 328 scoped_ptr<WebContents> web_contents(content::WebContents::Create( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 350 | 352 |
| 351 static jlong GetAwDrawGLFunction(JNIEnv* env, const JavaParamRef<jclass>&) { | 353 static jlong GetAwDrawGLFunction(JNIEnv* env, const JavaParamRef<jclass>&) { |
| 352 return reinterpret_cast<intptr_t>(&DrawGLFunction); | 354 return reinterpret_cast<intptr_t>(&DrawGLFunction); |
| 353 } | 355 } |
| 354 | 356 |
| 355 // static | 357 // static |
| 356 jint GetNativeInstanceCount(JNIEnv* env, const JavaParamRef<jclass>&) { | 358 jint GetNativeInstanceCount(JNIEnv* env, const JavaParamRef<jclass>&) { |
| 357 return base::subtle::NoBarrier_Load(&g_instance_count); | 359 return base::subtle::NoBarrier_Load(&g_instance_count); |
| 358 } | 360 } |
| 359 | 361 |
| 360 jlong AwContents::GetAwDrawGLViewContext(JNIEnv* env, jobject obj) { | 362 jlong AwContents::GetAwDrawGLViewContext(JNIEnv* env, |
| 363 const JavaParamRef<jobject>& obj) { | |
| 361 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 364 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 362 return reinterpret_cast<intptr_t>( | 365 return reinterpret_cast<intptr_t>( |
| 363 browser_view_renderer_.GetAwDrawGLViewContext()); | 366 browser_view_renderer_.GetAwDrawGLViewContext()); |
| 364 } | 367 } |
| 365 | 368 |
| 366 namespace { | 369 namespace { |
| 367 void DocumentHasImagesCallback(const ScopedJavaGlobalRef<jobject>& message, | 370 void DocumentHasImagesCallback(const ScopedJavaGlobalRef<jobject>& message, |
| 368 bool has_images) { | 371 bool has_images) { |
| 369 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), | 372 Java_AwContents_onDocumentHasImagesResponse(AttachCurrentThread(), |
| 370 has_images, | 373 has_images, |
| 371 message.obj()); | 374 message.obj()); |
| 372 } | 375 } |
| 373 } // namespace | 376 } // namespace |
| 374 | 377 |
| 375 void AwContents::DocumentHasImages(JNIEnv* env, jobject obj, jobject message) { | 378 void AwContents::DocumentHasImages(JNIEnv* env, |
| 379 const JavaParamRef<jobject>& obj, | |
| 380 const JavaParamRef<jobject>& message) { | |
| 376 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 381 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 377 ScopedJavaGlobalRef<jobject> j_message; | 382 ScopedJavaGlobalRef<jobject> j_message; |
| 378 j_message.Reset(env, message); | 383 j_message.Reset(env, message); |
| 379 render_view_host_ext_->DocumentHasImages( | 384 render_view_host_ext_->DocumentHasImages( |
| 380 base::Bind(&DocumentHasImagesCallback, j_message)); | 385 base::Bind(&DocumentHasImagesCallback, j_message)); |
| 381 } | 386 } |
| 382 | 387 |
| 383 namespace { | 388 namespace { |
| 384 void GenerateMHTMLCallback(ScopedJavaGlobalRef<jobject>* callback, | 389 void GenerateMHTMLCallback(ScopedJavaGlobalRef<jobject>* callback, |
| 385 const base::FilePath& path, int64 size) { | 390 const base::FilePath& path, int64 size) { |
| 386 JNIEnv* env = AttachCurrentThread(); | 391 JNIEnv* env = AttachCurrentThread(); |
| 387 // Android files are UTF8, so the path conversion below is safe. | 392 // Android files are UTF8, so the path conversion below is safe. |
| 388 Java_AwContents_generateMHTMLCallback( | 393 Java_AwContents_generateMHTMLCallback( |
| 389 env, | 394 env, |
| 390 ConvertUTF8ToJavaString(env, path.AsUTF8Unsafe()).obj(), | 395 ConvertUTF8ToJavaString(env, path.AsUTF8Unsafe()).obj(), |
| 391 size, callback->obj()); | 396 size, callback->obj()); |
| 392 } | 397 } |
| 393 } // namespace | 398 } // namespace |
| 394 | 399 |
| 395 void AwContents::GenerateMHTML(JNIEnv* env, jobject obj, | 400 void AwContents::GenerateMHTML(JNIEnv* env, |
| 396 jstring jpath, jobject callback) { | 401 const JavaParamRef<jobject>& obj, |
| 402 const JavaParamRef<jstring>& jpath, | |
| 403 const JavaParamRef<jobject>& callback) { | |
| 397 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 404 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 398 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); | 405 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); |
| 399 j_callback->Reset(env, callback); | 406 j_callback->Reset(env, callback); |
| 400 base::FilePath target_path(ConvertJavaStringToUTF8(env, jpath)); | 407 base::FilePath target_path(ConvertJavaStringToUTF8(env, jpath)); |
| 401 web_contents_->GenerateMHTML( | 408 web_contents_->GenerateMHTML( |
| 402 target_path, | 409 target_path, |
| 403 base::Bind(&GenerateMHTMLCallback, base::Owned(j_callback), target_path)); | 410 base::Bind(&GenerateMHTMLCallback, base::Owned(j_callback), target_path)); |
| 404 } | 411 } |
| 405 | 412 |
| 406 void AwContents::CreatePdfExporter(JNIEnv* env, | 413 void AwContents::CreatePdfExporter(JNIEnv* env, |
| 407 jobject obj, | 414 const JavaParamRef<jobject>& obj, |
| 408 jobject pdfExporter) { | 415 const JavaParamRef<jobject>& pdfExporter) { |
| 409 pdf_exporter_.reset( | 416 pdf_exporter_.reset( |
| 410 new AwPdfExporter(env, | 417 new AwPdfExporter(env, |
| 411 pdfExporter, | 418 pdfExporter, |
| 412 web_contents_.get())); | 419 web_contents_.get())); |
| 413 } | 420 } |
| 414 | 421 |
| 415 bool AwContents::OnReceivedHttpAuthRequest(const JavaRef<jobject>& handler, | 422 bool AwContents::OnReceivedHttpAuthRequest(const JavaRef<jobject>& handler, |
| 416 const std::string& host, | 423 const std::string& host, |
| 417 const std::string& realm) { | 424 const std::string& realm) { |
| 418 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 425 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 419 JNIEnv* env = AttachCurrentThread(); | 426 JNIEnv* env = AttachCurrentThread(); |
| 420 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 427 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 421 if (obj.is_null()) | 428 if (obj.is_null()) |
| 422 return false; | 429 return false; |
| 423 | 430 |
| 424 ScopedJavaLocalRef<jstring> jhost = ConvertUTF8ToJavaString(env, host); | 431 ScopedJavaLocalRef<jstring> jhost = ConvertUTF8ToJavaString(env, host); |
| 425 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); | 432 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); |
| 426 devtools_instrumentation::ScopedEmbedderCallbackTask embedder_callback( | 433 devtools_instrumentation::ScopedEmbedderCallbackTask embedder_callback( |
| 427 "onReceivedHttpAuthRequest"); | 434 "onReceivedHttpAuthRequest"); |
| 428 Java_AwContents_onReceivedHttpAuthRequest(env, obj.obj(), handler.obj(), | 435 Java_AwContents_onReceivedHttpAuthRequest(env, obj.obj(), handler.obj(), |
| 429 jhost.obj(), jrealm.obj()); | 436 jhost.obj(), jrealm.obj()); |
| 430 return true; | 437 return true; |
| 431 } | 438 } |
| 432 | 439 |
| 433 void AwContents::SetOffscreenPreRaster(bool enabled) { | 440 void AwContents::SetOffscreenPreRaster(bool enabled) { |
| 434 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 441 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 435 browser_view_renderer_.SetOffscreenPreRaster(enabled); | 442 browser_view_renderer_.SetOffscreenPreRaster(enabled); |
| 436 } | 443 } |
| 437 | 444 |
| 438 void AwContents::AddVisitedLinks(JNIEnv* env, | 445 void AwContents::AddVisitedLinks( |
| 439 jobject obj, | 446 JNIEnv* env, |
| 440 jobjectArray jvisited_links) { | 447 const JavaParamRef<jobject>& obj, |
| 448 const JavaParamRef<jobjectArray>& jvisited_links) { | |
| 441 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 449 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 442 std::vector<base::string16> visited_link_strings; | 450 std::vector<base::string16> visited_link_strings; |
| 443 base::android::AppendJavaStringArrayToStringVector( | 451 base::android::AppendJavaStringArrayToStringVector( |
| 444 env, jvisited_links, &visited_link_strings); | 452 env, jvisited_links, &visited_link_strings); |
| 445 | 453 |
| 446 std::vector<GURL> visited_link_gurls; | 454 std::vector<GURL> visited_link_gurls; |
| 447 std::vector<base::string16>::const_iterator itr; | 455 std::vector<base::string16>::const_iterator itr; |
| 448 for (itr = visited_link_strings.begin(); itr != visited_link_strings.end(); | 456 for (itr = visited_link_strings.begin(); itr != visited_link_strings.end(); |
| 449 ++itr) { | 457 ++itr) { |
| 450 visited_link_gurls.push_back(GURL(*itr)); | 458 visited_link_gurls.push_back(GURL(*itr)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 496 | 504 |
| 497 GURL origin = requesting_frame.GetOrigin(); | 505 GURL origin = requesting_frame.GetOrigin(); |
| 498 bool show_prompt = pending_geolocation_prompts_.empty(); | 506 bool show_prompt = pending_geolocation_prompts_.empty(); |
| 499 pending_geolocation_prompts_.push_back(OriginCallback(origin, callback)); | 507 pending_geolocation_prompts_.push_back(OriginCallback(origin, callback)); |
| 500 if (show_prompt) { | 508 if (show_prompt) { |
| 501 ShowGeolocationPromptHelper(java_ref_, origin); | 509 ShowGeolocationPromptHelper(java_ref_, origin); |
| 502 } | 510 } |
| 503 } | 511 } |
| 504 | 512 |
| 505 // Invoked from Java | 513 // Invoked from Java |
| 506 void AwContents::InvokeGeolocationCallback(JNIEnv* env, | 514 void AwContents::InvokeGeolocationCallback( |
| 507 jobject obj, | 515 JNIEnv* env, |
| 508 jboolean value, | 516 const JavaParamRef<jobject>& obj, |
| 509 jstring origin) { | 517 jboolean value, |
| 518 const JavaParamRef<jstring>& origin) { | |
| 510 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 519 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 511 if (pending_geolocation_prompts_.empty()) | 520 if (pending_geolocation_prompts_.empty()) |
| 512 return; | 521 return; |
| 513 | 522 |
| 514 GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin)); | 523 GURL callback_origin(base::android::ConvertJavaStringToUTF16(env, origin)); |
| 515 if (callback_origin.GetOrigin() == | 524 if (callback_origin.GetOrigin() == |
| 516 pending_geolocation_prompts_.front().first) { | 525 pending_geolocation_prompts_.front().first) { |
| 517 pending_geolocation_prompts_.front().second.Run(value); | 526 pending_geolocation_prompts_.front().second.Run(value); |
| 518 pending_geolocation_prompts_.pop_front(); | 527 pending_geolocation_prompts_.pop_front(); |
| 519 if (!pending_geolocation_prompts_.empty()) { | 528 if (!pending_geolocation_prompts_.empty()) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 JNIEnv* env = AttachCurrentThread(); | 583 JNIEnv* env = AttachCurrentThread(); |
| 575 ScopedJavaLocalRef<jobject> j_request = request->GetJavaObject(); | 584 ScopedJavaLocalRef<jobject> j_request = request->GetJavaObject(); |
| 576 ScopedJavaLocalRef<jobject> j_ref = java_ref_.get(env); | 585 ScopedJavaLocalRef<jobject> j_ref = java_ref_.get(env); |
| 577 if (j_request.is_null() || j_ref.is_null()) | 586 if (j_request.is_null() || j_ref.is_null()) |
| 578 return; | 587 return; |
| 579 | 588 |
| 580 Java_AwContents_onPermissionRequestCanceled( | 589 Java_AwContents_onPermissionRequestCanceled( |
| 581 env, j_ref.obj(), j_request.obj()); | 590 env, j_ref.obj(), j_request.obj()); |
| 582 } | 591 } |
| 583 | 592 |
| 584 void AwContents::PreauthorizePermission( | 593 void AwContents::PreauthorizePermission(JNIEnv* env, |
| 585 JNIEnv* env, | 594 const JavaParamRef<jobject>& obj, |
| 586 jobject obj, | 595 const JavaParamRef<jstring>& origin, |
| 587 jstring origin, | 596 jlong resources) { |
| 588 jlong resources) { | |
| 589 permission_request_handler_->PreauthorizePermission( | 597 permission_request_handler_->PreauthorizePermission( |
| 590 GURL(base::android::ConvertJavaStringToUTF8(env, origin)), resources); | 598 GURL(base::android::ConvertJavaStringToUTF8(env, origin)), resources); |
| 591 } | 599 } |
| 592 | 600 |
| 593 void AwContents::RequestProtectedMediaIdentifierPermission( | 601 void AwContents::RequestProtectedMediaIdentifierPermission( |
| 594 const GURL& origin, | 602 const GURL& origin, |
| 595 const base::Callback<void(bool)>& callback) { | 603 const base::Callback<void(bool)>& callback) { |
| 596 permission_request_handler_->SendRequest( | 604 permission_request_handler_->SendRequest( |
| 597 scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest( | 605 scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest( |
| 598 origin, AwPermissionRequest::ProtectedMediaId, callback))); | 606 origin, AwPermissionRequest::ProtectedMediaId, callback))); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 641 permission_request_handler_->SendRequest( | 649 permission_request_handler_->SendRequest( |
| 642 scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest( | 650 scoped_ptr<AwPermissionRequestDelegate>(new SimplePermissionRequest( |
| 643 origin, AwPermissionRequest::MIDISysex, callback))); | 651 origin, AwPermissionRequest::MIDISysex, callback))); |
| 644 } | 652 } |
| 645 | 653 |
| 646 void AwContents::CancelMIDISysexPermissionRequests(const GURL& origin) { | 654 void AwContents::CancelMIDISysexPermissionRequests(const GURL& origin) { |
| 647 permission_request_handler_->CancelRequest( | 655 permission_request_handler_->CancelRequest( |
| 648 origin, AwPermissionRequest::AwPermissionRequest::MIDISysex); | 656 origin, AwPermissionRequest::AwPermissionRequest::MIDISysex); |
| 649 } | 657 } |
| 650 | 658 |
| 651 void AwContents::FindAllAsync(JNIEnv* env, jobject obj, jstring search_string) { | 659 void AwContents::FindAllAsync(JNIEnv* env, |
| 660 const JavaParamRef<jobject>& obj, | |
| 661 const JavaParamRef<jstring>& search_string) { | |
| 652 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 662 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 653 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); | 663 GetFindHelper()->FindAllAsync(ConvertJavaStringToUTF16(env, search_string)); |
| 654 } | 664 } |
| 655 | 665 |
| 656 void AwContents::FindNext(JNIEnv* env, jobject obj, jboolean forward) { | 666 void AwContents::FindNext(JNIEnv* env, |
| 667 const JavaParamRef<jobject>& obj, | |
| 668 jboolean forward) { | |
| 657 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 669 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 658 GetFindHelper()->FindNext(forward); | 670 GetFindHelper()->FindNext(forward); |
| 659 } | 671 } |
| 660 | 672 |
| 661 void AwContents::ClearMatches(JNIEnv* env, jobject obj) { | 673 void AwContents::ClearMatches(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 662 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 674 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 663 GetFindHelper()->ClearMatches(); | 675 GetFindHelper()->ClearMatches(); |
| 664 } | 676 } |
| 665 | 677 |
| 666 void AwContents::ClearCache( | 678 void AwContents::ClearCache(JNIEnv* env, |
| 667 JNIEnv* env, | 679 const JavaParamRef<jobject>& obj, |
| 668 jobject obj, | 680 jboolean include_disk_files) { |
| 669 jboolean include_disk_files) { | |
| 670 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 681 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 671 render_view_host_ext_->ClearCache(); | 682 render_view_host_ext_->ClearCache(); |
| 672 | 683 |
| 673 if (include_disk_files) { | 684 if (include_disk_files) { |
| 674 RemoveHttpDiskCache(web_contents_->GetBrowserContext(), | 685 RemoveHttpDiskCache(web_contents_->GetBrowserContext(), |
| 675 web_contents_->GetRoutingID()); | 686 web_contents_->GetRoutingID()); |
| 676 } | 687 } |
| 677 } | 688 } |
| 678 | 689 |
| 679 FindHelper* AwContents::GetFindHelper() { | 690 FindHelper* AwContents::GetFindHelper() { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 757 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 768 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 758 if (!obj.is_null()) { | 769 if (!obj.is_null()) { |
| 759 devtools_instrumentation::ScopedEmbedderCallbackTask embedder_callback( | 770 devtools_instrumentation::ScopedEmbedderCallbackTask embedder_callback( |
| 760 "onNewPicture"); | 771 "onNewPicture"); |
| 761 Java_AwContents_onNewPicture(env, obj.obj()); | 772 Java_AwContents_onNewPicture(env, obj.obj()); |
| 762 } | 773 } |
| 763 } | 774 } |
| 764 | 775 |
| 765 base::android::ScopedJavaLocalRef<jbyteArray> AwContents::GetCertificate( | 776 base::android::ScopedJavaLocalRef<jbyteArray> AwContents::GetCertificate( |
| 766 JNIEnv* env, | 777 JNIEnv* env, |
| 767 jobject obj) { | 778 const JavaParamRef<jobject>& obj) { |
| 768 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 779 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 769 content::NavigationEntry* entry = | 780 content::NavigationEntry* entry = |
| 770 web_contents_->GetController().GetLastCommittedEntry(); | 781 web_contents_->GetController().GetLastCommittedEntry(); |
| 771 if (!entry) | 782 if (!entry) |
| 772 return ScopedJavaLocalRef<jbyteArray>(); | 783 return ScopedJavaLocalRef<jbyteArray>(); |
| 773 // Get the certificate | 784 // Get the certificate |
| 774 int cert_id = entry->GetSSL().cert_id; | 785 int cert_id = entry->GetSSL().cert_id; |
| 775 scoped_refptr<net::X509Certificate> cert; | 786 scoped_refptr<net::X509Certificate> cert; |
| 776 bool ok = content::CertStore::GetInstance()->RetrieveCert(cert_id, &cert); | 787 bool ok = content::CertStore::GetInstance()->RetrieveCert(cert_id, &cert); |
| 777 if (!ok) | 788 if (!ok) |
| 778 return ScopedJavaLocalRef<jbyteArray>(); | 789 return ScopedJavaLocalRef<jbyteArray>(); |
| 779 | 790 |
| 780 // Convert the certificate and return it | 791 // Convert the certificate and return it |
| 781 std::string der_string; | 792 std::string der_string; |
| 782 net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_string); | 793 net::X509Certificate::GetDEREncoded(cert->os_cert_handle(), &der_string); |
| 783 return base::android::ToJavaByteArray(env, | 794 return base::android::ToJavaByteArray(env, |
| 784 reinterpret_cast<const uint8*>(der_string.data()), der_string.length()); | 795 reinterpret_cast<const uint8*>(der_string.data()), der_string.length()); |
| 785 } | 796 } |
| 786 | 797 |
| 787 void AwContents::RequestNewHitTestDataAt(JNIEnv* env, | 798 void AwContents::RequestNewHitTestDataAt(JNIEnv* env, |
| 788 jobject obj, | 799 const JavaParamRef<jobject>& obj, |
| 789 jfloat x, | 800 jfloat x, |
| 790 jfloat y, | 801 jfloat y, |
| 791 jfloat touch_major) { | 802 jfloat touch_major) { |
| 792 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 803 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 793 gfx::PointF touch_center(x, y); | 804 gfx::PointF touch_center(x, y); |
| 794 gfx::SizeF touch_area(touch_major, touch_major); | 805 gfx::SizeF touch_area(touch_major, touch_major); |
| 795 render_view_host_ext_->RequestNewHitTestDataAt(touch_center, touch_area); | 806 render_view_host_ext_->RequestNewHitTestDataAt(touch_center, touch_area); |
| 796 } | 807 } |
| 797 | 808 |
| 798 void AwContents::UpdateLastHitTestData(JNIEnv* env, jobject obj) { | 809 void AwContents::UpdateLastHitTestData(JNIEnv* env, |
| 810 const JavaParamRef<jobject>& obj) { | |
| 799 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 811 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 800 if (!render_view_host_ext_->HasNewHitTestData()) return; | 812 if (!render_view_host_ext_->HasNewHitTestData()) return; |
| 801 | 813 |
| 802 const AwHitTestData& data = render_view_host_ext_->GetLastHitTestData(); | 814 const AwHitTestData& data = render_view_host_ext_->GetLastHitTestData(); |
| 803 render_view_host_ext_->MarkHitTestDataRead(); | 815 render_view_host_ext_->MarkHitTestDataRead(); |
| 804 | 816 |
| 805 // Make sure to null the Java object if data is empty/invalid. | 817 // Make sure to null the Java object if data is empty/invalid. |
| 806 ScopedJavaLocalRef<jstring> extra_data_for_type; | 818 ScopedJavaLocalRef<jstring> extra_data_for_type; |
| 807 if (data.extra_data_for_type.length()) | 819 if (data.extra_data_for_type.length()) |
| 808 extra_data_for_type = ConvertUTF8ToJavaString( | 820 extra_data_for_type = ConvertUTF8ToJavaString( |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 822 | 834 |
| 823 Java_AwContents_updateHitTestData(env, | 835 Java_AwContents_updateHitTestData(env, |
| 824 obj, | 836 obj, |
| 825 data.type, | 837 data.type, |
| 826 extra_data_for_type.obj(), | 838 extra_data_for_type.obj(), |
| 827 href.obj(), | 839 href.obj(), |
| 828 anchor_text.obj(), | 840 anchor_text.obj(), |
| 829 img_src.obj()); | 841 img_src.obj()); |
| 830 } | 842 } |
| 831 | 843 |
| 832 void AwContents::OnSizeChanged(JNIEnv* env, jobject obj, | 844 void AwContents::OnSizeChanged(JNIEnv* env, |
| 833 int w, int h, int ow, int oh) { | 845 const JavaParamRef<jobject>& obj, |
| 846 int w, | |
| 847 int h, | |
| 848 int ow, | |
| 849 int oh) { | |
| 834 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 850 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 835 browser_view_renderer_.OnSizeChanged(w, h); | 851 browser_view_renderer_.OnSizeChanged(w, h); |
| 836 } | 852 } |
| 837 | 853 |
| 838 void AwContents::SetViewVisibility(JNIEnv* env, jobject obj, bool visible) { | 854 void AwContents::SetViewVisibility(JNIEnv* env, |
| 855 const JavaParamRef<jobject>& obj, | |
| 856 bool visible) { | |
| 839 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 857 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 840 browser_view_renderer_.SetViewVisibility(visible); | 858 browser_view_renderer_.SetViewVisibility(visible); |
| 841 } | 859 } |
| 842 | 860 |
| 843 void AwContents::SetWindowVisibility(JNIEnv* env, jobject obj, bool visible) { | 861 void AwContents::SetWindowVisibility(JNIEnv* env, |
| 862 const JavaParamRef<jobject>& obj, | |
| 863 bool visible) { | |
| 844 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 864 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 845 browser_view_renderer_.SetWindowVisibility(visible); | 865 browser_view_renderer_.SetWindowVisibility(visible); |
| 846 } | 866 } |
| 847 | 867 |
| 848 void AwContents::SetIsPaused(JNIEnv* env, jobject obj, bool paused) { | 868 void AwContents::SetIsPaused(JNIEnv* env, |
| 869 const JavaParamRef<jobject>& obj, | |
| 870 bool paused) { | |
| 849 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 871 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 850 browser_view_renderer_.SetIsPaused(paused); | 872 browser_view_renderer_.SetIsPaused(paused); |
| 851 ContentViewCore* cvc = | 873 ContentViewCore* cvc = |
| 852 ContentViewCore::FromWebContents(web_contents_.get()); | 874 ContentViewCore::FromWebContents(web_contents_.get()); |
| 853 if (cvc) { | 875 if (cvc) { |
| 854 cvc->PauseOrResumeGeolocation(paused); | 876 cvc->PauseOrResumeGeolocation(paused); |
| 855 } | 877 } |
| 856 } | 878 } |
| 857 | 879 |
| 858 void AwContents::OnAttachedToWindow(JNIEnv* env, jobject obj, int w, int h) { | 880 void AwContents::OnAttachedToWindow(JNIEnv* env, |
| 881 const JavaParamRef<jobject>& obj, | |
| 882 int w, | |
| 883 int h) { | |
| 859 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 884 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 860 browser_view_renderer_.OnAttachedToWindow(w, h); | 885 browser_view_renderer_.OnAttachedToWindow(w, h); |
| 861 } | 886 } |
| 862 | 887 |
| 863 void AwContents::OnDetachedFromWindow(JNIEnv* env, jobject obj) { | 888 void AwContents::OnDetachedFromWindow(JNIEnv* env, |
| 889 const JavaParamRef<jobject>& obj) { | |
| 864 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 890 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 865 browser_view_renderer_.OnDetachedFromWindow(); | 891 browser_view_renderer_.OnDetachedFromWindow(); |
| 866 } | 892 } |
| 867 | 893 |
| 868 bool AwContents::IsVisible(JNIEnv* env, jobject obj) { | 894 bool AwContents::IsVisible(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 869 return browser_view_renderer_.IsClientVisible(); | 895 return browser_view_renderer_.IsClientVisible(); |
| 870 } | 896 } |
| 871 | 897 |
| 872 void AwContents::DetachFunctorFromView() { | 898 void AwContents::DetachFunctorFromView() { |
| 873 JNIEnv* env = AttachCurrentThread(); | 899 JNIEnv* env = AttachCurrentThread(); |
| 874 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 900 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 875 if (!obj.is_null()) | 901 if (!obj.is_null()) |
| 876 Java_AwContents_detachFunctorFromView(env, obj.obj()); | 902 Java_AwContents_detachFunctorFromView(env, obj.obj()); |
| 877 } | 903 } |
| 878 | 904 |
| 879 base::android::ScopedJavaLocalRef<jbyteArray> | 905 base::android::ScopedJavaLocalRef<jbyteArray> AwContents::GetOpaqueState( |
| 880 AwContents::GetOpaqueState(JNIEnv* env, jobject obj) { | 906 JNIEnv* env, |
| 907 const JavaParamRef<jobject>& obj) { | |
| 881 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 908 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 882 // Required optimization in WebViewClassic to not save any state if | 909 // Required optimization in WebViewClassic to not save any state if |
| 883 // there has been no navigations. | 910 // there has been no navigations. |
| 884 if (!web_contents_->GetController().GetEntryCount()) | 911 if (!web_contents_->GetController().GetEntryCount()) |
| 885 return ScopedJavaLocalRef<jbyteArray>(); | 912 return ScopedJavaLocalRef<jbyteArray>(); |
| 886 | 913 |
| 887 base::Pickle pickle; | 914 base::Pickle pickle; |
| 888 if (!WriteToPickle(*web_contents_, &pickle)) { | 915 if (!WriteToPickle(*web_contents_, &pickle)) { |
| 889 return ScopedJavaLocalRef<jbyteArray>(); | 916 return ScopedJavaLocalRef<jbyteArray>(); |
| 890 } else { | 917 } else { |
| 891 return base::android::ToJavaByteArray(env, | 918 return base::android::ToJavaByteArray(env, |
| 892 reinterpret_cast<const uint8*>(pickle.data()), pickle.size()); | 919 reinterpret_cast<const uint8*>(pickle.data()), pickle.size()); |
| 893 } | 920 } |
| 894 } | 921 } |
| 895 | 922 |
| 896 jboolean AwContents::RestoreFromOpaqueState( | 923 jboolean AwContents::RestoreFromOpaqueState( |
| 897 JNIEnv* env, jobject obj, jbyteArray state) { | 924 JNIEnv* env, |
| 925 const JavaParamRef<jobject>& obj, | |
| 926 const JavaParamRef<jbyteArray>& state) { | |
| 898 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 927 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 899 // TODO(boliu): This copy can be optimized out if this is a performance | 928 // TODO(boliu): This copy can be optimized out if this is a performance |
| 900 // problem. | 929 // problem. |
| 901 std::vector<uint8> state_vector; | 930 std::vector<uint8> state_vector; |
| 902 base::android::JavaByteArrayToByteVector(env, state, &state_vector); | 931 base::android::JavaByteArrayToByteVector(env, state, &state_vector); |
| 903 | 932 |
| 904 base::Pickle pickle(reinterpret_cast<const char*>(state_vector.data()), | 933 base::Pickle pickle(reinterpret_cast<const char*>(state_vector.data()), |
| 905 state_vector.size()); | 934 state_vector.size()); |
| 906 base::PickleIterator iterator(pickle); | 935 base::PickleIterator iterator(pickle); |
| 907 | 936 |
| 908 return RestoreFromPickle(&iterator, web_contents_.get()); | 937 return RestoreFromPickle(&iterator, web_contents_.get()); |
| 909 } | 938 } |
| 910 | 939 |
| 911 bool AwContents::OnDraw(JNIEnv* env, | 940 bool AwContents::OnDraw(JNIEnv* env, |
| 912 jobject obj, | 941 const JavaParamRef<jobject>& obj, |
| 913 jobject canvas, | 942 const JavaParamRef<jobject>& canvas, |
| 914 jboolean is_hardware_accelerated, | 943 jboolean is_hardware_accelerated, |
| 915 jint scroll_x, | 944 jint scroll_x, |
| 916 jint scroll_y, | 945 jint scroll_y, |
| 917 jint visible_left, | 946 jint visible_left, |
| 918 jint visible_top, | 947 jint visible_top, |
| 919 jint visible_right, | 948 jint visible_right, |
| 920 jint visible_bottom) { | 949 jint visible_bottom) { |
| 921 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 950 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 922 gfx::Vector2d scroll(scroll_x, scroll_y); | 951 gfx::Vector2d scroll(scroll_x, scroll_y); |
| 923 browser_view_renderer_.PrepareToDraw( | 952 browser_view_renderer_.PrepareToDraw( |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 959 << "popup window is still pending."; | 988 << "popup window is still pending."; |
| 960 base::MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); | 989 base::MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); |
| 961 return; | 990 return; |
| 962 } | 991 } |
| 963 pending_contents_.reset(new AwContents(pending.Pass())); | 992 pending_contents_.reset(new AwContents(pending.Pass())); |
| 964 // Set dip_scale for pending contents, which is necessary for the later | 993 // Set dip_scale for pending contents, which is necessary for the later |
| 965 // SynchronousCompositor and InputHandler setup. | 994 // SynchronousCompositor and InputHandler setup. |
| 966 pending_contents_->SetDipScaleInternal(browser_view_renderer_.dip_scale()); | 995 pending_contents_->SetDipScaleInternal(browser_view_renderer_.dip_scale()); |
| 967 } | 996 } |
| 968 | 997 |
| 969 void AwContents::FocusFirstNode(JNIEnv* env, jobject obj) { | 998 void AwContents::FocusFirstNode(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 970 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 999 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 971 web_contents_->FocusThroughTabTraversal(false); | 1000 web_contents_->FocusThroughTabTraversal(false); |
| 972 } | 1001 } |
| 973 | 1002 |
| 974 void AwContents::SetBackgroundColor(JNIEnv* env, jobject obj, jint color) { | 1003 void AwContents::SetBackgroundColor(JNIEnv* env, |
| 1004 const JavaParamRef<jobject>& obj, | |
| 1005 jint color) { | |
| 975 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1006 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 976 render_view_host_ext_->SetBackgroundColor(color); | 1007 render_view_host_ext_->SetBackgroundColor(color); |
| 977 } | 1008 } |
| 978 | 1009 |
| 979 void AwContents::OnComputeScroll(JNIEnv* env, | 1010 void AwContents::OnComputeScroll(JNIEnv* env, |
| 980 jobject obj, | 1011 const JavaParamRef<jobject>& obj, |
| 981 jlong animation_time_millis) { | 1012 jlong animation_time_millis) { |
| 982 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1013 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 983 browser_view_renderer_.OnComputeScroll( | 1014 browser_view_renderer_.OnComputeScroll( |
| 984 base::TimeTicks() + | 1015 base::TimeTicks() + |
| 985 base::TimeDelta::FromMilliseconds(animation_time_millis)); | 1016 base::TimeDelta::FromMilliseconds(animation_time_millis)); |
| 986 } | 1017 } |
| 987 | 1018 |
| 988 jlong AwContents::ReleasePopupAwContents(JNIEnv* env, jobject obj) { | 1019 jlong AwContents::ReleasePopupAwContents(JNIEnv* env, |
| 1020 const JavaParamRef<jobject>& obj) { | |
| 989 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1021 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 990 return reinterpret_cast<intptr_t>(pending_contents_.release()); | 1022 return reinterpret_cast<intptr_t>(pending_contents_.release()); |
| 991 } | 1023 } |
| 992 | 1024 |
| 993 gfx::Point AwContents::GetLocationOnScreen() { | 1025 gfx::Point AwContents::GetLocationOnScreen() { |
| 994 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1026 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 995 JNIEnv* env = AttachCurrentThread(); | 1027 JNIEnv* env = AttachCurrentThread(); |
| 996 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1028 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 997 if (obj.is_null()) | 1029 if (obj.is_null()) |
| 998 return gfx::Point(); | 1030 return gfx::Point(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1040 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1072 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1041 JNIEnv* env = AttachCurrentThread(); | 1073 JNIEnv* env = AttachCurrentThread(); |
| 1042 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1074 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1043 if (obj.is_null()) | 1075 if (obj.is_null()) |
| 1044 return; | 1076 return; |
| 1045 Java_AwContents_didOverscroll(env, obj.obj(), overscroll_delta.x(), | 1077 Java_AwContents_didOverscroll(env, obj.obj(), overscroll_delta.x(), |
| 1046 overscroll_delta.y(), overscroll_velocity.x(), | 1078 overscroll_delta.y(), overscroll_velocity.x(), |
| 1047 overscroll_velocity.y()); | 1079 overscroll_velocity.y()); |
| 1048 } | 1080 } |
| 1049 | 1081 |
| 1050 void AwContents::SetDipScale(JNIEnv* env, jobject obj, jfloat dip_scale) { | 1082 void AwContents::SetDipScale(JNIEnv* env, |
| 1083 const JavaParamRef<jobject>& obj, | |
| 1084 jfloat dip_scale) { | |
| 1051 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1085 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1052 SetDipScaleInternal(dip_scale); | 1086 SetDipScaleInternal(dip_scale); |
| 1053 } | 1087 } |
| 1054 | 1088 |
| 1055 void AwContents::SetDipScaleInternal(float dip_scale) { | 1089 void AwContents::SetDipScaleInternal(float dip_scale) { |
| 1056 browser_view_renderer_.SetDipScale(dip_scale); | 1090 browser_view_renderer_.SetDipScale(dip_scale); |
| 1057 } | 1091 } |
| 1058 | 1092 |
| 1059 void AwContents::ScrollTo(JNIEnv* env, jobject obj, jint x, jint y) { | 1093 void AwContents::ScrollTo(JNIEnv* env, |
| 1094 const JavaParamRef<jobject>& obj, | |
| 1095 jint x, | |
| 1096 jint y) { | |
| 1060 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1097 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1061 browser_view_renderer_.ScrollTo(gfx::Vector2d(x, y)); | 1098 browser_view_renderer_.ScrollTo(gfx::Vector2d(x, y)); |
| 1062 } | 1099 } |
| 1063 | 1100 |
| 1064 void AwContents::SmoothScroll(JNIEnv* env, | 1101 void AwContents::SmoothScroll(JNIEnv* env, |
| 1065 jobject obj, | 1102 const JavaParamRef<jobject>& obj, |
| 1066 jint target_x, | 1103 jint target_x, |
| 1067 jint target_y, | 1104 jint target_y, |
| 1068 jlong duration_ms) { | 1105 jlong duration_ms) { |
| 1069 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1070 | 1107 |
| 1071 float scale = browser_view_renderer_.dip_scale() * | 1108 float scale = browser_view_renderer_.dip_scale() * |
| 1072 browser_view_renderer_.page_scale_factor(); | 1109 browser_view_renderer_.page_scale_factor(); |
| 1073 render_view_host_ext_->SmoothScroll(target_x / scale, target_y / scale, | 1110 render_view_host_ext_->SmoothScroll(target_x / scale, target_y / scale, |
| 1074 duration_ms); | 1111 duration_ms); |
| 1075 } | 1112 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1089 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1126 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1090 JNIEnv* env = AttachCurrentThread(); | 1127 JNIEnv* env = AttachCurrentThread(); |
| 1091 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 1128 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 1092 if (obj.is_null()) | 1129 if (obj.is_null()) |
| 1093 return; | 1130 return; |
| 1094 Java_AwContents_onWebLayoutContentsSizeChanged( | 1131 Java_AwContents_onWebLayoutContentsSizeChanged( |
| 1095 env, obj.obj(), contents_size.width(), contents_size.height()); | 1132 env, obj.obj(), contents_size.width(), contents_size.height()); |
| 1096 } | 1133 } |
| 1097 | 1134 |
| 1098 jlong AwContents::CapturePicture(JNIEnv* env, | 1135 jlong AwContents::CapturePicture(JNIEnv* env, |
| 1099 jobject obj, | 1136 const JavaParamRef<jobject>& obj, |
| 1100 int width, | 1137 int width, |
| 1101 int height) { | 1138 int height) { |
| 1102 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1139 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1103 return reinterpret_cast<intptr_t>( | 1140 return reinterpret_cast<intptr_t>( |
| 1104 new AwPicture(browser_view_renderer_.CapturePicture(width, height))); | 1141 new AwPicture(browser_view_renderer_.CapturePicture(width, height))); |
| 1105 } | 1142 } |
| 1106 | 1143 |
| 1107 void AwContents::EnableOnNewPicture(JNIEnv* env, | 1144 void AwContents::EnableOnNewPicture(JNIEnv* env, |
| 1108 jobject obj, | 1145 const JavaParamRef<jobject>& obj, |
| 1109 jboolean enabled) { | 1146 jboolean enabled) { |
| 1110 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1147 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1111 browser_view_renderer_.EnableOnNewPicture(enabled); | 1148 browser_view_renderer_.EnableOnNewPicture(enabled); |
| 1112 } | 1149 } |
| 1113 | 1150 |
| 1114 namespace { | 1151 namespace { |
| 1115 void InvokeVisualStateCallback(const JavaObjectWeakGlobalRef& java_ref, | 1152 void InvokeVisualStateCallback(const JavaObjectWeakGlobalRef& java_ref, |
| 1116 jlong request_id, | 1153 jlong request_id, |
| 1117 ScopedJavaGlobalRef<jobject>* callback, | 1154 ScopedJavaGlobalRef<jobject>* callback, |
| 1118 bool result) { | 1155 bool result) { |
| 1119 JNIEnv* env = AttachCurrentThread(); | 1156 JNIEnv* env = AttachCurrentThread(); |
| 1120 ScopedJavaLocalRef<jobject> obj = java_ref.get(env); | 1157 ScopedJavaLocalRef<jobject> obj = java_ref.get(env); |
| 1121 if (obj.is_null()) | 1158 if (obj.is_null()) |
| 1122 return; | 1159 return; |
| 1123 Java_AwContents_invokeVisualStateCallback( | 1160 Java_AwContents_invokeVisualStateCallback( |
| 1124 env, obj.obj(), callback->obj(), request_id); | 1161 env, obj.obj(), callback->obj(), request_id); |
| 1125 } | 1162 } |
| 1126 } // namespace | 1163 } // namespace |
| 1127 | 1164 |
| 1128 void AwContents::InsertVisualStateCallback( | 1165 void AwContents::InsertVisualStateCallback( |
| 1129 JNIEnv* env, jobject obj, jlong request_id, jobject callback) { | 1166 JNIEnv* env, |
| 1167 const JavaParamRef<jobject>& obj, | |
| 1168 jlong request_id, | |
| 1169 const JavaParamRef<jobject>& callback) { | |
| 1130 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1170 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1131 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); | 1171 ScopedJavaGlobalRef<jobject>* j_callback = new ScopedJavaGlobalRef<jobject>(); |
| 1132 j_callback->Reset(env, callback); | 1172 j_callback->Reset(env, callback); |
| 1133 web_contents_->GetMainFrame()->InsertVisualStateCallback( | 1173 web_contents_->GetMainFrame()->InsertVisualStateCallback( |
| 1134 base::Bind(&InvokeVisualStateCallback, java_ref_, request_id, | 1174 base::Bind(&InvokeVisualStateCallback, java_ref_, request_id, |
| 1135 base::Owned(j_callback))); | 1175 base::Owned(j_callback))); |
| 1136 } | 1176 } |
| 1137 | 1177 |
| 1138 void AwContents::ClearView(JNIEnv* env, jobject obj) { | 1178 void AwContents::ClearView(JNIEnv* env, const JavaParamRef<jobject>& obj) { |
| 1139 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1179 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1140 browser_view_renderer_.ClearView(); | 1180 browser_view_renderer_.ClearView(); |
| 1141 } | 1181 } |
| 1142 | 1182 |
| 1143 void AwContents::SetExtraHeadersForUrl(JNIEnv* env, jobject obj, | 1183 void AwContents::SetExtraHeadersForUrl( |
| 1144 jstring url, jstring jextra_headers) { | 1184 JNIEnv* env, |
| 1185 const JavaParamRef<jobject>& obj, | |
| 1186 const JavaParamRef<jstring>& url, | |
| 1187 const JavaParamRef<jstring>& jextra_headers) { | |
| 1145 std::string extra_headers; | 1188 std::string extra_headers; |
| 1146 if (jextra_headers) | 1189 if (jextra_headers) |
| 1147 extra_headers = ConvertJavaStringToUTF8(env, jextra_headers); | 1190 extra_headers = ConvertJavaStringToUTF8(env, jextra_headers); |
| 1148 AwResourceContext* resource_context = static_cast<AwResourceContext*>( | 1191 AwResourceContext* resource_context = static_cast<AwResourceContext*>( |
| 1149 AwBrowserContext::FromWebContents(web_contents_.get())-> | 1192 AwBrowserContext::FromWebContents(web_contents_.get())-> |
| 1150 GetResourceContext()); | 1193 GetResourceContext()); |
| 1151 resource_context->SetExtraHeaders(GURL(ConvertJavaStringToUTF8(env, url)), | 1194 resource_context->SetExtraHeaders(GURL(ConvertJavaStringToUTF8(env, url)), |
| 1152 extra_headers); | 1195 extra_headers); |
| 1153 } | 1196 } |
| 1154 | 1197 |
| 1155 void AwContents::SetJsOnlineProperty(JNIEnv* env, | 1198 void AwContents::SetJsOnlineProperty(JNIEnv* env, |
| 1156 jobject obj, | 1199 const JavaParamRef<jobject>& obj, |
| 1157 jboolean network_up) { | 1200 jboolean network_up) { |
| 1158 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1201 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1159 render_view_host_ext_->SetJsOnlineProperty(network_up); | 1202 render_view_host_ext_->SetJsOnlineProperty(network_up); |
| 1160 } | 1203 } |
| 1161 | 1204 |
| 1162 void AwContents::TrimMemory(JNIEnv* env, | 1205 void AwContents::TrimMemory(JNIEnv* env, |
| 1163 jobject obj, | 1206 const JavaParamRef<jobject>& obj, |
| 1164 jint level, | 1207 jint level, |
| 1165 jboolean visible) { | 1208 jboolean visible) { |
| 1166 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 1209 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 1167 browser_view_renderer_.TrimMemory(level, visible); | 1210 browser_view_renderer_.TrimMemory(level, visible); |
| 1168 } | 1211 } |
| 1169 | 1212 |
| 1170 // TODO(sgurun) add support for posting a frame whose name is known (only | 1213 // TODO(sgurun) add support for posting a frame whose name is known (only |
| 1171 // main frame is supported at this time, see crbug.com/389721) | 1214 // main frame is supported at this time, see crbug.com/389721) |
| 1172 void AwContents::PostMessageToFrame(JNIEnv* env, jobject obj, | 1215 void AwContents::PostMessageToFrame(JNIEnv* env, |
| 1173 jstring frame_name, jstring message, jstring target_origin, | 1216 const JavaParamRef<jobject>& obj, |
| 1174 jintArray sent_ports) { | 1217 const JavaParamRef<jstring>& frame_name, |
| 1175 | 1218 const JavaParamRef<jstring>& message, |
| 1219 const JavaParamRef<jstring>& target_origin, | |
| 1220 const JavaParamRef<jintArray>& sent_ports) { | |
| 1176 // Use an empty source origin for android webview. | 1221 // Use an empty source origin for android webview. |
| 1177 base::string16 source_origin; | 1222 base::string16 source_origin; |
| 1178 base::string16 j_target_origin(ConvertJavaStringToUTF16(env, target_origin)); | 1223 base::string16 j_target_origin(ConvertJavaStringToUTF16(env, target_origin)); |
| 1179 base::string16 j_message(ConvertJavaStringToUTF16(env, message)); | 1224 base::string16 j_message(ConvertJavaStringToUTF16(env, message)); |
| 1180 std::vector<int> j_ports; | 1225 std::vector<int> j_ports; |
| 1181 | 1226 |
| 1182 if (sent_ports != nullptr) { | 1227 if (sent_ports != nullptr) { |
| 1183 base::android::JavaIntArrayToIntVector(env, sent_ports, &j_ports); | 1228 base::android::JavaIntArrayToIntVector(env, sent_ports, &j_ports); |
| 1184 BrowserThread::PostTask( | 1229 BrowserThread::PostTask( |
| 1185 BrowserThread::IO, | 1230 BrowserThread::IO, |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 1204 if (message_port_message_filter_.get() == nullptr) { | 1249 if (message_port_message_filter_.get() == nullptr) { |
| 1205 message_port_message_filter_ = | 1250 message_port_message_filter_ = |
| 1206 new AwMessagePortMessageFilter( | 1251 new AwMessagePortMessageFilter( |
| 1207 web_contents_->GetMainFrame()->GetRoutingID()); | 1252 web_contents_->GetMainFrame()->GetRoutingID()); |
| 1208 web_contents_->GetRenderProcessHost()->AddFilter( | 1253 web_contents_->GetRenderProcessHost()->AddFilter( |
| 1209 message_port_message_filter_.get()); | 1254 message_port_message_filter_.get()); |
| 1210 } | 1255 } |
| 1211 return message_port_message_filter_; | 1256 return message_port_message_filter_; |
| 1212 } | 1257 } |
| 1213 | 1258 |
| 1214 void AwContents::CreateMessageChannel(JNIEnv* env, jobject obj, | 1259 void AwContents::CreateMessageChannel(JNIEnv* env, |
| 1215 jobjectArray ports) { | 1260 const JavaParamRef<jobject>& obj, |
| 1216 | 1261 const JavaParamRef<jobjectArray>& ports) { |
| 1217 AwMessagePortServiceImpl::GetInstance()->CreateMessageChannel(env, ports, | 1262 AwMessagePortServiceImpl::GetInstance()->CreateMessageChannel(env, ports, |
| 1218 GetMessagePortMessageFilter()); | 1263 GetMessagePortMessageFilter()); |
| 1219 } | 1264 } |
| 1220 | 1265 |
| 1221 void AwContents::GrantFileSchemeAccesstoChildProcess(JNIEnv* env, jobject obj) { | 1266 void AwContents::GrantFileSchemeAccesstoChildProcess( |
| 1267 JNIEnv* env, | |
| 1268 const JavaParamRef<jobject>& obj) { | |
| 1222 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( | 1269 content::ChildProcessSecurityPolicy::GetInstance()->GrantScheme( |
| 1223 web_contents_->GetRenderProcessHost()->GetID(), url::kFileScheme); | 1270 web_contents_->GetRenderProcessHost()->GetID(), url::kFileScheme); |
| 1224 } | 1271 } |
| 1225 | 1272 |
| 1226 void AwContents::ResumeLoadingCreatedPopupWebContents(JNIEnv* env, | 1273 void AwContents::ResumeLoadingCreatedPopupWebContents( |
| 1227 jobject obj) { | 1274 JNIEnv* env, |
| 1275 const JavaParamRef<jobject>& obj) { | |
| 1228 web_contents_->ResumeLoadingCreatedWebContents(); | 1276 web_contents_->ResumeLoadingCreatedWebContents(); |
| 1229 } | 1277 } |
| 1230 | 1278 |
| 1231 void SetShouldDownloadFavicons(JNIEnv* env, | 1279 void SetShouldDownloadFavicons(JNIEnv* env, |
| 1232 const JavaParamRef<jclass>& jclazz) { | 1280 const JavaParamRef<jclass>& jclazz) { |
| 1233 g_should_download_favicons = true; | 1281 g_should_download_favicons = true; |
| 1234 } | 1282 } |
| 1235 | 1283 |
| 1236 } // namespace android_webview | 1284 } // namespace android_webview |
| OLD | NEW |