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