Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: chrome/browser/download/download_shelf_context_menu.cc

Issue 10831302: Download resumption - Preliminary (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fixed signed/unsigned compare issue. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
14 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
14 #include "content/public/browser/download_item.h" 16 #include "content/public/browser/download_item.h"
15 #include "content/public/browser/download_manager.h" 17 #include "content/public/browser/download_manager.h"
16 #include "content/public/browser/page_navigator.h" 18 #include "content/public/browser/page_navigator.h"
17 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util.h" 20 #include "ui/base/l10n/l10n_util.h"
19 21
20 using content::DownloadItem; 22 using content::DownloadItem;
21 using extensions::Extension; 23 using extensions::Extension;
22 24
(...skipping 16 matching lines...) Expand all
39 if (download_model_->IsMalicious()) 41 if (download_model_->IsMalicious())
40 model = GetMaliciousMenuModel(); 42 model = GetMaliciousMenuModel();
41 else if (download_item_->IsComplete()) 43 else if (download_item_->IsComplete())
42 model = GetFinishedMenuModel(); 44 model = GetFinishedMenuModel();
43 else 45 else
44 model = GetInProgressMenuModel(); 46 model = GetInProgressMenuModel();
45 return model; 47 return model;
46 } 48 }
47 49
48 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { 50 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const {
51 static bool restart_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
52 switches::kEnableDownloadResumption);
49 switch (command_id) { 53 switch (command_id) {
50 case SHOW_IN_FOLDER: 54 case SHOW_IN_FOLDER:
51 return download_item_->CanShowInFolder() && 55 return download_item_->CanShowInFolder() &&
52 !download_item_->IsTemporary(); 56 !download_item_->IsTemporary();
53 case OPEN_WHEN_COMPLETE: 57 case OPEN_WHEN_COMPLETE:
54 return download_item_->CanShowInFolder() && 58 return download_item_->CanShowInFolder() &&
55 !download_item_->IsTemporary() && 59 !download_item_->IsTemporary() &&
56 (!download_crx_util::IsExtensionDownload(*download_item_) || 60 (!download_crx_util::IsExtensionDownload(*download_item_) ||
57 download_item_->IsComplete()); 61 download_item_->IsComplete());
58 case ALWAYS_OPEN_TYPE: 62 case ALWAYS_OPEN_TYPE:
59 // For temporary downloads, the target filename might be a temporary 63 // For temporary downloads, the target filename might be a temporary
60 // filename. Don't base an "Always open" decision based on it. Also 64 // filename. Don't base an "Always open" decision based on it. Also
61 // exclude extensions. 65 // exclude extensions.
62 return download_item_->CanOpenDownload() && 66 return download_item_->CanOpenDownload() &&
63 !download_crx_util::IsExtensionDownload(*download_item_) && 67 !download_crx_util::IsExtensionDownload(*download_item_) &&
64 !download_item_->IsTemporary(); 68 !download_item_->IsTemporary();
65 case CANCEL: 69 case CANCEL:
66 return download_item_->IsPartialDownload(); 70 return download_item_->IsPartialDownload();
67 case TOGGLE_PAUSE: 71 case TOGGLE_PAUSE:
68 return download_item_->IsInProgress(); 72 return restart_enabled && download_item_->CanResumeDownload();
69 default: 73 default:
70 return command_id > 0 && command_id < MENU_LAST; 74 return command_id > 0 && command_id < MENU_LAST;
71 } 75 }
72 } 76 }
73 77
74 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { 78 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const {
75 switch (command_id) { 79 switch (command_id) {
76 case OPEN_WHEN_COMPLETE: 80 case OPEN_WHEN_COMPLETE:
77 return download_item_->GetOpenWhenComplete() || 81 return download_item_->GetOpenWhenComplete() ||
78 download_crx_util::IsExtensionDownload(*download_item_); 82 download_crx_util::IsExtensionDownload(*download_item_);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW); 161 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW);
158 case OPEN_WHEN_COMPLETE: 162 case OPEN_WHEN_COMPLETE:
159 if (download_item_->IsInProgress()) 163 if (download_item_->IsInProgress())
160 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); 164 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
161 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); 165 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN);
162 case ALWAYS_OPEN_TYPE: 166 case ALWAYS_OPEN_TYPE:
163 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); 167 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE);
164 case CANCEL: 168 case CANCEL:
165 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); 169 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL);
166 case TOGGLE_PAUSE: { 170 case TOGGLE_PAUSE: {
167 if (download_item_->IsPaused()) 171 if (download_item_->IsPaused() ||
172 download_item_->CanResumeInterrupted()) {
168 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); 173 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
174 }
169 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); 175 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
170 } 176 }
171 case DISCARD: 177 case DISCARD:
172 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); 178 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD);
173 case KEEP: 179 case KEEP:
174 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); 180 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP);
175 case LEARN_MORE: 181 case LEARN_MORE:
176 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE); 182 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE);
177 default: 183 default:
178 NOTREACHED(); 184 NOTREACHED();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 malicious_download_menu_model_->AddItemWithStringId( 238 malicious_download_menu_model_->AddItemWithStringId(
233 DISCARD, IDS_DOWNLOAD_MENU_DISCARD); 239 DISCARD, IDS_DOWNLOAD_MENU_DISCARD);
234 malicious_download_menu_model_->AddItemWithStringId( 240 malicious_download_menu_model_->AddItemWithStringId(
235 KEEP, IDS_DOWNLOAD_MENU_KEEP); 241 KEEP, IDS_DOWNLOAD_MENU_KEEP);
236 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 242 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
237 malicious_download_menu_model_->AddItemWithStringId( 243 malicious_download_menu_model_->AddItemWithStringId(
238 LEARN_MORE, IDS_DOWNLOAD_MENU_LEARN_MORE); 244 LEARN_MORE, IDS_DOWNLOAD_MENU_LEARN_MORE);
239 245
240 return malicious_download_menu_model_.get(); 246 return malicious_download_menu_model_.get();
241 } 247 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_item_model_unittest.cc ('k') | chrome/browser/plugins/plugin_installer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698