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_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
8 #include "android_webview/browser/aw_browser_main_parts.h" | 8 #include "android_webview/browser/aw_browser_main_parts.h" |
9 #include "android_webview/browser/browser_view_renderer_impl.h" | 9 #include "android_webview/browser/browser_view_renderer_impl.h" |
10 #include "android_webview/browser/net_disk_cache_remover.h" | 10 #include "android_webview/browser/net_disk_cache_remover.h" |
11 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 11 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
12 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" | 12 #include "android_webview/browser/renderer_host/aw_resource_dispatcher_host_dele
gate.h" |
13 #include "android_webview/common/aw_hit_test_data.h" | 13 #include "android_webview/common/aw_hit_test_data.h" |
14 #include "android_webview/native/aw_browser_dependency_factory.h" | 14 #include "android_webview/native/aw_browser_dependency_factory.h" |
| 15 #include "android_webview/native/aw_contents_client_bridge.h" |
15 #include "android_webview/native/aw_contents_io_thread_client_impl.h" | 16 #include "android_webview/native/aw_contents_io_thread_client_impl.h" |
16 #include "android_webview/native/aw_web_contents_delegate.h" | 17 #include "android_webview/native/aw_web_contents_delegate.h" |
17 #include "android_webview/native/java_browser_view_renderer_helper.h" | 18 #include "android_webview/native/java_browser_view_renderer_helper.h" |
18 #include "android_webview/native/state_serializer.h" | 19 #include "android_webview/native/state_serializer.h" |
19 #include "android_webview/public/browser/draw_gl.h" | 20 #include "android_webview/public/browser/draw_gl.h" |
20 #include "base/android/jni_android.h" | 21 #include "base/android/jni_android.h" |
21 #include "base/android/jni_array.h" | 22 #include "base/android/jni_array.h" |
22 #include "base/android/jni_string.h" | 23 #include "base/android/jni_string.h" |
23 #include "base/bind.h" | 24 #include "base/bind.h" |
24 #include "base/callback.h" | 25 #include "base/callback.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 content::RenderViewHost::FromID(render_process_id, render_view_id); | 105 content::RenderViewHost::FromID(render_process_id, render_view_id); |
105 if (!rvh) return NULL; | 106 if (!rvh) return NULL; |
106 content::WebContents* web_contents = | 107 content::WebContents* web_contents = |
107 content::WebContents::FromRenderViewHost(rvh); | 108 content::WebContents::FromRenderViewHost(rvh); |
108 if (!web_contents) return NULL; | 109 if (!web_contents) return NULL; |
109 return FromWebContents(web_contents); | 110 return FromWebContents(web_contents); |
110 } | 111 } |
111 | 112 |
112 AwContents::AwContents(JNIEnv* env, | 113 AwContents::AwContents(JNIEnv* env, |
113 jobject obj, | 114 jobject obj, |
114 jobject web_contents_delegate) | 115 jobject web_contents_delegate, |
| 116 jobject contents_client_bridge) |
115 : java_ref_(env, obj), | 117 : java_ref_(env, obj), |
116 web_contents_delegate_( | 118 web_contents_delegate_( |
117 new AwWebContentsDelegate(env, web_contents_delegate)), | 119 new AwWebContentsDelegate(env, web_contents_delegate)), |
| 120 contents_client_bridge_( |
| 121 new AwContentsClientBridge(env, contents_client_bridge)), |
118 ALLOW_THIS_IN_INITIALIZER_LIST(browser_view_renderer_( | 122 ALLOW_THIS_IN_INITIALIZER_LIST(browser_view_renderer_( |
119 BrowserViewRendererImpl::Create(this, &java_renderer_helper))) { | 123 BrowserViewRendererImpl::Create(this, &java_renderer_helper))) { |
120 android_webview::AwBrowserDependencyFactory* dependency_factory = | 124 android_webview::AwBrowserDependencyFactory* dependency_factory = |
121 android_webview::AwBrowserDependencyFactory::GetInstance(); | 125 android_webview::AwBrowserDependencyFactory::GetInstance(); |
122 | 126 |
123 // TODO(joth): rather than create and set the WebContents here, expose the | 127 // TODO(joth): rather than create and set the WebContents here, expose the |
124 // factory method to java side and have that orchestrate the construction | 128 // factory method to java side and have that orchestrate the construction |
125 // order. | 129 // order. |
126 SetWebContents(dependency_factory->CreateWebContents()); | 130 SetWebContents(dependency_factory->CreateWebContents()); |
127 } | 131 } |
128 | 132 |
129 void AwContents::SetWebContents(content::WebContents* web_contents) { | 133 void AwContents::SetWebContents(content::WebContents* web_contents) { |
130 web_contents_.reset(web_contents); | 134 web_contents_.reset(web_contents); |
131 if (find_helper_.get()) { | 135 if (find_helper_.get()) { |
132 find_helper_->SetListener(NULL); | 136 find_helper_->SetListener(NULL); |
133 } | 137 } |
134 icon_helper_.reset(new IconHelper(web_contents_.get())); | 138 icon_helper_.reset(new IconHelper(web_contents_.get())); |
135 icon_helper_->SetListener(this); | 139 icon_helper_->SetListener(this); |
136 web_contents_->SetUserData(kAwContentsUserDataKey, | 140 web_contents_->SetUserData(kAwContentsUserDataKey, |
137 new AwContentsUserData(this)); | 141 new AwContentsUserData(this)); |
| 142 AwContentsClientBridgeBase::Associate(web_contents_.get(), |
| 143 contents_client_bridge_.get()); |
138 web_contents_->SetDelegate(web_contents_delegate_.get()); | 144 web_contents_->SetDelegate(web_contents_delegate_.get()); |
139 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents_.get())); | 145 render_view_host_ext_.reset(new AwRenderViewHostExt(web_contents_.get())); |
140 } | 146 } |
141 | 147 |
142 void AwContents::SetWebContents(JNIEnv* env, jobject obj, jint new_wc) { | 148 void AwContents::SetWebContents(JNIEnv* env, jobject obj, jint new_wc) { |
143 SetWebContents(reinterpret_cast<content::WebContents*>(new_wc)); | 149 SetWebContents(reinterpret_cast<content::WebContents*>(new_wc)); |
144 } | 150 } |
145 | 151 |
146 AwContents::~AwContents() { | 152 AwContents::~AwContents() { |
147 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); | 153 DCHECK(AwContents::FromWebContents(web_contents_.get()) == this); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 283 |
278 void AwContents::PerformLongClick() { | 284 void AwContents::PerformLongClick() { |
279 JNIEnv* env = AttachCurrentThread(); | 285 JNIEnv* env = AttachCurrentThread(); |
280 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); | 286 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
281 if (obj.is_null()) | 287 if (obj.is_null()) |
282 return; | 288 return; |
283 | 289 |
284 Java_AwContents_performLongClick(env, obj.obj()); | 290 Java_AwContents_performLongClick(env, obj.obj()); |
285 } | 291 } |
286 | 292 |
287 void AwContents::OnReceivedHttpAuthRequest(const JavaRef<jobject>& handler, | 293 bool AwContents::OnReceivedHttpAuthRequest(const JavaRef<jobject>& handler, |
288 const std::string& host, | 294 const std::string& host, |
289 const std::string& realm) { | 295 const std::string& realm) { |
290 JNIEnv* env = AttachCurrentThread(); | 296 JNIEnv* env = AttachCurrentThread(); |
| 297 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); |
| 298 if (obj.is_null()) |
| 299 return false; |
| 300 |
291 ScopedJavaLocalRef<jstring> jhost = ConvertUTF8ToJavaString(env, host); | 301 ScopedJavaLocalRef<jstring> jhost = ConvertUTF8ToJavaString(env, host); |
292 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); | 302 ScopedJavaLocalRef<jstring> jrealm = ConvertUTF8ToJavaString(env, realm); |
293 Java_AwContents_onReceivedHttpAuthRequest(env, java_ref_.get(env).obj(), | 303 Java_AwContents_onReceivedHttpAuthRequest(env, obj.obj(), handler.obj(), |
294 handler.obj(), jhost.obj(), | 304 jhost.obj(), jrealm.obj()); |
295 jrealm.obj()); | 305 return true; |
296 } | 306 } |
297 | 307 |
298 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { | 308 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
300 AwContentsIoThreadClientImpl::Associate( | 310 AwContentsIoThreadClientImpl::Associate( |
301 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, client)); | 311 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, client)); |
302 int child_id = web_contents_->GetRenderProcessHost()->GetID(); | 312 int child_id = web_contents_->GetRenderProcessHost()->GetID(); |
303 int route_id = web_contents_->GetRoutingID(); | 313 int route_id = web_contents_->GetRoutingID(); |
304 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id); | 314 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id); |
305 } | 315 } |
(...skipping 21 matching lines...) Expand all Loading... |
327 ++itr) { | 337 ++itr) { |
328 visited_link_gurls.push_back(GURL(*itr)); | 338 visited_link_gurls.push_back(GURL(*itr)); |
329 } | 339 } |
330 | 340 |
331 AwBrowserContext::FromWebContents(web_contents_.get()) | 341 AwBrowserContext::FromWebContents(web_contents_.get()) |
332 ->AddVisitedURLs(visited_link_gurls); | 342 ->AddVisitedURLs(visited_link_gurls); |
333 } | 343 } |
334 | 344 |
335 static jint Init(JNIEnv* env, | 345 static jint Init(JNIEnv* env, |
336 jobject obj, | 346 jobject obj, |
337 jobject web_contents_delegate) { | 347 jobject web_contents_delegate, |
338 AwContents* tab = new AwContents(env, obj, web_contents_delegate); | 348 jobject contents_client_bridge) { |
| 349 AwContents* tab = new AwContents(env, obj, web_contents_delegate, |
| 350 contents_client_bridge); |
339 return reinterpret_cast<jint>(tab); | 351 return reinterpret_cast<jint>(tab); |
340 } | 352 } |
341 | 353 |
342 bool RegisterAwContents(JNIEnv* env) { | 354 bool RegisterAwContents(JNIEnv* env) { |
343 return RegisterNativesImpl(env) >= 0; | 355 return RegisterNativesImpl(env) >= 0; |
344 } | 356 } |
345 | 357 |
346 namespace { | 358 namespace { |
347 | 359 |
348 void ShowGeolocationPromptHelperTask(const JavaObjectWeakGlobalRef& java_ref, | 360 void ShowGeolocationPromptHelperTask(const JavaObjectWeakGlobalRef& java_ref, |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 if (enabled) { | 691 if (enabled) { |
680 mode = invalidation_only ? | 692 mode = invalidation_only ? |
681 BrowserViewRenderer::kOnNewPictureInvalidationOnly : | 693 BrowserViewRenderer::kOnNewPictureInvalidationOnly : |
682 BrowserViewRenderer::kOnNewPictureEnabled; | 694 BrowserViewRenderer::kOnNewPictureEnabled; |
683 } | 695 } |
684 | 696 |
685 browser_view_renderer_->EnableOnNewPicture(mode); | 697 browser_view_renderer_->EnableOnNewPicture(mode); |
686 } | 698 } |
687 | 699 |
688 } // namespace android_webview | 700 } // namespace android_webview |
OLD | NEW |