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