Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(39)

Side by Side Diff: chrome/browser/download/chrome_download_manager_delegate.cc

Issue 11640007: Make the UI an observer of downloads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Android clang build Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 21 matching lines...) Expand all
32 #include "chrome/browser/extensions/api/downloads/downloads_api.h" 32 #include "chrome/browser/extensions/api/downloads/downloads_api.h"
33 #include "chrome/browser/extensions/crx_installer.h" 33 #include "chrome/browser/extensions/crx_installer.h"
34 #include "chrome/browser/extensions/extension_service.h" 34 #include "chrome/browser/extensions/extension_service.h"
35 #include "chrome/browser/extensions/extension_system.h" 35 #include "chrome/browser/extensions/extension_system.h"
36 #include "chrome/browser/history/history_service.h" 36 #include "chrome/browser/history/history_service.h"
37 #include "chrome/browser/history/history_service_factory.h" 37 #include "chrome/browser/history/history_service_factory.h"
38 #include "chrome/browser/platform_util.h" 38 #include "chrome/browser/platform_util.h"
39 #include "chrome/browser/prefs/pref_registry_syncable.h" 39 #include "chrome/browser/prefs/pref_registry_syncable.h"
40 #include "chrome/browser/profiles/profile.h" 40 #include "chrome/browser/profiles/profile.h"
41 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 41 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
42 #include "chrome/browser/ui/browser.h"
43 #include "chrome/browser/ui/host_desktop.h" 42 #include "chrome/browser/ui/host_desktop.h"
44 #include "chrome/browser/ui/tabs/tab_strip_model.h" 43 #include "chrome/browser/ui/tabs/tab_strip_model.h"
45 #include "chrome/common/chrome_notification_types.h" 44 #include "chrome/common/chrome_notification_types.h"
46 #include "chrome/common/extensions/feature_switch.h" 45 #include "chrome/common/extensions/feature_switch.h"
47 #include "chrome/common/extensions/user_script.h" 46 #include "chrome/common/extensions/user_script.h"
48 #include "chrome/common/pref_names.h" 47 #include "chrome/common/pref_names.h"
49 #include "content/public/browser/download_item.h" 48 #include "content/public/browser/download_item.h"
50 #include "content/public/browser/download_manager.h" 49 #include "content/public/browser/download_manager.h"
51 #include "content/public/browser/notification_source.h" 50 #include "content/public/browser/notification_source.h"
52 #include "content/public/browser/web_contents.h" 51 #include "content/public/browser/web_contents.h"
53 #include "content/public/browser/web_contents_delegate.h" 52 #include "content/public/browser/web_contents_delegate.h"
54 #include "grit/generated_resources.h" 53 #include "grit/generated_resources.h"
55 #include "net/base/net_util.h" 54 #include "net/base/net_util.h"
56 #include "ui/base/l10n/l10n_util.h" 55 #include "ui/base/l10n/l10n_util.h"
57 56
58 #if !defined(OS_ANDROID)
59 #include "chrome/browser/ui/browser.h"
60 #include "chrome/browser/ui/browser_finder.h"
61 #endif
62
63 #if defined(OS_CHROMEOS) 57 #if defined(OS_CHROMEOS)
64 #include "chrome/browser/chromeos/drive/drive_download_handler.h" 58 #include "chrome/browser/chromeos/drive/drive_download_handler.h"
65 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" 59 #include "chrome/browser/chromeos/drive/drive_file_system_util.h"
66 #include "chrome/browser/download/download_file_picker_chromeos.h" 60 #include "chrome/browser/download/download_file_picker_chromeos.h"
67 #include "chrome/browser/download/save_package_file_picker_chromeos.h" 61 #include "chrome/browser/download/save_package_file_picker_chromeos.h"
68 #endif 62 #endif
69 63
70 using content::BrowserContext; 64 using content::BrowserContext;
71 using content::BrowserThread; 65 using content::BrowserThread;
72 using content::DownloadId; 66 using content::DownloadId;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 DownloadFilePicker* file_picker = 249 DownloadFilePicker* file_picker =
256 #if defined(OS_CHROMEOS) 250 #if defined(OS_CHROMEOS)
257 new DownloadFilePickerChromeOS(); 251 new DownloadFilePickerChromeOS();
258 #else 252 #else
259 new DownloadFilePicker(); 253 new DownloadFilePicker();
260 #endif 254 #endif
261 file_picker->Init(download_manager_, item, suggested_path, 255 file_picker->Init(download_manager_, item, suggested_path,
262 file_selected_callback); 256 file_selected_callback);
263 } 257 }
264 258
265 WebContents* ChromeDownloadManagerDelegate::
266 GetAlternativeWebContentsToNotifyForDownload() {
267 #if defined(OS_ANDROID)
268 // Android does not implement BrowserList or any other way to get an
269 // alternate web contents.
270 return NULL;
271 #else
272 // Start the download in the last active browser. This is not ideal but better
273 // than fully hiding the download from the user.
274 Browser* last_active = chrome::FindLastActiveWithProfile(profile_,
275 chrome::GetActiveDesktop());
276 return last_active ? last_active->tab_strip_model()->GetActiveWebContents()
277 : NULL;
278 #endif
279 }
280
281 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension( 259 bool ChromeDownloadManagerDelegate::ShouldOpenFileBasedOnExtension(
282 const base::FilePath& path) { 260 const base::FilePath& path) {
283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
284 base::FilePath::StringType extension = path.Extension(); 262 base::FilePath::StringType extension = path.Extension();
285 if (extension.empty()) 263 if (extension.empty())
286 return false; 264 return false;
287 if (extensions::Extension::IsExtension(path)) 265 if (extensions::Extension::IsExtension(path))
288 return false; 266 return false;
289 DCHECK(extension[0] == base::FilePath::kExtensionSeparator); 267 DCHECK(extension[0] == base::FilePath::kExtensionSeparator);
290 extension.erase(0, 1); 268 extension.erase(0, 1);
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a 879 // TODO(asanka): This logic is a hack. DownloadFilePicker should give us a
902 // directory to persist. Or perhaps, if the Drive path 880 // directory to persist. Or perhaps, if the Drive path
903 // substitution logic is moved here, then we would have a 881 // substitution logic is moved here, then we would have a
904 // persistable path after the DownloadFilePicker is done. 882 // persistable path after the DownloadFilePicker is done.
905 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT && 883 if (disposition == DownloadItem::TARGET_DISPOSITION_PROMPT &&
906 !download->IsTemporary()) 884 !download->IsTemporary())
907 last_download_path_ = target_path.DirName(); 885 last_download_path_ = target_path.DirName();
908 } 886 }
909 callback.Run(target_path, disposition, danger_type, intermediate_path); 887 callback.Run(target_path, disposition, danger_type, intermediate_path);
910 } 888 }
OLDNEW
« no previous file with comments | « chrome/browser/download/chrome_download_manager_delegate.h ('k') | chrome/browser/download/download_item_model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698