Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: android_webview/native/aw_contents.cc

Issue 24228003: Upstream ShouldOverrideUrlLoading changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 19 matching lines...) Expand all
30 #include "base/bind.h" 30 #include "base/bind.h"
31 #include "base/callback.h" 31 #include "base/callback.h"
32 #include "base/memory/memory_pressure_listener.h" 32 #include "base/memory/memory_pressure_listener.h"
33 #include "base/message_loop/message_loop.h" 33 #include "base/message_loop/message_loop.h"
34 #include "base/pickle.h" 34 #include "base/pickle.h"
35 #include "base/strings/string16.h" 35 #include "base/strings/string16.h"
36 #include "base/supports_user_data.h" 36 #include "base/supports_user_data.h"
37 #include "components/autofill/content/browser/autofill_driver_impl.h" 37 #include "components/autofill/content/browser/autofill_driver_impl.h"
38 #include "components/autofill/core/browser/autofill_manager.h" 38 #include "components/autofill/core/browser/autofill_manager.h"
39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 39 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
40 #include "components/navigation_interception/intercept_navigation_delegate.h"
41 #include "content/public/browser/android/content_view_core.h" 40 #include "content/public/browser/android/content_view_core.h"
42 #include "content/public/browser/browser_thread.h" 41 #include "content/public/browser/browser_thread.h"
43 #include "content/public/browser/cert_store.h" 42 #include "content/public/browser/cert_store.h"
44 #include "content/public/browser/favicon_status.h" 43 #include "content/public/browser/favicon_status.h"
45 #include "content/public/browser/navigation_entry.h" 44 #include "content/public/browser/navigation_entry.h"
46 #include "content/public/browser/render_process_host.h" 45 #include "content/public/browser/render_process_host.h"
47 #include "content/public/browser/render_view_host.h" 46 #include "content/public/browser/render_view_host.h"
48 #include "content/public/browser/web_contents.h" 47 #include "content/public/browser/web_contents.h"
49 #include "content/public/common/renderer_preferences.h" 48 #include "content/public/common/renderer_preferences.h"
50 #include "content/public/common/ssl_status.h" 49 #include "content/public/common/ssl_status.h"
(...skipping 12 matching lines...) Expand all
63 using autofill::AutofillDriverImpl; 62 using autofill::AutofillDriverImpl;
64 using autofill::AutofillManager; 63 using autofill::AutofillManager;
65 using base::android::AttachCurrentThread; 64 using base::android::AttachCurrentThread;
66 using base::android::ConvertJavaStringToUTF16; 65 using base::android::ConvertJavaStringToUTF16;
67 using base::android::ConvertJavaStringToUTF8; 66 using base::android::ConvertJavaStringToUTF8;
68 using base::android::ConvertUTF16ToJavaString; 67 using base::android::ConvertUTF16ToJavaString;
69 using base::android::ConvertUTF8ToJavaString; 68 using base::android::ConvertUTF8ToJavaString;
70 using base::android::JavaRef; 69 using base::android::JavaRef;
71 using base::android::ScopedJavaGlobalRef; 70 using base::android::ScopedJavaGlobalRef;
72 using base::android::ScopedJavaLocalRef; 71 using base::android::ScopedJavaLocalRef;
73 using navigation_interception::InterceptNavigationDelegate;
74 using content::BrowserThread; 72 using content::BrowserThread;
75 using content::ContentViewCore; 73 using content::ContentViewCore;
76 using content::WebContents; 74 using content::WebContents;
77 75
78 extern "C" { 76 extern "C" {
79 static AwDrawGLFunction DrawGLFunction; 77 static AwDrawGLFunction DrawGLFunction;
80 static void DrawGLFunction(int view_context, 78 static void DrawGLFunction(int view_context,
81 AwDrawGLInfo* draw_info, 79 AwDrawGLInfo* draw_info,
82 void* spare) { 80 void* spare) {
83 // |view_context| is the value that was returned from the java 81 // |view_context| is the value that was returned from the java
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 InitAutofillIfNecessary(autofill_manager_delegate->GetSaveFormData()); 192 InitAutofillIfNecessary(autofill_manager_delegate->GetSaveFormData());
195 193
196 SetAndroidWebViewRendererPrefs(); 194 SetAndroidWebViewRendererPrefs();
197 } 195 }
198 196
199 void AwContents::SetJavaPeers(JNIEnv* env, 197 void AwContents::SetJavaPeers(JNIEnv* env,
200 jobject obj, 198 jobject obj,
201 jobject aw_contents, 199 jobject aw_contents,
202 jobject web_contents_delegate, 200 jobject web_contents_delegate,
203 jobject contents_client_bridge, 201 jobject contents_client_bridge,
204 jobject io_thread_client, 202 jobject io_thread_client) {
205 jobject intercept_navigation_delegate) {
206 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
207 // The |aw_content| param is technically spurious as it duplicates |obj| but 204 // The |aw_content| param is technically spurious as it duplicates |obj| but
208 // is passed over anyway to make the binding more explicit. 205 // is passed over anyway to make the binding more explicit.
209 java_ref_ = JavaObjectWeakGlobalRef(env, aw_contents); 206 java_ref_ = JavaObjectWeakGlobalRef(env, aw_contents);
210 207
211 web_contents_delegate_.reset( 208 web_contents_delegate_.reset(
212 new AwWebContentsDelegate(env, web_contents_delegate)); 209 new AwWebContentsDelegate(env, web_contents_delegate));
213 web_contents_->SetDelegate(web_contents_delegate_.get()); 210 web_contents_->SetDelegate(web_contents_delegate_.get());
214 211
215 contents_client_bridge_.reset( 212 contents_client_bridge_.reset(
216 new AwContentsClientBridge(env, contents_client_bridge)); 213 new AwContentsClientBridge(env, contents_client_bridge));
217 AwContentsClientBridgeBase::Associate(web_contents_.get(), 214 AwContentsClientBridgeBase::Associate(web_contents_.get(),
218 contents_client_bridge_.get()); 215 contents_client_bridge_.get());
219 216
220 AwContentsIoThreadClientImpl::Associate( 217 AwContentsIoThreadClientImpl::Associate(
221 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, io_thread_client)); 218 web_contents_.get(), ScopedJavaLocalRef<jobject>(env, io_thread_client));
222 int child_id = web_contents_->GetRenderProcessHost()->GetID(); 219 int child_id = web_contents_->GetRenderProcessHost()->GetID();
223 int route_id = web_contents_->GetRoutingID(); 220 int route_id = web_contents_->GetRoutingID();
224 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id); 221 AwResourceDispatcherHostDelegate::OnIoThreadClientReady(child_id, route_id);
225
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
227 InterceptNavigationDelegate::Associate(
228 web_contents_.get(),
229 make_scoped_ptr(new InterceptNavigationDelegate(
230 env, intercept_navigation_delegate)));
231 } 222 }
232 223
233 void AwContents::SetSaveFormData(bool enabled) { 224 void AwContents::SetSaveFormData(bool enabled) {
234 InitAutofillIfNecessary(enabled); 225 InitAutofillIfNecessary(enabled);
235 // We need to check for the existence, since autofill_manager_delegate 226 // We need to check for the existence, since autofill_manager_delegate
236 // may not be created when the setting is false. 227 // may not be created when the setting is false.
237 if (AutofillDriverImpl::FromWebContents(web_contents_.get())) { 228 if (AutofillDriverImpl::FromWebContents(web_contents_.get())) {
238 AwAutofillManagerDelegate::FromWebContents(web_contents_.get())-> 229 AwAutofillManagerDelegate::FromWebContents(web_contents_.get())->
239 SetSaveFormData(enabled); 230 SetSaveFormData(enabled);
240 } 231 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 icon_helper_->SetListener(NULL); 288 icon_helper_->SetListener(NULL);
298 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1); 289 base::subtle::NoBarrier_AtomicIncrement(&g_instance_count, -1);
299 } 290 }
300 291
301 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) { 292 jint AwContents::GetWebContents(JNIEnv* env, jobject obj) {
302 DCHECK(web_contents_); 293 DCHECK(web_contents_);
303 return reinterpret_cast<jint>(web_contents_.get()); 294 return reinterpret_cast<jint>(web_contents_.get());
304 } 295 }
305 296
306 void AwContents::Destroy(JNIEnv* env, jobject obj) { 297 void AwContents::Destroy(JNIEnv* env, jobject obj) {
307 delete this; 298 java_ref_.reset();
308 299 // We do not delete AwContents immediately. Some applications try to delete
300 // Webview in ShouldOverrideUrlLoading callback, which is a sync IPC from
301 // Webkit.
302 BrowserThread::DeleteSoon(BrowserThread::UI, FROM_HERE, this);
309 // When the last WebView is destroyed free all discardable memory allocated by 303 // When the last WebView is destroyed free all discardable memory allocated by
310 // Chromium, because the app process may continue to run for a long time 304 // Chromium, because the app process may continue to run for a long time
311 // without ever using another WebView. 305 // without ever using another WebView.
312 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) { 306 if (base::subtle::NoBarrier_Load(&g_instance_count) == 0) {
313 base::MemoryPressureListener::NotifyMemoryPressure( 307 base::MemoryPressureListener::NotifyMemoryPressure(
314 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL); 308 base::MemoryPressureListener::MEMORY_PRESSURE_CRITICAL);
315 } 309 }
316 } 310 }
317 311
318 static jint Init(JNIEnv* env, jclass, jobject browser_context) { 312 static jint Init(JNIEnv* env, jclass, jobject browser_context) {
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 void AwContents::OnWebLayoutContentsSizeChanged( 846 void AwContents::OnWebLayoutContentsSizeChanged(
853 const gfx::Size& contents_size) { 847 const gfx::Size& contents_size) {
854 JNIEnv* env = AttachCurrentThread(); 848 JNIEnv* env = AttachCurrentThread();
855 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env); 849 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
856 if (obj.is_null()) 850 if (obj.is_null())
857 return; 851 return;
858 Java_AwContents_onWebLayoutContentsSizeChanged( 852 Java_AwContents_onWebLayoutContentsSizeChanged(
859 env, obj.obj(), contents_size.width(), contents_size.height()); 853 env, obj.obj(), contents_size.width(), contents_size.height());
860 } 854 }
861 855
856 bool AwContents::OnShouldOverrideUrlLoading(const base::string16& url) {
857 JNIEnv* env = AttachCurrentThread();
858 ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
859 if (obj.is_null())
860 return false;
861 ScopedJavaLocalRef<jstring> jurl = ConvertUTF16ToJavaString(env, url);
862 return Java_AwContents_onShouldOverrideUrlLoading(env, obj.obj(),
863 jurl.obj());
864 }
865
862 jint AwContents::CapturePicture(JNIEnv* env, 866 jint AwContents::CapturePicture(JNIEnv* env,
863 jobject obj, 867 jobject obj,
864 int width, 868 int width,
865 int height) { 869 int height) {
866 return reinterpret_cast<jint>(new AwPicture( 870 return reinterpret_cast<jint>(new AwPicture(
867 browser_view_renderer_->CapturePicture(width, height))); 871 browser_view_renderer_->CapturePicture(width, height)));
868 } 872 }
869 873
870 void AwContents::EnableOnNewPicture(JNIEnv* env, 874 void AwContents::EnableOnNewPicture(JNIEnv* env,
871 jobject obj, 875 jobject obj,
872 jboolean enabled) { 876 jboolean enabled) {
873 browser_view_renderer_->EnableOnNewPicture(enabled); 877 browser_view_renderer_->EnableOnNewPicture(enabled);
874 } 878 }
875 879
876 void AwContents::SetJsOnlineProperty(JNIEnv* env, 880 void AwContents::SetJsOnlineProperty(JNIEnv* env,
877 jobject obj, 881 jobject obj,
878 jboolean network_up) { 882 jboolean network_up) {
879 render_view_host_ext_->SetJsOnlineProperty(network_up); 883 render_view_host_ext_->SetJsOnlineProperty(network_up);
880 } 884 }
881 885
882 } // namespace android_webview 886 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698