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 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 DCHECK(success); | 343 DCHECK(success); |
344 | 344 |
345 if (draft_page_count != -1 && preview_modifiable && | 345 if (draft_page_count != -1 && preview_modifiable && |
346 print_preview_ui->GetAvailableDraftPageCount() != draft_page_count) { | 346 print_preview_ui->GetAvailableDraftPageCount() != draft_page_count) { |
347 settings->SetBoolean(printing::kSettingGenerateDraftData, true); | 347 settings->SetBoolean(printing::kSettingGenerateDraftData, true); |
348 } | 348 } |
349 } | 349 } |
350 | 350 |
351 VLOG(1) << "Print preview request start"; | 351 VLOG(1) << "Print preview request start"; |
352 RenderViewHost* rvh = initiator_tab->web_contents()->GetRenderViewHost(); | 352 RenderViewHost* rvh = initiator_tab->web_contents()->GetRenderViewHost(); |
353 rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings)); | 353 rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), *settings)); |
354 } | 354 } |
355 | 355 |
356 void PrintPreviewHandler::HandlePrint(const ListValue* args) { | 356 void PrintPreviewHandler::HandlePrint(const ListValue* args) { |
357 ReportStats(); | 357 ReportStats(); |
358 | 358 |
359 // Record the number of times the user requests to regenerate preview data | 359 // Record the number of times the user requests to regenerate preview data |
360 // before printing. | 360 // before printing. |
361 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", | 361 UMA_HISTOGRAM_COUNTS("PrintPreview.RegeneratePreviewRequest.BeforePrint", |
362 regenerate_preview_request_count_); | 362 regenerate_preview_request_count_); |
363 | 363 |
364 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 364 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
365 if (initiator_tab) { | 365 if (initiator_tab) { |
366 RenderViewHost* rvh = initiator_tab->web_contents()->GetRenderViewHost(); | 366 RenderViewHost* rvh = initiator_tab->web_contents()->GetRenderViewHost(); |
367 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->routing_id())); | 367 rvh->Send(new PrintMsg_ResetScriptedPrintCount(rvh->GetRoutingID())); |
368 } | 368 } |
369 | 369 |
370 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); | 370 scoped_ptr<DictionaryValue> settings(GetSettingsDictionary(args)); |
371 if (!settings.get()) | 371 if (!settings.get()) |
372 return; | 372 return; |
373 | 373 |
374 // Storing last used settings. | 374 // Storing last used settings. |
375 GetStickySettings()->Store(*settings); | 375 GetStickySettings()->Store(*settings); |
376 | 376 |
377 // Never try to add headers/footers here. It's already in the generated PDF. | 377 // Never try to add headers/footers here. It's already in the generated PDF. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
413 web_ui()->GetController()); | 413 web_ui()->GetController()); |
414 print_preview_ui->OnHidePreviewTab(); | 414 print_preview_ui->OnHidePreviewTab(); |
415 | 415 |
416 // Do this so the initiator tab can open a new print preview tab. | 416 // Do this so the initiator tab can open a new print preview tab. |
417 ClearInitiatorTabDetails(); | 417 ClearInitiatorTabDetails(); |
418 | 418 |
419 // The PDF being printed contains only the pages that the user selected, | 419 // The PDF being printed contains only the pages that the user selected, |
420 // so ignore the page range and print all pages. | 420 // so ignore the page range and print all pages. |
421 settings->Remove(printing::kSettingPageRange, NULL); | 421 settings->Remove(printing::kSettingPageRange, NULL); |
422 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); | 422 RenderViewHost* rvh = web_ui()->GetWebContents()->GetRenderViewHost(); |
423 rvh->Send(new PrintMsg_PrintForPrintPreview(rvh->routing_id(), *settings)); | 423 rvh->Send( |
| 424 new PrintMsg_PrintForPrintPreview(rvh->GetRoutingID(), *settings)); |
424 | 425 |
425 // For all other cases above, the tab will stay open until the printing has | 426 // For all other cases above, the tab will stay open until the printing has |
426 // finished. Then the tab closes and PrintPreviewDone() gets called. Here, | 427 // finished. Then the tab closes and PrintPreviewDone() gets called. Here, |
427 // since we are hiding the tab, and not closing it, we need to make this | 428 // since we are hiding the tab, and not closing it, we need to make this |
428 // call. | 429 // call. |
429 if (initiator_tab) | 430 if (initiator_tab) |
430 initiator_tab->print_view_manager()->PrintPreviewDone(); | 431 initiator_tab->print_view_manager()->PrintPreviewDone(); |
431 } | 432 } |
432 } | 433 } |
433 | 434 |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 if (print_preview_ui->source_is_modifiable()) { | 664 if (print_preview_ui->source_is_modifiable()) { |
664 GetStickySettings()->GetLastUsedMarginSettings(&initial_settings); | 665 GetStickySettings()->GetLastUsedMarginSettings(&initial_settings); |
665 GetNumberFormatAndMeasurementSystem(&initial_settings); | 666 GetNumberFormatAndMeasurementSystem(&initial_settings); |
666 } | 667 } |
667 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); | 668 web_ui()->CallJavascriptFunction("setInitialSettings", initial_settings); |
668 } | 669 } |
669 | 670 |
670 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { | 671 void PrintPreviewHandler::ActivateInitiatorTabAndClosePreviewTab() { |
671 TabContentsWrapper* initiator_tab = GetInitiatorTab(); | 672 TabContentsWrapper* initiator_tab = GetInitiatorTab(); |
672 if (initiator_tab) | 673 if (initiator_tab) |
673 initiator_tab->web_contents()->GetRenderViewHost()->delegate()->Activate(); | 674 initiator_tab->web_contents()->GetRenderViewHost()-> |
| 675 GetDelegate()->Activate(); |
674 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( | 676 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>( |
675 web_ui()->GetController()); | 677 web_ui()->GetController()); |
676 print_preview_ui->OnClosePrintPreviewTab(); | 678 print_preview_ui->OnClosePrintPreviewTab(); |
677 } | 679 } |
678 | 680 |
679 void PrintPreviewHandler::SendPrinterCapabilities( | 681 void PrintPreviewHandler::SendPrinterCapabilities( |
680 const DictionaryValue& settings_info) { | 682 const DictionaryValue& settings_info) { |
681 VLOG(1) << "Get printer capabilities finished"; | 683 VLOG(1) << "Get printer capabilities finished"; |
682 web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", | 684 web_ui()->CallJavascriptFunction("updateWithPrinterCapabilities", |
683 settings_info); | 685 settings_info); |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 return; | 862 return; |
861 | 863 |
862 // We no longer require the initiator tab details. Remove those details | 864 // We no longer require the initiator tab details. Remove those details |
863 // associated with the preview tab to allow the initiator tab to create | 865 // associated with the preview tab to allow the initiator tab to create |
864 // another preview tab. | 866 // another preview tab. |
865 printing::PrintPreviewTabController* tab_controller = | 867 printing::PrintPreviewTabController* tab_controller = |
866 printing::PrintPreviewTabController::GetInstance(); | 868 printing::PrintPreviewTabController::GetInstance(); |
867 if (tab_controller) | 869 if (tab_controller) |
868 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); | 870 tab_controller->EraseInitiatorTabInfo(preview_tab_wrapper()); |
869 } | 871 } |
OLD | NEW |