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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) |
126 if (CanOpenPdfInReader()) { | 126 if (CanOpenPdfInReader()) { |
127 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( | 127 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( |
128 download_item_->GetBrowserContext()); | 128 download_item_->GetBrowserContext()); |
129 return prefs->ShouldOpenPdfInAdobeReader(); | 129 return prefs->ShouldOpenPdfInAdobeReader(); |
130 } | 130 } |
| 131 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
| 132 if (CanOpenPdfInReader()) { |
| 133 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( |
| 134 download_item_->GetBrowserContext()); |
| 135 return prefs->ShouldOpenPdfInSystemReader(); |
| 136 } |
131 #endif | 137 #endif |
132 return download_item_->ShouldOpenFileBasedOnExtension(); | 138 return download_item_->ShouldOpenFileBasedOnExtension(); |
133 case TOGGLE_PAUSE: | 139 case TOGGLE_PAUSE: |
134 return download_item_->IsPaused(); | 140 return download_item_->IsPaused(); |
135 } | 141 } |
136 return false; | 142 return false; |
137 } | 143 } |
138 | 144 |
139 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { | 145 bool DownloadShelfContextMenu::IsCommandIdVisible(int command_id) const { |
140 if (!download_item_) | 146 if (!download_item_) |
(...skipping 20 matching lines...) Expand all Loading... |
161 bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE); | 167 bool is_checked = IsCommandIdChecked(ALWAYS_OPEN_TYPE); |
162 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( | 168 DownloadPrefs* prefs = DownloadPrefs::FromBrowserContext( |
163 download_item_->GetBrowserContext()); | 169 download_item_->GetBrowserContext()); |
164 #if defined(OS_WIN) | 170 #if defined(OS_WIN) |
165 if (CanOpenPdfInReader()) { | 171 if (CanOpenPdfInReader()) { |
166 prefs->SetShouldOpenPdfInAdobeReader(!is_checked); | 172 prefs->SetShouldOpenPdfInAdobeReader(!is_checked); |
167 DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser( | 173 DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser( |
168 is_checked); | 174 is_checked); |
169 break; | 175 break; |
170 } | 176 } |
| 177 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
| 178 if (CanOpenPdfInReader()) { |
| 179 prefs->SetShouldOpenPdfInSystemReader(!is_checked); |
| 180 DownloadItemModel(download_item_).SetShouldPreferOpeningInBrowser( |
| 181 is_checked); |
| 182 break; |
| 183 } |
171 #endif | 184 #endif |
172 base::FilePath path = download_item_->GetTargetFilePath(); | 185 base::FilePath path = download_item_->GetTargetFilePath(); |
173 if (is_checked) | 186 if (is_checked) |
174 prefs->DisableAutoOpenBasedOnExtension(path); | 187 prefs->DisableAutoOpenBasedOnExtension(path); |
175 else | 188 else |
176 prefs->EnableAutoOpenBasedOnExtension(path); | 189 prefs->EnableAutoOpenBasedOnExtension(path); |
177 break; | 190 break; |
178 } | 191 } |
179 case PLATFORM_OPEN: | 192 case PLATFORM_OPEN: |
180 DownloadItemModel(download_item_).OpenUsingPlatformHandler(); | 193 DownloadItemModel(download_item_).OpenUsingPlatformHandler(); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 malicious_download_menu_model_->AddItemWithStringId( | 394 malicious_download_menu_model_->AddItemWithStringId( |
382 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); | 395 LEARN_MORE_SCANNING, IDS_DOWNLOAD_MENU_LEARN_MORE_SCANNING); |
383 | 396 |
384 return malicious_download_menu_model_.get(); | 397 return malicious_download_menu_model_.get(); |
385 } | 398 } |
386 | 399 |
387 int DownloadShelfContextMenu::GetAlwaysOpenStringId() const { | 400 int DownloadShelfContextMenu::GetAlwaysOpenStringId() const { |
388 #if defined(OS_WIN) | 401 #if defined(OS_WIN) |
389 if (CanOpenPdfInReader()) | 402 if (CanOpenPdfInReader()) |
390 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER; | 403 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_PDF_IN_READER; |
| 404 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
| 405 if (CanOpenPdfInReader()) |
| 406 return IDS_DOWNLOAD_MENU_PLATFORM_OPEN_ALWAYS; |
391 #endif | 407 #endif |
392 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE; | 408 return IDS_DOWNLOAD_MENU_ALWAYS_OPEN_TYPE; |
393 } | 409 } |
394 | 410 |
395 #if defined(OS_WIN) | 411 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) |
396 bool DownloadShelfContextMenu::IsDownloadPdf() const { | 412 bool DownloadShelfContextMenu::IsDownloadPdf() const { |
397 base::FilePath path = download_item_->GetTargetFilePath(); | 413 base::FilePath path = download_item_->GetTargetFilePath(); |
398 return path.MatchesExtension(FILE_PATH_LITERAL(".pdf")); | 414 return path.MatchesExtension(FILE_PATH_LITERAL(".pdf")); |
399 } | 415 } |
| 416 #endif |
400 | 417 |
| 418 #if defined(OS_WIN) |
401 bool DownloadShelfContextMenu::CanOpenPdfInReader() const { | 419 bool DownloadShelfContextMenu::CanOpenPdfInReader() const { |
402 return (is_pdf_reader_up_to_date_ && IsDownloadPdf()); | 420 return (is_pdf_reader_up_to_date_ && IsDownloadPdf()); |
403 } | 421 } |
| 422 #elif defined(OS_MACOSX) || defined(OS_LINUX) |
| 423 bool DownloadShelfContextMenu::CanOpenPdfInReader() const { |
| 424 return IsDownloadPdf(); |
| 425 } |
404 #endif | 426 #endif |
OLD | NEW |