| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // The cloud print OAuth2 scope. | 85 // The cloud print OAuth2 scope. |
| 86 const char kCloudPrintAuth[] = "https://www.googleapis.com/auth/cloudprint"; | 86 const char kCloudPrintAuth[] = "https://www.googleapis.com/auth/cloudprint"; |
| 87 | 87 |
| 88 enum UserActionBuckets { | 88 enum UserActionBuckets { |
| 89 PRINT_TO_PRINTER, | 89 PRINT_TO_PRINTER, |
| 90 PRINT_TO_PDF, | 90 PRINT_TO_PDF, |
| 91 CANCEL, | 91 CANCEL, |
| 92 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, | 92 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, |
| 93 PREVIEW_FAILED, | 93 PREVIEW_FAILED, |
| 94 PREVIEW_STARTED, | 94 PREVIEW_STARTED, |
| 95 INITIATOR_CRASHED, // UNUSED | 95 INITIATOR_TAB_CRASHED, // UNUSED |
| 96 INITIATOR_CLOSED, | 96 INITIATOR_TAB_CLOSED, |
| 97 PRINT_WITH_CLOUD_PRINT, | 97 PRINT_WITH_CLOUD_PRINT, |
| 98 USERACTION_BUCKET_BOUNDARY | 98 USERACTION_BUCKET_BOUNDARY |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 enum PrintSettingsBuckets { | 101 enum PrintSettingsBuckets { |
| 102 LANDSCAPE = 0, | 102 LANDSCAPE = 0, |
| 103 PORTRAIT, | 103 PORTRAIT, |
| 104 COLOR, | 104 COLOR, |
| 105 BLACK_AND_WHITE, | 105 BLACK_AND_WHITE, |
| 106 COLLATE, | 106 COLLATE, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 PRINT_DESTINATION_BUCKET_BOUNDARY); | 150 PRINT_DESTINATION_BUCKET_BOUNDARY); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void ReportGcpPromoHistogram(enum GcpPromoBuckets event) { | 153 void ReportGcpPromoHistogram(enum GcpPromoBuckets event) { |
| 154 UMA_HISTOGRAM_ENUMERATION("PrintPreview.GcpPromo", event, | 154 UMA_HISTOGRAM_ENUMERATION("PrintPreview.GcpPromo", event, |
| 155 GCP_PROMO_BUCKET_BOUNDARY); | 155 GCP_PROMO_BUCKET_BOUNDARY); |
| 156 } | 156 } |
| 157 | 157 |
| 158 // Name of a dictionary field holding cloud print related data; | 158 // Name of a dictionary field holding cloud print related data; |
| 159 const char kAppState[] = "appState"; | 159 const char kAppState[] = "appState"; |
| 160 // Name of a dictionary field holding the initiator title. | 160 // Name of a dictionary field holding the initiator tab title. |
| 161 const char kInitiatorTitle[] = "initiatorTitle"; | 161 const char kInitiatorTabTitle[] = "initiatorTabTitle"; |
| 162 // Name of a dictionary field holding the measurement system according to the | 162 // Name of a dictionary field holding the measurement system according to the |
| 163 // locale. | 163 // locale. |
| 164 const char kMeasurementSystem[] = "measurementSystem"; | 164 const char kMeasurementSystem[] = "measurementSystem"; |
| 165 // Name of a dictionary field holding the number format according to the locale. | 165 // Name of a dictionary field holding the number format according to the locale. |
| 166 const char kNumberFormat[] = "numberFormat"; | 166 const char kNumberFormat[] = "numberFormat"; |
| 167 // Name of a dictionary field specifying whether to print automatically in | 167 // Name of a dictionary field specifying whether to print automatically in |
| 168 // kiosk mode. See http://crbug.com/31395. | 168 // kiosk mode. See http://crbug.com/31395. |
| 169 const char kPrintAutomaticallyInKioskMode[] = "printAutomaticallyInKioskMode"; | 169 const char kPrintAutomaticallyInKioskMode[] = "printAutomaticallyInKioskMode"; |
| 170 // Name of a dictionary field holding the state of selection for document. | 170 // Name of a dictionary field holding the state of selection for document. |
| 171 const char kDocumentHasSelection[] = "documentHasSelection"; | 171 const char kDocumentHasSelection[] = "documentHasSelection"; |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 print_preview_ui->OnPrintPreviewRequest(request_id); | 438 print_preview_ui->OnPrintPreviewRequest(request_id); |
| 439 // Add an additional key in order to identify |print_preview_ui| later on | 439 // Add an additional key in order to identify |print_preview_ui| later on |
| 440 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 440 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
| 441 // thread. | 441 // thread. |
| 442 settings->SetInteger(printing::kPreviewUIID, | 442 settings->SetInteger(printing::kPreviewUIID, |
| 443 print_preview_ui->GetIDForPrintPreviewUI()); | 443 print_preview_ui->GetIDForPrintPreviewUI()); |
| 444 | 444 |
| 445 // Increment request count. | 445 // Increment request count. |
| 446 ++regenerate_preview_request_count_; | 446 ++regenerate_preview_request_count_; |
| 447 | 447 |
| 448 WebContents* initiator = GetInitiator(); | 448 WebContents* initiator_tab = GetInitiatorTab(); |
| 449 if (!initiator) { | 449 if (!initiator_tab) { |
| 450 ReportUserActionHistogram(INITIATOR_CLOSED); | 450 ReportUserActionHistogram(INITIATOR_TAB_CLOSED); |
| 451 print_preview_ui->OnClosePrintPreviewDialog(); | 451 print_preview_ui->OnClosePrintPreviewDialog(); |
| 452 return; | 452 return; |
| 453 } | 453 } |
| 454 | 454 |
| 455 // Retrieve the page title and url and send it to the renderer process if | 455 // Retrieve the page title and url and send it to the renderer process if |
| 456 // headers and footers are to be displayed. | 456 // headers and footers are to be displayed. |
| 457 bool display_header_footer = false; | 457 bool display_header_footer = false; |
| 458 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, | 458 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, |
| 459 &display_header_footer)) { | 459 &display_header_footer)) { |
| 460 NOTREACHED(); | 460 NOTREACHED(); |
| 461 } | 461 } |
| 462 if (display_header_footer) { | 462 if (display_header_footer) { |
| 463 settings->SetString(printing::kSettingHeaderFooterTitle, | 463 settings->SetString(printing::kSettingHeaderFooterTitle, |
| 464 initiator->GetTitle()); | 464 initiator_tab->GetTitle()); |
| 465 std::string url; | 465 std::string url; |
| 466 NavigationEntry* entry = initiator->GetController().GetActiveEntry(); | 466 NavigationEntry* entry = initiator_tab->GetController().GetActiveEntry(); |
| 467 if (entry) | 467 if (entry) |
| 468 url = entry->GetVirtualURL().spec(); | 468 url = entry->GetVirtualURL().spec(); |
| 469 settings->SetString(printing::kSettingHeaderFooterURL, url); | 469 settings->SetString(printing::kSettingHeaderFooterURL, url); |
| 470 } | 470 } |
| 471 | 471 |
| 472 bool generate_draft_data = false; | 472 bool generate_draft_data = false; |
| 473 bool success = settings->GetBoolean(printing::kSettingGenerateDraftData, | 473 bool success = settings->GetBoolean(printing::kSettingGenerateDraftData, |
| 474 &generate_draft_data); | 474 &generate_draft_data); |
| 475 DCHECK(success); | 475 DCHECK(success); |
| 476 | 476 |
| 477 if (!generate_draft_data) { | 477 if (!generate_draft_data) { |
| 478 double draft_page_count_double = -1; | 478 double draft_page_count_double = -1; |
| 479 success = args->GetDouble(1, &draft_page_count_double); | 479 success = args->GetDouble(1, &draft_page_count_double); |
| 480 DCHECK(success); | 480 DCHECK(success); |
| 481 int draft_page_count = static_cast<int>(draft_page_count_double); | 481 int draft_page_count = static_cast<int>(draft_page_count_double); |
| 482 | 482 |
| 483 bool preview_modifiable = false; | 483 bool preview_modifiable = false; |
| 484 success = args->GetBoolean(2, &preview_modifiable); | 484 success = args->GetBoolean(2, &preview_modifiable); |
| 485 DCHECK(success); | 485 DCHECK(success); |
| 486 | 486 |
| 487 if (draft_page_count != -1 && preview_modifiable && | 487 if (draft_page_count != -1 && preview_modifiable && |
| 488 print_preview_ui->GetAvailableDraftPageCount() != draft_page_count) { | 488 print_preview_ui->GetAvailableDraftPageCount() != draft_page_count) { |
| 489 settings->SetBoolean(printing::kSettingGenerateDraftData, true); | 489 settings->SetBoolean(printing::kSettingGenerateDraftData, true); |
| 490 } | 490 } |
| 491 } | 491 } |
| 492 | 492 |
| 493 VLOG(1) << "Print preview request start"; | 493 VLOG(1) << "Print preview request start"; |
| 494 RenderViewHost* rvh = initiator->GetRenderViewHost(); | 494 RenderViewHost* rvh = initiator_tab->GetRenderViewHost(); |
| 495 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); | 495 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
| 496 } | 496 } |
| 497 | 497 |
| 498 void PrintPreviewHandler::HandlePrint(const ListValue* args) { | 498 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
| 499 ReportStats(); | 499 ReportStats(); |
| 500 | 500 |
| 501 // Record the number of times the user requests to regenerate preview data | 501 // Record the number of times the user requests to regenerate preview data |
| 502 // before printing. | 502 // before printing. |
| 503 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 503 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
| 504 regenerate_preview_request_count_); | 504 regenerate_preview_request_count_); |
| 505 | 505 |
| 506 WebContents* initiator = GetInitiator(); | 506 WebContents* initiator_tab = GetInitiatorTab(); |
| 507 if (initiator) { | 507 if (initiator_tab) { |
| 508 RenderViewHost* rvh = initiator->GetRenderViewHost(); | 508 RenderViewHost* rvh = initiator_tab->GetRenderViewHost(); |
| 509 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->GetRoutingID())); | 509 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->GetRoutingID())); |
| 510 } | 510 } |
| 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 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 549 if (is_cloud_printer) { | 549 if (is_cloud_printer) { |
| 550 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint", | 550 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToCloudPrint", |
| 551 page_count); | 551 page_count); |
| 552 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); | 552 ReportUserActionHistogram(PRINT_WITH_CLOUD_PRINT); |
| 553 SendCloudPrintJob(data.get()); | 553 SendCloudPrintJob(data.get()); |
| 554 } else { | 554 } else { |
| 555 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count); | 555 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.PrintToPrinter", page_count); |
| 556 ReportUserActionHistogram(PRINT_TO_PRINTER); | 556 ReportUserActionHistogram(PRINT_TO_PRINTER); |
| 557 ReportPrintSettingsStats(*settings); | 557 ReportPrintSettingsStats(*settings); |
| 558 | 558 |
| 559 // This tries to activate the initiator as well, so do not clear the | 559 // This tries to activate the initiator tab as well, so do not clear the |
| 560 // association with the initiator yet. | 560 // association with the initiator tab yet. |
| 561 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 561 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 562 web_ui()->GetController()); | 562 web_ui()->GetController()); |
| 563 print_preview_ui->OnHidePreviewDialog(); | 563 print_preview_ui->OnHidePreviewDialog(); |
| 564 | 564 |
| 565 // Do this so the initiator can open a new print preview dialog, while the | 565 // Do this so the initiator tab can open a new print preview dialog, while |
| 566 // current print preview dialog is still handling its print job. | 566 // the current print preview dialog is still handling its print job. |
| 567 ClearInitiatorDetails(); | 567 ClearInitiatorTabDetails(); |
| 568 | 568 |
| 569 // The PDF being printed contains only the pages that the user selected, | 569 // The PDF being printed contains only the pages that the user selected, |
| 570 // so ignore the page range and print all pages. | 570 // so ignore the page range and print all pages. |
| 571 settings->Remove(printing::kSettingPageRange, NULL); | 571 settings->Remove(printing::kSettingPageRange, NULL); |
| 572 // Remove selection only flag for the same reason. | 572 // Remove selection only flag for the same reason. |
| 573 settings->Remove(printing::kSettingShouldPrintSelectionOnly, NULL); | 573 settings->Remove(printing::kSettingShouldPrintSelectionOnly, NULL); |
| 574 | 574 |
| 575 // Set ID to know whether printing is for preview. | 575 // Set ID to know whether printing is for preview. |
| 576 settings->SetInteger(printing::kPreviewUIID, | 576 settings->SetInteger(printing::kPreviewUIID, |
| 577 print_preview_ui->GetIDForPrintPreviewUI()); | 577 print_preview_ui->GetIDForPrintPreviewUI()); |
| 578 RenderViewHost* rvh = preview_web_contents()->GetRenderViewHost(); | 578 RenderViewHost* rvh = preview_web_contents()->GetRenderViewHost(); |
| 579 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), | 579 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), |
| 580 *settings)); | 580 *settings)); |
| 581 | 581 |
| 582 // For all other cases above, the preview dialog will stay open until the | 582 // For all other cases above, the preview dialog will stay open until the |
| 583 // printing has finished. Then the dialog closes and PrintPreviewDone() gets | 583 // printing has finished. Then the dialog closes and PrintPreviewDone() gets |
| 584 // called. In the case below, since the preview dialog will be hidden and | 584 // called. In the case below, since the preview dialog will be hidden and |
| 585 // not closed, we need to make this call. | 585 // not closed, we need to make this call. |
| 586 if (initiator) { | 586 if (initiator_tab) { |
| 587 printing::PrintViewManager* print_view_manager = | 587 printing::PrintViewManager* print_view_manager = |
| 588 printing::PrintViewManager::FromWebContents(initiator); | 588 printing::PrintViewManager::FromWebContents(initiator_tab); |
| 589 print_view_manager->PrintPreviewDone(); | 589 print_view_manager->PrintPreviewDone(); |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 | 593 |
| 594 void PrintPreviewHandler::PrintToPdf() { | 594 void PrintPreviewHandler::PrintToPdf() { |
| 595 if (print_to_pdf_path_.get()) { | 595 if (print_to_pdf_path_.get()) { |
| 596 // User has already selected a path, no need to show the dialog again. | 596 // User has already selected a path, no need to show the dialog again. |
| 597 PostPrintToPdfTask(); | 597 PostPrintToPdfTask(); |
| 598 } else if (!select_file_dialog_.get() || | 598 } else if (!select_file_dialog_.get() || |
| 599 !select_file_dialog_->IsRunning(platform_util::GetTopLevel( | 599 !select_file_dialog_->IsRunning(platform_util::GetTopLevel( |
| 600 preview_web_contents()->GetView()->GetNativeView()))) { | 600 preview_web_contents()->GetView()->GetNativeView()))) { |
| 601 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 601 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 602 web_ui()->GetController()); | 602 web_ui()->GetController()); |
| 603 // Pre-populating select file dialog with print job title. | 603 // Pre-populating select file dialog with print job title. |
| 604 string16 print_job_title_utf16 = print_preview_ui->initiator_title(); | 604 string16 print_job_title_utf16 = print_preview_ui->initiator_tab_title(); |
| 605 | 605 |
| 606 #if defined(OS_WIN) | 606 #if defined(OS_WIN) |
| 607 base::FilePath::StringType print_job_title(print_job_title_utf16); | 607 base::FilePath::StringType print_job_title(print_job_title_utf16); |
| 608 #elif defined(OS_POSIX) | 608 #elif defined(OS_POSIX) |
| 609 base::FilePath::StringType print_job_title = | 609 base::FilePath::StringType print_job_title = |
| 610 UTF16ToUTF8(print_job_title_utf16); | 610 UTF16ToUTF8(print_job_title_utf16); |
| 611 #endif | 611 #endif |
| 612 | 612 |
| 613 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); | 613 file_util::ReplaceIllegalCharactersInPath(&print_job_title, '_'); |
| 614 base::FilePath default_filename(print_job_title); | 614 base::FilePath default_filename(print_job_title); |
| 615 default_filename = | 615 default_filename = |
| 616 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); | 616 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| 617 | 617 |
| 618 SelectFile(default_filename); | 618 SelectFile(default_filename); |
| 619 } | 619 } |
| 620 } | 620 } |
| 621 | 621 |
| 622 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { | 622 void PrintPreviewHandler::HandleHidePreview(const ListValue* /*args*/) { |
| 623 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 623 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 624 web_ui()->GetController()); | 624 web_ui()->GetController()); |
| 625 print_preview_ui->OnHidePreviewDialog(); | 625 print_preview_ui->OnHidePreviewDialog(); |
| 626 } | 626 } |
| 627 | 627 |
| 628 void PrintPreviewHandler::HandleCancelPendingPrintRequest( | 628 void PrintPreviewHandler::HandleCancelPendingPrintRequest( |
| 629 const ListValue* /*args*/) { | 629 const ListValue* /*args*/) { |
| 630 WebContents* initiator = GetInitiator(); | 630 WebContents* initiator_tab = GetInitiatorTab(); |
| 631 if (initiator) | 631 if (initiator_tab) |
| 632 ClearInitiatorDetails(); | 632 ClearInitiatorTabDetails(); |
| 633 gfx::NativeWindow parent = initiator ? | 633 gfx::NativeWindow parent = initiator_tab ? |
| 634 initiator->GetView()->GetTopLevelNativeWindow() : | 634 initiator_tab->GetView()->GetTopLevelNativeWindow() : |
| 635 NULL; | 635 NULL; |
| 636 chrome::ShowPrintErrorDialog(parent); | 636 chrome::ShowPrintErrorDialog(parent); |
| 637 } | 637 } |
| 638 | 638 |
| 639 void PrintPreviewHandler::HandleSaveAppState(const ListValue* args) { | 639 void PrintPreviewHandler::HandleSaveAppState(const ListValue* args) { |
| 640 std::string data_to_save; | 640 std::string data_to_save; |
| 641 printing::StickySettings* sticky_settings = GetStickySettings(); | 641 printing::StickySettings* sticky_settings = GetStickySettings(); |
| 642 if (args->GetString(0, &data_to_save) && !data_to_save.empty()) | 642 if (args->GetString(0, &data_to_save) && !data_to_save.empty()) |
| 643 sticky_settings->StoreAppState(data_to_save); | 643 sticky_settings->StoreAppState(data_to_save); |
| 644 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( | 644 sticky_settings->SaveInPrefs(Profile::FromBrowserContext( |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 Referrer(), | 730 Referrer(), |
| 731 NEW_FOREGROUND_TAB, | 731 NEW_FOREGROUND_TAB, |
| 732 content::PAGE_TRANSITION_LINK, | 732 content::PAGE_TRANSITION_LINK, |
| 733 false)); | 733 false)); |
| 734 } | 734 } |
| 735 | 735 |
| 736 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* /*args*/) { | 736 void PrintPreviewHandler::HandleShowSystemDialog(const ListValue* /*args*/) { |
| 737 ReportStats(); | 737 ReportStats(); |
| 738 ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG); | 738 ReportUserActionHistogram(FALLBACK_TO_ADVANCED_SETTINGS_DIALOG); |
| 739 | 739 |
| 740 WebContents* initiator = GetInitiator(); | 740 WebContents* initiator_tab = GetInitiatorTab(); |
| 741 if (!initiator) | 741 if (!initiator_tab) |
| 742 return; | 742 return; |
| 743 | 743 |
| 744 printing::PrintViewManager* print_view_manager = | 744 printing::PrintViewManager* print_view_manager = |
| 745 printing::PrintViewManager::FromWebContents(initiator); | 745 printing::PrintViewManager::FromWebContents(initiator_tab); |
| 746 print_view_manager->set_observer(this); | 746 print_view_manager->set_observer(this); |
| 747 print_view_manager->PrintForSystemDialogNow(); | 747 print_view_manager->PrintForSystemDialogNow(); |
| 748 | 748 |
| 749 // Cancel the pending preview request if exists. | 749 // Cancel the pending preview request if exists. |
| 750 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 750 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 751 web_ui()->GetController()); | 751 web_ui()->GetController()); |
| 752 print_preview_ui->OnCancelPendingPreviewRequest(); | 752 print_preview_ui->OnCancelPendingPreviewRequest(); |
| 753 } | 753 } |
| 754 | 754 |
| 755 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { | 755 void PrintPreviewHandler::HandleManagePrinters(const ListValue* /*args*/) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 } | 841 } |
| 842 default: | 842 default: |
| 843 break; | 843 break; |
| 844 } | 844 } |
| 845 } | 845 } |
| 846 | 846 |
| 847 void PrintPreviewHandler::HandleForceOpenNewTab(const ListValue* args) { | 847 void PrintPreviewHandler::HandleForceOpenNewTab(const ListValue* args) { |
| 848 std::string url; | 848 std::string url; |
| 849 if (!args->GetString(0, &url)) | 849 if (!args->GetString(0, &url)) |
| 850 return; | 850 return; |
| 851 Browser* browser = chrome::FindBrowserWithWebContents(GetInitiator()); | 851 Browser* browser = chrome::FindBrowserWithWebContents(GetInitiatorTab()); |
| 852 if (!browser) | 852 if (!browser) |
| 853 return; | 853 return; |
| 854 chrome::AddSelectedTabWithURL(browser, | 854 chrome::AddSelectedTabWithURL(browser, |
| 855 GURL(url), | 855 GURL(url), |
| 856 content::PAGE_TRANSITION_LINK); | 856 content::PAGE_TRANSITION_LINK); |
| 857 } | 857 } |
| 858 | 858 |
| 859 void PrintPreviewHandler::SendInitialSettings( | 859 void PrintPreviewHandler::SendInitialSettings( |
| 860 const std::string& default_printer, | 860 const std::string& default_printer, |
| 861 const std::string& cloud_print_data) { | 861 const std::string& cloud_print_data) { |
| 862 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 862 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 863 web_ui()->GetController()); | 863 web_ui()->GetController()); |
| 864 | 864 |
| 865 base::DictionaryValue initial_settings; | 865 base::DictionaryValue initial_settings; |
| 866 initial_settings.SetString(kInitiatorTitle, | 866 initial_settings.SetString(kInitiatorTabTitle, |
| 867 print_preview_ui->initiator_title()); | 867 print_preview_ui->initiator_tab_title()); |
| 868 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, | 868 initial_settings.SetBoolean(printing::kSettingPreviewModifiable, |
| 869 print_preview_ui->source_is_modifiable()); | 869 print_preview_ui->source_is_modifiable()); |
| 870 initial_settings.SetString(printing::kSettingPrinterName, default_printer); | 870 initial_settings.SetString(printing::kSettingPrinterName, default_printer); |
| 871 initial_settings.SetBoolean(kDocumentHasSelection, | 871 initial_settings.SetBoolean(kDocumentHasSelection, |
| 872 print_preview_ui->source_has_selection()); | 872 print_preview_ui->source_has_selection()); |
| 873 initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, | 873 initial_settings.SetBoolean(printing::kSettingShouldPrintSelectionOnly, |
| 874 print_preview_ui->print_selection_only()); | 874 print_preview_ui->print_selection_only()); |
| 875 printing::StickySettings* sticky_settings = GetStickySettings(); | 875 printing::StickySettings* sticky_settings = GetStickySettings(); |
| 876 sticky_settings->RestoreFromPrefs(Profile::FromBrowserContext( | 876 sticky_settings->RestoreFromPrefs(Profile::FromBrowserContext( |
| 877 preview_web_contents()->GetBrowserContext())->GetPrefs()); | 877 preview_web_contents()->GetBrowserContext())->GetPrefs()); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 data->size()); | 937 data->size()); |
| 938 std::string base64_data; | 938 std::string base64_data; |
| 939 if (!base::Base64Encode(raw_data, &base64_data)) { | 939 if (!base::Base64Encode(raw_data, &base64_data)) { |
| 940 NOTREACHED() << "Base64 encoding PDF data."; | 940 NOTREACHED() << "Base64 encoding PDF data."; |
| 941 } | 941 } |
| 942 StringValue data_value(base64_data); | 942 StringValue data_value(base64_data); |
| 943 | 943 |
| 944 web_ui()->CallJavascriptFunction("printToCloud", data_value); | 944 web_ui()->CallJavascriptFunction("printToCloud", data_value); |
| 945 } | 945 } |
| 946 | 946 |
| 947 WebContents* PrintPreviewHandler::GetInitiator() const { | 947 WebContents* PrintPreviewHandler::GetInitiatorTab() const { |
| 948 printing::PrintPreviewDialogController* dialog_controller = | 948 printing::PrintPreviewDialogController* dialog_controller = |
| 949 printing::PrintPreviewDialogController::GetInstance(); | 949 printing::PrintPreviewDialogController::GetInstance(); |
| 950 if (!dialog_controller) | 950 if (!dialog_controller) |
| 951 return NULL; | 951 return NULL; |
| 952 return dialog_controller->GetInitiator(preview_web_contents()); | 952 return dialog_controller->GetInitiatorTab(preview_web_contents()); |
| 953 } | 953 } |
| 954 | 954 |
| 955 void PrintPreviewHandler::OnPrintDialogShown() { | 955 void PrintPreviewHandler::OnPrintDialogShown() { |
| 956 ClosePreviewDialog(); | 956 ClosePreviewDialog(); |
| 957 } | 957 } |
| 958 | 958 |
| 959 void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename) { | 959 void PrintPreviewHandler::SelectFile(const base::FilePath& default_filename) { |
| 960 ui::SelectFileDialog::FileTypeInfo file_type_info; | 960 ui::SelectFileDialog::FileTypeInfo file_type_info; |
| 961 file_type_info.extensions.resize(1); | 961 file_type_info.extensions.resize(1); |
| 962 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); | 962 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("pdf")); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 984 sticky_settings->save_path()->Append(default_filename), | 984 sticky_settings->save_path()->Append(default_filename), |
| 985 &file_type_info, | 985 &file_type_info, |
| 986 0, | 986 0, |
| 987 base::FilePath::StringType(), | 987 base::FilePath::StringType(), |
| 988 platform_util::GetTopLevel( | 988 platform_util::GetTopLevel( |
| 989 preview_web_contents()->GetView()->GetNativeView()), | 989 preview_web_contents()->GetView()->GetNativeView()), |
| 990 NULL); | 990 NULL); |
| 991 } | 991 } |
| 992 | 992 |
| 993 void PrintPreviewHandler::OnPrintPreviewDialogDestroyed() { | 993 void PrintPreviewHandler::OnPrintPreviewDialogDestroyed() { |
| 994 WebContents* initiator = GetInitiator(); | 994 WebContents* initiator_tab = GetInitiatorTab(); |
| 995 if (!initiator) | 995 if (!initiator_tab) |
| 996 return; | 996 return; |
| 997 | 997 |
| 998 printing::PrintViewManager* print_view_manager = | 998 printing::PrintViewManager* print_view_manager = |
| 999 printing::PrintViewManager::FromWebContents(initiator); | 999 printing::PrintViewManager::FromWebContents(initiator_tab); |
| 1000 print_view_manager->set_observer(NULL); | 1000 print_view_manager->set_observer(NULL); |
| 1001 } | 1001 } |
| 1002 | 1002 |
| 1003 void PrintPreviewHandler::OnPrintPreviewFailed() { | 1003 void PrintPreviewHandler::OnPrintPreviewFailed() { |
| 1004 if (reported_failed_preview_) | 1004 if (reported_failed_preview_) |
| 1005 return; | 1005 return; |
| 1006 reported_failed_preview_ = true; | 1006 reported_failed_preview_ = true; |
| 1007 ReportUserActionHistogram(PREVIEW_FAILED); | 1007 ReportUserActionHistogram(PREVIEW_FAILED); |
| 1008 } | 1008 } |
| 1009 | 1009 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 print_to_pdf_path_.reset(); | 1048 print_to_pdf_path_.reset(); |
| 1049 ClosePreviewDialog(); | 1049 ClosePreviewDialog(); |
| 1050 } | 1050 } |
| 1051 | 1051 |
| 1052 void PrintPreviewHandler::FileSelectionCanceled(void* params) { | 1052 void PrintPreviewHandler::FileSelectionCanceled(void* params) { |
| 1053 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 1053 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 1054 web_ui()->GetController()); | 1054 web_ui()->GetController()); |
| 1055 print_preview_ui->OnFileSelectionCancelled(); | 1055 print_preview_ui->OnFileSelectionCancelled(); |
| 1056 } | 1056 } |
| 1057 | 1057 |
| 1058 void PrintPreviewHandler::ClearInitiatorDetails() { | 1058 void PrintPreviewHandler::ClearInitiatorTabDetails() { |
| 1059 WebContents* initiator = GetInitiator(); | 1059 WebContents* initiator_tab = GetInitiatorTab(); |
| 1060 if (!initiator) | 1060 if (!initiator_tab) |
| 1061 return; | 1061 return; |
| 1062 | 1062 |
| 1063 // We no longer require the initiator details. Remove those details associated | 1063 // We no longer require the initiator tab details. Remove those details |
| 1064 // with the preview dialog to allow the initiator to create another preview | 1064 // associated with the preview dialog to allow the initiator tab to create |
| 1065 // dialog. | 1065 // another preview dialog. |
| 1066 printing::PrintPreviewDialogController* dialog_controller = | 1066 printing::PrintPreviewDialogController* dialog_controller = |
| 1067 printing::PrintPreviewDialogController::GetInstance(); | 1067 printing::PrintPreviewDialogController::GetInstance(); |
| 1068 if (dialog_controller) | 1068 if (dialog_controller) |
| 1069 dialog_controller->EraseInitiatorInfo(preview_web_contents()); | 1069 dialog_controller->EraseInitiatorTabInfo(preview_web_contents()); |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 bool PrintPreviewHandler::GetPreviewDataAndTitle( | 1072 bool PrintPreviewHandler::GetPreviewDataAndTitle( |
| 1073 scoped_refptr<base::RefCountedBytes>* data, | 1073 scoped_refptr<base::RefCountedBytes>* data, |
| 1074 string16* title) const { | 1074 string16* title) const { |
| 1075 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 1075 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
| 1076 web_ui()->GetController()); | 1076 web_ui()->GetController()); |
| 1077 scoped_refptr<base::RefCountedBytes> tmp_data; | 1077 scoped_refptr<base::RefCountedBytes> tmp_data; |
| 1078 print_preview_ui->GetPrintPreviewDataForIndex( | 1078 print_preview_ui->GetPrintPreviewDataForIndex( |
| 1079 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &tmp_data); | 1079 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &tmp_data); |
| 1080 | 1080 |
| 1081 if (!tmp_data.get()) { | 1081 if (!tmp_data.get()) { |
| 1082 // Nothing to print, no preview available. | 1082 // Nothing to print, no preview available. |
| 1083 return false; | 1083 return false; |
| 1084 } | 1084 } |
| 1085 DCHECK(tmp_data->size() && tmp_data->front()); | 1085 DCHECK(tmp_data->size() && tmp_data->front()); |
| 1086 | 1086 |
| 1087 *data = tmp_data; | 1087 *data = tmp_data; |
| 1088 *title = print_preview_ui->initiator_title(); | 1088 *title = print_preview_ui->initiator_tab_title(); |
| 1089 return true; | 1089 return true; |
| 1090 } | 1090 } |
| 1091 | 1091 |
| OLD | NEW |