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 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 | 285 |
286 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { | 286 void PrintPreviewHandler::HandleGetPreview(const ListValue* args) { |
287 DCHECK_EQ(3U, args->GetSize()); | 287 DCHECK_EQ(3U, args->GetSize()); |
288 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 288 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
289 if (!settings.get()) | 289 if (!settings.get()) |
290 return; | 290 return; |
291 int request_id = -1; | 291 int request_id = -1; |
292 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) | 292 if (!settings->GetInteger(printing::kPreviewRequestID, &request_id)) |
293 return; | 293 return; |
294 | 294 |
295 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 295 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 296 web_ui()->GetController()); |
296 print_preview_ui->OnPrintPreviewRequest(request_id); | 297 print_preview_ui->OnPrintPreviewRequest(request_id); |
297 // Add an additional key in order to identify |print_preview_ui| later on | 298 // Add an additional key in order to identify |print_preview_ui| later on |
298 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 299 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
299 // thread. | 300 // thread. |
300 settings->SetString(printing::kPreviewUIAddr, | 301 settings->SetString(printing::kPreviewUIAddr, |
301 print_preview_ui->GetPrintPreviewUIAddress()); | 302 print_preview_ui->GetPrintPreviewUIAddress()); |
302 | 303 |
303 // Increment request count. | 304 // Increment request count. |
304 ++regenerate_preview_request_count_; | 305 ++regenerate_preview_request_count_; |
305 | 306 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
416 } else if (is_cloud_dialog && !open_pdf_in_preview) { | 417 } else if (is_cloud_dialog && !open_pdf_in_preview) { |
417 HandlePrintWithCloudPrint(); | 418 HandlePrintWithCloudPrint(); |
418 } else { | 419 } else { |
419 ReportPrintSettingsStats(*settings); | 420 ReportPrintSettingsStats(*settings); |
420 ReportUserActionHistogram(PRINT_TO_PRINTER); | 421 ReportUserActionHistogram(PRINT_TO_PRINTER); |
421 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", | 422 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", |
422 GetPageCountFromSettingsDictionary(*settings)); | 423 GetPageCountFromSettingsDictionary(*settings)); |
423 | 424 |
424 // This tries to activate the initiator tab as well, so do not clear the | 425 // This tries to activate the initiator tab as well, so do not clear the |
425 // association with the initiator tab yet. | 426 // association with the initiator tab yet. |
426 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 427 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 428 web_ui()->GetController()); |
427 print_preview_ui->OnHidePreviewTab(); | 429 print_preview_ui->OnHidePreviewTab(); |
428 | 430 |
429 // Do this so the initiator tab can open a new print preview tab. | 431 // Do this so the initiator tab can open a new print preview tab. |
430 ClearInitiatorTabDetails(); | 432 ClearInitiatorTabDetails(); |
431 | 433 |
432 // The PDF being printed contains only the pages that the user selected, | 434 // The PDF being printed contains only the pages that the user selected, |
433 // so ignore the page range and print all pages. | 435 // so ignore the page range and print all pages. |
434 settings->Remove(printing::kSettingPageRange, NULL); | 436 settings->Remove(printing::kSettingPageRange, NULL); |
435 RenderViewHost* rvh = web_ui()->web_contents()->GetRenderViewHost(); | 437 RenderViewHost* rvh = web_ui()->web_contents()->GetRenderViewHost(); |
436 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); | 438 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); |
437 } | 439 } |
438 if (initiator_tab) | 440 if (initiator_tab) |
439 initiator_tab->print_view_manager()->PrintPreviewDone(); | 441 initiator_tab->print_view_manager()->PrintPreviewDone(); |
440 } | 442 } |
441 | 443 |
442 void PrintPreviewHandler::HandlePrintToPdf( | 444 void PrintPreviewHandler::HandlePrintToPdf( |
443 const base::DictionaryValue& settings) { | 445 const base::DictionaryValue& settings) { |
444 if (print_to_pdf_path_.get()) { | 446 if (print_to_pdf_path_.get()) { |
445 // User has already selected a path, no need to show the dialog again. | 447 // User has already selected a path, no need to show the dialog again. |
446 PostPrintToPdfTask(); | 448 PostPrintToPdfTask(); |
447 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( | 449 } else if (!select_file_dialog_.get() || !select_file_dialog_->IsRunning( |
448 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { | 450 platform_util::GetTopLevel(preview_tab()->GetNativeView()))) { |
449 ReportUserActionHistogram(PRINT_TO_PDF); | 451 ReportUserActionHistogram(PRINT_TO_PDF); |
450 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", | 452 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPDF", |
451 GetPageCountFromSettingsDictionary(settings)); | 453 GetPageCountFromSettingsDictionary(settings)); |
452 | 454 |
453 // Pre-populating select file dialog with print job title. | 455 // Pre-populating select file dialog with print job title. |
454 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 456 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 457 web_ui()->GetController()); |
455 string16 print_job_title_utf16 = print_preview_ui->initiator_tab_title(); | 458 string16 print_job_title_utf16 = print_preview_ui->initiator_tab_title(); |
456 | 459 |
457 #if defined(OS_WIN) | 460 #if defined(OS_WIN) |
458 FilePath::StringType print_job_title(print_job_title_utf16); | 461 FilePath::StringType print_job_title(print_job_title_utf16); |
459 #elif defined(OS_POSIX) | 462 #elif defined(OS_POSIX) |
460 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); | 463 FilePath::StringType print_job_title = UTF16ToUTF8(print_job_title_utf16); |
461 #endif | 464 #endif |
462 | 465 |
463 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); | 466 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
464 FilePath default_filename(print_job_title); | 467 FilePath default_filename(print_job_title); |
465 default_filename = | 468 default_filename = |
466 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); | 469 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
467 | 470 |
468 SelectFile(default_filename); | 471 SelectFile(default_filename); |
469 } | 472 } |
470 } | 473 } |
471 | 474 |
472 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { | 475 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { |
473 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 476 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 477 web_ui()->GetController()); |
474 print_preview_ui->OnHidePreviewTab(); | 478 print_preview_ui->OnHidePreviewTab(); |
475 } | 479 } |
476 | 480 |
477 void PrintPreviewHandler::HandleCancelPendingPrintRequest( | 481 void PrintPreviewHandler::HandleCancelPendingPrintRequest( |
478 const ListValue* /*args*/) { | 482 const ListValue* /*args*/) { |
479 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 483 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
480 if (initiator_tab) { | 484 if (initiator_tab) { |
481 ClearInitiatorTabDetails(); | 485 ClearInitiatorTabDetails(); |
482 } else { | 486 } else { |
483 // Initiator tab does not exists. Get the wrapper contents of current tab. | 487 // Initiator tab does not exists. Get the wrapper contents of current tab. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { | 529 void PrintPreviewHandler::HandleSignin(const ListValue* /*args*/) { |
526 cloud_print_signin_dialog::CreateCloudPrintSigninDialog(preview_tab()); | 530 cloud_print_signin_dialog::CreateCloudPrintSigninDialog(preview_tab()); |
527 } | 531 } |
528 | 532 |
529 void PrintPreviewHandler::HandlePrintWithCloudPrint() { | 533 void PrintPreviewHandler::HandlePrintWithCloudPrint() { |
530 // Record the number of times the user asks to print via cloud print | 534 // Record the number of times the user asks to print via cloud print |
531 // instead of the print preview dialog. | 535 // instead of the print preview dialog. |
532 ReportStats(); | 536 ReportStats(); |
533 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); | 537 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); |
534 | 538 |
535 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 539 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 540 web_ui()->GetController()); |
536 scoped_refptr<RefCountedBytes> data; | 541 scoped_refptr<RefCountedBytes> data; |
537 print_preview_ui->GetPrintPreviewDataForIndex( | 542 print_preview_ui->GetPrintPreviewDataForIndex( |
538 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 543 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
539 CHECK(data.get()); | 544 CHECK(data.get()); |
540 DCHECK_GT(data->size(), 0U); | 545 DCHECK_GT(data->size(), 0U); |
541 print_dialog_cloud::CreatePrintDialogForBytes(data, | 546 print_dialog_cloud::CreatePrintDialogForBytes(data, |
542 string16(print_preview_ui->initiator_tab_title()), | 547 string16(print_preview_ui->initiator_tab_title()), |
543 string16(), | 548 string16(), |
544 std::string("application/pdf"), | 549 std::string("application/pdf"), |
545 true); | 550 true); |
(...skipping 21 matching lines...) Expand all Loading... |
567 | 572 |
568 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 573 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
569 if (!initiator_tab) | 574 if (!initiator_tab) |
570 return; | 575 return; |
571 | 576 |
572 printing::PrintViewManager* manager = initiator_tab->print_view_manager(); | 577 printing::PrintViewManager* manager = initiator_tab->print_view_manager(); |
573 manager->set_observer(this); | 578 manager->set_observer(this); |
574 manager->PrintForSystemDialogNow(); | 579 manager->PrintForSystemDialogNow(); |
575 | 580 |
576 // Cancel the pending preview request if exists. | 581 // Cancel the pending preview request if exists. |
577 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 582 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 583 web_ui()->GetController()); |
578 print_preview_ui->OnCancelPendingPreviewRequest(); | 584 print_preview_ui->OnCancelPendingPreviewRequest(); |
579 } | 585 } |
580 | 586 |
581 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { | 587 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { |
582 ++manage_printers_dialog_request_count_; | 588 ++manage_printers_dialog_request_count_; |
583 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); | 589 printing::PrinterManagerDialog::ShowPrinterManagerDialog(); |
584 } | 590 } |
585 | 591 |
586 void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* /*args*/) { | 592 void PrintPreviewHandler::HandleClosePreviewTab(const ListValue* /*args*/) { |
587 ReportStats(); | 593 ReportStats(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 print_backend_.get(), | 642 print_backend_.get(), |
637 has_logged_printers_count_); | 643 has_logged_printers_count_); |
638 BrowserThread::PostTask( | 644 BrowserThread::PostTask( |
639 BrowserThread::FILE, FROM_HERE, | 645 BrowserThread::FILE, FROM_HERE, |
640 base::Bind(&PrintSystemTaskProxy::GetDefaultPrinter, task.get())); | 646 base::Bind(&PrintSystemTaskProxy::GetDefaultPrinter, task.get())); |
641 } | 647 } |
642 | 648 |
643 void PrintPreviewHandler::SendInitialSettings( | 649 void PrintPreviewHandler::SendInitialSettings( |
644 const std::string& default_printer, | 650 const std::string& default_printer, |
645 const std::string& cloud_print_data) { | 651 const std::string& cloud_print_data) { |
646 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 652 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 653 web_ui()->GetController()); |
647 | 654 |
648 base::DictionaryValue initial_settings; | 655 base::DictionaryValue initial_settings; |
649 initial_settings.SetString(kInitiatorTabTitle, | 656 initial_settings.SetString(kInitiatorTabTitle, |
650 print_preview_ui->initiator_tab_title()); | 657 print_preview_ui->initiator_tab_title()); |
651 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, | 658 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, |
652 print_preview_ui->source_is_modifiable()); | 659 print_preview_ui->source_is_modifiable()); |
653 initial_settings.SetString(printing::kSettingPrinterName, | 660 initial_settings.SetString(printing::kSettingPrinterName, |
654 default_printer); | 661 default_printer); |
655 initial_settings.SetString(kCloudPrintData, cloud_print_data); | 662 initial_settings.SetString(kCloudPrintData, cloud_print_data); |
656 | 663 |
(...skipping 10 matching lines...) Expand all Loading... |
667 GetLastUsedMarginSettings(&initial_settings); | 674 GetLastUsedMarginSettings(&initial_settings); |
668 GetNumberFormatAndMeasurementSystem(&initial_settings); | 675 GetNumberFormatAndMeasurementSystem(&initial_settings); |
669 } | 676 } |
670 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 677 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |
671 } | 678 } |
672 | 679 |
673 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 680 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
674 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 681 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
675 if (initiator_tab) | 682 if (initiator_tab) |
676 initiator_tab->web_contents()->GetRenderViewHost()->delegate()->Activate(); | 683 initiator_tab->web_contents()->GetRenderViewHost()->delegate()->Activate(); |
677 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 684 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 685 web_ui()->GetController()); |
678 print_preview_ui->OnClosePrintPreviewTab(); | 686 print_preview_ui->OnClosePrintPreviewTab(); |
679 } | 687 } |
680 | 688 |
681 void PrintPreviewHandler::SendPrinterCapabilities( | 689 void PrintPreviewHandler::SendPrinterCapabilities( |
682 const DictionaryValue& settings_info) { | 690 const DictionaryValue& settings_info) { |
683 VLOG(1) << "Get printer capabilities finished"; | 691 VLOG(1) << "Get printer capabilities finished"; |
684 web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", | 692 web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", |
685 settings_info); | 693 settings_info); |
686 } | 694 } |
687 | 695 |
688 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { | 696 void PrintPreviewHandler::SetupPrinterList(const ListValue& printers) { |
689 SendCloudPrintEnabled(); | 697 SendCloudPrintEnabled(); |
690 web_ui()->CallJavascriptFunction("setPrinters", printers); | 698 web_ui()->CallJavascriptFunction("setPrinters", printers); |
691 } | 699 } |
692 | 700 |
693 void PrintPreviewHandler::SendCloudPrintEnabled() { | 701 void PrintPreviewHandler::SendCloudPrintEnabled() { |
694 Profile* profile = BrowserList::GetLastActive()->profile(); | 702 Profile* profile = BrowserList::GetLastActive()->profile(); |
695 PrefService* prefs = profile->GetPrefs(); | 703 PrefService* prefs = profile->GetPrefs(); |
696 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { | 704 if (prefs->GetBoolean(prefs::kCloudPrintSubmitEnabled)) { |
697 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL()); | 705 GURL gcp_url(CloudPrintURL(profile).GetCloudPrintServiceURL()); |
698 base::StringValue gcp_url_value(gcp_url.spec()); | 706 base::StringValue gcp_url_value(gcp_url.spec()); |
699 web_ui()->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); | 707 web_ui()->CallJavascriptFunction("setUseCloudPrint", gcp_url_value); |
700 } | 708 } |
701 } | 709 } |
702 | 710 |
703 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, | 711 void PrintPreviewHandler::SendCloudPrintJob(const DictionaryValue& settings, |
704 std::string print_ticket) { | 712 std::string print_ticket) { |
705 scoped_refptr<RefCountedBytes> data; | 713 scoped_refptr<RefCountedBytes> data; |
706 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 714 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 715 web_ui()->GetController()); |
707 print_preview_ui->GetPrintPreviewDataForIndex( | 716 print_preview_ui->GetPrintPreviewDataForIndex( |
708 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 717 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
709 CHECK(data.get()); | 718 CHECK(data.get()); |
710 DCHECK_GT(data->size(), 0U); | 719 DCHECK_GT(data->size(), 0U); |
711 | 720 |
712 string16 print_job_title_utf16 = | 721 string16 print_job_title_utf16 = |
713 preview_tab_wrapper()->print_view_manager()->RenderSourceName(); | 722 preview_tab_wrapper()->print_view_manager()->RenderSourceName(); |
714 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); | 723 std::string print_job_title = UTF16ToUTF8(print_job_title_utf16); |
715 std::string printer_id; | 724 std::string printer_id; |
716 settings.GetString(printing::kSettingCloudPrintId, &printer_id); | 725 settings.GetString(printing::kSettingCloudPrintId, &printer_id); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 | 825 |
817 void PrintPreviewHandler::ShowSystemDialog() { | 826 void PrintPreviewHandler::ShowSystemDialog() { |
818 HandleShowSystemDialog(NULL); | 827 HandleShowSystemDialog(NULL); |
819 } | 828 } |
820 | 829 |
821 void PrintPreviewHandler::FileSelected(const FilePath& path, | 830 void PrintPreviewHandler::FileSelected(const FilePath& path, |
822 int index, void* params) { | 831 int index, void* params) { |
823 // Updating last_saved_path_ to the newly selected folder. | 832 // Updating last_saved_path_ to the newly selected folder. |
824 *last_saved_path_ = path.DirName(); | 833 *last_saved_path_ = path.DirName(); |
825 | 834 |
826 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 835 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
827 print_preview_ui->CallJavascriptFunction("fileSelectionCompleted"); | 836 web_ui()->GetController()); |
| 837 print_preview_ui->web_ui()->CallJavascriptFunction("fileSelectionCompleted"); |
828 scoped_refptr<RefCountedBytes> data; | 838 scoped_refptr<RefCountedBytes> data; |
829 print_preview_ui->GetPrintPreviewDataForIndex( | 839 print_preview_ui->GetPrintPreviewDataForIndex( |
830 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 840 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
831 print_to_pdf_path_.reset(new FilePath(path)); | 841 print_to_pdf_path_.reset(new FilePath(path)); |
832 if (data.get()) | 842 if (data.get()) |
833 PostPrintToPdfTask(); | 843 PostPrintToPdfTask(); |
834 } | 844 } |
835 | 845 |
836 void PrintPreviewHandler::PostPrintToPdfTask() { | 846 void PrintPreviewHandler::PostPrintToPdfTask() { |
837 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 847 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 848 web_ui()->GetController()); |
838 scoped_refptr<RefCountedBytes> data; | 849 scoped_refptr<RefCountedBytes> data; |
839 print_preview_ui->GetPrintPreviewDataForIndex( | 850 print_preview_ui->GetPrintPreviewDataForIndex( |
840 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 851 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
841 DCHECK(data.get()); | 852 DCHECK(data.get()); |
842 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; | 853 printing::PreviewMetafile* metafile = new printing::PreviewMetafile; |
843 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); | 854 metafile->InitFromData(static_cast<const void*>(data->front()), data->size()); |
844 // PrintToPdfCallback takes ownership of |metafile|. | 855 // PrintToPdfCallback takes ownership of |metafile|. |
845 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 856 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
846 base::Bind(&PrintToPdfCallback, metafile, | 857 base::Bind(&PrintToPdfCallback, metafile, |
847 *print_to_pdf_path_)); | 858 *print_to_pdf_path_)); |
848 print_to_pdf_path_.reset(); | 859 print_to_pdf_path_.reset(); |
849 ActivateInitiatorTabAndClosePreviewTab(); | 860 ActivateInitiatorTabAndClosePreviewTab(); |
850 } | 861 } |
851 | 862 |
852 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 863 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
853 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui()); | 864 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 865 web_ui()->GetController()); |
854 print_preview_ui->OnFileSelectionCancelled(); | 866 print_preview_ui->OnFileSelectionCancelled(); |
855 } | 867 } |
856 | 868 |
857 void PrintPreviewHandler::ClearInitiatorTabDetails() { | 869 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
858 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 870 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
859 if (!initiator_tab) | 871 if (!initiator_tab) |
860 return; | 872 return; |
861 | 873 |
862 // We no longer require the initiator tab details. Remove those details | 874 // We no longer require the initiator tab details. Remove those details |
863 // associated with the preview tab to allow the initiator tab to create | 875 // associated with the preview tab to allow the initiator tab to create |
864 // another preview tab. | 876 // another preview tab. |
865 printing::PrintPreviewTabController* tab_controller = | 877 printing::PrintPreviewTabController* tab_controller = |
866 printing::PrintPreviewTabController::GetInstance(); | 878 printing::PrintPreviewTabController::GetInstance(); |
867 if (tab_controller) | 879 if (tab_controller) |
868 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 880 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
869 } | 881 } |
OLD | NEW |