Chromium Code Reviews| 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_android_impl.h" | 5 #include "content/browser/android/download_controller_android_impl.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 12 matching lines...) Expand all Loading... | |
| 23 #include "net/cookies/cookie_options.h" | 23 #include "net/cookies/cookie_options.h" |
| 24 #include "net/cookies/cookie_store.h" | 24 #include "net/cookies/cookie_store.h" |
| 25 #include "net/http/http_request_headers.h" | 25 #include "net/http/http_request_headers.h" |
| 26 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 27 #include "net/url_request/url_request.h" | 27 #include "net/url_request/url_request.h" |
| 28 #include "net/url_request/url_request_context.h" | 28 #include "net/url_request/url_request_context.h" |
| 29 | 29 |
| 30 using base::android::AttachCurrentThread; | 30 using base::android::AttachCurrentThread; |
| 31 using base::android::CheckException; | 31 using base::android::CheckException; |
| 32 using base::android::ConvertUTF8ToJavaString; | 32 using base::android::ConvertUTF8ToJavaString; |
| 33 using base::android::GetClass; | |
| 34 using base::android::MethodID; | 33 using base::android::MethodID; |
| 35 using base::android::ScopedJavaLocalRef; | 34 using base::android::ScopedJavaLocalRef; |
| 36 | 35 |
| 37 namespace { | |
| 38 const char kDownloadControllerClassPathName[] = | |
|
Yaron
2013/03/12 21:51:54
You can revert this. I've fixed this file in https
qinmin
2013/03/12 22:27:32
Done.
| |
| 39 "org/chromium/content/browser/DownloadController"; | |
| 40 } // namespace | |
| 41 | |
| 42 namespace content { | 36 namespace content { |
| 43 | 37 |
| 44 // JNI methods | 38 // JNI methods |
| 45 static void Init(JNIEnv* env, jobject obj) { | 39 static void Init(JNIEnv* env, jobject obj) { |
| 46 DownloadControllerAndroidImpl::GetInstance()->Init(env, obj); | 40 DownloadControllerAndroidImpl::GetInstance()->Init(env, obj); |
| 47 } | 41 } |
| 48 | 42 |
| 49 struct DownloadControllerAndroidImpl::JavaObject { | 43 struct DownloadControllerAndroidImpl::JavaObject { |
| 50 ScopedJavaLocalRef<jobject> Controller(JNIEnv* env) { | 44 ScopedJavaLocalRef<jobject> Controller(JNIEnv* env) { |
| 51 return GetRealObject(env, obj); | 45 return GetRealObject(env, obj); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 ScopedJavaLocalRef<jobject>(); | 312 ScopedJavaLocalRef<jobject>(); |
| 319 } | 313 } |
| 320 | 314 |
| 321 DownloadControllerAndroidImpl::JavaObject* | 315 DownloadControllerAndroidImpl::JavaObject* |
| 322 DownloadControllerAndroidImpl::GetJavaObject() { | 316 DownloadControllerAndroidImpl::GetJavaObject() { |
| 323 if (!java_object_) { | 317 if (!java_object_) { |
| 324 // Initialize Java DownloadController by calling | 318 // Initialize Java DownloadController by calling |
| 325 // DownloadController.getInstance(), which will call Init() | 319 // DownloadController.getInstance(), which will call Init() |
| 326 // if Java DownloadController is not instantiated already. | 320 // if Java DownloadController is not instantiated already. |
| 327 JNIEnv* env = AttachCurrentThread(); | 321 JNIEnv* env = AttachCurrentThread(); |
| 328 ScopedJavaLocalRef<jclass> clazz = | |
| 329 GetClass(env, kDownloadControllerClassPathName); | |
| 330 jmethodID get_instance = MethodID::Get<MethodID::TYPE_STATIC>( | 322 jmethodID get_instance = MethodID::Get<MethodID::TYPE_STATIC>( |
| 331 env, clazz.obj(), "getInstance", | 323 env, g_DownloadController_clazz, "getInstance", |
| 332 "()Lorg/chromium/content/browser/DownloadController;"); | 324 "()Lorg/chromium/content/browser/DownloadController;"); |
| 333 ScopedJavaLocalRef<jobject> jobj(env, | 325 ScopedJavaLocalRef<jobject> jobj(env, |
| 334 env->CallStaticObjectMethod(clazz.obj(), get_instance)); | 326 env->CallStaticObjectMethod(g_DownloadController_clazz, get_instance)); |
| 335 CheckException(env); | 327 CheckException(env); |
| 336 } | 328 } |
| 337 | 329 |
| 338 DCHECK(java_object_); | 330 DCHECK(java_object_); |
| 339 return java_object_; | 331 return java_object_; |
| 340 } | 332 } |
| 341 | 333 |
| 342 DownloadControllerAndroidImpl::DownloadInfoAndroid::DownloadInfoAndroid( | 334 DownloadControllerAndroidImpl::DownloadInfoAndroid::DownloadInfoAndroid( |
| 343 net::URLRequest* request) { | 335 net::URLRequest* request) { |
| 344 request->GetResponseHeaderByName("content-disposition", &content_disposition); | 336 request->GetResponseHeaderByName("content-disposition", &content_disposition); |
| 345 | 337 |
| 346 if (request->response_headers()) | 338 if (request->response_headers()) |
| 347 request->response_headers()->GetMimeType(&original_mime_type); | 339 request->response_headers()->GetMimeType(&original_mime_type); |
| 348 | 340 |
| 349 request->extra_request_headers().GetHeader( | 341 request->extra_request_headers().GetHeader( |
| 350 net::HttpRequestHeaders::kUserAgent, &user_agent); | 342 net::HttpRequestHeaders::kUserAgent, &user_agent); |
| 351 GURL referer_url(request->GetSanitizedReferrer()); | 343 GURL referer_url(request->GetSanitizedReferrer()); |
| 352 if (referer_url.is_valid()) | 344 if (referer_url.is_valid()) |
| 353 referer = referer_url.spec(); | 345 referer = referer_url.spec(); |
| 354 if (!request->url_chain().empty()) { | 346 if (!request->url_chain().empty()) { |
| 355 original_url = request->url_chain().front(); | 347 original_url = request->url_chain().front(); |
| 356 url = request->url_chain().back(); | 348 url = request->url_chain().back(); |
| 357 } | 349 } |
| 358 } | 350 } |
| 359 | 351 |
| 360 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 352 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
| 361 | 353 |
| 362 } // namespace content | 354 } // namespace content |
| OLD | NEW |