Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: chrome/browser/ui/webui/print_preview/print_preview_ui.cc

Issue 1995113002: Rename WebUI::CallJavascriptFunction to WebUI::CallJavascriptFunctionUnsafe (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_ui.h" 5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
6 6
7 #include <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/id_map.h" 10 #include "base/id_map.h"
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 if (background_printing_manager->HasPrintPreviewDialog(preview_dialog)) 495 if (background_printing_manager->HasPrintPreviewDialog(preview_dialog))
496 return; 496 return;
497 OnClosePrintPreviewDialog(); 497 OnClosePrintPreviewDialog();
498 } 498 }
499 499
500 void PrintPreviewUI::OnInitiatorClosed() { 500 void PrintPreviewUI::OnInitiatorClosed() {
501 WebContents* preview_dialog = web_ui()->GetWebContents(); 501 WebContents* preview_dialog = web_ui()->GetWebContents();
502 printing::BackgroundPrintingManager* background_printing_manager = 502 printing::BackgroundPrintingManager* background_printing_manager =
503 g_browser_process->background_printing_manager(); 503 g_browser_process->background_printing_manager();
504 if (background_printing_manager->HasPrintPreviewDialog(preview_dialog)) 504 if (background_printing_manager->HasPrintPreviewDialog(preview_dialog))
505 web_ui()->CallJavascriptFunction("cancelPendingPrintRequest"); 505 web_ui()->CallJavascriptFunctionUnsafe("cancelPendingPrintRequest");
506 else 506 else
507 OnClosePrintPreviewDialog(); 507 OnClosePrintPreviewDialog();
508 } 508 }
509 509
510 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) { 510 void PrintPreviewUI::OnPrintPreviewRequest(int request_id) {
511 if (!initial_preview_start_time_.is_null()) { 511 if (!initial_preview_start_time_.is_null()) {
512 UMA_HISTOGRAM_TIMES("PrintPreview.InitializationTime", 512 UMA_HISTOGRAM_TIMES("PrintPreview.InitializationTime",
513 base::TimeTicks::Now() - initial_preview_start_time_); 513 base::TimeTicks::Now() - initial_preview_start_time_);
514 } 514 }
515 g_print_preview_request_id_map.Get().Set(id_, request_id); 515 g_print_preview_request_id_map.Get().Set(id_, request_id);
516 } 516 }
517 517
518 #if defined(ENABLE_BASIC_PRINTING) 518 #if defined(ENABLE_BASIC_PRINTING)
519 void PrintPreviewUI::OnShowSystemDialog() { 519 void PrintPreviewUI::OnShowSystemDialog() {
520 web_ui()->CallJavascriptFunction("onSystemDialogLinkClicked"); 520 web_ui()->CallJavascriptFunctionUnsafe("onSystemDialogLinkClicked");
521 } 521 }
522 #endif // ENABLE_BASIC_PRINTING 522 #endif // ENABLE_BASIC_PRINTING
523 523
524 void PrintPreviewUI::OnDidGetPreviewPageCount( 524 void PrintPreviewUI::OnDidGetPreviewPageCount(
525 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { 525 const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
526 DCHECK_GT(params.page_count, 0); 526 DCHECK_GT(params.page_count, 0);
527 if (g_testing_delegate) 527 if (g_testing_delegate)
528 g_testing_delegate->DidGetPreviewPageCount(params.page_count); 528 g_testing_delegate->DidGetPreviewPageCount(params.page_count);
529 base::FundamentalValue count(params.page_count); 529 base::FundamentalValue count(params.page_count);
530 base::FundamentalValue request_id(params.preview_request_id); 530 base::FundamentalValue request_id(params.preview_request_id);
531 web_ui()->CallJavascriptFunction("onDidGetPreviewPageCount", 531 web_ui()->CallJavascriptFunctionUnsafe("onDidGetPreviewPageCount", count,
532 count, 532 request_id);
533 request_id);
534 } 533 }
535 534
536 void PrintPreviewUI::OnDidGetDefaultPageLayout( 535 void PrintPreviewUI::OnDidGetDefaultPageLayout(
537 const PageSizeMargins& page_layout, const gfx::Rect& printable_area, 536 const PageSizeMargins& page_layout, const gfx::Rect& printable_area,
538 bool has_custom_page_size_style) { 537 bool has_custom_page_size_style) {
539 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 || 538 if (page_layout.margin_top < 0 || page_layout.margin_left < 0 ||
540 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 || 539 page_layout.margin_bottom < 0 || page_layout.margin_right < 0 ||
541 page_layout.content_width < 0 || page_layout.content_height < 0 || 540 page_layout.content_width < 0 || page_layout.content_height < 0 ||
542 printable_area.width() <= 0 || printable_area.height() <= 0) { 541 printable_area.width() <= 0 || printable_area.height() <= 0) {
543 NOTREACHED(); 542 NOTREACHED();
544 return; 543 return;
545 } 544 }
546 545
547 base::DictionaryValue layout; 546 base::DictionaryValue layout;
548 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top); 547 layout.SetDouble(printing::kSettingMarginTop, page_layout.margin_top);
549 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left); 548 layout.SetDouble(printing::kSettingMarginLeft, page_layout.margin_left);
550 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom); 549 layout.SetDouble(printing::kSettingMarginBottom, page_layout.margin_bottom);
551 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right); 550 layout.SetDouble(printing::kSettingMarginRight, page_layout.margin_right);
552 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width); 551 layout.SetDouble(printing::kSettingContentWidth, page_layout.content_width);
553 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height); 552 layout.SetDouble(printing::kSettingContentHeight, page_layout.content_height);
554 layout.SetInteger(printing::kSettingPrintableAreaX, printable_area.x()); 553 layout.SetInteger(printing::kSettingPrintableAreaX, printable_area.x());
555 layout.SetInteger(printing::kSettingPrintableAreaY, printable_area.y()); 554 layout.SetInteger(printing::kSettingPrintableAreaY, printable_area.y());
556 layout.SetInteger(printing::kSettingPrintableAreaWidth, 555 layout.SetInteger(printing::kSettingPrintableAreaWidth,
557 printable_area.width()); 556 printable_area.width());
558 layout.SetInteger(printing::kSettingPrintableAreaHeight, 557 layout.SetInteger(printing::kSettingPrintableAreaHeight,
559 printable_area.height()); 558 printable_area.height());
560 559
561 base::FundamentalValue has_page_size_style(has_custom_page_size_style); 560 base::FundamentalValue has_page_size_style(has_custom_page_size_style);
562 web_ui()->CallJavascriptFunction("onDidGetDefaultPageLayout", layout, 561 web_ui()->CallJavascriptFunctionUnsafe("onDidGetDefaultPageLayout", layout,
563 has_page_size_style); 562 has_page_size_style);
564 } 563 }
565 564
566 void PrintPreviewUI::OnDidPreviewPage(int page_number, 565 void PrintPreviewUI::OnDidPreviewPage(int page_number,
567 int preview_request_id) { 566 int preview_request_id) {
568 DCHECK_GE(page_number, 0); 567 DCHECK_GE(page_number, 0);
569 base::FundamentalValue number(page_number); 568 base::FundamentalValue number(page_number);
570 base::FundamentalValue ui_identifier(id_); 569 base::FundamentalValue ui_identifier(id_);
571 base::FundamentalValue request_id(preview_request_id); 570 base::FundamentalValue request_id(preview_request_id);
572 if (g_testing_delegate) 571 if (g_testing_delegate)
573 g_testing_delegate->DidRenderPreviewPage(web_ui()->GetWebContents()); 572 g_testing_delegate->DidRenderPreviewPage(web_ui()->GetWebContents());
574 web_ui()->CallJavascriptFunction( 573 web_ui()->CallJavascriptFunctionUnsafe("onDidPreviewPage", number,
575 "onDidPreviewPage", number, ui_identifier, request_id); 574 ui_identifier, request_id);
576 if (g_testing_delegate && g_testing_delegate->IsAutoCancelEnabled()) 575 if (g_testing_delegate && g_testing_delegate->IsAutoCancelEnabled())
577 web_ui()->CallJavascriptFunction("autoCancelForTesting"); 576 web_ui()->CallJavascriptFunctionUnsafe("autoCancelForTesting");
578 } 577 }
579 578
580 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, 579 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count,
581 int preview_request_id) { 580 int preview_request_id) {
582 VLOG(1) << "Print preview request finished with " 581 VLOG(1) << "Print preview request finished with "
583 << expected_pages_count << " pages"; 582 << expected_pages_count << " pages";
584 583
585 if (!initial_preview_start_time_.is_null()) { 584 if (!initial_preview_start_time_.is_null()) {
586 UMA_HISTOGRAM_TIMES("PrintPreview.InitialDisplayTime", 585 UMA_HISTOGRAM_TIMES("PrintPreview.InitialDisplayTime",
587 base::TimeTicks::Now() - initial_preview_start_time_); 586 base::TimeTicks::Now() - initial_preview_start_time_);
588 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.Initial", 587 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.Initial",
589 expected_pages_count); 588 expected_pages_count);
590 UMA_HISTOGRAM_COUNTS( 589 UMA_HISTOGRAM_COUNTS(
591 "PrintPreview.RegeneratePreviewRequest.BeforeFirstData", 590 "PrintPreview.RegeneratePreviewRequest.BeforeFirstData",
592 handler_->regenerate_preview_request_count()); 591 handler_->regenerate_preview_request_count());
593 initial_preview_start_time_ = base::TimeTicks(); 592 initial_preview_start_time_ = base::TimeTicks();
594 } 593 }
595 base::FundamentalValue ui_identifier(id_); 594 base::FundamentalValue ui_identifier(id_);
596 base::FundamentalValue ui_preview_request_id(preview_request_id); 595 base::FundamentalValue ui_preview_request_id(preview_request_id);
597 web_ui()->CallJavascriptFunction("updatePrintPreview", ui_identifier, 596 web_ui()->CallJavascriptFunctionUnsafe("updatePrintPreview", ui_identifier,
598 ui_preview_request_id); 597 ui_preview_request_id);
599 } 598 }
600 599
601 void PrintPreviewUI::OnFileSelectionCancelled() { 600 void PrintPreviewUI::OnFileSelectionCancelled() {
602 web_ui()->CallJavascriptFunction("fileSelectionCancelled"); 601 web_ui()->CallJavascriptFunctionUnsafe("fileSelectionCancelled");
603 } 602 }
604 603
605 void PrintPreviewUI::OnCancelPendingPreviewRequest() { 604 void PrintPreviewUI::OnCancelPendingPreviewRequest() {
606 g_print_preview_request_id_map.Get().Set(id_, -1); 605 g_print_preview_request_id_map.Get().Set(id_, -1);
607 } 606 }
608 607
609 void PrintPreviewUI::OnPrintPreviewFailed() { 608 void PrintPreviewUI::OnPrintPreviewFailed() {
610 handler_->OnPrintPreviewFailed(); 609 handler_->OnPrintPreviewFailed();
611 web_ui()->CallJavascriptFunction("printPreviewFailed"); 610 web_ui()->CallJavascriptFunctionUnsafe("printPreviewFailed");
612 } 611 }
613 612
614 void PrintPreviewUI::OnInvalidPrinterSettings() { 613 void PrintPreviewUI::OnInvalidPrinterSettings() {
615 web_ui()->CallJavascriptFunction("invalidPrinterSettings"); 614 web_ui()->CallJavascriptFunctionUnsafe("invalidPrinterSettings");
616 } 615 }
617 616
618 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() { 617 PrintPreviewDataService* PrintPreviewUI::print_preview_data_service() {
619 return PrintPreviewDataService::GetInstance(); 618 return PrintPreviewDataService::GetInstance();
620 } 619 }
621 620
622 void PrintPreviewUI::OnHidePreviewDialog() { 621 void PrintPreviewUI::OnHidePreviewDialog() {
623 WebContents* preview_dialog = web_ui()->GetWebContents(); 622 WebContents* preview_dialog = web_ui()->GetWebContents();
624 printing::BackgroundPrintingManager* background_printing_manager = 623 printing::BackgroundPrintingManager* background_printing_manager =
625 g_browser_process->background_printing_manager(); 624 g_browser_process->background_printing_manager();
(...skipping 13 matching lines...) Expand all
639 return; 638 return;
640 dialog_closed_ = true; 639 dialog_closed_ = true;
641 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate(); 640 ConstrainedWebDialogDelegate* delegate = GetConstrainedDelegate();
642 if (!delegate) 641 if (!delegate)
643 return; 642 return;
644 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string()); 643 delegate->GetWebDialogDelegate()->OnDialogClosed(std::string());
645 delegate->OnDialogCloseFromWebUI(); 644 delegate->OnDialogCloseFromWebUI();
646 } 645 }
647 646
648 void PrintPreviewUI::OnReloadPrintersList() { 647 void PrintPreviewUI::OnReloadPrintersList() {
649 web_ui()->CallJavascriptFunction("reloadPrintersList"); 648 web_ui()->CallJavascriptFunctionUnsafe("reloadPrintersList");
650 } 649 }
651 650
652 void PrintPreviewUI::OnSetOptionsFromDocument( 651 void PrintPreviewUI::OnSetOptionsFromDocument(
653 const PrintHostMsg_SetOptionsFromDocument_Params& params) { 652 const PrintHostMsg_SetOptionsFromDocument_Params& params) {
654 base::DictionaryValue options; 653 base::DictionaryValue options;
655 options.SetBoolean(printing::kSettingDisableScaling, 654 options.SetBoolean(printing::kSettingDisableScaling,
656 params.is_scaling_disabled); 655 params.is_scaling_disabled);
657 options.SetInteger(printing::kSettingCopies, params.copies); 656 options.SetInteger(printing::kSettingCopies, params.copies);
658 options.SetInteger(printing::kSettingDuplexMode, params.duplex); 657 options.SetInteger(printing::kSettingDuplexMode, params.duplex);
659 web_ui()->CallJavascriptFunction("printPresetOptionsFromDocument", options); 658 web_ui()->CallJavascriptFunctionUnsafe("printPresetOptionsFromDocument",
659 options);
660 } 660 }
661 661
662 // static 662 // static
663 void PrintPreviewUI::SetDelegateForTesting(TestingDelegate* delegate) { 663 void PrintPreviewUI::SetDelegateForTesting(TestingDelegate* delegate) {
664 g_testing_delegate = delegate; 664 g_testing_delegate = delegate;
665 } 665 }
666 666
667 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) { 667 void PrintPreviewUI::SetSelectedFileForTesting(const base::FilePath& path) {
668 handler_->FileSelected(path, 0, NULL); 668 handler_->FileSelected(path, 0, NULL);
669 } 669 }
670 670
671 void PrintPreviewUI::SetPdfSavedClosureForTesting( 671 void PrintPreviewUI::SetPdfSavedClosureForTesting(
672 const base::Closure& closure) { 672 const base::Closure& closure) {
673 handler_->SetPdfSavedClosureForTesting(closure); 673 handler_->SetPdfSavedClosureForTesting(closure);
674 } 674 }
675 675
676 base::WeakPtr<PrintPreviewUI> PrintPreviewUI::GetWeakPtr() { 676 base::WeakPtr<PrintPreviewUI> PrintPreviewUI::GetWeakPtr() {
677 return weak_ptr_factory_.GetWeakPtr(); 677 return weak_ptr_factory_.GetWeakPtr();
678 } 678 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/print_preview/print_preview_handler.cc ('k') | chrome/browser/ui/webui/profiler_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698