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 "content/components/web_contents_delegate_android/web_contents_delegate
_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" |
11 #include "content/public/browser/android/content_view_core.h" | 11 #include "content/public/browser/android/content_view_core.h" |
12 #include "content/public/browser/render_widget_host_view.h" | 12 #include "content/public/browser/render_widget_host_view.h" |
13 #include "content/public/browser/invalidate_type.h" | 13 #include "content/public/browser/invalidate_type.h" |
14 #include "content/public/browser/page_navigator.h" | 14 #include "content/public/browser/page_navigator.h" |
15 #include "content/public/browser/navigation_controller.h" | 15 #include "content/public/browser/navigation_controller.h" |
16 #include "content/public/browser/navigation_entry.h" | 16 #include "content/public/browser/navigation_entry.h" |
17 #include "content/public/browser/web_contents.h" | 17 #include "content/public/browser/web_contents.h" |
18 #include "content/public/common/page_transition_types.h" | 18 #include "content/public/common/page_transition_types.h" |
19 #include "content/public/common/referrer.h" | 19 #include "content/public/common/referrer.h" |
20 #include "jni/WebContentsDelegateAndroid_jni.h" | 20 #include "jni/WebContentsDelegateAndroid_jni.h" |
21 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
22 #include "webkit/glue/window_open_disposition.h" | 22 #include "webkit/glue/window_open_disposition.h" |
23 | 23 |
24 using base::android::AttachCurrentThread; | 24 using base::android::AttachCurrentThread; |
25 using base::android::ConvertUTF8ToJavaString; | 25 using base::android::ConvertUTF8ToJavaString; |
26 using base::android::ConvertUTF16ToJavaString; | 26 using base::android::ConvertUTF16ToJavaString; |
27 using base::android::HasClass; | 27 using base::android::HasClass; |
28 using base::android::ScopedJavaLocalRef; | 28 using base::android::ScopedJavaLocalRef; |
29 using content::WebContents; | |
30 | 29 |
31 namespace web_contents_delegate_android { | 30 namespace content { |
32 | 31 |
33 WebContentsDelegateAndroid::WebContentsDelegateAndroid(JNIEnv* env, jobject obj) | 32 WebContentsDelegateAndroid::WebContentsDelegateAndroid(JNIEnv* env, jobject obj) |
34 : weak_java_delegate_(env, obj) { | 33 : weak_java_delegate_(env, obj) { |
35 } | 34 } |
36 | 35 |
37 WebContentsDelegateAndroid::~WebContentsDelegateAndroid() { | 36 WebContentsDelegateAndroid::~WebContentsDelegateAndroid() { |
38 } | 37 } |
39 | 38 |
40 ScopedJavaLocalRef<jobject> | 39 ScopedJavaLocalRef<jobject> |
41 WebContentsDelegateAndroid::GetJavaDelegate(JNIEnv* env) const { | 40 WebContentsDelegateAndroid::GetJavaDelegate(JNIEnv* env) const { |
42 return weak_java_delegate_.get(env); | 41 return weak_java_delegate_.get(env); |
43 } | 42 } |
44 | 43 |
45 // ---------------------------------------------------------------------------- | 44 // ---------------------------------------------------------------------------- |
46 // WebContentsDelegate methods | 45 // WebContentsDelegate methods |
47 // ---------------------------------------------------------------------------- | 46 // ---------------------------------------------------------------------------- |
48 | 47 |
49 // OpenURLFromTab() will be called when we're performing a browser-intiated | 48 // OpenURLFromTab() will be called when we're performing a browser-intiated |
50 // navigation. The most common scenario for this is opening new tabs (see | 49 // navigation. The most common scenario for this is opening new tabs (see |
51 // RenderViewImpl::decidePolicyForNavigation for more details). | 50 // RenderViewImpl::decidePolicyForNavigation for more details). |
52 WebContents* WebContentsDelegateAndroid::OpenURLFromTab( | 51 WebContents* WebContentsDelegateAndroid::OpenURLFromTab( |
53 WebContents* source, | 52 WebContents* source, |
54 const content::OpenURLParams& params) { | 53 const OpenURLParams& params) { |
55 const GURL& url = params.url; | 54 const GURL& url = params.url; |
56 WindowOpenDisposition disposition = params.disposition; | 55 WindowOpenDisposition disposition = params.disposition; |
57 content::PageTransition transition( | 56 PageTransition transition( |
58 PageTransitionFromInt(params.transition)); | 57 PageTransitionFromInt(params.transition)); |
59 | 58 |
60 if (!source || (disposition != CURRENT_TAB && | 59 if (!source || (disposition != CURRENT_TAB && |
61 disposition != NEW_FOREGROUND_TAB && | 60 disposition != NEW_FOREGROUND_TAB && |
62 disposition != NEW_BACKGROUND_TAB && | 61 disposition != NEW_BACKGROUND_TAB && |
63 disposition != OFF_THE_RECORD)) { | 62 disposition != OFF_THE_RECORD)) { |
64 NOTIMPLEMENTED(); | 63 NOTIMPLEMENTED(); |
65 return NULL; | 64 return NULL; |
66 } | 65 } |
67 | 66 |
(...skipping 15 matching lines...) Expand all Loading... |
83 return NULL; | 82 return NULL; |
84 } | 83 } |
85 | 84 |
86 source->GetController().LoadURL(url, params.referrer, transition, | 85 source->GetController().LoadURL(url, params.referrer, transition, |
87 std::string()); | 86 std::string()); |
88 return source; | 87 return source; |
89 } | 88 } |
90 | 89 |
91 void WebContentsDelegateAndroid::NavigationStateChanged( | 90 void WebContentsDelegateAndroid::NavigationStateChanged( |
92 const WebContents* source, unsigned changed_flags) { | 91 const WebContents* source, unsigned changed_flags) { |
93 if (changed_flags & content::INVALIDATE_TYPE_TITLE) { | 92 if (changed_flags & INVALIDATE_TYPE_TITLE) { |
94 JNIEnv* env = AttachCurrentThread(); | 93 JNIEnv* env = AttachCurrentThread(); |
95 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 94 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
96 if (obj.is_null()) | 95 if (obj.is_null()) |
97 return; | 96 return; |
98 Java_WebContentsDelegateAndroid_onTitleUpdated( | 97 Java_WebContentsDelegateAndroid_onTitleUpdated( |
99 env, obj.obj()); | 98 env, obj.obj()); |
100 } | 99 } |
101 } | 100 } |
102 | 101 |
103 void WebContentsDelegateAndroid::AddNewContents( | 102 void WebContentsDelegateAndroid::AddNewContents( |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 if (obj.is_null()) | 236 if (obj.is_null()) |
238 return; | 237 return; |
239 ScopedJavaLocalRef<jstring> java_url = | 238 ScopedJavaLocalRef<jstring> java_url = |
240 ConvertUTF8ToJavaString(env, source->GetURL().spec()); | 239 ConvertUTF8ToJavaString(env, source->GetURL().spec()); |
241 Java_WebContentsDelegateAndroid_onUpdateUrl(env, | 240 Java_WebContentsDelegateAndroid_onUpdateUrl(env, |
242 obj.obj(), | 241 obj.obj(), |
243 java_url.obj()); | 242 java_url.obj()); |
244 } | 243 } |
245 | 244 |
246 void WebContentsDelegateAndroid::HandleKeyboardEvent( | 245 void WebContentsDelegateAndroid::HandleKeyboardEvent( |
247 content::WebContents* source, | 246 WebContents* source, |
248 const content::NativeWebKeyboardEvent& event) { | 247 const NativeWebKeyboardEvent& event) { |
249 jobject key_event = event.os_event; | 248 jobject key_event = event.os_event; |
250 if (key_event) { | 249 if (key_event) { |
251 JNIEnv* env = AttachCurrentThread(); | 250 JNIEnv* env = AttachCurrentThread(); |
252 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 251 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
253 if (obj.is_null()) | 252 if (obj.is_null()) |
254 return; | 253 return; |
255 Java_WebContentsDelegateAndroid_handleKeyboardEvent( | 254 Java_WebContentsDelegateAndroid_handleKeyboardEvent( |
256 env, obj.obj(), key_event); | 255 env, obj.obj(), key_event); |
257 } | 256 } |
258 } | 257 } |
259 | 258 |
260 bool WebContentsDelegateAndroid::TakeFocus(WebContents* source, bool reverse) { | 259 bool WebContentsDelegateAndroid::TakeFocus(WebContents* source, bool reverse) { |
261 JNIEnv* env = AttachCurrentThread(); | 260 JNIEnv* env = AttachCurrentThread(); |
262 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 261 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
263 if (obj.is_null()) | 262 if (obj.is_null()) |
264 return WebContentsDelegate::TakeFocus(source, reverse); | 263 return WebContentsDelegate::TakeFocus(source, reverse); |
265 return Java_WebContentsDelegateAndroid_takeFocus( | 264 return Java_WebContentsDelegateAndroid_takeFocus( |
266 env, obj.obj(), reverse); | 265 env, obj.obj(), reverse); |
267 } | 266 } |
268 | 267 |
269 void WebContentsDelegateAndroid::ShowRepostFormWarningDialog( | 268 void WebContentsDelegateAndroid::ShowRepostFormWarningDialog( |
270 WebContents* source) { | 269 WebContents* source) { |
271 JNIEnv* env = AttachCurrentThread(); | 270 JNIEnv* env = AttachCurrentThread(); |
272 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 271 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
273 if (obj.is_null()) | 272 if (obj.is_null()) |
274 return; | 273 return; |
275 ScopedJavaLocalRef<jobject> content_view_core = | 274 ScopedJavaLocalRef<jobject> content_view_core = |
276 content::ContentViewCore::FromWebContents(source)->GetJavaObject(); | 275 ContentViewCore::FromWebContents(source)->GetJavaObject(); |
277 if (content_view_core.is_null()) | 276 if (content_view_core.is_null()) |
278 return; | 277 return; |
279 Java_WebContentsDelegateAndroid_showRepostFormWarningDialog(env, obj.obj(), | 278 Java_WebContentsDelegateAndroid_showRepostFormWarningDialog(env, obj.obj(), |
280 content_view_core.obj()); | 279 content_view_core.obj()); |
281 } | 280 } |
282 | 281 |
283 void WebContentsDelegateAndroid::ToggleFullscreenModeForTab( | 282 void WebContentsDelegateAndroid::ToggleFullscreenModeForTab( |
284 WebContents* web_contents, | 283 WebContents* web_contents, |
285 bool enter_fullscreen) { | 284 bool enter_fullscreen) { |
286 JNIEnv* env = AttachCurrentThread(); | 285 JNIEnv* env = AttachCurrentThread(); |
(...skipping 21 matching lines...) Expand all Loading... |
308 // Register native methods | 307 // Register native methods |
309 | 308 |
310 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { | 309 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { |
311 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { | 310 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { |
312 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; | 311 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; |
313 return false; | 312 return false; |
314 } | 313 } |
315 return RegisterNativesImpl(env); | 314 return RegisterNativesImpl(env); |
316 } | 315 } |
317 | 316 |
318 } // namespace web_contents_delegate_android | 317 } // namespace content |
OLD | NEW |