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" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
| 13 #include "content/browser/android/content_view_core_impl.h" | 13 #include "content/browser/android/content_view_core_impl.h" |
| 14 #include "content/browser/download/download_item_impl.h" | 14 #include "content/browser/download/download_item_impl.h" |
| 15 #include "content/browser/download/download_manager_impl.h" | 15 #include "content/browser/download/download_manager_impl.h" |
| 16 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 16 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_process_host_impl.h" | 17 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 18 #include "content/browser/renderer_host/render_view_host_delegate.h" | 18 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 19 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 20 #include "content/browser/web_contents/web_contents_impl.h" | 20 #include "content/browser/web_contents/web_contents_impl.h" |
| 21 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
| 22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 23 #include "content/public/browser/download_url_parameters.h" | 23 #include "content/public/browser/download_url_parameters.h" |
| 24 #include "content/public/browser/global_request_id.h" | 24 #include "content/public/browser/global_request_id.h" |
| 25 #include "content/public/browser/resource_request_info.h" | |
| 25 #include "content/public/common/referrer.h" | 26 #include "content/public/common/referrer.h" |
| 26 #include "jni/DownloadController_jni.h" | 27 #include "jni/DownloadController_jni.h" |
| 27 #include "net/cookies/cookie_options.h" | 28 #include "net/cookies/cookie_options.h" |
| 28 #include "net/cookies/cookie_store.h" | 29 #include "net/cookies/cookie_store.h" |
| 29 #include "net/http/http_content_disposition.h" | 30 #include "net/http/http_content_disposition.h" |
| 30 #include "net/http/http_request_headers.h" | 31 #include "net/http/http_request_headers.h" |
| 31 #include "net/http/http_response_headers.h" | 32 #include "net/http/http_response_headers.h" |
| 32 #include "net/url_request/url_request.h" | 33 #include "net/url_request/url_request.h" |
| 33 #include "net/url_request/url_request_context.h" | 34 #include "net/url_request/url_request_context.h" |
| 34 | 35 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 | 224 |
| 224 // Try parsing the content disposition header to get a | 225 // Try parsing the content disposition header to get a |
| 225 // explicitly specified filename if available. | 226 // explicitly specified filename if available. |
| 226 net::HttpContentDisposition header(info.content_disposition, ""); | 227 net::HttpContentDisposition header(info.content_disposition, ""); |
| 227 ScopedJavaLocalRef<jstring> jfilename = | 228 ScopedJavaLocalRef<jstring> jfilename = |
| 228 ConvertUTF8ToJavaString(env, header.filename()); | 229 ConvertUTF8ToJavaString(env, header.filename()); |
| 229 | 230 |
| 230 Java_DownloadController_newHttpGetDownload( | 231 Java_DownloadController_newHttpGetDownload( |
| 231 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(), | 232 env, GetJavaObject()->Controller(env).obj(), view.obj(), jurl.obj(), |
| 232 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(), | 233 juser_agent.obj(), jcontent_disposition.obj(), jmime_type.obj(), |
| 233 jcookie.obj(), jreferer.obj(), jfilename.obj(), info.total_bytes); | 234 jcookie.obj(), jreferer.obj(), info.has_user_gesture, jfilename.obj(), |
| 235 info.total_bytes); | |
| 234 } | 236 } |
| 235 | 237 |
| 236 void DownloadControllerAndroidImpl::OnDownloadStarted( | 238 void DownloadControllerAndroidImpl::OnDownloadStarted( |
| 237 DownloadItem* download_item) { | 239 DownloadItem* download_item) { |
| 238 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 240 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 239 if (!download_item->GetWebContents()) | 241 if (!download_item->GetWebContents()) |
| 240 return; | 242 return; |
| 241 | 243 |
| 242 JNIEnv* env = base::android::AttachCurrentThread(); | 244 JNIEnv* env = base::android::AttachCurrentThread(); |
| 243 | 245 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 DownloadItem* item = dlm->GetDownload(download_id); | 396 DownloadItem* item = dlm->GetDownload(download_id); |
| 395 if (!item) | 397 if (!item) |
| 396 return; | 398 return; |
| 397 if (accept) | 399 if (accept) |
| 398 item->ValidateDangerousDownload(); | 400 item->ValidateDangerousDownload(); |
| 399 else | 401 else |
| 400 item->Remove(); | 402 item->Remove(); |
| 401 } | 403 } |
| 402 | 404 |
| 403 DownloadControllerAndroidImpl::DownloadInfoAndroid::DownloadInfoAndroid( | 405 DownloadControllerAndroidImpl::DownloadInfoAndroid::DownloadInfoAndroid( |
| 404 net::URLRequest* request) { | 406 net::URLRequest* request) |
| 407 : has_user_gesture(false) { | |
| 405 request->GetResponseHeaderByName("content-disposition", &content_disposition); | 408 request->GetResponseHeaderByName("content-disposition", &content_disposition); |
| 406 | 409 |
| 407 if (request->response_headers()) | 410 if (request->response_headers()) |
| 408 request->response_headers()->GetMimeType(&original_mime_type); | 411 request->response_headers()->GetMimeType(&original_mime_type); |
| 409 | 412 |
| 410 request->extra_request_headers().GetHeader( | 413 request->extra_request_headers().GetHeader( |
| 411 net::HttpRequestHeaders::kUserAgent, &user_agent); | 414 net::HttpRequestHeaders::kUserAgent, &user_agent); |
| 412 GURL referer_url(request->referrer()); | 415 GURL referer_url(request->referrer()); |
| 413 if (referer_url.is_valid()) | 416 if (referer_url.is_valid()) |
| 414 referer = referer_url.spec(); | 417 referer = referer_url.spec(); |
| 415 if (!request->url_chain().empty()) { | 418 if (!request->url_chain().empty()) { |
| 416 original_url = request->url_chain().front(); | 419 original_url = request->url_chain().front(); |
| 417 url = request->url_chain().back(); | 420 url = request->url_chain().back(); |
| 418 } | 421 } |
| 422 | |
| 423 const content::ResourceRequestInfo* info( | |
| 424 content::ResourceRequestInfo::ForRequest(request)); | |
|
boliu
2014/07/29 23:26:33
nit: use assignment syntax? Using this on raw poin
tommycli
2014/07/29 23:59:40
Done.
| |
| 425 if (info) | |
| 426 has_user_gesture = info->HasUserGesture(); | |
| 419 } | 427 } |
| 420 | 428 |
| 421 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 429 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
| 422 | 430 |
| 423 } // namespace content | 431 } // namespace content |
| OLD | NEW |