Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_shelf_context_menu.h" | 5 #include "chrome/browser/download/download_shelf_context_menu.h" |
| 6 | 6 |
| 7 #include "base/command_line.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/safe_browsing/download_protection_service.h" | 12 #include "chrome/browser/safe_browsing/download_protection_service.h" |
| 12 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 13 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 14 #include "chrome/common/url_constants.h" | 15 #include "chrome/common/url_constants.h" |
| 15 #include "content/public/browser/download_item.h" | 16 #include "content/public/browser/download_item.h" |
| 16 #include "content/public/browser/download_manager.h" | 17 #include "content/public/browser/download_manager.h" |
| 17 #include "content/public/browser/page_navigator.h" | 18 #include "content/public/browser/page_navigator.h" |
| 19 #include "content/public/common/content_switches.h" | |
| 18 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 20 | 22 |
| 21 using content::DownloadItem; | 23 using content::DownloadItem; |
| 22 using extensions::Extension; | 24 using extensions::Extension; |
| 23 | 25 |
| 26 namespace { | |
| 27 | |
| 28 // Returns true if downloads resumption is enabled. | |
| 29 bool IsDownloadResumptionEnabled() { | |
| 30 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | |
| 31 return command_line.HasSwitch(switches::kEnableDownloadResumption); | |
| 32 } | |
| 33 | |
| 34 } // namespace | |
| 35 | |
| 24 DownloadShelfContextMenu::~DownloadShelfContextMenu() { | 36 DownloadShelfContextMenu::~DownloadShelfContextMenu() { |
| 25 DetachFromDownloadItem(); | 37 DetachFromDownloadItem(); |
| 26 } | 38 } |
| 27 | 39 |
| 28 DownloadShelfContextMenu::DownloadShelfContextMenu( | 40 DownloadShelfContextMenu::DownloadShelfContextMenu( |
| 29 DownloadItem* download_item, | 41 DownloadItem* download_item, |
| 30 content::PageNavigator* navigator) | 42 content::PageNavigator* navigator) |
| 31 : download_item_(download_item), | 43 : download_item_(download_item), |
| 32 navigator_(navigator) { | 44 navigator_(navigator) { |
| 33 DCHECK(download_item_); | 45 DCHECK(download_item_); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 case OPEN_WHEN_COMPLETE: | 78 case OPEN_WHEN_COMPLETE: |
| 67 return download_item_->CanOpenDownload() && | 79 return download_item_->CanOpenDownload() && |
| 68 !download_crx_util::IsExtensionDownload(*download_item_); | 80 !download_crx_util::IsExtensionDownload(*download_item_); |
| 69 case ALWAYS_OPEN_TYPE: | 81 case ALWAYS_OPEN_TYPE: |
| 70 // For temporary downloads, the target filename might be a temporary | 82 // For temporary downloads, the target filename might be a temporary |
| 71 // filename. Don't base an "Always open" decision based on it. Also | 83 // filename. Don't base an "Always open" decision based on it. Also |
| 72 // exclude extensions. | 84 // exclude extensions. |
| 73 return download_item_->CanOpenDownload() && | 85 return download_item_->CanOpenDownload() && |
| 74 !download_crx_util::IsExtensionDownload(*download_item_); | 86 !download_crx_util::IsExtensionDownload(*download_item_); |
| 75 case CANCEL: | 87 case CANCEL: |
| 76 return download_item_->IsPartialDownload(); | 88 return download_item_->IsPartialDownload() || download_item_->CanResume(); |
|
Randy Smith (Not in Mondays)
2013/06/04 17:08:59
Why not IsInterrupted() instead of CanResume()? S
asanka
2013/06/04 18:52:39
In theory, IsPartialDownload() should imply that t
Randy Smith (Not in Mondays)
2013/06/05 20:05:34
SGTM; I'm neutral about the order the CLs are land
asanka
2013/06/05 20:09:27
Yup. Long term all interrupted downloads will be r
| |
| 77 case TOGGLE_PAUSE: | 89 case TOGGLE_PAUSE: |
| 78 return download_item_->GetState() == DownloadItem::IN_PROGRESS; | 90 return download_item_->GetState() == DownloadItem::IN_PROGRESS; |
| 91 case RESUME_INTERRUPTED: | |
| 92 return download_item_->CanResume(); | |
|
Randy Smith (Not in Mondays)
2013/06/04 17:08:59
This is true for IN_PROGRESS downloads as well. W
asanka
2013/06/04 18:52:39
IsCommandIdEnabled() is only called on items that
Randy Smith (Not in Mondays)
2013/06/05 20:05:34
Ah, sorry, missed that.
| |
| 79 case DISCARD: | 93 case DISCARD: |
| 80 case KEEP: | 94 case KEEP: |
| 81 case LEARN_MORE_SCANNING: | 95 case LEARN_MORE_SCANNING: |
| 82 case LEARN_MORE_INTERRUPTED: | 96 case LEARN_MORE_INTERRUPTED: |
| 83 return true; | 97 return true; |
| 84 } | 98 } |
| 85 return false; | 99 return false; |
| 86 } | 100 } |
| 87 | 101 |
| 88 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { | 102 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 // It is possible for the download to complete before the user clicks the | 143 // It is possible for the download to complete before the user clicks the |
| 130 // menu item, recheck if the download is in progress state before toggling | 144 // menu item, recheck if the download is in progress state before toggling |
| 131 // pause. | 145 // pause. |
| 132 if (download_item_->IsPartialDownload()) { | 146 if (download_item_->IsPartialDownload()) { |
| 133 if (download_item_->IsPaused()) | 147 if (download_item_->IsPaused()) |
| 134 download_item_->Resume(); | 148 download_item_->Resume(); |
| 135 else | 149 else |
| 136 download_item_->Pause(); | 150 download_item_->Pause(); |
| 137 } | 151 } |
| 138 break; | 152 break; |
| 153 case RESUME_INTERRUPTED: | |
| 154 // Check again, in case the download was cancelled before the user clicks | |
| 155 // the menu item. Also, it's possible the download automatically resumed | |
| 156 // in the meantime. | |
| 157 if (download_item_->CanResume()) | |
| 158 download_item_->Resume(); | |
|
Randy Smith (Not in Mondays)
2013/06/04 17:08:59
Any reason not to just unilaterally resume? It lo
asanka
2013/06/04 18:52:39
Done.
| |
| 159 break; | |
| 139 case DISCARD: | 160 case DISCARD: |
| 140 download_item_->Remove(); | 161 download_item_->Remove(); |
| 141 break; | 162 break; |
| 142 case KEEP: | 163 case KEEP: |
| 143 download_item_->ValidateDangerousDownload(); | 164 download_item_->ValidateDangerousDownload(); |
| 144 break; | 165 break; |
| 145 case LEARN_MORE_SCANNING: { | 166 case LEARN_MORE_SCANNING: { |
| 146 #if defined(FULL_SAFE_BROWSING) | 167 #if defined(FULL_SAFE_BROWSING) |
| 147 using safe_browsing::DownloadProtectionService; | 168 using safe_browsing::DownloadProtectionService; |
| 148 SafeBrowsingService* sb_service = | 169 SafeBrowsingService* sb_service = |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); | 209 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); |
| 189 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); | 210 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); |
| 190 case ALWAYS_OPEN_TYPE: | 211 case ALWAYS_OPEN_TYPE: |
| 191 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); | 212 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); |
| 192 case CANCEL: | 213 case CANCEL: |
| 193 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); | 214 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); |
| 194 case TOGGLE_PAUSE: | 215 case TOGGLE_PAUSE: |
| 195 if (download_item_ && download_item_->IsPaused()) | 216 if (download_item_ && download_item_->IsPaused()) |
| 196 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); | 217 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); |
| 197 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); | 218 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); |
| 219 case RESUME_INTERRUPTED: | |
| 220 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); | |
| 198 case DISCARD: | 221 case DISCARD: |
| 199 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); | 222 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); |
| 200 case KEEP: | 223 case KEEP: |
| 201 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); | 224 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); |
| 202 case LEARN_MORE_SCANNING: | 225 case LEARN_MORE_SCANNING: |
| 203 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); | 226 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); |
| 204 case LEARN_MORE_INTERRUPTED: | 227 case LEARN_MORE_INTERRUPTED: |
| 205 return l10n_util::GetStringUTF16( | 228 return l10n_util::GetStringUTF16( |
| 206 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); | 229 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); |
| 207 } | 230 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 finished_download_menu_model_->AddItemWithStringId( | 281 finished_download_menu_model_->AddItemWithStringId( |
| 259 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); | 282 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); |
| 260 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 283 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 261 finished_download_menu_model_->AddItemWithStringId( | 284 finished_download_menu_model_->AddItemWithStringId( |
| 262 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); | 285 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); |
| 263 | 286 |
| 264 return finished_download_menu_model_.get(); | 287 return finished_download_menu_model_.get(); |
| 265 } | 288 } |
| 266 | 289 |
| 267 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { | 290 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { |
| 268 #if defined(OS_WIN) | 291 #if !defined(OS_WIN) |
| 269 // The Help Center article is currently Windows specific. | 292 // If resumption isn't enabled and we aren't on Windows, then none of the |
| 270 // TODO(asanka): Enable this for other platforms when the article is expanded | 293 // options here are applicable. |
| 271 // for other platforms. | 294 if (!IsDownloadResumptionEnabled()) |
| 295 return GetInProgressMenuModel(); | |
| 296 #endif | |
| 297 | |
| 272 if (interrupted_download_menu_model_) | 298 if (interrupted_download_menu_model_) |
| 273 return interrupted_download_menu_model_.get(); | 299 return interrupted_download_menu_model_.get(); |
| 274 | 300 |
| 275 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 301 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 276 | 302 |
| 303 if (IsDownloadResumptionEnabled()) { | |
| 304 interrupted_download_menu_model_->AddItemWithStringId( | |
| 305 RESUME_INTERRUPTED, IDS_DOWNLOAD_MENU_RESUME_ITEM); | |
| 306 } | |
| 307 #if defined(OS_WIN) | |
| 308 // The Help Center article is currently Windows specific. | |
| 309 // TODO(asanka): Enable this for other platforms when the article is expanded | |
| 310 // for other platforms. | |
| 277 interrupted_download_menu_model_->AddItemWithStringId( | 311 interrupted_download_menu_model_->AddItemWithStringId( |
| 278 LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); | 312 LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); |
| 313 #endif | |
| 314 if (IsDownloadResumptionEnabled()) { | |
| 315 interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 316 interrupted_download_menu_model_->AddItemWithStringId( | |
| 317 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); | |
| 318 } | |
| 279 | 319 |
| 280 return interrupted_download_menu_model_.get(); | 320 return interrupted_download_menu_model_.get(); |
| 281 #else | |
| 282 return GetInProgressMenuModel(); | |
| 283 #endif | |
| 284 } | 321 } |
| 285 | 322 |
| 286 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { | 323 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { |
| 287 if (malicious_download_menu_model_) | 324 if (malicious_download_menu_model_) |
| 288 return malicious_download_menu_model_.get(); | 325 return malicious_download_menu_model_.get(); |
| 289 | 326 |
| 290 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 327 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 291 | 328 |
| 292 malicious_download_menu_model_->AddItemWithStringId( | 329 malicious_download_menu_model_->AddItemWithStringId( |
| 293 DISCARD, IDS_DOWNLOAD_MENU_DISCARD); | 330 DISCARD, IDS_DOWNLOAD_MENU_DISCARD); |
| 294 malicious_download_menu_model_->AddItemWithStringId( | 331 malicious_download_menu_model_->AddItemWithStringId( |
| 295 KEEP, IDS_DOWNLOAD_MENU_KEEP); | 332 KEEP, IDS_DOWNLOAD_MENU_KEEP); |
| 296 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 333 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 297 malicious_download_menu_model_->AddItemWithStringId( | 334 malicious_download_menu_model_->AddItemWithStringId( |
| 298 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); | 335 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); |
| 299 | 336 |
| 300 return malicious_download_menu_model_.get(); | 337 return malicious_download_menu_model_.get(); |
| 301 } | 338 } |
| OLD | NEW |