| 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.h" | 5 #include "android_webview/native/aw_contents.h" |
| 6 | 6 |
| 7 #include <sys/system_properties.h> | 7 #include <sys/system_properties.h> |
| 8 | 8 |
| 9 #include "android_webview/browser/aw_browser_main_parts.h" | 9 #include "android_webview/browser/aw_browser_main_parts.h" |
| 10 #include "android_webview/browser/net_disk_cache_remover.h" | 10 #include "android_webview/browser/net_disk_cache_remover.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "content/components/navigation_interception/intercept_navigation_delega
te.h" | 30 #include "content/components/navigation_interception/intercept_navigation_delega
te.h" |
| 31 #include "content/public/browser/android/content_view_core.h" | 31 #include "content/public/browser/android/content_view_core.h" |
| 32 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/cert_store.h" | 33 #include "content/public/browser/cert_store.h" |
| 34 #include "content/public/browser/navigation_entry.h" | 34 #include "content/public/browser/navigation_entry.h" |
| 35 #include "content/public/browser/render_process_host.h" | 35 #include "content/public/browser/render_process_host.h" |
| 36 #include "content/public/browser/web_contents.h" | 36 #include "content/public/browser/web_contents.h" |
| 37 #include "content/public/common/ssl_status.h" | 37 #include "content/public/common/ssl_status.h" |
| 38 #include "jni/AwContents_jni.h" | 38 #include "jni/AwContents_jni.h" |
| 39 #include "net/base/x509_certificate.h" | 39 #include "net/base/x509_certificate.h" |
| 40 #include "skia/ext/refptr.h" | |
| 41 #include "third_party/skia/include/core/SkBitmap.h" | 40 #include "third_party/skia/include/core/SkBitmap.h" |
| 42 #include "third_party/skia/include/core/SkCanvas.h" | 41 #include "third_party/skia/include/core/SkCanvas.h" |
| 43 #include "third_party/skia/include/core/SkDevice.h" | 42 #include "third_party/skia/include/core/SkDevice.h" |
| 44 #include "third_party/skia/include/core/SkPicture.h" | |
| 45 #include "ui/gfx/transform.h" | 43 #include "ui/gfx/transform.h" |
| 46 #include "ui/gl/gl_bindings.h" | 44 #include "ui/gl/gl_bindings.h" |
| 47 | 45 |
| 48 // TODO(leandrogracia): remove when crbug.com/164140 is closed. | 46 // TODO(leandrogracia): remove when crbug.com/164140 is closed. |
| 49 // Borrowed from gl2ext.h. Cannot be included due to conflicts with | 47 // Borrowed from gl2ext.h. Cannot be included due to conflicts with |
| 50 // gl_bindings.h and the EGL library methods (eglGetCurrentContext). | 48 // gl_bindings.h and the EGL library methods (eglGetCurrentContext). |
| 51 #ifndef GL_TEXTURE_EXTERNAL_OES | 49 #ifndef GL_TEXTURE_EXTERNAL_OES |
| 52 #define GL_TEXTURE_EXTERNAL_OES 0x8D65 | 50 #define GL_TEXTURE_EXTERNAL_OES 0x8D65 |
| 53 #endif | 51 #endif |
| 54 | 52 |
| 55 #ifndef GL_TEXTURE_BINDING_EXTERNAL_OES | 53 #ifndef GL_TEXTURE_BINDING_EXTERNAL_OES |
| 56 #define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 | 54 #define GL_TEXTURE_BINDING_EXTERNAL_OES 0x8D67 |
| 57 #endif | 55 #endif |
| 58 | 56 |
| 59 using base::android::AttachCurrentThread; | 57 using base::android::AttachCurrentThread; |
| 60 using base::android::ConvertJavaStringToUTF16; | 58 using base::android::ConvertJavaStringToUTF16; |
| 61 using base::android::ConvertJavaStringToUTF8; | 59 using base::android::ConvertJavaStringToUTF8; |
| 62 using base::android::ConvertUTF16ToJavaString; | 60 using base::android::ConvertUTF16ToJavaString; |
| 63 using base::android::ConvertUTF8ToJavaString; | 61 using base::android::ConvertUTF8ToJavaString; |
| 62 using base::android::GetClass; |
| 63 using base::android::GetFieldID; |
| 64 using base::android::JavaRef; | 64 using base::android::JavaRef; |
| 65 using base::android::ScopedJavaGlobalRef; | 65 using base::android::ScopedJavaGlobalRef; |
| 66 using base::android::ScopedJavaLocalRef; | 66 using base::android::ScopedJavaLocalRef; |
| 67 using content::BrowserThread; | 67 using content::BrowserThread; |
| 68 using content::ContentViewCore; | 68 using content::ContentViewCore; |
| 69 using content::InterceptNavigationDelegate; | 69 using content::InterceptNavigationDelegate; |
| 70 using content::WebContents; | 70 using content::WebContents; |
| 71 | 71 |
| 72 extern "C" { | 72 extern "C" { |
| 73 static AwDrawGLFunction DrawGLFunction; | 73 static AwDrawGLFunction DrawGLFunction; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 AwContents::AwContents(JNIEnv* env, | 115 AwContents::AwContents(JNIEnv* env, |
| 116 jobject obj, | 116 jobject obj, |
| 117 jobject web_contents_delegate, | 117 jobject web_contents_delegate, |
| 118 bool private_browsing) | 118 bool private_browsing) |
| 119 : java_ref_(env, obj), | 119 : java_ref_(env, obj), |
| 120 web_contents_delegate_( | 120 web_contents_delegate_( |
| 121 new AwWebContentsDelegate(env, web_contents_delegate)), | 121 new AwWebContentsDelegate(env, web_contents_delegate)), |
| 122 view_visible_(false), | 122 view_visible_(false), |
| 123 compositor_visible_(false), | 123 compositor_visible_(false), |
| 124 is_composite_pending_(false), | 124 is_composite_pending_(false), |
| 125 on_new_picture_enabled_(false), |
| 126 on_new_picture_invalidation_only_(false), |
| 125 last_frame_context_(NULL) { | 127 last_frame_context_(NULL) { |
| 126 RendererPictureMap::CreateInstance(); | 128 RendererPictureMap::CreateInstance(); |
| 127 android_webview::AwBrowserDependencyFactory* dependency_factory = | 129 android_webview::AwBrowserDependencyFactory* dependency_factory = |
| 128 android_webview::AwBrowserDependencyFactory::GetInstance(); | 130 android_webview::AwBrowserDependencyFactory::GetInstance(); |
| 129 | 131 |
| 130 // TODO(joth): rather than create and set the WebContents here, expose the | 132 // TODO(joth): rather than create and set the WebContents here, expose the |
| 131 // factory method to java side and have that orchestrate the construction | 133 // factory method to java side and have that orchestrate the construction |
| 132 // order. | 134 // order. |
| 133 SetWebContents(dependency_factory->CreateWebContents(private_browsing)); | 135 SetWebContents(dependency_factory->CreateWebContents(private_browsing)); |
| 134 } | 136 } |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 375 |
| 374 glScissor(scissor_box[0], scissor_box[1], scissor_box[2], | 376 glScissor(scissor_box[0], scissor_box[1], scissor_box[2], |
| 375 scissor_box[3]); | 377 scissor_box[3]); |
| 376 | 378 |
| 377 glUseProgram(current_program); | 379 glUseProgram(current_program); |
| 378 } | 380 } |
| 379 // --------------------------------------------------------------------------- | 381 // --------------------------------------------------------------------------- |
| 380 } | 382 } |
| 381 | 383 |
| 382 bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) { | 384 bool AwContents::DrawSW(JNIEnv* env, jobject obj, jobject java_canvas) { |
| 383 skia::RefPtr<SkPicture> picture = | 385 // TODO(leandrogracia): once Ubercompositor is ready and we support software |
| 384 RendererPictureMap::GetInstance()->GetRendererPicture( | 386 // rendering mode, we should avoid this as much as we can, ideally always. |
| 385 web_contents_->GetRoutingID()); | 387 // This includes finding a proper replacement for onDraw calls in hardware |
| 388 // mode with software canvases. |
| 389 skia::RefPtr<SkPicture> picture = GetLastCapturedPicture(); |
| 386 if (!picture) | 390 if (!picture) |
| 387 return false; | 391 return false; |
| 388 | 392 |
| 389 AwPixelInfo* pixels; | 393 AwPixelInfo* pixels; |
| 390 if (!g_draw_sw_functions || | 394 if (!g_draw_sw_functions || |
| 391 (pixels = g_draw_sw_functions->access_pixels(env, java_canvas)) == NULL) { | 395 (pixels = g_draw_sw_functions->access_pixels(env, java_canvas)) == NULL) { |
| 392 // TODO(joth): Fall back to slow path rendering via temporary bitmap. | 396 // TODO(joth): Fall back to slow path rendering via temporary bitmap. |
| 393 return false; | 397 return false; |
| 394 } | 398 } |
| 395 | 399 |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 is_composite_pending_ = true; | 680 is_composite_pending_ = true; |
| 677 Invalidate(); | 681 Invalidate(); |
| 678 } | 682 } |
| 679 | 683 |
| 680 void AwContents::Invalidate() { | 684 void AwContents::Invalidate() { |
| 681 JNIEnv* env = AttachCurrentThread(); | 685 JNIEnv* env = AttachCurrentThread(); |
| 682 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 686 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 683 if (obj.is_null()) | 687 if (obj.is_null()) |
| 684 return; | 688 return; |
| 685 | 689 |
| 686 Java_AwContents_invalidate(env, obj.obj()); | 690 if (view_visible_) |
| 691 Java_AwContents_invalidate(env, obj.obj()); |
| 692 |
| 693 if (on_new_picture_enabled_ && on_new_picture_invalidation_only_) |
| 694 Java_AwContents_onNewPicture(env, obj.obj(), 0, 0, 0); |
| 687 } | 695 } |
| 688 | 696 |
| 689 void AwContents::SetCompositorVisibility(bool visible) { | 697 void AwContents::SetCompositorVisibility(bool visible) { |
| 690 if (compositor_visible_ != visible) { | 698 if (compositor_visible_ != visible) { |
| 691 compositor_visible_ = visible; | 699 compositor_visible_ = visible; |
| 692 compositor_->SetVisible(compositor_visible_); | 700 compositor_->SetVisible(compositor_visible_); |
| 693 } | 701 } |
| 694 } | 702 } |
| 695 | 703 |
| 696 void AwContents::OnSwapBuffersCompleted() { | 704 void AwContents::OnSwapBuffersCompleted() { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 } | 836 } |
| 829 | 837 |
| 830 void AwContents::FocusFirstNode(JNIEnv* env, jobject obj) { | 838 void AwContents::FocusFirstNode(JNIEnv* env, jobject obj) { |
| 831 web_contents_->FocusThroughTabTraversal(false); | 839 web_contents_->FocusThroughTabTraversal(false); |
| 832 } | 840 } |
| 833 | 841 |
| 834 jint AwContents::ReleasePopupWebContents(JNIEnv* env, jobject obj) { | 842 jint AwContents::ReleasePopupWebContents(JNIEnv* env, jobject obj) { |
| 835 return reinterpret_cast<jint>(pending_contents_.release()); | 843 return reinterpret_cast<jint>(pending_contents_.release()); |
| 836 } | 844 } |
| 837 | 845 |
| 846 void AwContents::CapturePicture(JNIEnv* env, |
| 847 jobject obj, |
| 848 jobject picture_data) { |
| 849 skia::RefPtr<SkPicture> picture = GetLastCapturedPicture(); |
| 850 ScopedJavaLocalRef<jclass> external_picture_class = GetClass(env, |
| 851 "org/chromium/android_webview/AwContentsClient$ExternalPictureData"); |
| 852 env->SetIntField(picture_data, |
| 853 GetFieldID(env, external_picture_class, "nativePicture", "I"), |
| 854 reinterpret_cast<jint>(picture.get())); |
| 855 env->SetIntField(picture_data, |
| 856 GetFieldID(env, external_picture_class, "width", "I"), |
| 857 picture ? picture->width() : 0); |
| 858 env->SetIntField(picture_data, |
| 859 GetFieldID(env, external_picture_class, "height", "I"), |
| 860 picture ? picture->height() : 0); |
| 861 } |
| 862 |
| 863 void AwContents::EnableOnNewPicture(JNIEnv* env, |
| 864 jobject obj, |
| 865 jboolean enabled, |
| 866 jboolean invalidation_only) { |
| 867 on_new_picture_enabled_ = enabled; |
| 868 on_new_picture_invalidation_only_ = invalidation_only; |
| 869 |
| 870 // If onNewPicture is triggered only on invalidation do not capture |
| 871 // pictures on every new frame. |
| 872 if (on_new_picture_invalidation_only_) |
| 873 return; |
| 874 |
| 875 // TODO(leandrogracia): uncomment when sw rendering uses Ubercompositor. |
| 876 // Until then we need the callback enabled for SW mode invalidation. |
| 877 // render_view_host_ext_->EnableCapturePictureCallback(enabled); |
| 878 } |
| 879 |
| 838 void AwContents::OnPictureUpdated(int process_id, int render_view_id) { | 880 void AwContents::OnPictureUpdated(int process_id, int render_view_id) { |
| 839 CHECK_EQ(web_contents_->GetRenderProcessHost()->GetID(), process_id); | 881 CHECK_EQ(web_contents_->GetRenderProcessHost()->GetID(), process_id); |
| 840 if (render_view_id != web_contents_->GetRoutingID()) | 882 if (render_view_id != web_contents_->GetRoutingID()) |
| 841 return; | 883 return; |
| 842 | 884 |
| 885 // TODO(leandrogracia): this can be made unconditional once software rendering |
| 886 // uses Ubercompositor. Until then this path is required for SW invalidations. |
| 887 if (on_new_picture_enabled_ && !on_new_picture_invalidation_only_) { |
| 888 JNIEnv* env = AttachCurrentThread(); |
| 889 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 890 if (!obj.is_null()) { |
| 891 skia::RefPtr<SkPicture> picture = GetLastCapturedPicture(); |
| 892 Java_AwContents_onNewPicture(env, obj.obj(), |
| 893 reinterpret_cast<jint>(picture.get()), |
| 894 picture ? picture->width() : 0, |
| 895 picture ? picture->height() : 0); |
| 896 } |
| 897 } |
| 898 |
| 843 // TODO(leandrogracia): delete when sw rendering uses Ubercompositor. | 899 // TODO(leandrogracia): delete when sw rendering uses Ubercompositor. |
| 844 // Invalidation should be provided by the compositor only. | 900 // Invalidation should be provided by the compositor only. |
| 845 Invalidate(); | 901 Invalidate(); |
| 846 } | 902 } |
| 847 | 903 |
| 904 skia::RefPtr<SkPicture> AwContents::GetLastCapturedPicture() { |
| 905 // Use the latest available picture if the listener callback is enabled. |
| 906 skia::RefPtr<SkPicture> picture; |
| 907 if (on_new_picture_enabled_) |
| 908 picture = RendererPictureMap::GetInstance()->GetRendererPicture( |
| 909 web_contents_->GetRoutingID()); |
| 910 |
| 911 // If not available or not in listener mode get it synchronously. |
| 912 if (!picture) { |
| 913 render_view_host_ext_->CapturePictureSync(); |
| 914 picture = RendererPictureMap::GetInstance()->GetRendererPicture( |
| 915 web_contents_->GetRoutingID()); |
| 916 } |
| 917 |
| 918 return picture; |
| 919 } |
| 920 |
| 848 } // namespace android_webview | 921 } // namespace android_webview |
| OLD | NEW |