| 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 "build/build_config.h" | 7 #include "build/build_config.h" |
| 8 #include "chrome/browser/download/download_item_model.h" | 8 #include "chrome/browser/download/download_item_model.h" |
| 9 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
| 10 #include "content/public/common/content_features.h" | 10 #include "content/public/common/content_features.h" |
| 11 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 | 13 |
| 14 #if defined(OS_WIN) | 14 #if defined(OS_WIN) |
| 15 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" | 15 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" |
| 16 #endif | 16 #endif |
| 17 | 17 |
| 18 using content::DownloadItem; | 18 using content::DownloadItem; |
| 19 | 19 |
| 20 namespace { | |
| 21 | |
| 22 // Returns true if downloads resumption is enabled. | |
| 23 bool IsDownloadResumptionEnabled() { | |
| 24 return base::FeatureList::IsEnabled(features::kDownloadResumption); | |
| 25 } | |
| 26 | |
| 27 } // namespace | |
| 28 | |
| 29 DownloadShelfContextMenu::~DownloadShelfContextMenu() { | 20 DownloadShelfContextMenu::~DownloadShelfContextMenu() { |
| 30 DetachFromDownloadItem(); | 21 DetachFromDownloadItem(); |
| 31 } | 22 } |
| 32 | 23 |
| 33 DownloadShelfContextMenu::DownloadShelfContextMenu(DownloadItem* download_item) | 24 DownloadShelfContextMenu::DownloadShelfContextMenu(DownloadItem* download_item) |
| 34 : download_item_(download_item), | 25 : download_item_(download_item), |
| 35 download_commands_(new DownloadCommands(download_item)) { | 26 download_commands_(new DownloadCommands(download_item)) { |
| 36 DCHECK(download_item_); | 27 DCHECK(download_item_); |
| 37 download_item_->AddObserver(this); | 28 download_item_->AddObserver(this); |
| 38 } | 29 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 DownloadCommands::SHOW_IN_FOLDER, | 248 DownloadCommands::SHOW_IN_FOLDER, |
| 258 GetLabelForCommandId(DownloadCommands::SHOW_IN_FOLDER)); | 249 GetLabelForCommandId(DownloadCommands::SHOW_IN_FOLDER)); |
| 259 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 250 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 260 finished_download_menu_model_->AddItem( | 251 finished_download_menu_model_->AddItem( |
| 261 DownloadCommands::CANCEL, GetLabelForCommandId(DownloadCommands::CANCEL)); | 252 DownloadCommands::CANCEL, GetLabelForCommandId(DownloadCommands::CANCEL)); |
| 262 | 253 |
| 263 return finished_download_menu_model_.get(); | 254 return finished_download_menu_model_.get(); |
| 264 } | 255 } |
| 265 | 256 |
| 266 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { | 257 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { |
| 267 #if !defined(OS_WIN) | |
| 268 // If resumption isn't enabled and we aren't on Windows, then none of the | |
| 269 // options here are applicable. | |
| 270 if (!IsDownloadResumptionEnabled()) | |
| 271 return GetInProgressMenuModel(); | |
| 272 #endif | |
| 273 | |
| 274 if (interrupted_download_menu_model_) | 258 if (interrupted_download_menu_model_) |
| 275 return interrupted_download_menu_model_.get(); | 259 return interrupted_download_menu_model_.get(); |
| 276 | 260 |
| 277 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 261 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 278 | 262 |
| 279 if (IsDownloadResumptionEnabled()) { | 263 interrupted_download_menu_model_->AddItem( |
| 280 interrupted_download_menu_model_->AddItem( | 264 DownloadCommands::RESUME, GetLabelForCommandId(DownloadCommands::RESUME)); |
| 281 DownloadCommands::RESUME, | |
| 282 GetLabelForCommandId(DownloadCommands::RESUME)); | |
| 283 } | |
| 284 #if defined(OS_WIN) | 265 #if defined(OS_WIN) |
| 285 // The Help Center article is currently Windows specific. | 266 // The Help Center article is currently Windows specific. |
| 286 // TODO(asanka): Enable this for other platforms when the article is expanded | 267 // TODO(asanka): Enable this for other platforms when the article is expanded |
| 287 // for other platforms. | 268 // for other platforms. |
| 288 interrupted_download_menu_model_->AddItem( | 269 interrupted_download_menu_model_->AddItem( |
| 289 DownloadCommands::LEARN_MORE_INTERRUPTED, | 270 DownloadCommands::LEARN_MORE_INTERRUPTED, |
| 290 GetLabelForCommandId(DownloadCommands::LEARN_MORE_INTERRUPTED)); | 271 GetLabelForCommandId(DownloadCommands::LEARN_MORE_INTERRUPTED)); |
| 291 #endif | 272 #endif |
| 292 if (IsDownloadResumptionEnabled()) { | 273 interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 293 interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 274 interrupted_download_menu_model_->AddItem( |
| 294 interrupted_download_menu_model_->AddItem( | 275 DownloadCommands::CANCEL, GetLabelForCommandId(DownloadCommands::CANCEL)); |
| 295 DownloadCommands::CANCEL, | |
| 296 GetLabelForCommandId(DownloadCommands::CANCEL)); | |
| 297 } | |
| 298 | 276 |
| 299 return interrupted_download_menu_model_.get(); | 277 return interrupted_download_menu_model_.get(); |
| 300 } | 278 } |
| 301 | 279 |
| 302 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaybeMaliciousMenuModel() { | 280 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaybeMaliciousMenuModel() { |
| 303 if (maybe_malicious_download_menu_model_) | 281 if (maybe_malicious_download_menu_model_) |
| 304 return maybe_malicious_download_menu_model_.get(); | 282 return maybe_malicious_download_menu_model_.get(); |
| 305 | 283 |
| 306 maybe_malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 284 maybe_malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 307 | 285 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 318 if (malicious_download_menu_model_) | 296 if (malicious_download_menu_model_) |
| 319 return malicious_download_menu_model_.get(); | 297 return malicious_download_menu_model_.get(); |
| 320 | 298 |
| 321 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 299 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 322 malicious_download_menu_model_->AddItem( | 300 malicious_download_menu_model_->AddItem( |
| 323 DownloadCommands::LEARN_MORE_SCANNING, | 301 DownloadCommands::LEARN_MORE_SCANNING, |
| 324 GetLabelForCommandId(DownloadCommands::LEARN_MORE_SCANNING)); | 302 GetLabelForCommandId(DownloadCommands::LEARN_MORE_SCANNING)); |
| 325 | 303 |
| 326 return malicious_download_menu_model_.get(); | 304 return malicious_download_menu_model_.get(); |
| 327 } | 305 } |
| OLD | NEW |