OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 // Download utility implementation | 5 // Download utility implementation |
6 | 6 |
7 #include "chrome/browser/download/download_util.h" | 7 #include "chrome/browser/download/download_util.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <shobjidl.h> | 10 #include <shobjidl.h> |
11 #endif | 11 #endif |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "app/l10n_util.h" | 14 #include "app/l10n_util.h" |
15 #include "app/resource_bundle.h" | 15 #include "app/resource_bundle.h" |
16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
17 #include "base/i18n/rtl.h" | 17 #include "base/i18n/rtl.h" |
18 #include "base/i18n/time_formatting.h" | 18 #include "base/i18n/time_formatting.h" |
19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
20 #include "base/singleton.h" | 20 #include "base/singleton.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
22 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
23 #include "base/values.h" | 23 #include "base/values.h" |
24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chrome_thread.h" |
25 #include "chrome/browser/download/download_item.h" | 26 #include "chrome/browser/download/download_item.h" |
26 #include "chrome/browser/download/download_item_model.h" | 27 #include "chrome/browser/download/download_item_model.h" |
27 #include "chrome/browser/download/download_manager.h" | 28 #include "chrome/browser/download/download_manager.h" |
| 29 #include "chrome/browser/net/chrome_url_request_context.h" |
| 30 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
28 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/common/extensions/extension.h" | 32 #include "chrome/common/extensions/extension.h" |
30 #include "chrome/common/time_format.h" | 33 #include "chrome/common/time_format.h" |
31 #include "gfx/canvas_skia.h" | 34 #include "gfx/canvas_skia.h" |
32 #include "gfx/rect.h" | 35 #include "gfx/rect.h" |
33 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
34 #include "grit/locale_settings.h" | 37 #include "grit/locale_settings.h" |
35 #include "grit/theme_resources.h" | 38 #include "grit/theme_resources.h" |
36 #include "net/base/mime_util.h" | 39 #include "net/base/mime_util.h" |
37 #include "skia/ext/image_operations.h" | 40 #include "skia/ext/image_operations.h" |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 new_path = FilePath(path); | 511 new_path = FilePath(path); |
509 AppendNumberToPath(&new_path, count); | 512 AppendNumberToPath(&new_path, count); |
510 | 513 |
511 if (!file_util::PathExists(new_path)) | 514 if (!file_util::PathExists(new_path)) |
512 return count; | 515 return count; |
513 } | 516 } |
514 | 517 |
515 return -1; | 518 return -1; |
516 } | 519 } |
517 | 520 |
| 521 void DownloadUrl( |
| 522 const GURL& url, |
| 523 const GURL& referrer, |
| 524 const std::string& referrer_charset, |
| 525 const DownloadSaveInfo& save_info, |
| 526 ResourceDispatcherHost* rdh, |
| 527 int render_process_host_id, |
| 528 int render_view_id, |
| 529 URLRequestContextGetter* request_context_getter) { |
| 530 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 531 |
| 532 URLRequestContext* context = request_context_getter->GetURLRequestContext(); |
| 533 context->set_referrer_charset(referrer_charset); |
| 534 |
| 535 rdh->BeginDownload(url, |
| 536 referrer, |
| 537 save_info, |
| 538 true, // Show "Save as" UI. |
| 539 render_process_host_id, |
| 540 render_view_id, |
| 541 context); |
| 542 } |
| 543 |
| 544 void CancelDownloadRequest(ResourceDispatcherHost* rdh, |
| 545 int render_process_id, |
| 546 int request_id) { |
| 547 DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); |
| 548 rdh->CancelRequest(render_process_id, request_id, false); |
| 549 } |
| 550 |
518 } // namespace download_util | 551 } // namespace download_util |
OLD | NEW |