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

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

Issue 1236003005: Move closing-blank-tab logic in Browser class to DownloadUIConttroller (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/download/download_ui_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 // Some (app downloads) are not supposed to appear on the shelf.
93 if (DownloadItemModel(item).ShouldShowInShelf()) {
asanka 2015/07/16 19:28:15 Fold this condition to the previous if().
yoshiki 2015/07/16 23:58:14 Done.
94 // GetDownloadShelf creates the download shelf if it was not yet created.
95 browser->window()->GetDownloadShelf()->AddDownload(item);
96 }
97 }
90 } 98 }
91 99
92 #endif // !OS_ANDROID 100 #endif // !OS_ANDROID
93 101
94 } // namespace 102 } // namespace
95 103
96 DownloadUIController::Delegate::~Delegate() { 104 DownloadUIController::Delegate::~Delegate() {
97 } 105 }
98 106
99 DownloadUIController::DownloadUIController(content::DownloadManager* manager, 107 DownloadUIController::DownloadUIController(content::DownloadManager* manager,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // Ignore if we've already notified the UI about |item| or if it isn't a new 144 // Ignore if we've already notified the UI about |item| or if it isn't a new
137 // download. 145 // download.
138 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI()) 146 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI())
139 return; 147 return;
140 148
141 // Wait until the target path is determined. 149 // Wait until the target path is determined.
142 if (item->GetTargetFilePath().empty()) 150 if (item->GetTargetFilePath().empty())
143 return; 151 return;
144 152
145 DownloadItemModel(item).SetWasUINotified(true); 153 DownloadItemModel(item).SetWasUINotified(true);
154
155 #if !defined(OS_ANDROID)
156 content::WebContents* web_contents = item->GetWebContents();
157 if (web_contents) {
158 Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
159 // If the download occurs in a new tab, and it's not a save page
160 // download (started before initial navigation completed) close it.
161 // Avoid calling CloseContents if the tab is not in this browser's tab strip
162 // model; this can happen if the download was initiated by something
163 // internal to Chrome, such as by the app list.
164 if (browser && web_contents->GetController().IsInitialNavigation() &&
165 browser->tab_strip_model()->count() > 1 &&
166 browser->tab_strip_model()->GetIndexOfWebContents(web_contents) !=
167 TabStripModel::kNoTab &&
168 !item->IsSavePackageDownload()) {
169 web_contents->Close();
170 }
171 }
172 #endif
173
146 delegate_->OnNewDownloadReady(item); 174 delegate_->OnNewDownloadReady(item);
147 } 175 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/download/download_ui_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698