Chromium Code Reviews| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "chrome/browser/browser_process.h" | |
| 9 #include "chrome/browser/download/download_crx_util.h" | |
| 10 #include "chrome/browser/download/download_item_model.h" | 8 #include "chrome/browser/download/download_item_model.h" |
| 11 #include "chrome/browser/download/download_prefs.h" | |
| 12 #include "chrome/browser/download/download_target_determiner.h" | |
| 13 #include "chrome/browser/safe_browsing/download_protection_service.h" | |
| 14 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 16 #include "chrome/grit/generated_resources.h" | 9 #include "chrome/grit/generated_resources.h" |
| 17 #include "content/public/browser/download_item.h" | |
| 18 #include "content/public/browser/download_manager.h" | |
| 19 #include "content/public/browser/page_navigator.h" | |
| 20 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 21 #include "extensions/common/extension.h" | 11 #include "extensions/common/extension.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 23 | 13 |
| 24 #if defined(OS_WIN) | |
| 25 #include "chrome/browser/ui/pdf/adobe_reader_info_win.h" | |
| 26 #endif | |
| 27 | |
| 28 using content::DownloadItem; | 14 using content::DownloadItem; |
| 29 | 15 |
| 30 namespace { | 16 namespace { |
| 31 | 17 |
| 32 // Returns true if downloads resumption is enabled. | 18 // Returns true if downloads resumption is enabled. |
| 33 bool IsDownloadResumptionEnabled() { | 19 bool IsDownloadResumptionEnabled() { |
| 34 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 20 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 35 switches::kEnableDownloadResumption); | 21 switches::kEnableDownloadResumption); |
| 36 } | 22 } |
| 37 | 23 |
| 38 } // namespace | 24 } // namespace |
| 39 | 25 |
| 40 DownloadShelfContextMenu::~DownloadShelfContextMenu() { | 26 DownloadShelfContextMenu::~DownloadShelfContextMenu() { |
| 41 DetachFromDownloadItem(); | 27 DetachFromDownloadItem(); |
| 42 } | 28 } |
| 43 | 29 |
| 44 DownloadShelfContextMenu::DownloadShelfContextMenu( | 30 DownloadShelfContextMenu::DownloadShelfContextMenu(DownloadItem* download_item, |
| 45 DownloadItem* download_item, | 31 Profile* profile) |
|
asanka
2015/02/27 01:26:49
As mentioned elsewhere, Profile* is implicit for a
yoshiki
2015/02/28 10:50:53
Done.
| |
| 46 content::PageNavigator* navigator) | |
| 47 : download_item_(download_item), | 32 : download_item_(download_item), |
| 48 navigator_(navigator) { | 33 download_commands_(download_item), |
|
asanka
2015/02/27 01:26:49
Make download_commands_ a scoped_ptr<> and reset i
yoshiki
2015/02/28 10:50:53
Done.
| |
| 34 profile_(profile) { | |
| 49 DCHECK(download_item_); | 35 DCHECK(download_item_); |
| 50 download_item_->AddObserver(this); | 36 download_item_->AddObserver(this); |
| 51 | |
| 52 #if defined(OS_WIN) | |
| 53 is_adobe_pdf_reader_up_to_date_ = false; | |
| 54 if (IsDownloadPdf() && IsAdobeReaderDefaultPDFViewer()) { | |
| 55 is_adobe_pdf_reader_up_to_date_ = | |
| 56 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); | |
| 57 } | |
| 58 #endif // defined(OS_WIN) | |
| 59 } | 37 } |
| 60 | 38 |
| 61 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { | 39 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { |
| 62 ui::SimpleMenuModel* model = NULL; | 40 ui::SimpleMenuModel* model = NULL; |
| 63 | 41 |
| 64 if (!download_item_) | 42 if (!download_item_) |
| 65 return NULL; | 43 return NULL; |
| 66 | 44 |
| 67 DownloadItemModel download_model(download_item_); | 45 DownloadItemModel download_model(download_item_); |
| 68 // We shouldn't be opening a context menu for a dangerous download, unless it | 46 // We shouldn't be opening a context menu for a dangerous download, unless it |
| 69 // is a malicious download. | 47 // is a malicious download. |
| 70 DCHECK(!download_model.IsDangerous() || download_model.MightBeMalicious()); | 48 DCHECK(!download_model.IsDangerous() || download_model.MightBeMalicious()); |
| 71 | 49 |
| 72 if (download_model.IsMalicious()) | 50 if (download_model.IsMalicious()) |
| 73 model = GetMaliciousMenuModel(); | 51 model = GetMaliciousMenuModel(); |
| 74 else if (download_model.MightBeMalicious()) | 52 else if (download_model.MightBeMalicious()) |
| 75 model = GetMaybeMaliciousMenuModel(); | 53 model = GetMaybeMaliciousMenuModel(); |
| 76 else if (download_item_->GetState() == DownloadItem::COMPLETE) | 54 else if (download_item_->GetState() == DownloadItem::COMPLETE) |
| 77 model = GetFinishedMenuModel(); | 55 model = GetFinishedMenuModel(); |
| 78 else if (download_item_->GetState() == DownloadItem::INTERRUPTED) | 56 else if (download_item_->GetState() == DownloadItem::INTERRUPTED) |
| 79 model = GetInterruptedMenuModel(); | 57 model = GetInterruptedMenuModel(); |
| 58 else if (download_item_->IsPaused()) | |
| 59 model = GetInProgressPausedMenuModel(); | |
| 80 else | 60 else |
| 81 model = GetInProgressMenuModel(); | 61 model = GetInProgressMenuModel(); |
| 82 return model; | 62 return model; |
| 83 } | 63 } |
| 84 | 64 |
| 85 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { | 65 bool DownloadShelfContextMenu::IsCommandIdEnabled(int command_id) const { |
| 86 if (!download_item_) | 66 return download_commands_.IsCommandEnabled( |
| 87 return false; | 67 static_cast<DownloadCommands::Command>(command_id)); |
| 88 | |
| 89 switch (static_cast<ContextMenuCommands>(command_id)) { | |
| 90 case SHOW_IN_FOLDER: | |
| 91 return download_item_->CanShowInFolder(); | |
| 92 case OPEN_WHEN_COMPLETE: | |
| 93 case PLATFORM_OPEN: | |
| 94 return download_item_->CanOpenDownload() && | |
| 95 !download_crx_util::IsExtensionDownload(*download_item_); | |
| 96 case ALWAYS_OPEN_TYPE: | |
| 97 // For temporary downloads, the target filename might be a temporary | |
| 98 // filename. Don't base an "Always open" decision based on it. Also | |
| 99 // exclude extensions. | |
| 100 return download_item_->CanOpenDownload() && | |
| 101 !download_crx_util::IsExtensionDownload(*download_item_); | |
| 102 case CANCEL: | |
| 103 return !download_item_->IsDone(); | |
| 104 case TOGGLE_PAUSE: | |
| 105 return !download_item_->IsDone(); | |
| 106 case DISCARD: | |
| 107 case KEEP: | |
| 108 case LEARN_MORE_SCANNING: | |
| 109 case LEARN_MORE_INTERRUPTED: | |
| 110 return true; | |
| 111 } | |
| 112 NOTREACHED(); | |
| 113 return false; | |
| 114 } | 68 } |
| 115 | 69 |
| 116 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { | 70 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { |
| 117 if (!download_item_) | 71 return download_commands_.IsCommandChecked( |
| 118 return false; | 72 static_cast<DownloadCommands::Command>(command_id)); |
| 119 | |
| 120 switch (command_id) { | |
| 121 case OPEN_WHEN_COMPLETE: | |
| 122 return download_item_->GetOpenWhenComplete() || | |
| 123 download_crx_util::IsExtensionDownload(*download_item_); | |
| 124 case ALWAYS_OPEN_TYPE: | |
| 125 #if defined(OS_WIN) || defined(OS_LINUX) || \ | |
| 126 (defined(OS_MACOSX) && !defined(OS_IOS)) | |
| 127 if (CanOpenPdfInSystemViewer()) { | |
| 128 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( | |
| 129 download_item_->GetBrowserContext()); | |
| 130 return prefs->ShouldOpenPdfInSystemReader(); | |
| 131 } | |
| 132 #endif | |
| 133 return download_item_->ShouldOpenFileBasedOnExtension(); | |
| 134 case TOGGLE_PAUSE: | |
| 135 return download_item_->IsPaused(); | |
| 136 } | |
| 137 return false; | |
| 138 } | 73 } |
| 139 | 74 |
| 140 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { | 75 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { |
| 141 if (!download_item_) | 76 return download_commands_.IsCommandVisible( |
| 142 return false; | 77 static_cast<DownloadCommands::Command>(command_id)); |
| 143 | |
| 144 if (command_id == PLATFORM_OPEN) | |
| 145 return (DownloadItemModel(download_item_).ShouldPreferOpeningInBrowser()); | |
| 146 | |
| 147 return true; | |
| 148 } | 78 } |
| 149 | 79 |
| 150 void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) { | 80 void DownloadShelfContextMenu::ExecuteCommand(int command_id, int event_flags) { |
| 151 if (!download_item_) | 81 download_commands_.ExecuteCommand( |
| 152 return; | 82 static_cast<DownloadCommands::Command>(command_id), profile_); |
| 153 | |
| 154 switch (static_cast<ContextMenuCommands>(command_id)) { | |
| 155 case SHOW_IN_FOLDER: | |
| 156 download_item_->ShowDownloadInShell(); | |
| 157 break; | |
| 158 case OPEN_WHEN_COMPLETE: | |
| 159 download_item_->OpenDownload(); | |
| 160 break; | |
| 161 case ALWAYS_OPEN_TYPE: { | |
| 162 bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE); | |
| 163 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( | |
| 164 download_item_->GetBrowserContext()); | |
| 165 #if defined(OS_WIN) || defined(OS_LINUX) || \ | |
| 166 (defined(OS_MACOSX) && !defined(OS_IOS)) | |
| 167 if (CanOpenPdfInSystemViewer()) { | |
| 168 prefs->SetShouldOpenPdfInSystemReader(!is_checked); | |
| 169 DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser( | |
| 170 is_checked); | |
| 171 break; | |
| 172 } | |
| 173 #endif | |
| 174 base::FilePath path = download_item_->GetTargetFilePath(); | |
| 175 if (is_checked) | |
| 176 prefs->DisableAutoOpenBasedOnExtension(path); | |
| 177 else | |
| 178 prefs->EnableAutoOpenBasedOnExtension(path); | |
| 179 break; | |
| 180 } | |
| 181 case PLATFORM_OPEN: | |
| 182 DownloadItemModel(download_item_).OpenUsingPlatformHandler(); | |
| 183 break; | |
| 184 case CANCEL: | |
| 185 download_item_->Cancel(true /* Cancelled by user */); | |
| 186 break; | |
| 187 case TOGGLE_PAUSE: | |
| 188 if (download_item_->GetState() == DownloadItem::IN_PROGRESS && | |
| 189 !download_item_->IsPaused()) { | |
| 190 download_item_->Pause(); | |
| 191 } else { | |
| 192 download_item_->Resume(); | |
| 193 } | |
| 194 break; | |
| 195 case DISCARD: | |
| 196 download_item_->Remove(); | |
| 197 break; | |
| 198 case KEEP: | |
| 199 download_item_->ValidateDangerousDownload(); | |
| 200 break; | |
| 201 case LEARN_MORE_SCANNING: { | |
| 202 #if defined(FULL_SAFE_BROWSING) | |
| 203 using safe_browsing::DownloadProtectionService; | |
| 204 SafeBrowsingService* sb_service = | |
| 205 g_browser_process->safe_browsing_service(); | |
| 206 DownloadProtectionService* protection_service = | |
| 207 (sb_service ? sb_service->download_protection_service() : NULL); | |
| 208 if (protection_service) { | |
| 209 protection_service->ShowDetailsForDownload(*download_item_, navigator_); | |
| 210 } | |
| 211 #else | |
| 212 // Should only be getting invoked if we are using safe browsing. | |
| 213 NOTREACHED(); | |
| 214 #endif | |
| 215 break; | |
| 216 } | |
| 217 case LEARN_MORE_INTERRUPTED: | |
| 218 navigator_->OpenURL( | |
| 219 content::OpenURLParams(GURL(chrome::kDownloadInterruptedLearnMoreURL), | |
| 220 content::Referrer(), | |
| 221 NEW_FOREGROUND_TAB, | |
| 222 ui::PAGE_TRANSITION_LINK, | |
| 223 false)); | |
| 224 break; | |
| 225 } | |
| 226 } | 83 } |
| 227 | 84 |
| 228 bool DownloadShelfContextMenu::GetAcceleratorForCommandId( | 85 bool DownloadShelfContextMenu::GetAcceleratorForCommandId( |
| 229 int command_id, ui::Accelerator* accelerator) { | 86 int command_id, |
| 87 ui::Accelerator* accelerator) { | |
| 230 return false; | 88 return false; |
| 231 } | 89 } |
| 232 | 90 |
| 233 bool DownloadShelfContextMenu::IsItemForCommandIdDynamic(int command_id) const { | 91 bool DownloadShelfContextMenu::IsItemForCommandIdDynamic(int command_id) const { |
| 234 return command_id == TOGGLE_PAUSE; | 92 return false; |
| 235 } | 93 } |
| 236 | 94 |
| 237 base::string16 DownloadShelfContextMenu::GetLabelForCommandId( | 95 base::string16 DownloadShelfContextMenu::GetLabelForCommandId( |
| 238 int command_id) const { | 96 int command_id) const { |
| 239 switch (static_cast<ContextMenuCommands>(command_id)) { | 97 int id = -1; |
| 240 case SHOW_IN_FOLDER: | 98 |
| 241 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_SHOW); | 99 switch (static_cast<DownloadCommands::Command>(command_id)) { |
| 242 case OPEN_WHEN_COMPLETE: | 100 case DownloadCommands::OPEN_WHEN_COMPLETE: |
| 243 if (download_item_ && !download_item_->IsDone()) | 101 if (download_item_ && !download_item_->IsDone()) |
| 244 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); | 102 id = IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE; |
| 245 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_OPEN); | 103 else |
| 246 case ALWAYS_OPEN_TYPE: | 104 id = IDS_DOWNLOAD_MENU_OPEN; |
| 247 return l10n_util::GetStringUTF16(GetAlwaysOpenStringId()); | 105 break; |
| 248 case PLATFORM_OPEN: | 106 case DownloadCommands::PAUSE: |
| 249 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PLATFORM_OPEN); | 107 id = IDS_DOWNLOAD_MENU_PAUSE_ITEM; |
| 250 case CANCEL: | 108 break; |
| 251 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_CANCEL); | 109 case DownloadCommands::RESUME: |
| 252 case TOGGLE_PAUSE: | 110 id = IDS_DOWNLOAD_MENU_RESUME_ITEM; |
| 253 if (download_item_ && | 111 break; |
| 254 download_item_->GetState() == DownloadItem::IN_PROGRESS && | 112 case DownloadCommands::SHOW_IN_FOLDER: |
| 255 !download_item_->IsPaused()) | 113 id = IDS_DOWNLOAD_MENU_SHOW; |
| 256 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_PAUSE_ITEM); | 114 break; |
| 257 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_RESUME_ITEM); | 115 case DownloadCommands::DISCARD: |
| 258 case DISCARD: | 116 id = IDS_DOWNLOAD_MENU_DISCARD; |
| 259 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_DISCARD); | 117 break; |
| 260 case KEEP: | 118 case DownloadCommands::KEEP: |
| 261 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_KEEP); | 119 id = IDS_DOWNLOAD_MENU_KEEP; |
| 262 case LEARN_MORE_SCANNING: | 120 break; |
| 263 return l10n_util::GetStringUTF16(IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); | 121 case DownloadCommands::ALWAYS_OPEN_TYPE: { |
| 264 case LEARN_MORE_INTERRUPTED: | 122 bool can_open_pdf_in_system_viewer = |
| 265 return l10n_util::GetStringUTF16( | 123 DownloadCommands(download_item_).CanOpenPdfInSystemViewer(); |
| 266 IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); | 124 #if defined(OS_WIN) |
| 125 if (can_open_pdf_in_system_viewer) { | |
| 126 id = IsAdobeReaderDefaultPDFViewer() | |
| 127 ? IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER | |
| 128 : IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS; | |
| 129 break; | |
| 130 } | |
| 131 #elif defined(OS_MACOSX) || defined(OS_LINUX) | |
| 132 if (can_open_pdf_in_system_viewer) { | |
| 133 id = IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS; | |
| 134 break; | |
| 135 } | |
| 136 #endif | |
| 137 id = IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE; | |
| 138 break; | |
| 139 } | |
| 140 case DownloadCommands::PLATFORM_OPEN: | |
| 141 id = IDS_DOWNLOAD_MENU_PLATFORM_OPEN; | |
| 142 break; | |
| 143 case DownloadCommands::CANCEL: | |
| 144 id = IDS_DOWNLOAD_MENU_CANCEL; | |
| 145 break; | |
| 146 case DownloadCommands::LEARN_MORE_SCANNING: | |
| 147 id = IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING; | |
| 148 break; | |
| 149 case DownloadCommands::LEARN_MORE_INTERRUPTED: | |
| 150 id = IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED; | |
| 151 break; | |
| 152 case DownloadCommands::RETRY: | |
| 153 NOTREACHED(); | |
| 154 return base::string16(); | |
| 267 } | 155 } |
| 268 NOTREACHED(); | 156 CHECK(id != -1); |
| 269 return base::string16(); | 157 return l10n_util::GetStringUTF16(id); |
| 270 } | 158 } |
| 271 | 159 |
| 272 void DownloadShelfContextMenu::DetachFromDownloadItem() { | 160 void DownloadShelfContextMenu::DetachFromDownloadItem() { |
| 273 if (!download_item_) | 161 if (!download_item_) |
| 274 return; | 162 return; |
| 275 | 163 |
| 276 download_item_->RemoveObserver(this); | 164 download_item_->RemoveObserver(this); |
| 277 download_item_ = NULL; | 165 download_item_ = NULL; |
| 278 } | 166 } |
| 279 | 167 |
| 280 void DownloadShelfContextMenu::OnDownloadDestroyed(DownloadItem* download) { | 168 void DownloadShelfContextMenu::OnDownloadDestroyed(DownloadItem* download) { |
| 281 DCHECK(download_item_ == download); | 169 DCHECK(download_item_ == download); |
| 282 DetachFromDownloadItem(); | 170 DetachFromDownloadItem(); |
| 283 } | 171 } |
| 284 | 172 |
| 285 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel() { | 173 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressMenuModel() { |
| 286 if (in_progress_download_menu_model_) | 174 if (in_progress_download_menu_model_) |
| 287 return in_progress_download_menu_model_.get(); | 175 return in_progress_download_menu_model_.get(); |
| 288 | 176 |
| 289 in_progress_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 177 in_progress_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 290 | 178 |
| 291 in_progress_download_menu_model_->AddCheckItemWithStringId( | 179 in_progress_download_menu_model_->AddCheckItem( |
| 292 OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN_WHEN_COMPLETE); | 180 DownloadCommands::OPEN_WHEN_COMPLETE, |
| 293 in_progress_download_menu_model_->AddCheckItemWithStringId( | 181 GetLabelForCommandId(DownloadCommands::OPEN_WHEN_COMPLETE)); |
| 294 ALWAYS_OPEN_TYPE, GetAlwaysOpenStringId()); | 182 in_progress_download_menu_model_->AddCheckItem( |
| 183 DownloadCommands::ALWAYS_OPEN_TYPE, | |
| 184 GetLabelForCommandId(DownloadCommands::ALWAYS_OPEN_TYPE)); | |
| 295 in_progress_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 185 in_progress_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 296 in_progress_download_menu_model_->AddItemWithStringId( | 186 in_progress_download_menu_model_->AddItem( |
| 297 TOGGLE_PAUSE, IDS_DOWNLOAD_MENU_PAUSE_ITEM); | 187 DownloadCommands::PAUSE, GetLabelForCommandId(DownloadCommands::PAUSE)); |
| 298 in_progress_download_menu_model_->AddItemWithStringId( | 188 in_progress_download_menu_model_->AddItem( |
| 299 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); | 189 DownloadCommands::SHOW_IN_FOLDER, |
| 190 GetLabelForCommandId(DownloadCommands::SHOW_IN_FOLDER)); | |
| 300 in_progress_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 191 in_progress_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 301 in_progress_download_menu_model_->AddItemWithStringId( | 192 in_progress_download_menu_model_->AddItem( |
| 302 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); | 193 DownloadCommands::CANCEL, GetLabelForCommandId(DownloadCommands::CANCEL)); |
| 303 | 194 |
| 304 return in_progress_download_menu_model_.get(); | 195 return in_progress_download_menu_model_.get(); |
| 305 } | 196 } |
| 306 | 197 |
| 198 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInProgressPausedMenuModel() { | |
| 199 if (in_progress_download_paused_menu_model_) | |
| 200 return in_progress_download_paused_menu_model_.get(); | |
| 201 | |
| 202 in_progress_download_paused_menu_model_.reset(new ui::SimpleMenuModel(this)); | |
| 203 | |
| 204 in_progress_download_paused_menu_model_->AddCheckItem( | |
| 205 DownloadCommands::OPEN_WHEN_COMPLETE, | |
| 206 GetLabelForCommandId(DownloadCommands::OPEN_WHEN_COMPLETE)); | |
| 207 in_progress_download_paused_menu_model_->AddCheckItem( | |
| 208 DownloadCommands::ALWAYS_OPEN_TYPE, | |
| 209 GetLabelForCommandId(DownloadCommands::ALWAYS_OPEN_TYPE)); | |
| 210 in_progress_download_paused_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 211 in_progress_download_paused_menu_model_->AddItem( | |
| 212 DownloadCommands::RESUME, GetLabelForCommandId(DownloadCommands::RESUME)); | |
| 213 in_progress_download_paused_menu_model_->AddItem( | |
| 214 DownloadCommands::SHOW_IN_FOLDER, | |
| 215 GetLabelForCommandId(DownloadCommands::SHOW_IN_FOLDER)); | |
| 216 in_progress_download_paused_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | |
| 217 in_progress_download_paused_menu_model_->AddItem( | |
| 218 DownloadCommands::CANCEL, GetLabelForCommandId(DownloadCommands::CANCEL)); | |
| 219 | |
| 220 return in_progress_download_paused_menu_model_.get(); | |
| 221 } | |
| 222 | |
| 307 ui::SimpleMenuModel* DownloadShelfContextMenu::GetFinishedMenuModel() { | 223 ui::SimpleMenuModel* DownloadShelfContextMenu::GetFinishedMenuModel() { |
| 308 if (finished_download_menu_model_) | 224 if (finished_download_menu_model_) |
| 309 return finished_download_menu_model_.get(); | 225 return finished_download_menu_model_.get(); |
| 310 | 226 |
| 311 finished_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 227 finished_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 312 | 228 |
| 313 finished_download_menu_model_->AddItemWithStringId( | 229 finished_download_menu_model_->AddItem( |
| 314 OPEN_WHEN_COMPLETE, IDS_DOWNLOAD_MENU_OPEN); | 230 DownloadCommands::OPEN_WHEN_COMPLETE, |
| 315 finished_download_menu_model_->AddCheckItemWithStringId( | 231 GetLabelForCommandId(DownloadCommands::OPEN_WHEN_COMPLETE)); |
| 316 ALWAYS_OPEN_TYPE, GetAlwaysOpenStringId()); | 232 finished_download_menu_model_->AddCheckItem( |
| 317 finished_download_menu_model_->AddItemWithStringId( | 233 DownloadCommands::ALWAYS_OPEN_TYPE, |
| 318 PLATFORM_OPEN, IDS_DOWNLOAD_MENU_PLATFORM_OPEN); | 234 GetLabelForCommandId(DownloadCommands::ALWAYS_OPEN_TYPE)); |
| 235 finished_download_menu_model_->AddItem( | |
| 236 DownloadCommands::PLATFORM_OPEN, | |
| 237 GetLabelForCommandId(DownloadCommands::PLATFORM_OPEN)); | |
| 319 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 238 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 320 finished_download_menu_model_->AddItemWithStringId( | 239 finished_download_menu_model_->AddItem( |
| 321 SHOW_IN_FOLDER, IDS_DOWNLOAD_MENU_SHOW); | 240 DownloadCommands::SHOW_IN_FOLDER, |
| 241 GetLabelForCommandId(DownloadCommands::SHOW_IN_FOLDER)); | |
| 322 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 242 finished_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 323 finished_download_menu_model_->AddItemWithStringId( | 243 finished_download_menu_model_->AddItem( |
| 324 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); | 244 DownloadCommands::CANCEL, GetLabelForCommandId(DownloadCommands::CANCEL)); |
| 325 | 245 |
| 326 return finished_download_menu_model_.get(); | 246 return finished_download_menu_model_.get(); |
| 327 } | 247 } |
| 328 | 248 |
| 329 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { | 249 ui::SimpleMenuModel* DownloadShelfContextMenu::GetInterruptedMenuModel() { |
| 330 #if !defined(OS_WIN) | 250 #if !defined(OS_WIN) |
| 331 // If resumption isn't enabled and we aren't on Windows, then none of the | 251 // If resumption isn't enabled and we aren't on Windows, then none of the |
| 332 // options here are applicable. | 252 // options here are applicable. |
| 333 if (!IsDownloadResumptionEnabled()) | 253 if (!IsDownloadResumptionEnabled()) |
| 334 return GetInProgressMenuModel(); | 254 return GetInProgressMenuModel(); |
| 335 #endif | 255 #endif |
| 336 | 256 |
| 337 if (interrupted_download_menu_model_) | 257 if (interrupted_download_menu_model_) |
| 338 return interrupted_download_menu_model_.get(); | 258 return interrupted_download_menu_model_.get(); |
| 339 | 259 |
| 340 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 260 interrupted_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 341 | 261 |
| 342 if (IsDownloadResumptionEnabled()) { | 262 if (IsDownloadResumptionEnabled()) { |
| 343 interrupted_download_menu_model_->AddItemWithStringId( | 263 interrupted_download_menu_model_->AddItem( |
| 344 TOGGLE_PAUSE, IDS_DOWNLOAD_MENU_RESUME_ITEM); | 264 DownloadCommands::RESUME, |
| 265 GetLabelForCommandId(DownloadCommands::RESUME)); | |
| 345 } | 266 } |
| 346 #if defined(OS_WIN) | 267 #if defined(OS_WIN) |
| 347 // The Help Center article is currently Windows specific. | 268 // The Help Center article is currently Windows specific. |
| 348 // TODO(asanka): Enable this for other platforms when the article is expanded | 269 // TODO(asanka): Enable this for other platforms when the article is expanded |
| 349 // for other platforms. | 270 // for other platforms. |
| 350 interrupted_download_menu_model_->AddItemWithStringId( | 271 interrupted_download_menu_model_->AddItem( |
| 351 LEARN_MORE_INTERRUPTED, IDS_DOWNLOAD_MENU_LEARN_MORE_INTERRUPTED); | 272 DownloadCommands::LEARN_MORE_INTERRUPTED, |
| 273 GetLabelForCommandId(DownloadCommands::LEARN_MORE_INTERRUPTED)); | |
| 352 #endif | 274 #endif |
| 353 if (IsDownloadResumptionEnabled()) { | 275 if (IsDownloadResumptionEnabled()) { |
| 354 interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 276 interrupted_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 355 interrupted_download_menu_model_->AddItemWithStringId( | 277 interrupted_download_menu_model_->AddItem( |
| 356 CANCEL, IDS_DOWNLOAD_MENU_CANCEL); | 278 DownloadCommands::CANCEL, |
| 279 GetLabelForCommandId(DownloadCommands::CANCEL)); | |
| 357 } | 280 } |
| 358 | 281 |
| 359 return interrupted_download_menu_model_.get(); | 282 return interrupted_download_menu_model_.get(); |
| 360 } | 283 } |
| 361 | 284 |
| 362 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaybeMaliciousMenuModel() { | 285 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaybeMaliciousMenuModel() { |
| 363 if (maybe_malicious_download_menu_model_) | 286 if (maybe_malicious_download_menu_model_) |
| 364 return maybe_malicious_download_menu_model_.get(); | 287 return maybe_malicious_download_menu_model_.get(); |
| 365 | 288 |
| 366 maybe_malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 289 maybe_malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 367 | 290 |
| 368 maybe_malicious_download_menu_model_->AddItemWithStringId( | 291 maybe_malicious_download_menu_model_->AddItem( |
| 369 KEEP, IDS_DOWNLOAD_MENU_KEEP); | 292 DownloadCommands::KEEP, GetLabelForCommandId(DownloadCommands::KEEP)); |
| 370 maybe_malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); | 293 maybe_malicious_download_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR); |
| 371 maybe_malicious_download_menu_model_->AddItemWithStringId( | 294 maybe_malicious_download_menu_model_->AddItem( |
| 372 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); | 295 DownloadCommands::LEARN_MORE_SCANNING, |
| 296 GetLabelForCommandId(DownloadCommands::LEARN_MORE_SCANNING)); | |
| 373 return maybe_malicious_download_menu_model_.get(); | 297 return maybe_malicious_download_menu_model_.get(); |
| 374 } | 298 } |
| 375 | 299 |
| 376 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { | 300 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMaliciousMenuModel() { |
| 377 if (malicious_download_menu_model_) | 301 if (malicious_download_menu_model_) |
| 378 return malicious_download_menu_model_.get(); | 302 return malicious_download_menu_model_.get(); |
| 379 | 303 |
| 380 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); | 304 malicious_download_menu_model_.reset(new ui::SimpleMenuModel(this)); |
| 381 | 305 |
| 382 DownloadItemModel download_model(download_item_); | 306 DownloadItemModel download_model(download_item_); |
| 383 malicious_download_menu_model_->AddItemWithStringId( | 307 malicious_download_menu_model_->AddItem( |
| 384 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); | 308 DownloadCommands::LEARN_MORE_SCANNING, |
| 309 GetLabelForCommandId(DownloadCommands::LEARN_MORE_SCANNING)); | |
| 385 | 310 |
| 386 return malicious_download_menu_model_.get(); | 311 return malicious_download_menu_model_.get(); |
| 387 } | 312 } |
| 388 | |
| 389 int DownloadShelfContextMenu::GetAlwaysOpenStringId() const { | |
| 390 #if defined(OS_WIN) | |
| 391 if (CanOpenPdfInSystemViewer()) | |
| 392 return IsAdobeReaderDefaultPDFViewer() | |
| 393 ? IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER | |
| 394 : IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS; | |
| 395 #elif defined(OS_MACOSX) || defined(OS_LINUX) | |
| 396 if (CanOpenPdfInSystemViewer()) | |
| 397 return IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS; | |
| 398 #endif | |
| 399 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE; | |
| 400 } | |
| 401 | |
| 402 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) | |
| 403 bool DownloadShelfContextMenu::IsDownloadPdf() const { | |
| 404 base::FilePath path = download_item_->GetTargetFilePath(); | |
| 405 return path.MatchesExtension(FILE_PATH_LITERAL(".pdf")); | |
| 406 } | |
| 407 #endif | |
| 408 | |
| 409 bool DownloadShelfContextMenu::CanOpenPdfInSystemViewer() const { | |
| 410 #if defined(OS_WIN) | |
| 411 return IsDownloadPdf() && | |
| 412 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date_ : | |
| 413 true); | |
| 414 #elif defined(OS_MACOSX) || defined(OS_LINUX) | |
| 415 return IsDownloadPdf(); | |
| 416 #endif | |
| 417 } | |
| OLD | NEW |