| 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/browser/android/download_controller.h" | 5 #include "content/browser/android/download_controller.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "net/cookies/cookie_options.h" | 22 #include "net/cookies/cookie_options.h" |
| 23 #include "net/cookies/cookie_store.h" | 23 #include "net/cookies/cookie_store.h" |
| 24 #include "net/http/http_request_headers.h" | 24 #include "net/http/http_request_headers.h" |
| 25 #include "net/url_request/url_request.h" | 25 #include "net/url_request/url_request.h" |
| 26 #include "net/url_request/url_request_context.h" | 26 #include "net/url_request/url_request_context.h" |
| 27 | 27 |
| 28 using base::android::AttachCurrentThread; | 28 using base::android::AttachCurrentThread; |
| 29 using base::android::CheckException; | 29 using base::android::CheckException; |
| 30 using base::android::ConvertUTF8ToJavaString; | 30 using base::android::ConvertUTF8ToJavaString; |
| 31 using base::android::GetClass; | 31 using base::android::GetClass; |
| 32 using base::android::MethodID; |
| 32 using base::android::ScopedJavaLocalRef; | 33 using base::android::ScopedJavaLocalRef; |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 const char kDownloadControllerClassPathName[] = | 36 const char kDownloadControllerClassPathName[] = |
| 36 "org/chromium/content/browser/DownloadController"; | 37 "org/chromium/content/browser/DownloadController"; |
| 37 } // namespace | 38 } // namespace |
| 38 | 39 |
| 39 namespace content { | 40 namespace content { |
| 40 | 41 |
| 41 // JNI methods | 42 // JNI methods |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 } | 295 } |
| 295 | 296 |
| 296 DownloadController::JavaObject* DownloadController::GetJavaObject() { | 297 DownloadController::JavaObject* DownloadController::GetJavaObject() { |
| 297 if (!java_object_) { | 298 if (!java_object_) { |
| 298 // Initialize Java DownloadController by calling | 299 // Initialize Java DownloadController by calling |
| 299 // DownloadController.getInstance(), which will call Init() | 300 // DownloadController.getInstance(), which will call Init() |
| 300 // if Java DownloadController is not instantiated already. | 301 // if Java DownloadController is not instantiated already. |
| 301 JNIEnv* env = AttachCurrentThread(); | 302 JNIEnv* env = AttachCurrentThread(); |
| 302 ScopedJavaLocalRef<jclass> clazz = | 303 ScopedJavaLocalRef<jclass> clazz = |
| 303 GetClass(env, kDownloadControllerClassPathName); | 304 GetClass(env, kDownloadControllerClassPathName); |
| 304 jmethodID get_instance = GetStaticMethodID(env, clazz, "getInstance", | 305 jmethodID get_instance = MethodID::Get< |
| 305 "()Lorg/chromium/content/browser/DownloadController;"); | 306 MethodID::METHODTYPE_NORMAL, MethodID::EXCEPTIONCHECK_YES>( |
| 307 env, clazz.obj(), "getInstance", |
| 308 "()Lorg/chromium/content/browser/DownloadController;"); |
| 306 ScopedJavaLocalRef<jobject> jobj(env, | 309 ScopedJavaLocalRef<jobject> jobj(env, |
| 307 env->CallStaticObjectMethod(clazz.obj(), get_instance)); | 310 env->CallStaticObjectMethod(clazz.obj(), get_instance)); |
| 308 CheckException(env); | 311 CheckException(env); |
| 309 } | 312 } |
| 310 | 313 |
| 311 DCHECK(java_object_); | 314 DCHECK(java_object_); |
| 312 return java_object_; | 315 return java_object_; |
| 313 } | 316 } |
| 314 | 317 |
| 315 DownloadController::DownloadInfoAndroid::DownloadInfoAndroid( | 318 DownloadController::DownloadInfoAndroid::DownloadInfoAndroid( |
| 316 net::URLRequest* request) { | 319 net::URLRequest* request) { |
| 317 request->GetResponseHeaderByName("content-disposition", &content_disposition); | 320 request->GetResponseHeaderByName("content-disposition", &content_disposition); |
| 318 request->GetResponseHeaderByName("mime-type", &original_mime_type); | 321 request->GetResponseHeaderByName("mime-type", &original_mime_type); |
| 319 request->extra_request_headers().GetHeader( | 322 request->extra_request_headers().GetHeader( |
| 320 net::HttpRequestHeaders::kUserAgent, &user_agent); | 323 net::HttpRequestHeaders::kUserAgent, &user_agent); |
| 321 GURL referer_url(request->GetSanitizedReferrer()); | 324 GURL referer_url(request->GetSanitizedReferrer()); |
| 322 if (referer_url.is_valid()) | 325 if (referer_url.is_valid()) |
| 323 referer = referer_url.spec(); | 326 referer = referer_url.spec(); |
| 324 if (!request->url_chain().empty()) { | 327 if (!request->url_chain().empty()) { |
| 325 original_url = request->url_chain().front(); | 328 original_url = request->url_chain().front(); |
| 326 url = request->url_chain().back(); | 329 url = request->url_chain().back(); |
| 327 } | 330 } |
| 328 } | 331 } |
| 329 | 332 |
| 330 DownloadController::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 333 DownloadController::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
| 331 | 334 |
| 332 } // namespace content | 335 } // namespace content |
| OLD | NEW |