| 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 "chrome/browser/component/web_contents_delegate_android/web_contents_de
legate_android.h" | 5 #include "chrome/browser/component/web_contents_delegate_android/web_contents_de
legate_android.h" |
| 6 | 6 |
| 7 #include <android/keycodes.h> | 7 #include <android/keycodes.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 JNIEnv* env = AttachCurrentThread(); | 84 JNIEnv* env = AttachCurrentThread(); |
| 85 ScopedJavaLocalRef<jstring> java_url = | 85 ScopedJavaLocalRef<jstring> java_url = |
| 86 ConvertUTF8ToJavaString(env, url.spec()); | 86 ConvertUTF8ToJavaString(env, url.spec()); |
| 87 Java_WebContentsDelegateAndroid_openNewTab(env, | 87 Java_WebContentsDelegateAndroid_openNewTab(env, |
| 88 obj.obj(), | 88 obj.obj(), |
| 89 java_url.obj(), | 89 java_url.obj(), |
| 90 disposition == OFF_THE_RECORD); | 90 disposition == OFF_THE_RECORD); |
| 91 return NULL; | 91 return NULL; |
| 92 } | 92 } |
| 93 | 93 |
| 94 // TODO(mkosiba): This should be in platform_utils OpenExternal, b/6174564. | |
| 95 if (transition == content::PAGE_TRANSITION_LINK && ShouldOverrideLoading(url)) | |
| 96 return NULL; | |
| 97 | |
| 98 source->GetController().LoadURL(url, params.referrer, transition, | 94 source->GetController().LoadURL(url, params.referrer, transition, |
| 99 std::string()); | 95 std::string()); |
| 100 return source; | 96 return source; |
| 101 } | 97 } |
| 102 | 98 |
| 103 // ShouldIgnoreNavigation will be called for every non-local top level | |
| 104 // navigation made by the renderer. If true is returned the renderer will | |
| 105 // not perform the navigation. This is done by using synchronous IPC so we | |
| 106 // should avoid blocking calls from this method. | |
| 107 bool WebContentsDelegateAndroid::ShouldIgnoreNavigation( | |
| 108 WebContents* source, | |
| 109 const GURL& url, | |
| 110 const content::Referrer& referrer, | |
| 111 WindowOpenDisposition disposition, | |
| 112 content::PageTransition transition_type) { | |
| 113 | |
| 114 // Don't override new tabs. | |
| 115 if (disposition == NEW_FOREGROUND_TAB || | |
| 116 disposition == NEW_BACKGROUND_TAB || | |
| 117 disposition == OFF_THE_RECORD) | |
| 118 return false; | |
| 119 | |
| 120 return ShouldOverrideLoading(url); | |
| 121 } | |
| 122 | |
| 123 void WebContentsDelegateAndroid::NavigationStateChanged( | 99 void WebContentsDelegateAndroid::NavigationStateChanged( |
| 124 const WebContents* source, unsigned changed_flags) { | 100 const WebContents* source, unsigned changed_flags) { |
| 125 if (changed_flags & ( | 101 if (changed_flags & ( |
| 126 content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { | 102 content::INVALIDATE_TYPE_TAB | content::INVALIDATE_TYPE_TITLE)) { |
| 127 JNIEnv* env = AttachCurrentThread(); | 103 JNIEnv* env = AttachCurrentThread(); |
| 128 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 104 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 129 if (obj.is_null()) | 105 if (obj.is_null()) |
| 130 return; | 106 return; |
| 131 Java_WebContentsDelegateAndroid_onTabHeaderStateChanged( | 107 Java_WebContentsDelegateAndroid_onTabHeaderStateChanged( |
| 132 env, obj.obj()); | 108 env, obj.obj()); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 } | 267 } |
| 292 | 268 |
| 293 void WebContentsDelegateAndroid::OnStartDownload(WebContents* source, | 269 void WebContentsDelegateAndroid::OnStartDownload(WebContents* source, |
| 294 DownloadItem* download) { | 270 DownloadItem* download) { |
| 295 // TODO(leandrogracia): re-enable this when calling DownloadController | 271 // TODO(leandrogracia): re-enable this when calling DownloadController |
| 296 // doesn't introduce a DEPS layering violation. | 272 // doesn't introduce a DEPS layering violation. |
| 297 // DownloadController::GetInstance()->OnPostDownloadStarted( | 273 // DownloadController::GetInstance()->OnPostDownloadStarted( |
| 298 // source, download); | 274 // source, download); |
| 299 } | 275 } |
| 300 | 276 |
| 301 bool WebContentsDelegateAndroid::ShouldOverrideLoading(const GURL& url) { | |
| 302 if (!url.is_valid()) | |
| 303 return false; | |
| 304 | |
| 305 JNIEnv* env = AttachCurrentThread(); | |
| 306 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | |
| 307 if (obj.is_null()) | |
| 308 return WebContentsDelegate::ShouldOverrideLoading(url); | |
| 309 ScopedJavaLocalRef<jstring> jstring_url = | |
| 310 ConvertUTF8ToJavaString(env, url.spec()); | |
| 311 bool ret = Java_WebContentsDelegateAndroid_shouldOverrideUrlLoading( | |
| 312 env, obj.obj(), jstring_url.obj()); | |
| 313 return ret; | |
| 314 } | |
| 315 | |
| 316 void WebContentsDelegateAndroid::HandleKeyboardEvent( | 277 void WebContentsDelegateAndroid::HandleKeyboardEvent( |
| 317 content::WebContents* source, | 278 content::WebContents* source, |
| 318 const content::NativeWebKeyboardEvent& event) { | 279 const content::NativeWebKeyboardEvent& event) { |
| 319 jobject key_event = event.os_event; | 280 jobject key_event = event.os_event; |
| 320 if (key_event) { | 281 if (key_event) { |
| 321 JNIEnv* env = AttachCurrentThread(); | 282 JNIEnv* env = AttachCurrentThread(); |
| 322 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 283 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 323 if (obj.is_null()) | 284 if (obj.is_null()) |
| 324 return; | 285 return; |
| 325 Java_WebContentsDelegateAndroid_handleKeyboardEvent( | 286 Java_WebContentsDelegateAndroid_handleKeyboardEvent( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 349 | 310 |
| 350 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { | 311 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { |
| 351 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { | 312 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { |
| 352 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; | 313 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; |
| 353 return false; | 314 return false; |
| 354 } | 315 } |
| 355 return RegisterNativesImpl(env); | 316 return RegisterNativesImpl(env); |
| 356 } | 317 } |
| 357 | 318 |
| 358 } // namespace web_contents_delegate_android | 319 } // namespace web_contents_delegate_android |
| OLD | NEW |