| 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" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/download/download_crx_util.h" | 9 #include "chrome/browser/download/download_crx_util.h" |
| 10 #include "chrome/browser/download/download_item_model.h" | 10 #include "chrome/browser/download/download_item_model.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 DownloadShelfContextMenu::DownloadShelfContextMenu( | 44 DownloadShelfContextMenu::DownloadShelfContextMenu( |
| 45 DownloadItem* download_item, | 45 DownloadItem* download_item, |
| 46 content::PageNavigator* navigator) | 46 content::PageNavigator* navigator) |
| 47 : download_item_(download_item), | 47 : download_item_(download_item), |
| 48 navigator_(navigator) { | 48 navigator_(navigator) { |
| 49 DCHECK(download_item_); | 49 DCHECK(download_item_); |
| 50 download_item_->AddObserver(this); | 50 download_item_->AddObserver(this); |
| 51 | 51 |
| 52 #if defined(OS_WIN) | 52 #if defined(OS_WIN) |
| 53 is_pdf_reader_up_to_date_ = false; | 53 is_adobe_pdf_reader_up_to_date_ = false; |
| 54 if (IsDownloadPdf() && IsAdobeReaderDefaultPDFViewer()) { | 54 if (IsDownloadPdf() && IsAdobeReaderDefaultPDFViewer()) { |
| 55 is_pdf_reader_up_to_date_ = | 55 is_adobe_pdf_reader_up_to_date_ = |
| 56 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); | 56 DownloadTargetDeterminer::IsAdobeReaderUpToDate(); |
| 57 } | 57 } |
| 58 #endif // defined(OS_WIN) | 58 #endif // defined(OS_WIN) |
| 59 } | 59 } |
| 60 | 60 |
| 61 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { | 61 ui::SimpleMenuModel* DownloadShelfContextMenu::GetMenuModel() { |
| 62 ui::SimpleMenuModel* model = NULL; | 62 ui::SimpleMenuModel* model = NULL; |
| 63 | 63 |
| 64 if (!download_item_) | 64 if (!download_item_) |
| 65 return NULL; | 65 return NULL; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { | 116 bool DownloadShelfContextMenu::IsCommandIdChecked(int command_id) const { |
| 117 if (!download_item_) | 117 if (!download_item_) |
| 118 return false; | 118 return false; |
| 119 | 119 |
| 120 switch (command_id) { | 120 switch (command_id) { |
| 121 case OPEN_WHEN_COMPLETE: | 121 case OPEN_WHEN_COMPLETE: |
| 122 return download_item_->GetOpenWhenComplete() || | 122 return download_item_->GetOpenWhenComplete() || |
| 123 download_crx_util::IsExtensionDownload(*download_item_); | 123 download_crx_util::IsExtensionDownload(*download_item_); |
| 124 case ALWAYS_OPEN_TYPE: | 124 case ALWAYS_OPEN_TYPE: |
| 125 #if defined(OS_WIN) | 125 #if defined(OS_WIN) || defined(OS_LINUX) || \ |
| 126 if (CanOpenPdfInReader()) { | 126 (defined(OS_MACOSX) && !defined(OS_IOS)) |
| 127 if (CanOpenPdfInSystemViewer()) { |
| 127 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( | 128 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( |
| 128 download_item_->GetBrowserContext()); | 129 download_item_->GetBrowserContext()); |
| 129 return prefs->ShouldOpenPdfInAdobeReader(); | 130 return prefs->ShouldOpenPdfInSystemReader(); |
| 130 } | 131 } |
| 131 #endif | 132 #endif |
| 132 return download_item_->ShouldOpenFileBasedOnExtension(); | 133 return download_item_->ShouldOpenFileBasedOnExtension(); |
| 133 case TOGGLE_PAUSE: | 134 case TOGGLE_PAUSE: |
| 134 return download_item_->IsPaused(); | 135 return download_item_->IsPaused(); |
| 135 } | 136 } |
| 136 return false; | 137 return false; |
| 137 } | 138 } |
| 138 | 139 |
| 139 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { | 140 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 154 case SHOW_IN_FOLDER: | 155 case SHOW_IN_FOLDER: |
| 155 download_item_->ShowDownloadInShell(); | 156 download_item_->ShowDownloadInShell(); |
| 156 break; | 157 break; |
| 157 case OPEN_WHEN_COMPLETE: | 158 case OPEN_WHEN_COMPLETE: |
| 158 download_item_->OpenDownload(); | 159 download_item_->OpenDownload(); |
| 159 break; | 160 break; |
| 160 case ALWAYS_OPEN_TYPE: { | 161 case ALWAYS_OPEN_TYPE: { |
| 161 bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE); | 162 bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE); |
| 162 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( | 163 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( |
| 163 download_item_->GetBrowserContext()); | 164 download_item_->GetBrowserContext()); |
| 164 #if defined(OS_WIN) | 165 #if defined(OS_WIN) || defined(OS_LINUX) || \ |
| 165 if (CanOpenPdfInReader()) { | 166 (defined(OS_MACOSX) && !defined(OS_IOS)) |
| 166 prefs->SetShouldOpenPdfInAdobeReader(!is_checked); | 167 if (CanOpenPdfInSystemViewer()) { |
| 168 prefs->SetShouldOpenPdfInSystemReader(!is_checked); |
| 167 DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser( | 169 DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser( |
| 168 is_checked); | 170 is_checked); |
| 169 break; | 171 break; |
| 170 } | 172 } |
| 171 #endif | 173 #endif |
| 172 base::FilePath path = download_item_->GetTargetFilePath(); | 174 base::FilePath path = download_item_->GetTargetFilePath(); |
| 173 if (is_checked) | 175 if (is_checked) |
| 174 prefs->DisableAutoOpenBasedOnExtension(path); | 176 prefs->DisableAutoOpenBasedOnExtension(path); |
| 175 else | 177 else |
| 176 prefs->EnableAutoOpenBasedOnExtension(path); | 178 prefs->EnableAutoOpenBasedOnExtension(path); |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 | 381 |
| 380 DownloadItemModel download_model(download_item_); | 382 DownloadItemModel download_model(download_item_); |
| 381 malicious_download_menu_model_->AddItemWithStringId( | 383 malicious_download_menu_model_->AddItemWithStringId( |
| 382 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); | 384 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); |
| 383 | 385 |
| 384 return malicious_download_menu_model_.get(); | 386 return malicious_download_menu_model_.get(); |
| 385 } | 387 } |
| 386 | 388 |
| 387 int DownloadShelfContextMenu::GetAlwaysOpenStringId() const { | 389 int DownloadShelfContextMenu::GetAlwaysOpenStringId() const { |
| 388 #if defined(OS_WIN) | 390 #if defined(OS_WIN) |
| 389 if (CanOpenPdfInReader()) | 391 if (CanOpenPdfInSystemViewer()) |
| 390 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER; | 392 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER; |
| 393 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
| 394 if (CanOpenPdfInSystemViewer()) |
| 395 return IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS; |
| 391 #endif | 396 #endif |
| 392 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE; | 397 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE; |
| 393 } | 398 } |
| 394 | 399 |
| 395 #if defined(OS_WIN) | 400 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
| 396 bool DownloadShelfContextMenu::IsDownloadPdf() const { | 401 bool DownloadShelfContextMenu::IsDownloadPdf() const { |
| 397 base::FilePath path = download_item_->GetTargetFilePath(); | 402 base::FilePath path = download_item_->GetTargetFilePath(); |
| 398 return path.MatchesExtension(FILE_PATH_LITERAL(".pdf")); | 403 return path.MatchesExtension(FILE_PATH_LITERAL(".pdf")); |
| 399 } | 404 } |
| 405 #endif |
| 400 | 406 |
| 401 bool DownloadShelfContextMenu::CanOpenPdfInReader() const { | 407 #if defined(OS_WIN) |
| 402 return (is_pdf_reader_up_to_date_ && IsDownloadPdf()); | 408 bool DownloadShelfContextMenu::CanOpenPdfInSystemViewer() const { |
| 409 return IsDownloadPdf() && |
| 410 (IsAdobeReaderDefaultPDFViewer() ? is_adobe_pdf_reader_up_to_date_ : |
| 411 true); |
| 412 } |
| 413 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
| 414 bool DownloadShelfContextMenu::CanOpenPdfInSystemViewer() const { |
| 415 return IsDownloadPdf(); |
| 403 } | 416 } |
| 404 #endif | 417 #endif |
| OLD | NEW |