OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_commands.h" | 5 #include "chrome/browser/download/download_commands.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/download/download_crx_util.h" | 9 #include "chrome/browser/download/download_crx_util.h" |
10 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 } | 33 } |
34 | 34 |
35 int DownloadCommands::GetCommandIconId(Command command) const { | 35 int DownloadCommands::GetCommandIconId(Command command) const { |
36 switch (command) { | 36 switch (command) { |
37 case PAUSE: | 37 case PAUSE: |
38 return IDR_DOWNLOAD_NOTIFICATION_MENU_PAUSE; | 38 return IDR_DOWNLOAD_NOTIFICATION_MENU_PAUSE; |
39 case RESUME: | 39 case RESUME: |
40 return IDR_DOWNLOAD_NOTIFICATION_MENU_RESUME; | 40 return IDR_DOWNLOAD_NOTIFICATION_MENU_RESUME; |
41 case SHOW_IN_FOLDER: | 41 case SHOW_IN_FOLDER: |
42 return IDR_DOWNLOAD_NOTIFICATION_MENU_FOLDER; | 42 return IDR_DOWNLOAD_NOTIFICATION_MENU_FOLDER; |
43 case RETRY: | |
44 case KEEP: | 43 case KEEP: |
45 return IDR_DOWNLOAD_NOTIFICATION_MENU_DOWNLOAD; | 44 return IDR_DOWNLOAD_NOTIFICATION_MENU_DOWNLOAD; |
46 case DISCARD: | 45 case DISCARD: |
47 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; | 46 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; |
48 case CANCEL: | 47 case CANCEL: |
49 // TODO(yoshiki): This is a temporary image for Download Notification | 48 // TODO(yoshiki): This is a temporary image for Download Notification |
50 // feature behind the flag. We have to replace the image with proper one | 49 // feature behind the flag. We have to replace the image with proper one |
51 // before the feature launch. http://crbug.com/468559 | 50 // before the feature launch. http://crbug.com/468559 |
52 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; | 51 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; |
53 case OPEN_WHEN_COMPLETE: | 52 case OPEN_WHEN_COMPLETE: |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 return !download_item_->IsDone() && !download_item_->IsPaused() && | 95 return !download_item_->IsDone() && !download_item_->IsPaused() && |
97 download_item_->GetState() == content::DownloadItem::IN_PROGRESS; | 96 download_item_->GetState() == content::DownloadItem::IN_PROGRESS; |
98 case RESUME: | 97 case RESUME: |
99 return download_item_->CanResume() && | 98 return download_item_->CanResume() && |
100 (download_item_->IsPaused() || | 99 (download_item_->IsPaused() || |
101 download_item_->GetState() != content::DownloadItem::IN_PROGRESS); | 100 download_item_->GetState() != content::DownloadItem::IN_PROGRESS); |
102 case DISCARD: | 101 case DISCARD: |
103 case KEEP: | 102 case KEEP: |
104 case LEARN_MORE_SCANNING: | 103 case LEARN_MORE_SCANNING: |
105 case LEARN_MORE_INTERRUPTED: | 104 case LEARN_MORE_INTERRUPTED: |
106 case RETRY: | |
107 return true; | 105 return true; |
108 } | 106 } |
109 NOTREACHED(); | 107 NOTREACHED(); |
110 return false; | 108 return false; |
111 } | 109 } |
112 | 110 |
113 bool DownloadCommands::IsCommandChecked(Command command) const { | 111 bool DownloadCommands::IsCommandChecked(Command command) const { |
114 switch (command) { | 112 switch (command) { |
115 case OPEN_WHEN_COMPLETE: | 113 case OPEN_WHEN_COMPLETE: |
116 return download_item_->GetOpenWhenComplete() || | 114 return download_item_->GetOpenWhenComplete() || |
117 download_crx_util::IsExtensionDownload(*download_item_); | 115 download_crx_util::IsExtensionDownload(*download_item_); |
118 case ALWAYS_OPEN_TYPE: | 116 case ALWAYS_OPEN_TYPE: |
119 #if defined(OS_WIN) || defined(OS_LINUX) || \ | 117 #if defined(OS_WIN) || defined(OS_LINUX) || \ |
120 (defined(OS_MACOSX) && !defined(OS_IOS)) | 118 (defined(OS_MACOSX) && !defined(OS_IOS)) |
121 if (CanOpenPdfInSystemViewer()) { | 119 if (CanOpenPdfInSystemViewer()) { |
122 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( | 120 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( |
123 download_item_->GetBrowserContext()); | 121 download_item_->GetBrowserContext()); |
124 return prefs->ShouldOpenPdfInSystemReader(); | 122 return prefs->ShouldOpenPdfInSystemReader(); |
125 } | 123 } |
126 #endif | 124 #endif |
127 return download_item_->ShouldOpenFileBasedOnExtension(); | 125 return download_item_->ShouldOpenFileBasedOnExtension(); |
128 case PAUSE: | 126 case PAUSE: |
129 case RESUME: | 127 case RESUME: |
130 return download_item_->IsPaused(); | 128 return download_item_->IsPaused(); |
131 case SHOW_IN_FOLDER: | 129 case SHOW_IN_FOLDER: |
132 case PLATFORM_OPEN: | 130 case PLATFORM_OPEN: |
133 case CANCEL: | 131 case CANCEL: |
134 case DISCARD: | 132 case DISCARD: |
135 case KEEP: | 133 case KEEP: |
136 case RETRY: | |
137 case LEARN_MORE_SCANNING: | 134 case LEARN_MORE_SCANNING: |
138 case LEARN_MORE_INTERRUPTED: | 135 case LEARN_MORE_INTERRUPTED: |
139 return false; | 136 return false; |
140 } | 137 } |
141 return false; | 138 return false; |
142 } | 139 } |
143 | 140 |
144 bool DownloadCommands::IsCommandVisible(Command command) const { | 141 bool DownloadCommands::IsCommandVisible(Command command) const { |
145 if (command == PLATFORM_OPEN) | 142 if (command == PLATFORM_OPEN) |
146 return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()); | 143 return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 GetBrowser()->OpenURL(content::OpenURLParams( | 206 GetBrowser()->OpenURL(content::OpenURLParams( |
210 GetLearnMoreURLForInterruptedDownload(), content::Referrer(), | 207 GetLearnMoreURLForInterruptedDownload(), content::Referrer(), |
211 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, false)); | 208 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, false)); |
212 break; | 209 break; |
213 case PAUSE: | 210 case PAUSE: |
214 download_item_->Pause(); | 211 download_item_->Pause(); |
215 break; | 212 break; |
216 case RESUME: | 213 case RESUME: |
217 download_item_->Resume(); | 214 download_item_->Resume(); |
218 break; | 215 break; |
219 case RETRY: | |
220 if (download_item_->CanResume()) { | |
221 download_item_->Resume(); | |
222 } else { | |
223 // TODO(yoshiki): Implement retry logic. | |
224 } | |
225 break; | |
226 } | 216 } |
227 } | 217 } |
228 | 218 |
229 Browser* DownloadCommands::GetBrowser() const { | 219 Browser* DownloadCommands::GetBrowser() const { |
230 Profile* profile = | 220 Profile* profile = |
231 Profile::FromBrowserContext(download_item_->GetBrowserContext()); | 221 Profile::FromBrowserContext(download_item_->GetBrowserContext()); |
232 chrome::ScopedTabbedBrowserDisplayer browser_displayer( | 222 chrome::ScopedTabbedBrowserDisplayer browser_displayer( |
233 profile, chrome::GetActiveDesktop()); | 223 profile, chrome::GetActiveDesktop()); |
234 DCHECK(browser_displayer.browser()); | 224 DCHECK(browser_displayer.browser()); |
235 return browser_displayer.browser(); | 225 return browser_displayer.browser(); |
(...skipping 13 matching lines...) Expand all Loading... |
249 is_adobe_pdf_reader_up_to_date = | 239 is_adobe_pdf_reader_up_to_date = |
250 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); | 240 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); |
251 } | 241 } |
252 return IsDownloadPdf() && | 242 return IsDownloadPdf() && |
253 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date | 243 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date |
254 : true); | 244 : true); |
255 #elif defined(OS_MACOSX) || defined(OS_LINUX) | 245 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
256 return IsDownloadPdf(); | 246 return IsDownloadPdf(); |
257 #endif | 247 #endif |
258 } | 248 } |
OLD | NEW |