| 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" |
| 11 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
| 12 #include "content/public/browser/download_item.h" | |
| 13 #include "content/public/browser/invalidate_type.h" | 12 #include "content/public/browser/invalidate_type.h" |
| 14 #include "content/public/browser/page_navigator.h" | 13 #include "content/public/browser/page_navigator.h" |
| 15 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
| 16 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
| 17 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
| 19 #include "content/public/common/referrer.h" | 18 #include "content/public/common/referrer.h" |
| 20 #include "jni/WebContentsDelegateAndroid_jni.h" | 19 #include "jni/WebContentsDelegateAndroid_jni.h" |
| 21 #include "net/http/http_request_headers.h" | |
| 22 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 23 #include "webkit/glue/window_open_disposition.h" | 21 #include "webkit/glue/window_open_disposition.h" |
| 24 | 22 |
| 25 using base::android::AttachCurrentThread; | 23 using base::android::AttachCurrentThread; |
| 26 using base::android::CheckException; | |
| 27 using base::android::ConvertUTF8ToJavaString; | 24 using base::android::ConvertUTF8ToJavaString; |
| 28 using base::android::ConvertUTF16ToJavaString; | 25 using base::android::ConvertUTF16ToJavaString; |
| 29 using base::android::GetClass; | |
| 30 using base::android::GetMethodID; | |
| 31 using base::android::HasClass; | 26 using base::android::HasClass; |
| 32 using base::android::ScopedJavaLocalRef; | 27 using base::android::ScopedJavaLocalRef; |
| 33 using content::DownloadItem; | |
| 34 using content::JavaScriptDialogCreator; | |
| 35 using content::RenderViewHost; | |
| 36 using content::WebContents; | 28 using content::WebContents; |
| 37 | 29 |
| 38 namespace web_contents_delegate_android { | 30 namespace web_contents_delegate_android { |
| 39 | 31 |
| 40 WebContentsDelegateAndroid::WebContentsDelegateAndroid(JNIEnv* env, jobject obj) | 32 WebContentsDelegateAndroid::WebContentsDelegateAndroid(JNIEnv* env, jobject obj) |
| 41 : weak_java_delegate_(env, obj) { | 33 : weak_java_delegate_(env, obj) { |
| 42 } | 34 } |
| 43 | 35 |
| 44 WebContentsDelegateAndroid::~WebContentsDelegateAndroid() { | 36 WebContentsDelegateAndroid::~WebContentsDelegateAndroid() { |
| 45 } | 37 } |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 259 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 268 if (obj.is_null()) | 260 if (obj.is_null()) |
| 269 return; | 261 return; |
| 270 ScopedJavaLocalRef<jstring> java_url = | 262 ScopedJavaLocalRef<jstring> java_url = |
| 271 ConvertUTF8ToJavaString(env, source->GetURL().spec()); | 263 ConvertUTF8ToJavaString(env, source->GetURL().spec()); |
| 272 Java_WebContentsDelegateAndroid_onUpdateUrl(env, | 264 Java_WebContentsDelegateAndroid_onUpdateUrl(env, |
| 273 obj.obj(), | 265 obj.obj(), |
| 274 java_url.obj()); | 266 java_url.obj()); |
| 275 } | 267 } |
| 276 | 268 |
| 277 bool WebContentsDelegateAndroid::CanDownload( | |
| 278 RenderViewHost* source, | |
| 279 int request_id, | |
| 280 const std::string& request_method) { | |
| 281 if (request_method == net::HttpRequestHeaders::kGetMethod) { | |
| 282 // TODO(leandrogracia): re-enable this when calling DownloadController | |
| 283 // doesn't introduce a DEPS layering violation. | |
| 284 // DownloadController::GetInstance()->CreateGETDownload( | |
| 285 // source, request_id); | |
| 286 return false; | |
| 287 } | |
| 288 return true; | |
| 289 } | |
| 290 | |
| 291 void WebContentsDelegateAndroid::OnStartDownload(WebContents* source, | |
| 292 DownloadItem* download) { | |
| 293 // TODO(leandrogracia): re-enable this when calling DownloadController | |
| 294 // doesn't introduce a DEPS layering violation. | |
| 295 // DownloadController::GetInstance()->OnPostDownloadStarted( | |
| 296 // source, download); | |
| 297 } | |
| 298 | |
| 299 bool WebContentsDelegateAndroid::ShouldOverrideLoading(const GURL& url) { | 269 bool WebContentsDelegateAndroid::ShouldOverrideLoading(const GURL& url) { |
| 300 if (!url.is_valid()) | 270 if (!url.is_valid()) |
| 301 return false; | 271 return false; |
| 302 | 272 |
| 303 JNIEnv* env = AttachCurrentThread(); | 273 JNIEnv* env = AttachCurrentThread(); |
| 304 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); | 274 ScopedJavaLocalRef<jobject> obj = GetJavaDelegate(env); |
| 305 if (obj.is_null()) | 275 if (obj.is_null()) |
| 306 return WebContentsDelegate::ShouldOverrideLoading(url); | 276 return WebContentsDelegate::ShouldOverrideLoading(url); |
| 307 ScopedJavaLocalRef<jstring> jstring_url = | 277 ScopedJavaLocalRef<jstring> jstring_url = |
| 308 ConvertUTF8ToJavaString(env, url.spec()); | 278 ConvertUTF8ToJavaString(env, url.spec()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 312 |
| 343 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { | 313 bool RegisterWebContentsDelegateAndroid(JNIEnv* env) { |
| 344 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { | 314 if (!HasClass(env, kWebContentsDelegateAndroidClassPath)) { |
| 345 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; | 315 DLOG(ERROR) << "Unable to find class WebContentsDelegateAndroid!"; |
| 346 return false; | 316 return false; |
| 347 } | 317 } |
| 348 return RegisterNativesImpl(env); | 318 return RegisterNativesImpl(env); |
| 349 } | 319 } |
| 350 | 320 |
| 351 } // namespace web_contents_delegate_android | 321 } // namespace web_contents_delegate_android |
| OLD | NEW |