OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/download/download_item_model.h" | 7 #include "chrome/browser/download/download_item_model.h" |
8 #include "chrome/browser/download/download_prefs.h" | 8 #include "chrome/browser/download/download_prefs.h" |
| 9 #include "chrome/browser/google/google_util.h" |
| 10 #include "chrome/browser/ui/browser_list.h" |
9 #include "chrome/common/extensions/extension.h" | 11 #include "chrome/common/extensions/extension.h" |
| 12 #include "chrome/common/url_constants.h" |
10 #include "content/browser/download/download_item.h" | 13 #include "content/browser/download/download_item.h" |
11 #include "content/browser/download/download_manager.h" | 14 #include "content/browser/download/download_manager.h" |
| 15 #include "content/browser/tab_contents/page_navigator.h" |
12 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
13 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
14 | 18 |
15 DownloadShelfContextMenu::~DownloadShelfContextMenu() {} | 19 DownloadShelfContextMenu::~DownloadShelfContextMenu() {} |
16 | 20 |
17 DownloadShelfContextMenu::DownloadShelfContextMenu( | 21 DownloadShelfContextMenu::DownloadShelfContextMenu( |
18 BaseDownloadItemModel* download_model) | 22 BaseDownloadItemModel* download_model) |
19 : download_model_(download_model), | 23 : download_model_(download_model), |
20 download_item_(download_model->download()) { | 24 download_item_(download_model->download()) { |
21 } | 25 } |
22 | 26 |
23 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { | 27 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { |
24 return download_item_->IsComplete() ? GetFinishedMenuModel() | 28 ui::SimpleMenuModel* model = NULL; |
25 : GetInProgressMenuModel(); | 29 |
| 30 if (download_item_->GetSafetyState() == DownloadItem::DANGEROUS) { |
| 31 if (download_item_->GetDangerType() == DownloadStateInfo::DANGEROUS_URL || |
| 32 download_item_->GetDangerType() == |
| 33 DownloadStateInfo::DANGEROUS_CONTENT) { |
| 34 model = GetMaliciousMenuModel(); |
| 35 } else { |
| 36 NOTREACHED(); |
| 37 } |
| 38 } else if (download_item_->IsComplete()) { |
| 39 model = GetFinishedMenuModel(); |
| 40 } else { |
| 41 model = GetInProgressMenuModel(); |
| 42 } |
| 43 return model; |
26 } | 44 } |
27 | 45 |
28 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { | 46 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { |
29 switch (command_id) { | 47 switch (command_id) { |
30 case SHOW_IN_FOLDER: | 48 case SHOW_IN_FOLDER: |
31 case OPEN_WHEN_COMPLETE: | 49 case OPEN_WHEN_COMPLETE: |
32 return download_item_->CanShowInFolder(); | 50 return download_item_->CanShowInFolder(); |
33 case ALWAYS_OPEN_TYPE: | 51 case ALWAYS_OPEN_TYPE: |
34 return download_item_->CanOpenDownload() && | 52 return download_item_->CanOpenDownload() && |
35 !Extension::IsExtension(download_item_->GetStateInfo().target_name); | 53 !Extension::IsExtension(download_item_->GetStateInfo().target_name); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 case CANCEL: | 93 case CANCEL: |
76 download_model_->CancelTask(); | 94 download_model_->CancelTask(); |
77 break; | 95 break; |
78 case TOGGLE_PAUSE: | 96 case TOGGLE_PAUSE: |
79 // It is possible for the download to complete before the user clicks the | 97 // It is possible for the download to complete before the user clicks the |
80 // menu item, recheck if the download is in progress state before toggling | 98 // menu item, recheck if the download is in progress state before toggling |
81 // pause. | 99 // pause. |
82 if (download_item_->IsPartialDownload()) | 100 if (download_item_->IsPartialDownload()) |
83 download_item_->TogglePause(); | 101 download_item_->TogglePause(); |
84 break; | 102 break; |
| 103 case DISCARD: |
| 104 download_item_->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); |
| 105 break; |
| 106 case KEEP: |
| 107 download_item_->DangerousDownloadValidated(); |
| 108 break; |
| 109 case LEARN_MORE: { |
| 110 Browser* browser = BrowserList::GetLastActive(); |
| 111 DCHECK(browser && browser->is_type_tabbed()); |
| 112 GURL learn_more_url(chrome::kDownloadScanningLearnMoreURL); |
| 113 OpenURLParams params(google_util::AppendGoogleLocaleParam(learn_more_url), |
| 114 GURL(), NEW_FOREGROUND_TAB, |
| 115 content::PAGE_TRANSITION_TYPED, false); |
| 116 browser->OpenURL(params); |
| 117 break; |
| 118 } |
85 default: | 119 default: |
86 NOTREACHED(); | 120 NOTREACHED(); |
87 } | 121 } |
88 } | 122 } |
89 | 123 |
90 bool DownloadShelfContextMenu::GetAcceleratorForCommandId( | 124 bool DownloadShelfContextMenu::GetAcceleratorForCommandId( |
91 int command_id, ui::Accelerator* accelerator) { | 125 int command_id, ui::Accelerator* accelerator) { |
92 return false; | 126 return false; |
93 } | 127 } |
94 | 128 |
(...skipping 11 matching lines...) Expand all Loading... |
106 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); | 140 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); |
107 case ALWAYS_OPEN_TYPE: | 141 case ALWAYS_OPEN_TYPE: |
108 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); | 142 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); |
109 case CANCEL: | 143 case CANCEL: |
110 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); | 144 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); |
111 case TOGGLE_PAUSE: { | 145 case TOGGLE_PAUSE: { |
112 if (download_item_->IsPaused()) | 146 if (download_item_->IsPaused()) |
113 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); | 147 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); |
114 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); | 148 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); |
115 } | 149 } |
| 150 case DISCARD: |
| 151 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); |
| 152 case KEEP: |
| 153 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); |
| 154 case LEARN_MORE: |
| 155 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE); |
116 default: | 156 default: |
117 NOTREACHED(); | 157 NOTREACHED(); |
118 break; | 158 break; |
119 } | 159 } |
120 return string16(); | 160 return string16(); |
121 } | 161 } |
122 | 162 |
123 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel() { | 163 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel() { |
124 if (in_progress_download_menu_model_.get()) | 164 if (in_progress_download_menu_model_.get()) |
125 return in_progress_download_menu_model_.get(); | 165 return in_progress_download_menu_model_.get(); |
(...skipping 28 matching lines...) Expand all Loading... |
154 ALWAYS_OPEN_TYPE, IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); | 194 ALWAYS_OPEN_TYPE, IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE); |
155 finished_download_menu_model_->AddSeparator(); | 195 finished_download_menu_model_->AddSeparator(); |
156 finished_download_menu_model_->AddItemWithStringId( | 196 finished_download_menu_model_->AddItemWithStringId( |
157 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); | 197 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); |
158 finished_download_menu_model_->AddSeparator(); | 198 finished_download_menu_model_->AddSeparator(); |
159 finished_download_menu_model_->AddItemWithStringId( | 199 finished_download_menu_model_->AddItemWithStringId( |
160 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); | 200 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); |
161 | 201 |
162 return finished_download_menu_model_.get(); | 202 return finished_download_menu_model_.get(); |
163 } | 203 } |
| 204 |
| 205 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { |
| 206 if (malicious_download_menu_model_.get()) |
| 207 return malicious_download_menu_model_.get(); |
| 208 |
| 209 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 210 |
| 211 malicious_download_menu_model_->AddItemWithStringId( |
| 212 DISCARD, IDS_DOWNLOAD_MENU_DISCARD); |
| 213 malicious_download_menu_model_->AddItemWithStringId( |
| 214 KEEP, IDS_DOWNLOAD_MENU_KEEP); |
| 215 malicious_download_menu_model_->AddSeparator(); |
| 216 malicious_download_menu_model_->AddItemWithStringId( |
| 217 LEARN_MORE, IDS_DOWNLOAD_MENU_LEARN_MORE); |
| 218 |
| 219 return malicious_download_menu_model_.get(); |
| 220 } |
OLD | NEW |