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

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 content unit tests. Created 8 years, 2 months 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 "chrome/common/extensions/extension_switch_utils.h" 16 #include "chrome/common/extensions/extension_switch_utils.h"
15 #include "content/public/browser/download_item.h" 17 #include "content/public/browser/download_item.h"
16 #include "content/public/browser/download_manager.h" 18 #include "content/public/browser/download_manager.h"
17 #include "content/public/browser/page_navigator.h" 19 #include "content/public/browser/page_navigator.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;
(...skipping 17 matching lines...) Expand all
40 if (download_model_->IsMalicious()) 42 if (download_model_->IsMalicious())
41 model = GetMaliciousMenuModel(); 43 model = GetMaliciousMenuModel();
42 else if (download_item_->IsComplete()) 44 else if (download_item_->IsComplete())
43 model = GetFinishedMenuModel(); 45 model = GetFinishedMenuModel();
44 else 46 else
45 model = GetInProgressMenuModel(); 47 model = GetInProgressMenuModel();
46 return model; 48 return model;
47 } 49 }
48 50
49 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { 51 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const {
52 static bool restart_enabled = CommandLine::ForCurrentProcess()->HasSwitch(
53 switches::kEnableDownloadResumption);
50 switch (command_id) { 54 switch (command_id) {
51 case SHOW_IN_FOLDER: 55 case SHOW_IN_FOLDER:
52 return download_item_->CanShowInFolder() && 56 return download_item_->CanShowInFolder() &&
53 !download_item_->IsTemporary(); 57 !download_item_->IsTemporary();
54 case OPEN_WHEN_COMPLETE: 58 case OPEN_WHEN_COMPLETE:
55 return download_item_->CanShowInFolder() && 59 return download_item_->CanShowInFolder() &&
56 !download_item_->IsTemporary() && 60 !download_item_->IsTemporary() &&
57 (!download_crx_util::IsExtensionDownload(*download_item_) || 61 (!download_crx_util::IsExtensionDownload(*download_item_) ||
58 download_item_->IsComplete()); 62 download_item_->IsComplete());
59 case ALWAYS_OPEN_TYPE: 63 case ALWAYS_OPEN_TYPE:
60 // For temporary downloads, the target filename might be a temporary 64 // For temporary downloads, the target filename might be a temporary
61 // filename. Don't base an "Always open" decision based on it. Also 65 // filename. Don't base an "Always open" decision based on it. Also
62 // exclude extensions. 66 // exclude extensions.
63 return download_item_->CanOpenDownload() && 67 return download_item_->CanOpenDownload() &&
64 !download_crx_util::IsExtensionDownload(*download_item_) && 68 !download_crx_util::IsExtensionDownload(*download_item_) &&
65 !download_item_->IsTemporary(); 69 !download_item_->IsTemporary();
66 case CANCEL: 70 case CANCEL:
67 return download_item_->IsPartialDownload(); 71 return download_item_->IsPartialDownload();
68 case TOGGLE_PAUSE: 72 case TOGGLE_PAUSE:
69 return download_item_->IsInProgress(); 73 return restart_enabled && download_item_->CanResumeDownload();
70 default: 74 default:
71 return command_id > 0 && command_id < MENU_LAST; 75 return command_id > 0 && command_id < MENU_LAST;
72 } 76 }
73 } 77 }
74 78
75 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { 79 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const {
76 switch (command_id) { 80 switch (command_id) {
77 case OPEN_WHEN_COMPLETE: 81 case OPEN_WHEN_COMPLETE:
78 return download_item_->GetOpenWhenComplete() || 82 return download_item_->GetOpenWhenComplete() ||
79 download_crx_util::IsExtensionDownload(*download_item_); 83 download_crx_util::IsExtensionDownload(*download_item_);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW); 162 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW);
159 case OPEN_WHEN_COMPLETE: 163 case OPEN_WHEN_COMPLETE:
160 if (download_item_->IsInProgress()) 164 if (download_item_->IsInProgress())
161 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); 165 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
162 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); 166 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN);
163 case ALWAYS_OPEN_TYPE: 167 case ALWAYS_OPEN_TYPE:
164 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); 168 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE);
165 case CANCEL: 169 case CANCEL:
166 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); 170 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL);
167 case TOGGLE_PAUSE: { 171 case TOGGLE_PAUSE: {
168 if (download_item_->IsPaused()) 172 if (download_item_->IsPaused() ||
173 (download_item_->CanResumeInterrupted() !=
174 DownloadItem::RESUME_MODE_INVALID)) {
169 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); 175 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
176 }
170 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); 177 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
171 } 178 }
172 case DISCARD: 179 case DISCARD:
173 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); 180 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD);
174 case KEEP: 181 case KEEP:
175 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); 182 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP);
176 case LEARN_MORE: 183 case LEARN_MORE:
177 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE); 184 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE);
178 default: 185 default:
179 NOTREACHED(); 186 NOTREACHED();
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 malicious_download_menu_model_->AddItemWithStringId( 240 malicious_download_menu_model_->AddItemWithStringId(
234 DISCARD, IDS_DOWNLOAD_MENU_DISCARD); 241 DISCARD, IDS_DOWNLOAD_MENU_DISCARD);
235 malicious_download_menu_model_->AddItemWithStringId( 242 malicious_download_menu_model_->AddItemWithStringId(
236 KEEP, IDS_DOWNLOAD_MENU_KEEP); 243 KEEP, IDS_DOWNLOAD_MENU_KEEP);
237 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); 244 malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
238 malicious_download_menu_model_->AddItemWithStringId( 245 malicious_download_menu_model_->AddItemWithStringId(
239 LEARN_MORE, IDS_DOWNLOAD_MENU_LEARN_MORE); 246 LEARN_MORE, IDS_DOWNLOAD_MENU_LEARN_MORE);
240 247
241 return malicious_download_menu_model_.get(); 248 return malicious_download_menu_model_.get();
242 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698