| 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 #include <vector> | 10 #include <vector> |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" | 41 #include "chrome/browser/ui/webui/print_preview/sticky_settings.h" |
| 42 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
| 43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 44 #include "chrome/common/print_messages.h" | 44 #include "chrome/common/print_messages.h" |
| 45 #include "content/public/browser/browser_thread.h" | 45 #include "content/public/browser/browser_thread.h" |
| 46 #include "content/public/browser/navigation_controller.h" | 46 #include "content/public/browser/navigation_controller.h" |
| 47 #include "content/public/browser/navigation_entry.h" | 47 #include "content/public/browser/navigation_entry.h" |
| 48 #include "content/public/browser/render_view_host.h" | 48 #include "content/public/browser/render_view_host.h" |
| 49 #include "content/public/browser/render_view_host_delegate.h" | 49 #include "content/public/browser/render_view_host_delegate.h" |
| 50 #include "content/public/browser/web_contents.h" | 50 #include "content/public/browser/web_contents.h" |
| 51 #include "content/public/browser/web_contents_view.h" |
| 51 #include "content/public/browser/web_ui.h" | 52 #include "content/public/browser/web_ui.h" |
| 52 #include "printing/backend/print_backend.h" | 53 #include "printing/backend/print_backend.h" |
| 53 #include "printing/metafile.h" | 54 #include "printing/metafile.h" |
| 54 #include "printing/metafile_impl.h" | 55 #include "printing/metafile_impl.h" |
| 55 #include "printing/page_range.h" | 56 #include "printing/page_range.h" |
| 56 #include "printing/page_size_margins.h" | 57 #include "printing/page_size_margins.h" |
| 57 #include "printing/print_settings.h" | 58 #include "printing/print_settings.h" |
| 58 #include "unicode/ulocdata.h" | 59 #include "unicode/ulocdata.h" |
| 59 | 60 |
| 60 #if !defined(OS_MACOSX) | 61 #if !defined(OS_MACOSX) |
| (...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 const base::WeakPtr<PrintPreviewHandler>& handler) { | 541 const base::WeakPtr<PrintPreviewHandler>& handler) { |
| 541 if (handler.get()) { | 542 if (handler.get()) { |
| 542 PrintPreviewUI* print_preview_ui = | 543 PrintPreviewUI* print_preview_ui = |
| 543 static_cast<PrintPreviewUI*>(handler->web_ui()->GetController()); | 544 static_cast<PrintPreviewUI*>(handler->web_ui()->GetController()); |
| 544 if (print_preview_ui) | 545 if (print_preview_ui) |
| 545 print_preview_ui->OnReloadPrintersList(); | 546 print_preview_ui->OnReloadPrintersList(); |
| 546 } | 547 } |
| 547 } | 548 } |
| 548 | 549 |
| 549 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { | 550 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { |
| 551 gfx::NativeWindow modal_parent = |
| 552 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); |
| 550 print_dialog_cloud::CreateCloudPrintSigninDialog( | 553 print_dialog_cloud::CreateCloudPrintSigninDialog( |
| 554 web_ui()->GetWebContents()->GetBrowserContext(), |
| 555 modal_parent, |
| 551 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr())); | 556 base::Bind(&PrintPreviewHandler::OnSigninComplete, AsWeakPtr())); |
| 552 } | 557 } |
| 553 | 558 |
| 554 void PrintPreviewHandler::HandlePrintWithCloudPrint() { | 559 void PrintPreviewHandler::HandlePrintWithCloudPrint() { |
| 555 // Record the number of times the user asks to print via cloud print | 560 // Record the number of times the user asks to print via cloud print |
| 556 // instead of the print preview dialog. | 561 // instead of the print preview dialog. |
| 557 ReportStats(); | 562 ReportStats(); |
| 558 | 563 |
| 559 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 564 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 560 web_ui()->GetController()); | 565 web_ui()->GetController()); |
| 561 scoped_refptr<base::RefCountedBytes> data; | 566 scoped_refptr<base::RefCountedBytes> data; |
| 562 print_preview_ui->GetPrintPreviewDataForIndex( | 567 print_preview_ui->GetPrintPreviewDataForIndex( |
| 563 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 568 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| 564 if (!data.get()) { | 569 if (!data.get()) { |
| 565 NOTREACHED(); | 570 NOTREACHED(); |
| 566 return; | 571 return; |
| 567 } | 572 } |
| 568 DCHECK_GT(data->size(), 0U); | 573 DCHECK_GT(data->size(), 0U); |
| 569 print_dialog_cloud::CreatePrintDialogForBytes(data, | 574 |
| 575 gfx::NativeWindow modal_parent = |
| 576 web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); |
| 577 print_dialog_cloud::CreatePrintDialogForBytes( |
| 578 web_ui()->GetWebContents()->GetBrowserContext(), |
| 579 modal_parent, |
| 580 data, |
| 570 string16(print_preview_ui->initiator_tab_title()), | 581 string16(print_preview_ui->initiator_tab_title()), |
| 571 string16(), | 582 string16(), |
| 572 std::string("application/pdf"), | 583 std::string("application/pdf")); |
| 573 true); | |
| 574 | 584 |
| 575 // Once the cloud print dialog comes up we're no longer in a background | 585 // Once the cloud print dialog comes up we're no longer in a background |
| 576 // printing situation. Close the print preview. | 586 // printing situation. Close the print preview. |
| 577 // TODO(abodenha@chromium.org) The flow should be changed as described in | 587 // TODO(abodenha@chromium.org) The flow should be changed as described in |
| 578 // http://code.google.com/p/chromium/issues/detail?id=44093 | 588 // http://code.google.com/p/chromium/issues/detail?id=44093 |
| 579 ActivateInitiatorTabAndClosePreviewTab(); | 589 ActivateInitiatorTabAndClosePreviewTab(); |
| 580 } | 590 } |
| 581 | 591 |
| 582 void PrintPreviewHandler::HandleManageCloudPrint(const ListValue* /*args*/) { | 592 void PrintPreviewHandler::HandleManageCloudPrint(const ListValue* /*args*/) { |
| 583 ++manage_cloud_printers_dialog_request_count_; | 593 ++manage_cloud_printers_dialog_request_count_; |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 return; | 914 return; |
| 905 | 915 |
| 906 // We no longer require the initiator tab details. Remove those details | 916 // We no longer require the initiator tab details. Remove those details |
| 907 // associated with the preview tab to allow the initiator tab to create | 917 // associated with the preview tab to allow the initiator tab to create |
| 908 // another preview tab. | 918 // another preview tab. |
| 909 printing::PrintPreviewTabController* tab_controller = | 919 printing::PrintPreviewTabController* tab_controller = |
| 910 printing::PrintPreviewTabController::GetInstance(); | 920 printing::PrintPreviewTabController::GetInstance(); |
| 911 if (tab_controller) | 921 if (tab_controller) |
| 912 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 922 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
| 913 } | 923 } |
| OLD | NEW |