| 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // if Java DownloadController is not instantiated already. | 383 // if Java DownloadController is not instantiated already. |
| 384 JNIEnv* env = base::android::AttachCurrentThread(); | 384 JNIEnv* env = base::android::AttachCurrentThread(); |
| 385 Java_DownloadController_getInstance(env); | 385 Java_DownloadController_getInstance(env); |
| 386 } | 386 } |
| 387 | 387 |
| 388 DCHECK(java_object_); | 388 DCHECK(java_object_); |
| 389 return java_object_; | 389 return java_object_; |
| 390 } | 390 } |
| 391 | 391 |
| 392 void DownloadControllerAndroidImpl::StartContextMenuDownload( | 392 void DownloadControllerAndroidImpl::StartContextMenuDownload( |
| 393 const ContextMenuParams& params, WebContents* web_contents, bool is_link) { | 393 const ContextMenuParams& params, WebContents* web_contents, bool is_link, |
| 394 const std::string& extra_headers) { |
| 394 const GURL& url = is_link ? params.link_url : params.src_url; | 395 const GURL& url = is_link ? params.link_url : params.src_url; |
| 395 const GURL& referring_url = params.frame_url.is_empty() ? | 396 const GURL& referring_url = params.frame_url.is_empty() ? |
| 396 params.page_url : params.frame_url; | 397 params.page_url : params.frame_url; |
| 397 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( | 398 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( |
| 398 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())); | 399 BrowserContext::GetDownloadManager(web_contents->GetBrowserContext())); |
| 399 scoped_ptr<DownloadUrlParameters> dl_params( | 400 scoped_ptr<DownloadUrlParameters> dl_params( |
| 400 DownloadUrlParameters::FromWebContents(web_contents, url)); | 401 DownloadUrlParameters::FromWebContents(web_contents, url)); |
| 401 content::Referrer referrer = content::Referrer::SanitizeForRequest( | 402 content::Referrer referrer = content::Referrer::SanitizeForRequest( |
| 402 url, | 403 url, |
| 403 content::Referrer(referring_url.GetAsReferrer(), | 404 content::Referrer(referring_url.GetAsReferrer(), |
| 404 params.referrer_policy)); | 405 params.referrer_policy)); |
| 405 dl_params->set_referrer(referrer); | 406 dl_params->set_referrer(referrer); |
| 406 if (is_link) | 407 if (is_link) |
| 407 dl_params->set_referrer_encoding(params.frame_charset); | 408 dl_params->set_referrer_encoding(params.frame_charset); |
| 408 else | 409 net::HttpRequestHeaders headers; |
| 410 headers.AddHeadersFromString(extra_headers); |
| 411 for (net::HttpRequestHeaders::Iterator it(headers); it.GetNext();) |
| 412 dl_params->add_request_header(it.name(), it.value()); |
| 413 if (!is_link && extra_headers.empty()) |
| 409 dl_params->set_prefer_cache(true); | 414 dl_params->set_prefer_cache(true); |
| 410 dl_params->set_prompt(false); | 415 dl_params->set_prompt(false); |
| 411 dlm->DownloadUrl(dl_params.Pass()); | 416 dlm->DownloadUrl(dl_params.Pass()); |
| 412 } | 417 } |
| 413 | 418 |
| 414 void DownloadControllerAndroidImpl::DangerousDownloadValidated( | 419 void DownloadControllerAndroidImpl::DangerousDownloadValidated( |
| 415 WebContents* web_contents, int download_id, bool accept) { | 420 WebContents* web_contents, int download_id, bool accept) { |
| 416 if (!web_contents) | 421 if (!web_contents) |
| 417 return; | 422 return; |
| 418 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( | 423 DownloadManagerImpl* dlm = static_cast<DownloadManagerImpl*>( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 448 | 453 |
| 449 const content::ResourceRequestInfo* info = | 454 const content::ResourceRequestInfo* info = |
| 450 content::ResourceRequestInfo::ForRequest(request); | 455 content::ResourceRequestInfo::ForRequest(request); |
| 451 if (info) | 456 if (info) |
| 452 has_user_gesture = info->HasUserGesture(); | 457 has_user_gesture = info->HasUserGesture(); |
| 453 } | 458 } |
| 454 | 459 |
| 455 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} | 460 DownloadControllerAndroidImpl::DownloadInfoAndroid::~DownloadInfoAndroid() {} |
| 456 | 461 |
| 457 } // namespace content | 462 } // namespace content |
| OLD | NEW |