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

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

Issue 852043002: Initial Implementation of Download Notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 10 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 "base/command_line.h"
8 #include "chrome/browser/browser_process.h" 8 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/download/download_commands.h"
9 #include "chrome/browser/download/download_crx_util.h" 10 #include "chrome/browser/download/download_crx_util.h"
10 #include "chrome/browser/download/download_item_model.h" 11 #include "chrome/browser/download/download_item_model.h"
11 #include "chrome/browser/download/download_prefs.h" 12 #include "chrome/browser/download/download_prefs.h"
12 #include "chrome/browser/download/download_target_determiner.h" 13 #include "chrome/browser/download/download_target_determiner.h"
13 #include "chrome/browser/safe_browsing/download_protection_service.h" 14 #include "chrome/browser/safe_browsing/download_protection_service.h"
14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
15 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
16 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
17 #include "content/public/browser/download_item.h" 18 #include "content/public/browser/download_item.h"
18 #include "content/public/browser/download_manager.h" 19 #include "content/public/browser/download_manager.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 model = GetInterruptedMenuModel(); 80 model = GetInterruptedMenuModel();
80 else 81 else
81 model = GetInProgressMenuModel(); 82 model = GetInProgressMenuModel();
82 return model; 83 return model;
83 } 84 }
84 85
85 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { 86 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const {
86 if (!download_item_) 87 if (!download_item_)
87 return false; 88 return false;
88 89
89 switch (static_cast<ContextMenuCommands>(command_id)) { 90 switch (static_cast<DownloadCommands>(command_id)) {
90 case SHOW_IN_FOLDER: 91 case SHOW_IN_FOLDER:
91 return download_item_->CanShowInFolder(); 92 return download_item_->CanShowInFolder();
92 case OPEN_WHEN_COMPLETE: 93 case OPEN_WHEN_COMPLETE:
93 case PLATFORM_OPEN: 94 case PLATFORM_OPEN:
94 return download_item_->CanOpenDownload() && 95 return download_item_->CanOpenDownload() &&
95 !download_crx_util::IsExtensionDownload(*download_item_); 96 !download_crx_util::IsExtensionDownload(*download_item_);
96 case ALWAYS_OPEN_TYPE: 97 case ALWAYS_OPEN_TYPE:
97 // For temporary downloads, the target filename might be a temporary 98 // For temporary downloads, the target filename might be a temporary
98 // filename. Don't base an "Always open" decision based on it. Also 99 // filename. Don't base an "Always open" decision based on it. Also
99 // exclude extensions. 100 // exclude extensions.
100 return download_item_->CanOpenDownload() && 101 return download_item_->CanOpenDownload() &&
101 !download_crx_util::IsExtensionDownload(*download_item_); 102 !download_crx_util::IsExtensionDownload(*download_item_);
102 case CANCEL: 103 case CANCEL:
103 return !download_item_->IsDone(); 104 return !download_item_->IsDone();
104 case TOGGLE_PAUSE: 105 case TOGGLE_PAUSE:
105 return !download_item_->IsDone(); 106 return !download_item_->IsDone();
106 case DISCARD: 107 case DISCARD:
107 case KEEP: 108 case KEEP:
108 case LEARN_MORE_SCANNING: 109 case LEARN_MORE_SCANNING:
109 case LEARN_MORE_INTERRUPTED: 110 case LEARN_MORE_INTERRUPTED:
110 return true; 111 return true;
112 default:
113 break;
111 } 114 }
112 NOTREACHED(); 115 NOTREACHED();
113 return false; 116 return false;
114 } 117 }
115 118
116 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { 119 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const {
117 if (!download_item_) 120 if (!download_item_)
118 return false; 121 return false;
119 122
120 switch (command_id) { 123 switch (static_cast<DownloadCommands>(command_id)) {
121 case OPEN_WHEN_COMPLETE: 124 case OPEN_WHEN_COMPLETE:
122 return download_item_->GetOpenWhenComplete() || 125 return download_item_->GetOpenWhenComplete() ||
123 download_crx_util::IsExtensionDownload(*download_item_); 126 download_crx_util::IsExtensionDownload(*download_item_);
124 case ALWAYS_OPEN_TYPE: 127 case ALWAYS_OPEN_TYPE:
125 #if defined(OS_WIN) || defined(OS_LINUX) || \ 128 #if defined(OS_WIN) || defined(OS_LINUX) || \
126 (defined(OS_MACOSX) && !defined(OS_IOS)) 129 (defined(OS_MACOSX) && !defined(OS_IOS))
127 if (CanOpenPdfInSystemViewer()) { 130 if (CanOpenPdfInSystemViewer()) {
128 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( 131 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext(
129 download_item_->GetBrowserContext()); 132 download_item_->GetBrowserContext());
130 return prefs->ShouldOpenPdfInSystemReader(); 133 return prefs->ShouldOpenPdfInSystemReader();
131 } 134 }
132 #endif 135 #endif
133 return download_item_->ShouldOpenFileBasedOnExtension(); 136 return download_item_->ShouldOpenFileBasedOnExtension();
134 case TOGGLE_PAUSE: 137 case TOGGLE_PAUSE:
135 return download_item_->IsPaused(); 138 return download_item_->IsPaused();
139 default:
140 break;
136 } 141 }
137 return false; 142 return false;
138 } 143 }
139 144
140 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { 145 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const {
141 if (!download_item_) 146 if (!download_item_)
142 return false; 147 return false;
143 148
144 if (command_id == PLATFORM_OPEN) 149 if (command_id == PLATFORM_OPEN)
145 return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()); 150 return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser());
146 151
147 return true; 152 return true;
148 } 153 }
149 154
150 void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) { 155 void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) {
151 if (!download_item_) 156 if (!download_item_)
152 return; 157 return;
153 158
154 switch (static_cast<ContextMenuCommands>(command_id)) { 159 switch (static_cast<DownloadCommands>(command_id)) {
155 case SHOW_IN_FOLDER: 160 case SHOW_IN_FOLDER:
156 download_item_->ShowDownloadInShell(); 161 download_item_->ShowDownloadInShell();
157 break; 162 break;
158 case OPEN_WHEN_COMPLETE: 163 case OPEN_WHEN_COMPLETE:
159 download_item_->OpenDownload(); 164 download_item_->OpenDownload();
160 break; 165 break;
161 case ALWAYS_OPEN_TYPE: { 166 case ALWAYS_OPEN_TYPE: {
162 bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE); 167 bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE);
163 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( 168 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext(
164 download_item_->GetBrowserContext()); 169 download_item_->GetBrowserContext());
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 break; 220 break;
216 } 221 }
217 case LEARN_MORE_INTERRUPTED: 222 case LEARN_MORE_INTERRUPTED:
218 navigator_->OpenURL( 223 navigator_->OpenURL(
219 content::OpenURLParams(GURL(chrome::kDownloadInterruptedLearnMoreURL), 224 content::OpenURLParams(GURL(chrome::kDownloadInterruptedLearnMoreURL),
220 content::Referrer(), 225 content::Referrer(),
221 NEW_FOREGROUND_TAB, 226 NEW_FOREGROUND_TAB,
222 ui::PAGE_TRANSITION_LINK, 227 ui::PAGE_TRANSITION_LINK,
223 false)); 228 false));
224 break; 229 break;
230 default:
231 break;
225 } 232 }
226 } 233 }
227 234
228 bool DownloadShelfContextMenu::GetAcceleratorForCommandId( 235 bool DownloadShelfContextMenu::GetAcceleratorForCommandId(
229 int command_id, ui::Accelerator* accelerator) { 236 int command_id, ui::Accelerator* accelerator) {
230 return false; 237 return false;
231 } 238 }
232 239
233 bool DownloadShelfContextMenu::IsItemForCommandIdDynamic(int command_id) const { 240 bool DownloadShelfContextMenu::IsItemForCommandIdDynamic(int command_id) const {
234 return command_id == TOGGLE_PAUSE; 241 return command_id == TOGGLE_PAUSE;
235 } 242 }
236 243
237 base::string16 DownloadShelfContextMenu::GetLabelForCommandId( 244 base::string16 DownloadShelfContextMenu::GetLabelForCommandId(
238 int command_id) const { 245 int command_id) const {
239 switch (static_cast<ContextMenuCommands>(command_id)) { 246 switch (static_cast<DownloadCommands>(command_id)) {
240 case SHOW_IN_FOLDER: 247 case SHOW_IN_FOLDER:
241 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW); 248 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW);
242 case OPEN_WHEN_COMPLETE: 249 case OPEN_WHEN_COMPLETE:
243 if (download_item_ && !download_item_->IsDone()) 250 if (download_item_ && !download_item_->IsDone())
244 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); 251 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE);
245 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); 252 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN);
246 case ALWAYS_OPEN_TYPE: 253 case ALWAYS_OPEN_TYPE:
247 return l10n_util::GetStringUTF16(GetAlwaysOpenStringId()); 254 return l10n_util::GetStringUTF16(GetAlwaysOpenStringId());
248 case PLATFORM_OPEN: 255 case PLATFORM_OPEN:
249 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PLATFORM_OPEN); 256 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PLATFORM_OPEN);
250 case CANCEL: 257 case CANCEL:
251 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); 258 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL);
252 case TOGGLE_PAUSE: 259 case TOGGLE_PAUSE:
253 if (download_item_ && 260 if (download_item_ &&
254 download_item_->GetState() == DownloadItem::IN_PROGRESS && 261 download_item_->GetState() == DownloadItem::IN_PROGRESS &&
255 !download_item_->IsPaused()) 262 !download_item_->IsPaused())
256 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); 263 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM);
257 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); 264 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM);
258 case DISCARD: 265 case DISCARD:
259 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); 266 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD);
260 case KEEP: 267 case KEEP:
261 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); 268 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP);
262 case LEARN_MORE_SCANNING: 269 case LEARN_MORE_SCANNING:
263 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); 270 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING);
264 case LEARN_MORE_INTERRUPTED: 271 case LEARN_MORE_INTERRUPTED:
265 return l10n_util::GetStringUTF16( 272 return l10n_util::GetStringUTF16(
266 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); 273 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED);
274 default:
275 break;
267 } 276 }
268 NOTREACHED(); 277 NOTREACHED();
269 return base::string16(); 278 return base::string16();
270 } 279 }
271 280
272 void DownloadShelfContextMenu::DetachFromDownloadItem() { 281 void DownloadShelfContextMenu::DetachFromDownloadItem() {
273 if (!download_item_) 282 if (!download_item_)
274 return; 283 return;
275 284
276 download_item_->RemoveObserver(this); 285 download_item_->RemoveObserver(this);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 417
409 bool DownloadShelfContextMenu::CanOpenPdfInSystemViewer() const { 418 bool DownloadShelfContextMenu::CanOpenPdfInSystemViewer() const {
410 #if defined(OS_WIN) 419 #if defined(OS_WIN)
411 return IsDownloadPdf() && 420 return IsDownloadPdf() &&
412 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date_ : 421 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date_ :
413 true); 422 true);
414 #elif defined(OS_MACOSX) || defined(OS_LINUX) 423 #elif defined(OS_MACOSX) || defined(OS_LINUX)
415 return IsDownloadPdf(); 424 return IsDownloadPdf();
416 #endif 425 #endif
417 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698