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

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_handler.cc

Issue 2139303003: Modified printing to no longer store its own save path. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed comments, spacing Created 4 years, 5 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/ui/webui/print_preview/print_preview_handler.h" 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 16 matching lines...) Expand all
27 #include "base/strings/string_number_conversions.h" 27 #include "base/strings/string_number_conversions.h"
28 #include "base/strings/stringprintf.h" 28 #include "base/strings/stringprintf.h"
29 #include "base/strings/utf_string_conversions.h" 29 #include "base/strings/utf_string_conversions.h"
30 #include "base/task_runner_util.h" 30 #include "base/task_runner_util.h"
31 #include "base/threading/thread.h" 31 #include "base/threading/thread.h"
32 #include "base/threading/thread_restrictions.h" 32 #include "base/threading/thread_restrictions.h"
33 #include "base/values.h" 33 #include "base/values.h"
34 #include "build/build_config.h" 34 #include "build/build_config.h"
35 #include "chrome/browser/app_mode/app_mode_utils.h" 35 #include "chrome/browser/app_mode/app_mode_utils.h"
36 #include "chrome/browser/browser_process.h" 36 #include "chrome/browser/browser_process.h"
37 #include "chrome/browser/download/download_prefs.h"
37 #include "chrome/browser/platform_util.h" 38 #include "chrome/browser/platform_util.h"
38 #include "chrome/browser/printing/print_dialog_cloud.h" 39 #include "chrome/browser/printing/print_dialog_cloud.h"
39 #include "chrome/browser/printing/print_error_dialog.h" 40 #include "chrome/browser/printing/print_error_dialog.h"
40 #include "chrome/browser/printing/print_job_manager.h" 41 #include "chrome/browser/printing/print_job_manager.h"
41 #include "chrome/browser/printing/print_preview_dialog_controller.h" 42 #include "chrome/browser/printing/print_preview_dialog_controller.h"
42 #include "chrome/browser/printing/print_view_manager.h" 43 #include "chrome/browser/printing/print_view_manager.h"
43 #include "chrome/browser/printing/printer_manager_dialog.h" 44 #include "chrome/browser/printing/printer_manager_dialog.h"
44 #include "chrome/browser/profiles/profile.h" 45 #include "chrome/browser/profiles/profile.h"
45 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h" 46 #include "chrome/browser/signin/gaia_cookie_manager_service_factory.h"
46 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 47 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
(...skipping 1303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename, 1351 void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename,
1351 bool prompt_user) { 1352 bool prompt_user) {
1352 if (prompt_user) { 1353 if (prompt_user) {
1353 ChromeSelectFilePolicy policy(GetInitiator()); 1354 ChromeSelectFilePolicy policy(GetInitiator());
1354 if (!policy.CanOpenSelectFileDialog()) { 1355 if (!policy.CanOpenSelectFileDialog()) {
1355 policy.SelectFileDenied(); 1356 policy.SelectFileDenied();
1356 return ClosePreviewDialog(); 1357 return ClosePreviewDialog();
1357 } 1358 }
1358 } 1359 }
1359 1360
1360 // Initializing |save_path_| if it is not already initialized. 1361 // Get save location from Download Preferences.
1361 printing::StickySettings* sticky_settings = GetStickySettings(); 1362 printing::StickySettings* sticky_settings = GetStickySettings();
Lei Zhang 2016/07/13 22:16:09 Move this down to line 1365, so it is closer to wh
1362 if (!sticky_settings->save_path()) { 1363 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
1363 // Allowing IO operation temporarily. It is ok to do so here because 1364 preview_web_contents()->GetBrowserContext());
1364 // the select file dialog performs IO anyway in order to display the 1365 base::FilePath file_path = download_prefs->SaveFilePath();
1365 // folders and also it is modal. 1366 sticky_settings->SaveInPrefs(Profile::FromBrowserContext(
1366 base::ThreadRestrictions::ScopedAllowIO allow_io; 1367 preview_web_contents()->GetBrowserContext())->GetPrefs());
Lei Zhang 2016/07/13 22:20:52 The #includes for base/path_service.h, base/thread
1367 base::FilePath file_path;
1368 PathService::Get(chrome::DIR_USER_DOCUMENTS, &file_path);
1369 sticky_settings->StoreSavePath(file_path);
1370 sticky_settings->SaveInPrefs(Profile::FromBrowserContext(
1371 preview_web_contents()->GetBrowserContext())->GetPrefs());
1372 }
1373
1374 // Handle the no prompting case. Like the dialog prompt, this function 1368 // Handle the no prompting case. Like the dialog prompt, this function
1375 // returns and eventually FileSelected() gets called. 1369 // returns and eventually FileSelected() gets called.
1376 if (!prompt_user) { 1370 if (!prompt_user) {
1377 base::PostTaskAndReplyWithResult( 1371 base::PostTaskAndReplyWithResult(
1378 BrowserThread::GetBlockingPool(), 1372 BrowserThread::GetBlockingPool(),
1379 FROM_HERE, 1373 FROM_HERE,
1380 base::Bind(&GetUniquePath, 1374 base::Bind(&GetUniquePath,
1381 sticky_settings->save_path()->Append(default_filename)), 1375 download_prefs->SaveFilePath().Append(default_filename)),
1382 base::Bind(&PrintPreviewHandler::OnGotUniqueFileName, 1376 base::Bind(&PrintPreviewHandler::OnGotUniqueFileName,
1383 weak_factory_.GetWeakPtr())); 1377 weak_factory_.GetWeakPtr()));
1384 return; 1378 return;
1385 } 1379 }
1386 1380
1387 // Otherwise prompt the user. 1381 // Otherwise prompt the user.
1388 ui::SelectFileDialog::FileTypeInfo file_type_info; 1382 ui::SelectFileDialog::FileTypeInfo file_type_info;
1389 file_type_info.extensions.resize(1); 1383 file_type_info.extensions.resize(1);
1390 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); 1384 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf"));
1391 1385
1392 select_file_dialog_ = 1386 select_file_dialog_ =
1393 ui::SelectFileDialog::Create(this, nullptr /*policy already checked*/); 1387 ui::SelectFileDialog::Create(this, nullptr /*policy already checked*/);
1394 select_file_dialog_->SelectFile( 1388 select_file_dialog_->SelectFile(
1395 ui::SelectFileDialog::SELECT_SAVEAS_FILE, 1389 ui::SelectFileDialog::SELECT_SAVEAS_FILE,
1396 base::string16(), 1390 base::string16(),
1397 sticky_settings->save_path()->Append(default_filename), 1391 download_prefs->SaveFilePath().Append(default_filename),
1398 &file_type_info, 1392 &file_type_info,
1399 0, 1393 0,
1400 base::FilePath::StringType(), 1394 base::FilePath::StringType(),
1401 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), 1395 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()),
1402 NULL); 1396 NULL);
1403 } 1397 }
1404 1398
1405 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) { 1399 void PrintPreviewHandler::OnGotUniqueFileName(const base::FilePath& path) {
1406 FileSelected(path, 0, nullptr); 1400 FileSelected(path, 0, nullptr);
1407 } 1401 }
1408 1402
1409 void PrintPreviewHandler::OnPrintPreviewFailed() { 1403 void PrintPreviewHandler::OnPrintPreviewFailed() {
1410 if (reported_failed_preview_) 1404 if (reported_failed_preview_)
1411 return; 1405 return;
1412 reported_failed_preview_ = true; 1406 reported_failed_preview_ = true;
1413 ReportUserActionHistogram(PREVIEW_FAILED); 1407 ReportUserActionHistogram(PREVIEW_FAILED);
1414 } 1408 }
1415 1409
1416 #if defined(ENABLE_BASIC_PRINTING) 1410 #if defined(ENABLE_BASIC_PRINTING)
1417 void PrintPreviewHandler::ShowSystemDialog() { 1411 void PrintPreviewHandler::ShowSystemDialog() {
1418 HandleShowSystemDialog(NULL); 1412 HandleShowSystemDialog(NULL);
1419 } 1413 }
1420 #endif // ENABLE_BASIC_PRINTING 1414 #endif // ENABLE_BASIC_PRINTING
1421 1415
1422 void PrintPreviewHandler::FileSelected(const base::FilePath& path, 1416 void PrintPreviewHandler::FileSelected(const base::FilePath& path,
1423 int /* index */, 1417 int /* index */,
1424 void* /* params */) { 1418 void* /* params */) {
1425 // Updating |save_path_| to the newly selected folder. 1419 // Update downloads location and save sticky settings.
1426 printing::StickySettings* sticky_settings = GetStickySettings(); 1420 printing::StickySettings* sticky_settings = GetStickySettings();
1427 sticky_settings->StoreSavePath(path.DirName()); 1421 DownloadPrefs* download_prefs = DownloadPrefs::FromBrowserContext(
1422 preview_web_contents()->GetBrowserContext());
1423 download_prefs->SetSaveFilePath(path.DirName());
1428 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( 1424 sticky_settings->SaveInPrefs(Profile::FromBrowserContext(
1429 preview_web_contents()->GetBrowserContext())->GetPrefs()); 1425 preview_web_contents()->GetBrowserContext())->GetPrefs());
1430 web_ui()->CallJavascriptFunctionUnsafe("fileSelectionCompleted"); 1426 web_ui()->CallJavascriptFunctionUnsafe("fileSelectionCompleted");
1431 print_to_pdf_path_ = path; 1427 print_to_pdf_path_ = path;
1432 PostPrintToPdfTask(); 1428 PostPrintToPdfTask();
1433 } 1429 }
1434 1430
1435 void PrintPreviewHandler::PostPrintToPdfTask() { 1431 void PrintPreviewHandler::PostPrintToPdfTask() {
1436 scoped_refptr<base::RefCountedBytes> data; 1432 scoped_refptr<base::RefCountedBytes> data;
1437 base::string16 title; 1433 base::string16 title;
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
1765 1761
1766 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { 1762 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() {
1767 if (gaia_cookie_manager_service_) 1763 if (gaia_cookie_manager_service_)
1768 gaia_cookie_manager_service_->RemoveObserver(this); 1764 gaia_cookie_manager_service_->RemoveObserver(this);
1769 } 1765 }
1770 1766
1771 void PrintPreviewHandler::SetPdfSavedClosureForTesting( 1767 void PrintPreviewHandler::SetPdfSavedClosureForTesting(
1772 const base::Closure& closure) { 1768 const base::Closure& closure) {
1773 pdf_file_saved_closure_ = closure; 1769 pdf_file_saved_closure_ = closure;
1774 } 1770 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698