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/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "chrome/browser/download/download_item_model.h" | 9 #include "chrome/browser/download/download_item_model.h" |
10 #include "chrome/browser/download/download_shelf.h" | 10 #include "chrome/browser/download/download_shelf.h" |
11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
12 #include "chrome/browser/ui/browser_tabstrip.h" | 12 #include "chrome/browser/ui/browser_tabstrip.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "content/public/browser/download_item.h" | 15 #include "content/public/browser/download_item.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/browser/web_contents_delegate.h" | 17 #include "content/public/browser/web_contents_delegate.h" |
18 | 18 |
19 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) && !defined(USE_AURA) |
20 #include "content/public/browser/android/download_controller_android.h" | 20 #include "content/public/browser/android/download_controller_android.h" |
21 #else | 21 #else |
22 #include "chrome/browser/download/notification/download_notification_manager.h" | 22 #include "chrome/browser/download/notification/download_notification_manager.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
25 #include "chrome/browser/ui/host_desktop.h" | 25 #include "chrome/browser/ui/host_desktop.h" |
26 #endif | 26 #endif |
27 | 27 |
28 namespace { | 28 namespace { |
29 | 29 |
30 // DownloadShelfUIControllerDelegate{Android,} is used when a | 30 // DownloadShelfUIControllerDelegate{Android,} is used when a |
31 // DownloadUIController is | 31 // DownloadUIController is |
32 // constructed without specifying an explicit Delegate. | 32 // constructed without specifying an explicit Delegate. |
33 #if defined(OS_ANDROID) | 33 #if defined(OS_ANDROID) && !defined(USE_AURA) |
34 | 34 |
35 class AndroidUIControllerDelegate : public DownloadUIController::Delegate { | 35 class AndroidUIControllerDelegate : public DownloadUIController::Delegate { |
36 public: | 36 public: |
37 AndroidUIControllerDelegate() {} | 37 AndroidUIControllerDelegate() {} |
38 ~AndroidUIControllerDelegate() override {} | 38 ~AndroidUIControllerDelegate() override {} |
39 | 39 |
40 private: | 40 private: |
41 // DownloadUIController::Delegate | 41 // DownloadUIController::Delegate |
42 void OnNewDownloadReady(content::DownloadItem* item) override; | 42 void OnNewDownloadReady(content::DownloadItem* item) override; |
43 }; | 43 }; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } // namespace | 98 } // namespace |
99 | 99 |
100 DownloadUIController::Delegate::~Delegate() { | 100 DownloadUIController::Delegate::~Delegate() { |
101 } | 101 } |
102 | 102 |
103 DownloadUIController::DownloadUIController(content::DownloadManager* manager, | 103 DownloadUIController::DownloadUIController(content::DownloadManager* manager, |
104 scoped_ptr<Delegate> delegate) | 104 scoped_ptr<Delegate> delegate) |
105 : download_notifier_(manager, this), | 105 : download_notifier_(manager, this), |
106 delegate_(delegate.Pass()) { | 106 delegate_(delegate.Pass()) { |
107 if (!delegate_) { | 107 if (!delegate_) { |
108 #if defined(OS_ANDROID) | 108 #if defined(OS_ANDROID) && !defined(USE_AURA) |
109 delegate_.reset(new AndroidUIControllerDelegate()); | 109 delegate_.reset(new AndroidUIControllerDelegate()); |
110 #else | 110 #else |
111 // The delegate should not be invoked after the profile has gone away. This | 111 // The delegate should not be invoked after the profile has gone away. This |
112 // should be the case since DownloadUIController is owned by | 112 // should be the case since DownloadUIController is owned by |
113 // DownloadService, which in turn is a profile keyed service. | 113 // DownloadService, which in turn is a profile keyed service. |
114 if (DownloadNotificationManager::IsEnabled()) { | 114 if (DownloadNotificationManager::IsEnabled()) { |
115 delegate_.reset(new DownloadNotificationManager( | 115 delegate_.reset(new DownloadNotificationManager( |
116 Profile::FromBrowserContext(manager->GetBrowserContext()))); | 116 Profile::FromBrowserContext(manager->GetBrowserContext()))); |
117 } else { | 117 } else { |
118 delegate_.reset(new DownloadShelfUIControllerDelegate( | 118 delegate_.reset(new DownloadShelfUIControllerDelegate( |
(...skipping 21 matching lines...) Expand all Loading... |
140 // download. | 140 // download. |
141 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI()) | 141 if (item_model.WasUINotified() || !item_model.ShouldNotifyUI()) |
142 return; | 142 return; |
143 | 143 |
144 // Wait until the target path is determined. | 144 // Wait until the target path is determined. |
145 if (item->GetTargetFilePath().empty()) | 145 if (item->GetTargetFilePath().empty()) |
146 return; | 146 return; |
147 | 147 |
148 DownloadItemModel(item).SetWasUINotified(true); | 148 DownloadItemModel(item).SetWasUINotified(true); |
149 | 149 |
150 #if !defined(OS_ANDROID) | 150 #if !defined(OS_ANDROID) || defined(USE_AURA) |
151 content::WebContents* web_contents = item->GetWebContents(); | 151 content::WebContents* web_contents = item->GetWebContents(); |
152 if (web_contents) { | 152 if (web_contents) { |
153 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 153 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
154 // If the download occurs in a new tab, and it's not a save page | 154 // If the download occurs in a new tab, and it's not a save page |
155 // download (started before initial navigation completed) close it. | 155 // download (started before initial navigation completed) close it. |
156 // Avoid calling CloseContents if the tab is not in this browser's tab strip | 156 // Avoid calling CloseContents if the tab is not in this browser's tab strip |
157 // model; this can happen if the download was initiated by something | 157 // model; this can happen if the download was initiated by something |
158 // internal to Chrome, such as by the app list. | 158 // internal to Chrome, such as by the app list. |
159 if (browser && web_contents->GetController().IsInitialNavigation() && | 159 if (browser && web_contents->GetController().IsInitialNavigation() && |
160 browser->tab_strip_model()->count() > 1 && | 160 browser->tab_strip_model()->count() > 1 && |
161 browser->tab_strip_model()->GetIndexOfWebContents(web_contents) != | 161 browser->tab_strip_model()->GetIndexOfWebContents(web_contents) != |
162 TabStripModel::kNoTab && | 162 TabStripModel::kNoTab && |
163 !item->IsSavePackageDownload()) { | 163 !item->IsSavePackageDownload()) { |
164 web_contents->Close(); | 164 web_contents->Close(); |
165 } | 165 } |
166 } | 166 } |
167 #endif | 167 #endif |
168 | 168 |
169 delegate_->OnNewDownloadReady(item); | 169 delegate_->OnNewDownloadReady(item); |
170 } | 170 } |
OLD | NEW |