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 "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/download/download_crx_util.h" | 9 #include "chrome/browser/download/download_crx_util.h" |
9 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
10 #include "chrome/browser/download/download_prefs.h" | 11 #include "chrome/browser/download/download_prefs.h" |
11 #include "chrome/browser/profiles/profile_manager.h" | 12 #include "chrome/browser/profiles/profile_manager.h" |
12 #include "chrome/browser/safe_browsing/download_protection_service.h" | 13 #include "chrome/browser/safe_browsing/download_protection_service.h" |
13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
14 #include "chrome/browser/ui/browser_finder.h" | 15 #include "chrome/browser/ui/browser_finder.h" |
15 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 16 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
16 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 20 #include "net/base/url_util.h" |
19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
21 | 23 |
22 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
23 #include "chrome/browser/download/download_target_determiner.h" | 25 #include "chrome/browser/download/download_target_determiner.h" |
24 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" | 26 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" |
25 #endif | 27 #endif |
26 | 28 |
27 DownloadCommands::DownloadCommands(content::DownloadItem* download_item) | 29 DownloadCommands::DownloadCommands(content::DownloadItem* download_item) |
28 : download_item_(download_item) { | 30 : download_item_(download_item) { |
29 DCHECK(download_item); | 31 DCHECK(download_item); |
30 } | 32 } |
31 | 33 |
32 int DownloadCommands::GetCommandIconId(Command command) { | 34 int DownloadCommands::GetCommandIconId(Command command) const { |
33 switch (command) { | 35 switch (command) { |
34 case PAUSE: | 36 case PAUSE: |
35 return IDR_DOWNLOAD_NOTIFICATION_MENU_PAUSE; | 37 return IDR_DOWNLOAD_NOTIFICATION_MENU_PAUSE; |
36 case RESUME: | 38 case RESUME: |
37 return IDR_DOWNLOAD_NOTIFICATION_MENU_RESUME; | 39 return IDR_DOWNLOAD_NOTIFICATION_MENU_RESUME; |
38 case SHOW_IN_FOLDER: | 40 case SHOW_IN_FOLDER: |
39 return IDR_DOWNLOAD_NOTIFICATION_MENU_FOLDER; | 41 return IDR_DOWNLOAD_NOTIFICATION_MENU_FOLDER; |
40 case RETRY: | 42 case RETRY: |
41 case KEEP: | 43 case KEEP: |
42 return IDR_DOWNLOAD_NOTIFICATION_MENU_DOWNLOAD; | 44 return IDR_DOWNLOAD_NOTIFICATION_MENU_DOWNLOAD; |
43 case DISCARD: | 45 case DISCARD: |
44 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; | 46 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; |
45 case CANCEL: | 47 case CANCEL: |
46 // TODO(yoshiki): This is a temporary image for Download Notification | 48 // TODO(yoshiki): This is a temporary image for Download Notification |
47 // 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 |
48 // before the feature launch. http://crbug.com/468559 | 50 // before the feature launch. http://crbug.com/468559 |
49 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; | 51 return IDR_DOWNLOAD_NOTIFICATION_MENU_DELETE; |
50 case OPEN_WHEN_COMPLETE: | 52 case OPEN_WHEN_COMPLETE: |
51 case ALWAYS_OPEN_TYPE: | 53 case ALWAYS_OPEN_TYPE: |
52 case PLATFORM_OPEN: | 54 case PLATFORM_OPEN: |
53 case LEARN_MORE_SCANNING: | 55 case LEARN_MORE_SCANNING: |
54 case LEARN_MORE_INTERRUPTED: | 56 case LEARN_MORE_INTERRUPTED: |
55 return -1; | 57 return -1; |
56 } | 58 } |
57 NOTREACHED(); | 59 NOTREACHED(); |
58 return -1; | 60 return -1; |
59 } | 61 } |
60 | 62 |
| 63 GURL DownloadCommands::GetLearnMoreURLForInterruptedDownload() const { |
| 64 GURL learn_more_url(chrome::kDownloadInterruptedLearnMoreURL); |
| 65 return net::AppendQueryParameter( |
| 66 learn_more_url, "ctx", |
| 67 base::StringPrintf("%d", |
| 68 static_cast<int>(download_item_->GetLastReason()))); |
| 69 } |
| 70 |
61 gfx::Image DownloadCommands::GetCommandIcon(Command command) { | 71 gfx::Image DownloadCommands::GetCommandIcon(Command command) { |
62 ResourceBundle& bundle = ResourceBundle::GetSharedInstance(); | 72 ResourceBundle& bundle = ResourceBundle::GetSharedInstance(); |
63 return bundle.GetImageNamed(GetCommandIconId(command)); | 73 return bundle.GetImageNamed(GetCommandIconId(command)); |
64 } | 74 } |
65 | 75 |
66 bool DownloadCommands::IsCommandEnabled(Command command) const { | 76 bool DownloadCommands::IsCommandEnabled(Command command) const { |
67 switch (command) { | 77 switch (command) { |
68 case SHOW_IN_FOLDER: | 78 case SHOW_IN_FOLDER: |
69 return download_item_->CanShowInFolder(); | 79 return download_item_->CanShowInFolder(); |
70 case OPEN_WHEN_COMPLETE: | 80 case OPEN_WHEN_COMPLETE: |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 protection_service->ShowDetailsForDownload(*download_item_, | 197 protection_service->ShowDetailsForDownload(*download_item_, |
188 GetBrowser()); | 198 GetBrowser()); |
189 #else | 199 #else |
190 // Should only be getting invoked if we are using safe browsing. | 200 // Should only be getting invoked if we are using safe browsing. |
191 NOTREACHED(); | 201 NOTREACHED(); |
192 #endif | 202 #endif |
193 break; | 203 break; |
194 } | 204 } |
195 case LEARN_MORE_INTERRUPTED: | 205 case LEARN_MORE_INTERRUPTED: |
196 GetBrowser()->OpenURL(content::OpenURLParams( | 206 GetBrowser()->OpenURL(content::OpenURLParams( |
197 GURL(chrome::kDownloadInterruptedLearnMoreURL), content::Referrer(), | 207 GetLearnMoreURLForInterruptedDownload(), content::Referrer(), |
198 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, false)); | 208 NEW_FOREGROUND_TAB, ui::PAGE_TRANSITION_LINK, false)); |
199 break; | 209 break; |
200 case PAUSE: | 210 case PAUSE: |
201 download_item_->Pause(); | 211 download_item_->Pause(); |
202 break; | 212 break; |
203 case RESUME: | 213 case RESUME: |
204 download_item_->Resume(); | 214 download_item_->Resume(); |
205 break; | 215 break; |
206 case RETRY: | 216 case RETRY: |
207 if (download_item_->CanResume()) { | 217 if (download_item_->CanResume()) { |
(...skipping 28 matching lines...) Expand all Loading... |
236 is_adobe_pdf_reader_up_to_date = | 246 is_adobe_pdf_reader_up_to_date = |
237 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); | 247 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); |
238 } | 248 } |
239 return IsDownloadPdf() && | 249 return IsDownloadPdf() && |
240 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date | 250 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date |
241 : true); | 251 : true); |
242 #elif defined(OS_MACOSX) || defined(OS_LINUX) | 252 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
243 return IsDownloadPdf(); | 253 return IsDownloadPdf(); |
244 #endif | 254 #endif |
245 } | 255 } |
OLD | NEW |