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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 JNIEnv* env = AttachCurrentThread(); | 75 JNIEnv* env = AttachCurrentThread(); |
76 ScopedJavaLocalRef<jstring> java_url = | 76 ScopedJavaLocalRef<jstring> java_url = |
77 ConvertUTF8ToJavaString(env, url.spec()); | 77 ConvertUTF8ToJavaString(env, url.spec()); |
78 Java_WebContentsDelegateAndroid_openNewTab(env, | 78 Java_WebContentsDelegateAndroid_openNewTab(env, |
79 obj.obj(), | 79 obj.obj(), |
80 java_url.obj(), | 80 java_url.obj(), |
81 disposition == OFF_THE_RECORD); | 81 disposition == OFF_THE_RECORD); |
82 return NULL; | 82 return NULL; |
83 } | 83 } |
84 | 84 |
85 // TODO(mkosiba): This should be in platform_utils OpenExternal, b/6174564. | |
86 if (transition == content::PAGE_TRANSITION_LINK && ShouldOverrideLoading(url)) | |
87 return NULL; | |
88 | |
89 source->GetController().LoadURL(url, params.referrer, transition, | 85 source->GetController().LoadURL(url, params.referrer, transition, |
90 std::string()); | 86 std::string()); |
91 return source; | 87 return source; |
92 } | 88 } |
93 | 89 |
94 // ShouldIgnoreNavigation will be called for every non-local top level | |
95 // navigation made by the renderer. If true is returned the renderer will | |
96 // not perform the navigation. This is done by using synchronous IPC so we | |
97 // should avoid blocking calls from this method. | |
98 bool WebContentsDelegateAndroid::ShouldIgnoreNavigation( | |
99 WebContents* source, | |
100 const GURL& url, | |
101 const content::Referrer& referrer, | |
102 WindowOpenDisposition disposition, | |
103 content::PageTransition transition_type) { | |
104 | |
105 // Don't override new tabs. | |
106 if (disposition == NEW_FOREGROUND_TAB || | |
107 disposition == NEW_BACKGROUND_TAB || | |
108 disposition == OFF_THE_RECORD) | |
109 return false; | |
110 | |
111 return ShouldOverrideLoading(url); | |
112 } | |
113 | |
114 void WebContentsDelegateAndroid::NavigationStateChanged( | 90 void WebContentsDelegateAndroid::NavigationStateChanged( |
115 const WebContents* source, unsigned changed_flags) { | 91 const WebContents* source, unsigned changed_flags) { |
116 if (changed_flags & content::INVALIDATE_TYPE_TITLE) { | 92 if (changed_flags & content::INVALIDATE_TYPE_TITLE) { |
117 JNIEnv* env = AttachCurrentThread(); | 93 JNIEnv* env = AttachCurrentThread(); |
118 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 94 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
119 if (obj.is_null()) | 95 if (obj.is_null()) |
120 return; | 96 return; |
121 Java_WebContentsDelegateAndroid_onTitleUpdated( | 97 Java_WebContentsDelegateAndroid_onTitleUpdated( |
122 env, obj.obj()); | 98 env, obj.obj()); |
123 } | 99 } |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 235 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
260 if (obj.is_null()) | 236 if (obj.is_null()) |
261 return; | 237 return; |
262 ScopedJavaLocalRef<jstring> java_url = | 238 ScopedJavaLocalRef<jstring> java_url = |
263 ConvertUTF8ToJavaString(env, source->GetURL().spec()); | 239 ConvertUTF8ToJavaString(env, source->GetURL().spec()); |
264 Java_WebContentsDelegateAndroid_onUpdateUrl(env, | 240 Java_WebContentsDelegateAndroid_onUpdateUrl(env, |
265 obj.obj(), | 241 obj.obj(), |
266 java_url.obj()); | 242 java_url.obj()); |
267 } | 243 } |
268 | 244 |
269 bool WebContentsDelegateAndroid::ShouldOverrideLoading(const GURL& url) { | |
270 if (!url.is_valid()) | |
271 return false; | |
272 | |
273 JNIEnv* env = AttachCurrentThread(); | |
274 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | |
275 if (obj.is_null()) | |
276 return WebContentsDelegate::ShouldOverrideLoading(url); | |
277 ScopedJavaLocalRef<jstring> jstring_url = | |
278 ConvertUTF8ToJavaString(env, url.spec()); | |
279 bool ret = Java_WebContentsDelegateAndroid_shouldOverrideUrlLoading( | |
280 env, obj.obj(), jstring_url.obj()); | |
281 return ret; | |
282 } | |
283 | |
284 void WebContentsDelegateAndroid::HandleKeyboardEvent( | 245 void WebContentsDelegateAndroid::HandleKeyboardEvent( |
285 content::WebContents* source, | 246 content::WebContents* source, |
286 const content::NativeWebKeyboardEvent& event) { | 247 const content::NativeWebKeyboardEvent& event) { |
287 jobject key_event = event.os_event; | 248 jobject key_event = event.os_event; |
288 if (key_event) { | 249 if (key_event) { |
289 JNIEnv* env = AttachCurrentThread(); | 250 JNIEnv* env = AttachCurrentThread(); |
290 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 251 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
291 if (obj.is_null()) | 252 if (obj.is_null()) |
292 return; | 253 return; |
293 Java_WebContentsDelegateAndroid_handleKeyboardEvent( | 254 Java_WebContentsDelegateAndroid_handleKeyboardEvent( |
(...skipping 18 matching lines...) Expand all Loading... |
312 | 273 |
313 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { | 274 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { |
314 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { | 275 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { |
315 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; | 276 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; |
316 return false; | 277 return false; |
317 } | 278 } |
318 return RegisterNativesImpl(env); | 279 return RegisterNativesImpl(env); |
319 } | 280 } |
320 | 281 |
321 } // namespace web_contents_delegate_android | 282 } // namespace web_contents_delegate_android |
OLD | NEW |