| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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 "chrome/browser/download/download_manager.h" | 5 #include "chrome/browser/download/download_manager.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/rand_util.h" | 12 #include "base/rand_util.h" |
| 13 #include "base/stl_util-inl.h" | 13 #include "base/stl_util-inl.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
| 16 #include "base/task.h" | 16 #include "base/task.h" |
| 17 #include "base/thread.h" | 17 #include "base/thread.h" |
| 18 #include "base/timer.h" | 18 #include "base/timer.h" |
| 19 #include "chrome/browser/browser_list.h" | 19 #include "chrome/browser/browser_list.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/download/download_file.h" | 21 #include "chrome/browser/download/download_file.h" |
| 22 #include "chrome/browser/download/download_util.h" | 22 #include "chrome/browser/download/download_util.h" |
| 23 #include "chrome/browser/extensions/crx_installer.h" | 23 #include "chrome/browser/extensions/crx_installer.h" |
| 24 #include "chrome/browser/extensions/extension_install_ui.h" | 24 #include "chrome/browser/extensions/extension_install_ui.h" |
| 25 #include "chrome/browser/extensions/extensions_service.h" | 25 #include "chrome/browser/extensions/extensions_service.h" |
| 26 #include "chrome/browser/net/chrome_url_request_context.h" |
| 26 #include "chrome/browser/profile.h" | 27 #include "chrome/browser/profile.h" |
| 27 #include "chrome/browser/renderer_host/render_process_host.h" | 28 #include "chrome/browser/renderer_host/render_process_host.h" |
| 28 #include "chrome/browser/renderer_host/render_view_host.h" | 29 #include "chrome/browser/renderer_host/render_view_host.h" |
| 29 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 30 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 30 #include "chrome/browser/tab_contents/tab_util.h" | 31 #include "chrome/browser/tab_contents/tab_util.h" |
| 31 #include "chrome/browser/tab_contents/tab_contents.h" | 32 #include "chrome/browser/tab_contents/tab_contents.h" |
| 32 #include "chrome/common/chrome_constants.h" | 33 #include "chrome/common/chrome_constants.h" |
| 33 #include "chrome/common/chrome_paths.h" | 34 #include "chrome/common/chrome_paths.h" |
| 34 #include "chrome/common/extensions/extension.h" | 35 #include "chrome/common/extensions/extension.h" |
| 35 #include "chrome/common/notification_service.h" | 36 #include "chrome/common/notification_service.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 } | 469 } |
| 469 } | 470 } |
| 470 | 471 |
| 471 // Query the history service for information about all persisted downloads. | 472 // Query the history service for information about all persisted downloads. |
| 472 bool DownloadManager::Init(Profile* profile) { | 473 bool DownloadManager::Init(Profile* profile) { |
| 473 DCHECK(profile); | 474 DCHECK(profile); |
| 474 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; | 475 DCHECK(!shutdown_needed_) << "DownloadManager already initialized."; |
| 475 shutdown_needed_ = true; | 476 shutdown_needed_ = true; |
| 476 | 477 |
| 477 profile_ = profile; | 478 profile_ = profile; |
| 478 request_context_ = profile_->GetRequestContext(); | 479 request_context_getter_ = profile_->GetRequestContext(); |
| 479 | 480 |
| 480 // 'incognito mode' will have access to past downloads, but we won't store | 481 // 'incognito mode' will have access to past downloads, but we won't store |
| 481 // information about new downloads while in that mode. | 482 // information about new downloads while in that mode. |
| 482 QueryHistoryForDownloads(); | 483 QueryHistoryForDownloads(); |
| 483 | 484 |
| 484 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); | 485 ResourceDispatcherHost* rdh = g_browser_process->resource_dispatcher_host(); |
| 485 if (!rdh) { | 486 if (!rdh) { |
| 486 NOTREACHED(); | 487 NOTREACHED(); |
| 487 return false; | 488 return false; |
| 488 } | 489 } |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1112 } | 1113 } |
| 1113 | 1114 |
| 1114 // Initiate a download of a specific URL. We send the request to the | 1115 // Initiate a download of a specific URL. We send the request to the |
| 1115 // ResourceDispatcherHost, and let it send us responses like a regular | 1116 // ResourceDispatcherHost, and let it send us responses like a regular |
| 1116 // download. | 1117 // download. |
| 1117 void DownloadManager::DownloadUrl(const GURL& url, | 1118 void DownloadManager::DownloadUrl(const GURL& url, |
| 1118 const GURL& referrer, | 1119 const GURL& referrer, |
| 1119 const std::string& referrer_charset, | 1120 const std::string& referrer_charset, |
| 1120 TabContents* tab_contents) { | 1121 TabContents* tab_contents) { |
| 1121 DCHECK(tab_contents); | 1122 DCHECK(tab_contents); |
| 1122 request_context_->set_referrer_charset(referrer_charset); | |
| 1123 file_manager_->DownloadUrl(url, | 1123 file_manager_->DownloadUrl(url, |
| 1124 referrer, | 1124 referrer, |
| 1125 referrer_charset, |
| 1125 tab_contents->process()->id(), | 1126 tab_contents->process()->id(), |
| 1126 tab_contents->render_view_host()->routing_id(), | 1127 tab_contents->render_view_host()->routing_id(), |
| 1127 request_context_.get()); | 1128 request_context_getter_); |
| 1128 } | 1129 } |
| 1129 | 1130 |
| 1130 void DownloadManager::GenerateExtension( | 1131 void DownloadManager::GenerateExtension( |
| 1131 const FilePath& file_name, | 1132 const FilePath& file_name, |
| 1132 const std::string& mime_type, | 1133 const std::string& mime_type, |
| 1133 FilePath::StringType* generated_extension) { | 1134 FilePath::StringType* generated_extension) { |
| 1134 // We're worried about three things here: | 1135 // We're worried about three things here: |
| 1135 // | 1136 // |
| 1136 // 1) Security. Many sites let users upload content, such as buddy icons, to | 1137 // 1) Security. Many sites let users upload content, such as buddy icons, to |
| 1137 // their web sites. We want to mitigate the case where an attacker | 1138 // their web sites. We want to mitigate the case where an attacker |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1548 | 1549 |
| 1549 if (contents) | 1550 if (contents) |
| 1550 contents->OnStartDownload(download); | 1551 contents->OnStartDownload(download); |
| 1551 } | 1552 } |
| 1552 | 1553 |
| 1553 // Clears the last download path, used to initialize "save as" dialogs. | 1554 // Clears the last download path, used to initialize "save as" dialogs. |
| 1554 void DownloadManager::ClearLastDownloadPath() { | 1555 void DownloadManager::ClearLastDownloadPath() { |
| 1555 last_download_path_ = FilePath(); | 1556 last_download_path_ = FilePath(); |
| 1556 } | 1557 } |
| 1557 | 1558 |
| OLD | NEW |