| 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 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 base::Unretained(this))); | 393 base::Unretained(this))); |
| 394 web_ui()->RegisterMessageCallback("saveAppState", | 394 web_ui()->RegisterMessageCallback("saveAppState", |
| 395 base::Bind(&PrintPreviewHandler::HandleSaveAppState, | 395 base::Bind(&PrintPreviewHandler::HandleSaveAppState, |
| 396 base::Unretained(this))); | 396 base::Unretained(this))); |
| 397 web_ui()->RegisterMessageCallback("getInitialSettings", | 397 web_ui()->RegisterMessageCallback("getInitialSettings", |
| 398 base::Bind(&PrintPreviewHandler::HandleGetInitialSettings, | 398 base::Bind(&PrintPreviewHandler::HandleGetInitialSettings, |
| 399 base::Unretained(this))); | 399 base::Unretained(this))); |
| 400 web_ui()->RegisterMessageCallback("reportUiEvent", | 400 web_ui()->RegisterMessageCallback("reportUiEvent", |
| 401 base::Bind(&PrintPreviewHandler::HandleReportUiEvent, | 401 base::Bind(&PrintPreviewHandler::HandleReportUiEvent, |
| 402 base::Unretained(this))); | 402 base::Unretained(this))); |
| 403 web_ui()->RegisterMessageCallback("printWithCloudPrint", | 403 web_ui()->RegisterMessageCallback("printWithCloudPrintDialog", |
| 404 base::Bind(&PrintPreviewHandler::HandlePrintWithCloudPrint, | 404 base::Bind(&PrintPreviewHandler::HandlePrintWithCloudPrintDialog, |
| 405 base::Unretained(this))); | 405 base::Unretained(this))); |
| 406 web_ui()->RegisterMessageCallback("forceOpenNewTab", | 406 web_ui()->RegisterMessageCallback("forceOpenNewTab", |
| 407 base::Bind(&PrintPreviewHandler::HandleForceOpenNewTab, | 407 base::Bind(&PrintPreviewHandler::HandleForceOpenNewTab, |
| 408 base::Unretained(this))); | 408 base::Unretained(this))); |
| 409 } | 409 } |
| 410 | 410 |
| 411 WebContents* PrintPreviewHandler::preview_web_contents() const { | 411 WebContents* PrintPreviewHandler::preview_web_contents() const { |
| 412 return web_ui()->GetWebContents(); | 412 return web_ui()->GetWebContents(); |
| 413 } | 413 } |
| 414 | 414 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 511 |
| 512 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 512 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
| 513 if (!settings.get()) | 513 if (!settings.get()) |
| 514 return; | 514 return; |
| 515 | 515 |
| 516 // Never try to add headers/footers here. It's already in the generated PDF. | 516 // Never try to add headers/footers here. It's already in the generated PDF. |
| 517 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); | 517 settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false); |
| 518 | 518 |
| 519 bool print_to_pdf = false; | 519 bool print_to_pdf = false; |
| 520 bool is_cloud_printer = false; | 520 bool is_cloud_printer = false; |
| 521 bool is_cloud_dialog = false; | |
| 522 | 521 |
| 523 bool open_pdf_in_preview = false; | 522 bool open_pdf_in_preview = false; |
| 524 #if defined(OS_MACOSX) | 523 #if defined(OS_MACOSX) |
| 525 open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview); | 524 open_pdf_in_preview = settings->HasKey(printing::kSettingOpenPDFInPreview); |
| 526 #endif | 525 #endif |
| 527 | 526 |
| 528 if (!open_pdf_in_preview) { | 527 if (!open_pdf_in_preview) { |
| 529 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); | 528 settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf); |
| 530 settings->GetBoolean(printing::kSettingCloudPrintDialog, &is_cloud_dialog); | |
| 531 is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); | 529 is_cloud_printer = settings->HasKey(printing::kSettingCloudPrintId); |
| 532 } | 530 } |
| 533 | 531 |
| 534 int page_count = 0; | 532 int page_count = 0; |
| 535 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count); | 533 settings->GetInteger(printing::kSettingPreviewPageCount, &page_count); |
| 536 | 534 |
| 537 if (print_to_pdf) { | 535 if (print_to_pdf) { |
| 538 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); | 536 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", page_count); |
| 539 ReportUserActionHistogram(PRINT_TO_PDF); | 537 ReportUserActionHistogram(PRINT_TO_PDF); |
| 540 PrintToPdf(); | 538 PrintToPdf(); |
| 541 return; | 539 return; |
| 542 } | 540 } |
| 543 | 541 |
| 544 scoped_refptr<base::RefCountedBytes> data; | 542 scoped_refptr<base::RefCountedBytes> data; |
| 545 string16 title; | 543 string16 title; |
| 546 if (!GetPreviewDataAndTitle(&data, &title)) { | 544 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 547 // Nothing to print, no preview available. | 545 // Nothing to print, no preview available. |
| 548 return; | 546 return; |
| 549 } | 547 } |
| 550 | 548 |
| 551 if (is_cloud_printer) { | 549 if (is_cloud_printer) { |
| 552 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint", | 550 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint", |
| 553 page_count); | 551 page_count); |
| 554 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); | 552 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); |
| 555 SendCloudPrintJob(data); | 553 SendCloudPrintJob(data); |
| 556 } else if (is_cloud_dialog) { | |
| 557 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrintWebDialog", | |
| 558 page_count); | |
| 559 PrintWithCloudPrintDialog(data, title); | |
| 560 } else { | 554 } else { |
| 561 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count); | 555 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count); |
| 562 ReportUserActionHistogram(PRINT_TO_PRINTER); | 556 ReportUserActionHistogram(PRINT_TO_PRINTER); |
| 563 ReportPrintSettingsStats(*settings); | 557 ReportPrintSettingsStats(*settings); |
| 564 | 558 |
| 565 // This tries to activate the initiator tab as well, so do not clear the | 559 // This tries to activate the initiator tab as well, so do not clear the |
| 566 // association with the initiator tab yet. | 560 // association with the initiator tab yet. |
| 567 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 561 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 568 web_ui()->GetController()); | 562 web_ui()->GetController()); |
| 569 print_preview_ui->OnHidePreviewDialog(); | 563 print_preview_ui->OnHidePreviewDialog(); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 | 685 |
| 692 void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) { | 686 void PrintPreviewHandler::HandleGetAccessToken(const base::ListValue* args) { |
| 693 std::string type; | 687 std::string type; |
| 694 if (!args->GetString(0, &type)) | 688 if (!args->GetString(0, &type)) |
| 695 return; | 689 return; |
| 696 if (!token_service_) | 690 if (!token_service_) |
| 697 token_service_.reset(new AccessTokenService(this)); | 691 token_service_.reset(new AccessTokenService(this)); |
| 698 token_service_->RequestToken(type); | 692 token_service_->RequestToken(type); |
| 699 } | 693 } |
| 700 | 694 |
| 701 void PrintPreviewHandler::PrintWithCloudPrintDialog( | 695 void PrintPreviewHandler::PrintWithCloudPrintDialog() { |
| 702 const base::RefCountedBytes* data, | |
| 703 const string16& title) { | |
| 704 // Record the number of times the user asks to print via cloud print | 696 // Record the number of times the user asks to print via cloud print |
| 705 // instead of the print preview dialog. | 697 // instead of the print preview dialog. |
| 706 ReportStats(); | 698 ReportStats(); |
| 707 | 699 |
| 700 scoped_refptr<base::RefCountedBytes> data; |
| 701 string16 title; |
| 702 if (!GetPreviewDataAndTitle(&data, &title)) { |
| 703 // Nothing to print, no preview available. |
| 704 return; |
| 705 } |
| 706 |
| 708 gfx::NativeWindow modal_parent = platform_util::GetTopLevel( | 707 gfx::NativeWindow modal_parent = platform_util::GetTopLevel( |
| 709 preview_web_contents()->GetView()->GetNativeView()); | 708 preview_web_contents()->GetView()->GetNativeView()); |
| 710 print_dialog_cloud::CreatePrintDialogForBytes( | 709 print_dialog_cloud::CreatePrintDialogForBytes( |
| 711 preview_web_contents()->GetBrowserContext(), | 710 preview_web_contents()->GetBrowserContext(), |
| 712 modal_parent, | 711 modal_parent, |
| 713 data, | 712 data, |
| 714 title, | 713 title, |
| 715 string16(), | 714 string16(), |
| 716 std::string("application/pdf")); | 715 std::string("application/pdf")); |
| 717 | 716 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 751 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 753 web_ui()->GetController()); | 752 web_ui()->GetController()); |
| 754 print_preview_ui->OnCancelPendingPreviewRequest(); | 753 print_preview_ui->OnCancelPendingPreviewRequest(); |
| 755 } | 754 } |
| 756 | 755 |
| 757 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { | 756 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { |
| 758 ++manage_printers_dialog_request_count_; | 757 ++manage_printers_dialog_request_count_; |
| 759 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); | 758 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); |
| 760 } | 759 } |
| 761 | 760 |
| 762 void PrintPreviewHandler::HandlePrintWithCloudPrint( | 761 void PrintPreviewHandler::HandlePrintWithCloudPrintDialog( |
| 763 const base::ListValue* /*args*/) { | 762 const base::ListValue* args) { |
| 764 scoped_refptr<base::RefCountedBytes> data; | 763 int page_count = 0; |
| 765 string16 title; | 764 if (!args || !args->GetInteger(0, &page_count)) |
| 766 if (!GetPreviewDataAndTitle(&data, &title)) { | |
| 767 // Nothing to print, no preview available. | |
| 768 return; | 765 return; |
| 769 } | 766 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrintWebDialog", |
| 770 PrintWithCloudPrintDialog(data, title); | 767 page_count); |
| 768 |
| 769 PrintWithCloudPrintDialog(); |
| 771 } | 770 } |
| 772 | 771 |
| 773 void PrintPreviewHandler::HandleClosePreviewDialog(const ListValue* /*args*/) { | 772 void PrintPreviewHandler::HandleClosePreviewDialog(const ListValue* /*args*/) { |
| 774 ReportStats(); | 773 ReportStats(); |
| 775 ReportUserActionHistogram(CANCEL); | 774 ReportUserActionHistogram(CANCEL); |
| 776 | 775 |
| 777 // Record the number of times the user requests to regenerate preview data | 776 // Record the number of times the user requests to regenerate preview data |
| 778 // before cancelling. | 777 // before cancelling. |
| 779 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel", | 778 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforeCancel", |
| 780 regenerate_preview_request_count_); | 779 regenerate_preview_request_count_); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1084 // Nothing to print, no preview available. | 1083 // Nothing to print, no preview available. |
| 1085 return false; | 1084 return false; |
| 1086 } | 1085 } |
| 1087 DCHECK(tmp_data->size() && tmp_data->front()); | 1086 DCHECK(tmp_data->size() && tmp_data->front()); |
| 1088 | 1087 |
| 1089 *data = tmp_data; | 1088 *data = tmp_data; |
| 1090 *title = print_preview_ui->initiator_tab_title(); | 1089 *title = print_preview_ui->initiator_tab_title(); |
| 1091 return true; | 1090 return true; |
| 1092 } | 1091 } |
| 1093 | 1092 |
| OLD | NEW |