| 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/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 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 } | 498 } |
| 499 } | 499 } |
| 500 | 500 |
| 501 void PrintPreviewHandler::PrintToPdf() { | 501 void PrintPreviewHandler::PrintToPdf() { |
| 502 if (print_to_pdf_path_.get()) { | 502 if (print_to_pdf_path_.get()) { |
| 503 // User has already selected a path, no need to show the dialog again. | 503 // User has already selected a path, no need to show the dialog again. |
| 504 PostPrintToPdfTask(); | 504 PostPrintToPdfTask(); |
| 505 } else if (!select_file_dialog_ || | 505 } else if (!select_file_dialog_ || |
| 506 !select_file_dialog_->IsRunning( | 506 !select_file_dialog_->IsRunning( |
| 507 platform_util::GetTopLevel( | 507 platform_util::GetTopLevel( |
| 508 preview_web_contents()->GetNativeView()))) { | 508 preview_web_contents()->GetView()->GetNativeView()))) { |
| 509 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 509 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 510 web_ui()->GetController()); | 510 web_ui()->GetController()); |
| 511 // Pre-populating select file dialog with print job title. | 511 // Pre-populating select file dialog with print job title. |
| 512 string16 print_job_title_utf16 = print_preview_ui->initiator_tab_title(); | 512 string16 print_job_title_utf16 = print_preview_ui->initiator_tab_title(); |
| 513 | 513 |
| 514 #if defined(OS_WIN) | 514 #if defined(OS_WIN) |
| 515 base::FilePath::StringType print_job_title(print_job_title_utf16); | 515 base::FilePath::StringType print_job_title(print_job_title_utf16); |
| 516 #elif defined(OS_POSIX) | 516 #elif defined(OS_POSIX) |
| 517 base::FilePath::StringType print_job_title = | 517 base::FilePath::StringType print_job_title = |
| 518 UTF16ToUTF8(print_job_title_utf16); | 518 UTF16ToUTF8(print_job_title_utf16); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 const base::WeakPtr<PrintPreviewHandler>& handler) { | 575 const base::WeakPtr<PrintPreviewHandler>& handler) { |
| 576 if (handler.get()) { | 576 if (handler.get()) { |
| 577 PrintPreviewUI* print_preview_ui = | 577 PrintPreviewUI* print_preview_ui = |
| 578 static_cast<PrintPreviewUI*>(handler->web_ui()->GetController()); | 578 static_cast<PrintPreviewUI*>(handler->web_ui()->GetController()); |
| 579 if (print_preview_ui) | 579 if (print_preview_ui) |
| 580 print_preview_ui->OnReloadPrintersList(); | 580 print_preview_ui->OnReloadPrintersList(); |
| 581 } | 581 } |
| 582 } | 582 } |
| 583 | 583 |
| 584 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { | 584 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { |
| 585 gfx::NativeWindow modal_parent = | 585 gfx::NativeWindow modal_parent = platform_util::GetTopLevel( |
| 586 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()); | 586 preview_web_contents()->GetView()->GetNativeView()); |
| 587 print_dialog_cloud::CreateCloudPrintSigninDialog( | 587 print_dialog_cloud::CreateCloudPrintSigninDialog( |
| 588 preview_web_contents()->GetBrowserContext(), | 588 preview_web_contents()->GetBrowserContext(), |
| 589 modal_parent, | 589 modal_parent, |
| 590 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr())); | 590 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr())); |
| 591 } | 591 } |
| 592 | 592 |
| 593 void PrintPreviewHandler::PrintWithCloudPrintDialog( | 593 void PrintPreviewHandler::PrintWithCloudPrintDialog( |
| 594 const base::RefCountedBytes* data, | 594 const base::RefCountedBytes* data, |
| 595 const string16& title) { | 595 const string16& title) { |
| 596 // Record the number of times the user asks to print via cloud print | 596 // Record the number of times the user asks to print via cloud print |
| 597 // instead of the print preview dialog. | 597 // instead of the print preview dialog. |
| 598 ReportStats(); | 598 ReportStats(); |
| 599 | 599 |
| 600 gfx::NativeWindow modal_parent = | 600 gfx::NativeWindow modal_parent = platform_util::GetTopLevel( |
| 601 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()); | 601 preview_web_contents()->GetView()->GetNativeView()); |
| 602 print_dialog_cloud::CreatePrintDialogForBytes( | 602 print_dialog_cloud::CreatePrintDialogForBytes( |
| 603 preview_web_contents()->GetBrowserContext(), | 603 preview_web_contents()->GetBrowserContext(), |
| 604 modal_parent, | 604 modal_parent, |
| 605 data, | 605 data, |
| 606 title, | 606 title, |
| 607 string16(), | 607 string16(), |
| 608 std::string("application/pdf")); | 608 std::string("application/pdf")); |
| 609 | 609 |
| 610 // Once the cloud print dialog comes up we're no longer in a background | 610 // Once the cloud print dialog comes up we're no longer in a background |
| 611 // printing situation. Close the print preview. | 611 // printing situation. Close the print preview. |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 870 | 870 |
| 871 select_file_dialog_ = ui::SelectFileDialog::Create( | 871 select_file_dialog_ = ui::SelectFileDialog::Create( |
| 872 this, new ChromeSelectFilePolicy(preview_web_contents())), | 872 this, new ChromeSelectFilePolicy(preview_web_contents())), |
| 873 select_file_dialog_->SelectFile( | 873 select_file_dialog_->SelectFile( |
| 874 ui::SelectFileDialog::SELECT_SAVEAS_FILE, | 874 ui::SelectFileDialog::SELECT_SAVEAS_FILE, |
| 875 string16(), | 875 string16(), |
| 876 sticky_settings->save_path()->Append(default_filename), | 876 sticky_settings->save_path()->Append(default_filename), |
| 877 &file_type_info, | 877 &file_type_info, |
| 878 0, | 878 0, |
| 879 FILE_PATH_LITERAL(""), | 879 FILE_PATH_LITERAL(""), |
| 880 platform_util::GetTopLevel(preview_web_contents()->GetNativeView()), | 880 platform_util::GetTopLevel( |
| 881 preview_web_contents()->GetView()->GetNativeView()), |
| 881 NULL); | 882 NULL); |
| 882 } | 883 } |
| 883 | 884 |
| 884 void PrintPreviewHandler::OnPrintPreviewDialogDestroyed() { | 885 void PrintPreviewHandler::OnPrintPreviewDialogDestroyed() { |
| 885 WebContents* initiator_tab = GetInitiatorTab(); | 886 WebContents* initiator_tab = GetInitiatorTab(); |
| 886 if (!initiator_tab) | 887 if (!initiator_tab) |
| 887 return; | 888 return; |
| 888 | 889 |
| 889 printing::PrintViewManager* print_view_manager = | 890 printing::PrintViewManager* print_view_manager = |
| 890 printing::PrintViewManager::FromWebContents(initiator_tab); | 891 printing::PrintViewManager::FromWebContents(initiator_tab); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 // Nothing to print, no preview available. | 974 // Nothing to print, no preview available. |
| 974 return false; | 975 return false; |
| 975 } | 976 } |
| 976 DCHECK(tmp_data->size() && tmp_data->front()); | 977 DCHECK(tmp_data->size() && tmp_data->front()); |
| 977 | 978 |
| 978 *data = tmp_data; | 979 *data = tmp_data; |
| 979 *title = print_preview_ui->initiator_tab_title(); | 980 *title = print_preview_ui->initiator_tab_title(); |
| 980 return true; | 981 return true; |
| 981 } | 982 } |
| 982 | 983 |
| OLD | NEW |