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 104 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 (defined(OS_MACOSX) && !defined(OS_IOS)) | |
126 if (CanOpenPdfInReader()) { | 127 if (CanOpenPdfInReader()) { |
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) || \ |
166 (defined(OS_MACOSX) && !defined(OS_IOS)) | |
165 if (CanOpenPdfInReader()) { | 167 if (CanOpenPdfInReader()) { |
166 prefs->SetShouldOpenPdfInAdobeReader(!is_checked); | 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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 (CanOpenPdfInReader()) |
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 (CanOpenPdfInReader()) | |
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 |
407 #if defined(OS_WIN) | |
401 bool DownloadShelfContextMenu::CanOpenPdfInReader() const { | 408 bool DownloadShelfContextMenu::CanOpenPdfInReader() const { |
asanka
2014/10/23 07:38:04
CanOpenPdfInSystemViewer?
palmer
2014/10/23 22:17:08
OK, changed the name.
| |
402 return (is_pdf_reader_up_to_date_ && IsDownloadPdf()); | 409 return (is_pdf_reader_up_to_date_ && IsDownloadPdf()); |
403 } | 410 } |
411 #elif defined(OS_MACOSX) || defined(OS_LINUX) | |
412 bool DownloadShelfContextMenu::CanOpenPdfInReader() const { | |
413 return IsDownloadPdf(); | |
414 } | |
404 #endif | 415 #endif |
OLD | NEW |