| 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 "android_webview/browser/aw_browser_main_parts.h" | 7 #include "android_webview/browser/aw_browser_main_parts.h" |
| 8 #include "android_webview/browser/net_disk_cache_remover.h" | 8 #include "android_webview/browser/net_disk_cache_remover.h" |
| 9 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 9 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
| 10 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" |
| 10 #include "android_webview/common/aw_hit_test_data.h" | 11 #include "android_webview/common/aw_hit_test_data.h" |
| 11 #include "android_webview/native/aw_browser_dependency_factory.h" | 12 #include "android_webview/native/aw_browser_dependency_factory.h" |
| 12 #include "android_webview/native/aw_contents_io_thread_client_impl.h" | 13 #include "android_webview/native/aw_contents_io_thread_client_impl.h" |
| 13 #include "android_webview/native/aw_web_contents_delegate.h" | 14 #include "android_webview/native/aw_web_contents_delegate.h" |
| 14 #include "android_webview/native/state_serializer.h" | 15 #include "android_webview/native/state_serializer.h" |
| 15 #include "base/android/jni_android.h" | 16 #include "base/android/jni_android.h" |
| 16 #include "base/android/jni_array.h" | 17 #include "base/android/jni_array.h" |
| 17 #include "base/android/jni_string.h" | 18 #include "base/android/jni_string.h" |
| 18 #include "base/bind.h" | 19 #include "base/bind.h" |
| 19 #include "base/callback.h" | 20 #include "base/callback.h" |
| 21 #include "base/message_loop.h" |
| 20 #include "base/pickle.h" | 22 #include "base/pickle.h" |
| 21 #include "base/supports_user_data.h" | 23 #include "base/supports_user_data.h" |
| 22 #include "content/components/navigation_interception/intercept_navigation_delega
te.h" | 24 #include "content/components/navigation_interception/intercept_navigation_delega
te.h" |
| 23 #include "content/public/browser/android/content_view_core.h" | 25 #include "content/public/browser/android/content_view_core.h" |
| 24 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/cert_store.h" | 27 #include "content/public/browser/cert_store.h" |
| 26 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
| 29 #include "content/public/browser/render_process_host.h" |
| 27 #include "content/public/browser/web_contents.h" | 30 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/ssl_status.h" | 31 #include "content/public/common/ssl_status.h" |
| 29 #include "jni/AwContents_jni.h" | 32 #include "jni/AwContents_jni.h" |
| 30 #include "net/base/x509_certificate.h" | 33 #include "net/base/x509_certificate.h" |
| 31 | 34 |
| 32 using base::android::AttachCurrentThread; | 35 using base::android::AttachCurrentThread; |
| 33 using base::android::ConvertJavaStringToUTF16; | 36 using base::android::ConvertJavaStringToUTF16; |
| 34 using base::android::ConvertJavaStringToUTF8; | 37 using base::android::ConvertJavaStringToUTF8; |
| 35 using base::android::ConvertUTF16ToJavaString; | 38 using base::android::ConvertUTF16ToJavaString; |
| 36 using base::android::ConvertUTF8ToJavaString; | 39 using base::android::ConvertUTF8ToJavaString; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 bool private_browsing) | 122 bool private_browsing) |
| 120 : java_ref_(env, obj), | 123 : java_ref_(env, obj), |
| 121 web_contents_delegate_( | 124 web_contents_delegate_( |
| 122 new AwWebContentsDelegate(env, web_contents_delegate)), | 125 new AwWebContentsDelegate(env, web_contents_delegate)), |
| 123 view_visible_(false), | 126 view_visible_(false), |
| 124 compositor_visible_(false), | 127 compositor_visible_(false), |
| 125 is_composite_pending_(false) { | 128 is_composite_pending_(false) { |
| 126 android_webview::AwBrowserDependencyFactory* dependency_factory = | 129 android_webview::AwBrowserDependencyFactory* dependency_factory = |
| 127 android_webview::AwBrowserDependencyFactory::GetInstance(); | 130 android_webview::AwBrowserDependencyFactory::GetInstance(); |
| 128 | 131 |
| 129 web_contents_.reset(dependency_factory->CreateWebContents(private_browsing)); | 132 // TODO(joth): rather than create and set the WebContents here, expose the |
| 133 // factory method to java side and have that orchestrate the construction |
| 134 // order. |
| 135 SetWebContents(dependency_factory->CreateWebContents(private_browsing)); |
| 136 } |
| 130 | 137 |
| 131 DCHECK(!AwContents::FromWebContents(web_contents_.get())); | 138 void AwContents::SetWebContents(content::WebContents* web_contents) { |
| 139 web_contents_.reset(web_contents); |
| 132 web_contents_->SetUserData(kAwContentsUserDataKey, | 140 web_contents_->SetUserData(kAwContentsUserDataKey, |
| 133 new AwContentsUserData(this)); | 141 new AwContentsUserData(this)); |
| 134 | 142 |
| 135 web_contents_->SetDelegate(web_contents_delegate_.get()); | 143 web_contents_->SetDelegate(web_contents_delegate_.get()); |
| 136 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents_.get())); | 144 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents_.get())); |
| 137 if (UseCompositorDirectDraw()) { | 145 if (UseCompositorDirectDraw()) { |
| 138 compositor_.reset(content::Compositor::Create(this)); | 146 compositor_.reset(content::Compositor::Create(this)); |
| 139 } else { | 147 } else { |
| 140 LOG(WARNING) << "Running on unsupported device: using null Compositor"; | 148 LOG(WARNING) << "Running on unsupported device: using null Compositor"; |
| 141 compositor_.reset(new NullCompositor); | 149 compositor_.reset(new NullCompositor); |
| 142 } | 150 } |
| 143 } | 151 } |
| 144 | 152 |
| 153 void AwContents::SetWebContents(JNIEnv* env, jobject obj, jint new_wc) { |
| 154 SetWebContents(reinterpret_cast<content::WebContents*>(new_wc)); |
| 155 } |
| 156 |
| 145 AwContents::~AwContents() { | 157 AwContents::~AwContents() { |
| 146 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); | 158 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); |
| 147 web_contents_->RemoveUserData(kAwContentsUserDataKey); | 159 web_contents_->RemoveUserData(kAwContentsUserDataKey); |
| 148 if (find_helper_.get()) | 160 if (find_helper_.get()) |
| 149 find_helper_->SetListener(NULL); | 161 find_helper_->SetListener(NULL); |
| 150 } | 162 } |
| 151 | 163 |
| 152 void AwContents::DrawGL(AwDrawGLInfo* draw_info) { | 164 void AwContents::DrawGL(AwDrawGLInfo* draw_info) { |
| 153 // TODO(joth): Use the |draw_info| parameters. | 165 // TODO(joth): Use the |draw_info| parameters. |
| 154 DLOG(INFO) << "Unimplemented AwContents::DrawGL params" | 166 DLOG(INFO) << "Unimplemented AwContents::DrawGL params" |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); | 307 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); |
| 296 Java_AwContents_onReceivedHttpAuthRequest(env, java_ref_.get(env).obj(), | 308 Java_AwContents_onReceivedHttpAuthRequest(env, java_ref_.get(env).obj(), |
| 297 handler.obj(), jhost.obj(), | 309 handler.obj(), jhost.obj(), |
| 298 jrealm.obj()); | 310 jrealm.obj()); |
| 299 } | 311 } |
| 300 | 312 |
| 301 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { | 313 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { |
| 302 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 314 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 303 AwContentsIoThreadClientImpl::Associate( | 315 AwContentsIoThreadClientImpl::Associate( |
| 304 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, client)); | 316 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, client)); |
| 317 int child_id = web_contents_->GetRenderProcessHost()->GetID(); |
| 318 int route_id = web_contents_->GetRoutingID(); |
| 319 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id); |
| 305 } | 320 } |
| 306 | 321 |
| 307 void AwContents::SetInterceptNavigationDelegate(JNIEnv* env, | 322 void AwContents::SetInterceptNavigationDelegate(JNIEnv* env, |
| 308 jobject obj, | 323 jobject obj, |
| 309 jobject delegate) { | 324 jobject delegate) { |
| 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 325 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 311 InterceptNavigationDelegate::Associate( | 326 InterceptNavigationDelegate::Associate( |
| 312 web_contents_.get(), | 327 web_contents_.get(), |
| 313 make_scoped_ptr(new InterceptNavigationDelegate(env, delegate))); | 328 make_scoped_ptr(new InterceptNavigationDelegate(env, delegate))); |
| 314 } | 329 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 std::vector<uint8> state_vector; | 520 std::vector<uint8> state_vector; |
| 506 base::android::JavaByteArrayToByteVector(env, state, &state_vector); | 521 base::android::JavaByteArrayToByteVector(env, state, &state_vector); |
| 507 | 522 |
| 508 Pickle pickle(reinterpret_cast<const char*>(state_vector.begin()), | 523 Pickle pickle(reinterpret_cast<const char*>(state_vector.begin()), |
| 509 state_vector.size()); | 524 state_vector.size()); |
| 510 PickleIterator iterator(pickle); | 525 PickleIterator iterator(pickle); |
| 511 | 526 |
| 512 return RestoreFromPickle(&iterator, web_contents_.get()); | 527 return RestoreFromPickle(&iterator, web_contents_.get()); |
| 513 } | 528 } |
| 514 | 529 |
| 530 void AwContents::SetPendingWebContentsForPopup( |
| 531 scoped_ptr<content::WebContents> pending) { |
| 532 if (pending_contents_.get()) { |
| 533 // TODO(benm): Support holding multiple pop up window requests. |
| 534 LOG(WARNING) << "Blocking popup window creation as an outstanding " |
| 535 << "popup window is still pending."; |
| 536 MessageLoop::current()->DeleteSoon(FROM_HERE, pending.release()); |
| 537 return; |
| 538 } |
| 539 pending_contents_ = pending.Pass(); |
| 540 } |
| 541 |
| 542 jint AwContents::ReleasePopupWebContents(JNIEnv* env, jobject obj) { |
| 543 return reinterpret_cast<jint>(pending_contents_.release()); |
| 544 } |
| 545 |
| 515 } // namespace android_webview | 546 } // namespace android_webview |
| OLD | NEW |