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 "chrome/browser/download/chrome_download_manager_delegate.h" | 5 #include "chrome/browser/download/chrome_download_manager_delegate.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" | 29 #include "chrome/browser/extensions/api/downloads/downloads_api.h" |
30 #include "chrome/browser/extensions/crx_installer.h" | 30 #include "chrome/browser/extensions/crx_installer.h" |
31 #include "chrome/browser/extensions/extension_service.h" | 31 #include "chrome/browser/extensions/extension_service.h" |
32 #include "chrome/browser/extensions/extension_system.h" | 32 #include "chrome/browser/extensions/extension_system.h" |
33 #include "chrome/browser/history/history.h" | 33 #include "chrome/browser/history/history.h" |
34 #include "chrome/browser/history/history_service_factory.h" | 34 #include "chrome/browser/history/history_service_factory.h" |
35 #include "chrome/browser/intents/web_intents_util.h" | 35 #include "chrome/browser/intents/web_intents_util.h" |
36 #include "chrome/browser/prefs/pref_service.h" | 36 #include "chrome/browser/prefs/pref_service.h" |
37 #include "chrome/browser/profiles/profile.h" | 37 #include "chrome/browser/profiles/profile.h" |
38 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 38 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
39 #include "chrome/browser/ui/browser_tabstrip.h" | |
40 #include "chrome/browser/ui/host_desktop.h" | 39 #include "chrome/browser/ui/host_desktop.h" |
41 #include "chrome/common/chrome_notification_types.h" | 40 #include "chrome/common/chrome_notification_types.h" |
42 #include "chrome/common/extensions/feature_switch.h" | 41 #include "chrome/common/extensions/feature_switch.h" |
43 #include "chrome/common/extensions/user_script.h" | 42 #include "chrome/common/extensions/user_script.h" |
44 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
45 #include "content/public/browser/download_item.h" | 44 #include "content/public/browser/download_item.h" |
46 #include "content/public/browser/download_manager.h" | 45 #include "content/public/browser/download_manager.h" |
47 #include "content/public/browser/notification_source.h" | 46 #include "content/public/browser/notification_source.h" |
48 #include "content/public/browser/web_contents.h" | 47 #include "content/public/browser/web_contents.h" |
49 #include "content/public/browser/web_contents_delegate.h" | 48 #include "content/public/browser/web_contents_delegate.h" |
50 #include "content/public/browser/web_intents_dispatcher.h" | 49 #include "content/public/browser/web_intents_dispatcher.h" |
51 #include "grit/generated_resources.h" | 50 #include "grit/generated_resources.h" |
52 #include "net/base/net_util.h" | 51 #include "net/base/net_util.h" |
53 #include "ui/base/l10n/l10n_util.h" | 52 #include "ui/base/l10n/l10n_util.h" |
54 #include "webkit/glue/web_intent_data.h" | 53 #include "webkit/glue/web_intent_data.h" |
55 #include "webkit/glue/web_intent_reply_data.h" | 54 #include "webkit/glue/web_intent_reply_data.h" |
56 | 55 |
57 #if !defined(OS_ANDROID) | 56 #if !defined(OS_ANDROID) |
58 #include "chrome/browser/ui/browser.h" | 57 #include "chrome/browser/ui/browser.h" |
59 #include "chrome/browser/ui/browser_finder.h" | |
60 #endif | 58 #endif |
61 | 59 |
62 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
63 #include "chrome/browser/chromeos/drive/drive_download_observer.h" | 61 #include "chrome/browser/chromeos/drive/drive_download_observer.h" |
64 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 62 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
65 #include "chrome/browser/download/download_file_picker_chromeos.h" | 63 #include "chrome/browser/download/download_file_picker_chromeos.h" |
66 #include "chrome/browser/download/save_package_file_picker_chromeos.h" | 64 #include "chrome/browser/download/save_package_file_picker_chromeos.h" |
67 #endif | 65 #endif |
68 | 66 |
69 using content::BrowserContext; | 67 using content::BrowserContext; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 l10n_util::GetStringUTF8(IDS_DOWNLOAD_UNCONFIRMED_PREFIX); | 249 l10n_util::GetStringUTF8(IDS_DOWNLOAD_UNCONFIRMED_PREFIX); |
252 #endif | 250 #endif |
253 base::SStringPrintf( | 251 base::SStringPrintf( |
254 &file_name, | 252 &file_name, |
255 unconfirmed_prefix.append( | 253 unconfirmed_prefix.append( |
256 FILE_PATH_LITERAL(" %d.crdownload")).c_str(), | 254 FILE_PATH_LITERAL(" %d.crdownload")).c_str(), |
257 base::RandInt(0, 1000000)); | 255 base::RandInt(0, 1000000)); |
258 return dir.Append(file_name); | 256 return dir.Append(file_name); |
259 } | 257 } |
260 | 258 |
261 WebContents* ChromeDownloadManagerDelegate:: | |
262 GetAlternativeWebContentsToNotifyForDownload() { | |
263 #if defined(OS_ANDROID) | |
264 // Android does not implement BrowserList or any other way to get an | |
265 // alternate web contents. | |
266 return NULL; | |
267 #else | |
268 // Start the download in the last active browser. This is not ideal but better | |
269 // than fully hiding the download from the user. | |
270 Browser* last_active = chrome::FindLastActiveWithProfile(profile_, | |
271 chrome::GetActiveDesktop()); | |
272 return last_active ? chrome::GetActiveWebContents(last_active) : NULL; | |
273 #endif | |
274 } | |
275 | |
276 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( | 259 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( |
277 const FilePath& path) { | 260 const FilePath& path) { |
278 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
279 FilePath::StringType extension = path.Extension(); | 262 FilePath::StringType extension = path.Extension(); |
280 if (extension.empty()) | 263 if (extension.empty()) |
281 return false; | 264 return false; |
282 if (extensions::Extension::IsExtension(path)) | 265 if (extensions::Extension::IsExtension(path)) |
283 return false; | 266 return false; |
284 DCHECK(extension[0] == FilePath::kExtensionSeparator); | 267 DCHECK(extension[0] == FilePath::kExtensionSeparator); |
285 extension.erase(0, 1); | 268 extension.erase(0, 1); |
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
853 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a | 836 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a |
854 // directory to persist. Or perhaps, if the Drive path | 837 // directory to persist. Or perhaps, if the Drive path |
855 // substitution logic is moved here, then we would have a | 838 // substitution logic is moved here, then we would have a |
856 // persistable path after the DownloadFilePicker is done. | 839 // persistable path after the DownloadFilePicker is done. |
857 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && | 840 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && |
858 !download->IsTemporary()) | 841 !download->IsTemporary()) |
859 last_download_path_ = target_path.DirName(); | 842 last_download_path_ = target_path.DirName(); |
860 } | 843 } |
861 callback.Run(target_path, disposition, danger_type, intermediate_path); | 844 callback.Run(target_path, disposition, danger_type, intermediate_path); |
862 } | 845 } |
OLD | NEW |