OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_ui_controller.h" | 5 #include "chrome/browser/download/download_ui_controller.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
| 11 #include "chrome/browser/download/download_shelf.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 12 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_tabstrip.h" | 13 #include "chrome/browser/ui/browser_tabstrip.h" |
| 14 #include "chrome/browser/ui/browser_window.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
13 #include "chrome/common/chrome_switches.h" | 16 #include "chrome/common/chrome_switches.h" |
14 #include "content/public/browser/download_item.h" | 17 #include "content/public/browser/download_item.h" |
15 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
16 #include "content/public/browser/web_contents_delegate.h" | 19 #include "content/public/browser/web_contents_delegate.h" |
17 | 20 |
18 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
19 #include "content/public/browser/android/download_controller_android.h" | 22 #include "content/public/browser/android/download_controller_android.h" |
20 #else | 23 #else |
21 #include "chrome/browser/download/notification/download_notification_manager.h" | 24 #include "chrome/browser/download/notification/download_notification_manager.h" |
22 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 Browser* browser = | 81 Browser* browser = |
79 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; | 82 web_contents ? chrome::FindBrowserWithWebContents(web_contents) : NULL; |
80 | 83 |
81 // As a last resort, use the last active browser for this profile. Not ideal, | 84 // As a last resort, use the last active browser for this profile. Not ideal, |
82 // but better than not showing the download at all. | 85 // but better than not showing the download at all. |
83 if (browser == NULL) { | 86 if (browser == NULL) { |
84 browser = chrome::FindLastActiveWithProfile(profile_, | 87 browser = chrome::FindLastActiveWithProfile(profile_, |
85 chrome::GetActiveDesktop()); | 88 chrome::GetActiveDesktop()); |
86 } | 89 } |
87 | 90 |
88 if (browser) | 91 if (browser && browser->window() && |
89 browser->ShowDownload(item); | 92 DownloadItemModel(item).ShouldShowInShelf()) { |
| 93 // GetDownloadShelf creates the download shelf if it was not yet created. |
| 94 browser->window()->GetDownloadShelf()->AddDownload(item); |
| 95 } |
90 } | 96 } |
91 | 97 |
92 #endif // !OS_ANDROID | 98 #endif // !OS_ANDROID |
93 | 99 |
94 } // namespace | 100 } // namespace |
95 | 101 |
96 DownloadUIController::Delegate::~Delegate() { | 102 DownloadUIController::Delegate::~Delegate() { |
97 } | 103 } |
98 | 104 |
99 DownloadUIController::DownloadUIController(content::DownloadManager* manager, | 105 DownloadUIController::DownloadUIController(content::DownloadManager* manager, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 // Ignore if we've already notified the UI about |item| or if it isn't a new | 142 // Ignore if we've already notified the UI about |item| or if it isn't a new |
137 // download. | 143 // download. |
138 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI()) | 144 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI()) |
139 return; | 145 return; |
140 | 146 |
141 // Wait until the target path is determined. | 147 // Wait until the target path is determined. |
142 if (item->GetTargetFilePath().empty()) | 148 if (item->GetTargetFilePath().empty()) |
143 return; | 149 return; |
144 | 150 |
145 DownloadItemModel(item).SetWasUINotified(true); | 151 DownloadItemModel(item).SetWasUINotified(true); |
| 152 |
| 153 #if !defined(OS_ANDROID) |
| 154 content::WebContents* web_contents = item->GetWebContents(); |
| 155 if (web_contents) { |
| 156 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 157 // If the download occurs in a new tab, and it's not a save page |
| 158 // download (started before initial navigation completed) close it. |
| 159 // Avoid calling CloseContents if the tab is not in this browser's tab strip |
| 160 // model; this can happen if the download was initiated by something |
| 161 // internal to Chrome, such as by the app list. |
| 162 if (browser && web_contents->GetController().IsInitialNavigation() && |
| 163 browser->tab_strip_model()->count() > 1 && |
| 164 browser->tab_strip_model()->GetIndexOfWebContents(web_contents) != |
| 165 TabStripModel::kNoTab && |
| 166 !item->IsSavePackageDownload()) { |
| 167 web_contents->Close(); |
| 168 } |
| 169 } |
| 170 #endif |
| 171 |
146 delegate_->OnNewDownloadReady(item); | 172 delegate_->OnNewDownloadReady(item); |
147 } | 173 } |
OLD | NEW |