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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 void 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; | |
benm (inactive)
2013/02/25 12:16:38
mm, this should probably return false and cancel t
sgurun-gerrit only
2013/02/25 19:45:22
Done.
| |
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()); | |
296 } | 305 } |
297 | 306 |
298 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { | 307 void AwContents::SetIoThreadClient(JNIEnv* env, jobject obj, jobject client) { |
299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
300 AwContentsIoThreadClientImpl::Associate( | 309 AwContentsIoThreadClientImpl::Associate( |
301 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, client)); | 310 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, client)); |
302 int child_id = web_contents_->GetRenderProcessHost()->GetID(); | 311 int child_id = web_contents_->GetRenderProcessHost()->GetID(); |
303 int route_id = web_contents_->GetRoutingID(); | 312 int route_id = web_contents_->GetRoutingID(); |
304 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id); | 313 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id); |
305 } | 314 } |
(...skipping 21 matching lines...) Expand all Loading... | |
327 ++itr) { | 336 ++itr) { |
328 visited_link_gurls.push_back(GURL(*itr)); | 337 visited_link_gurls.push_back(GURL(*itr)); |
329 } | 338 } |
330 | 339 |
331 AwBrowserContext::FromWebContents(web_contents_.get()) | 340 AwBrowserContext::FromWebContents(web_contents_.get()) |
332 ->AddVisitedURLs(visited_link_gurls); | 341 ->AddVisitedURLs(visited_link_gurls); |
333 } | 342 } |
334 | 343 |
335 static jint Init(JNIEnv* env, | 344 static jint Init(JNIEnv* env, |
336 jobject obj, | 345 jobject obj, |
337 jobject web_contents_delegate) { | 346 jobject web_contents_delegate, |
338 AwContents* tab = new AwContents(env, obj, web_contents_delegate); | 347 jobject contents_client_bridge) { |
348 AwContents* tab = new AwContents(env, obj, web_contents_delegate, | |
349 contents_client_bridge); | |
339 return reinterpret_cast<jint>(tab); | 350 return reinterpret_cast<jint>(tab); |
340 } | 351 } |
341 | 352 |
342 bool RegisterAwContents(JNIEnv* env) { | 353 bool RegisterAwContents(JNIEnv* env) { |
343 return RegisterNativesImpl(env) >= 0; | 354 return RegisterNativesImpl(env) >= 0; |
344 } | 355 } |
345 | 356 |
346 namespace { | 357 namespace { |
347 | 358 |
348 void ShowGeolocationPromptHelperTask(const JavaObjectWeakGlobalRef& java_ref, | 359 void ShowGeolocationPromptHelperTask(const JavaObjectWeakGlobalRef& java_ref, |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
679 if (enabled) { | 690 if (enabled) { |
680 mode = invalidation_only ? | 691 mode = invalidation_only ? |
681 BrowserViewRenderer::kOnNewPictureInvalidationOnly : | 692 BrowserViewRenderer::kOnNewPictureInvalidationOnly : |
682 BrowserViewRenderer::kOnNewPictureEnabled; | 693 BrowserViewRenderer::kOnNewPictureEnabled; |
683 } | 694 } |
684 | 695 |
685 browser_view_renderer_->EnableOnNewPicture(mode); | 696 browser_view_renderer_->EnableOnNewPicture(mode); |
686 } | 697 } |
687 | 698 |
688 } // namespace android_webview | 699 } // namespace android_webview |
OLD | NEW |