Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(822)

Side by Side Diff: chrome/browser/download/download_prefs.cc

Issue 2369353002: Adds a pref and a policy to decide if PDFs should always be opened externally. (Closed)
Patch Set: Rebase and move the friend decl in the ifdef. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_prefs.h" 5 #include "chrome/browser/download/download_prefs.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 131
132 // Ensure that the default download directory exists. 132 // Ensure that the default download directory exists.
133 BrowserThread::PostTask( 133 BrowserThread::PostTask(
134 BrowserThread::FILE, FROM_HERE, 134 BrowserThread::FILE, FROM_HERE,
135 base::Bind(base::IgnoreResult(&base::CreateDirectory), 135 base::Bind(base::IgnoreResult(&base::CreateDirectory),
136 GetDefaultDownloadDirectoryForProfile())); 136 GetDefaultDownloadDirectoryForProfile()));
137 #endif // defined(OS_CHROMEOS) 137 #endif // defined(OS_CHROMEOS)
138 138
139 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) 139 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
140 should_open_pdf_in_system_reader_ = 140 should_open_pdf_in_system_reader_ =
141 prefs->GetBoolean(prefs::kOpenPdfDownloadInSystemReader); 141 prefs->GetBoolean(prefs::kOpenPdfDownloadInSystemReader) ||
142 prefs->GetBoolean(prefs::kAlwaysOpenPdfExternally);
143 override_adobe_version_check_for_tests_ = false;
142 #endif 144 #endif
143 145
144 // If the download path is dangerous we forcefully reset it. But if we do 146 // If the download path is dangerous we forcefully reset it. But if we do
145 // so we set a flag to make sure we only do it once, to avoid fighting 147 // so we set a flag to make sure we only do it once, to avoid fighting
146 // the user if he really wants it on an unsafe place such as the desktop. 148 // the user if he really wants it on an unsafe place such as the desktop.
147 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) { 149 if (!prefs->GetBoolean(prefs::kDownloadDirUpgraded)) {
148 base::FilePath current_download_dir = prefs->GetFilePath( 150 base::FilePath current_download_dir = prefs->GetFilePath(
149 prefs::kDownloadDefaultDirectory); 151 prefs::kDownloadDefaultDirectory);
150 if (DownloadPathIsDangerous(current_download_dir)) { 152 if (DownloadPathIsDangerous(current_download_dir)) {
151 prefs->SetFilePath(prefs::kDownloadDefaultDirectory, 153 prefs->SetFilePath(prefs::kDownloadDefaultDirectory,
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 if (extension.empty()) 335 if (extension.empty())
334 return; 336 return;
335 DCHECK(extension[0] == base::FilePath::kExtensionSeparator); 337 DCHECK(extension[0] == base::FilePath::kExtensionSeparator);
336 extension.erase(0, 1); 338 extension.erase(0, 1);
337 auto_open_.erase(extension); 339 auto_open_.erase(extension);
338 SaveAutoOpenState(); 340 SaveAutoOpenState();
339 } 341 }
340 342
341 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) 343 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
342 void DownloadPrefs::SetShouldOpenPdfInSystemReader(bool should_open) { 344 void DownloadPrefs::SetShouldOpenPdfInSystemReader(bool should_open) {
343 if (should_open_pdf_in_system_reader_ == should_open) 345 should_open_pdf_in_system_reader_ = should_open ||
344 return; 346 profile_->GetPrefs()->GetBoolean(prefs::kAlwaysOpenPdfExternally);
345 should_open_pdf_in_system_reader_ = should_open;
346 profile_->GetPrefs()->SetBoolean(prefs::kOpenPdfDownloadInSystemReader, 347 profile_->GetPrefs()->SetBoolean(prefs::kOpenPdfDownloadInSystemReader,
347 should_open); 348 should_open);
348 } 349 }
349 350
350 bool DownloadPrefs::ShouldOpenPdfInSystemReader() const { 351 bool DownloadPrefs::ShouldOpenPdfInSystemReader() const {
351 #if defined(OS_WIN) 352 #if defined(OS_WIN)
352 if (IsAdobeReaderDefaultPDFViewer() && 353 if (!override_adobe_version_check_for_tests_ &&
asanka 2016/09/28 17:27:53 What should be the non-test behavior if |always_op
pastarmovj 2016/09/29 08:40:44 It will cause a regular file download and let the
354 IsAdobeReaderDefaultPDFViewer() &&
353 !DownloadTargetDeterminer::IsAdobeReaderUpToDate()) { 355 !DownloadTargetDeterminer::IsAdobeReaderUpToDate()) {
354 return false; 356 return false;
355 } 357 }
356 #endif 358 #endif
357 return should_open_pdf_in_system_reader_; 359 return should_open_pdf_in_system_reader_;
358 } 360 }
361
362 void DownloadPrefs::OverrideAdobeVersionCheckForTests() {
363 override_adobe_version_check_for_tests_ = true;
364 }
359 #endif 365 #endif
360 366
361 void DownloadPrefs::ResetAutoOpen() { 367 void DownloadPrefs::ResetAutoOpen() {
362 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX) 368 #if defined(OS_WIN) || defined(OS_LINUX) || defined(OS_MACOSX)
363 SetShouldOpenPdfInSystemReader(false); 369 SetShouldOpenPdfInSystemReader(false);
364 #endif 370 #endif
365 auto_open_.clear(); 371 auto_open_.clear();
366 SaveAutoOpenState(); 372 SaveAutoOpenState();
367 } 373 }
368 374
(...skipping 13 matching lines...) Expand all
382 extensions.erase(extensions.size() - 1); 388 extensions.erase(extensions.size() - 1);
383 389
384 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions); 390 profile_->GetPrefs()->SetString(prefs::kDownloadExtensionsToOpen, extensions);
385 } 391 }
386 392
387 bool DownloadPrefs::AutoOpenCompareFunctor::operator()( 393 bool DownloadPrefs::AutoOpenCompareFunctor::operator()(
388 const base::FilePath::StringType& a, 394 const base::FilePath::StringType& a,
389 const base::FilePath::StringType& b) const { 395 const base::FilePath::StringType& b) const {
390 return base::FilePath::CompareLessIgnoreCase(a, b); 396 return base::FilePath::CompareLessIgnoreCase(a, b);
391 } 397 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698