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_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/id_map.h" | 9 #include "base/id_map.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 source->AddResourcePath("images/pdf.png", IDR_PRINT_PREVIEW_IMAGES_PDF); | 331 source->AddResourcePath("images/pdf.png", IDR_PRINT_PREVIEW_IMAGES_PDF); |
332 source->AddResourcePath("images/mobile.png", IDR_PRINT_PREVIEW_IMAGES_MOBILE); | 332 source->AddResourcePath("images/mobile.png", IDR_PRINT_PREVIEW_IMAGES_MOBILE); |
333 source->AddResourcePath("images/mobile_shared.png", | 333 source->AddResourcePath("images/mobile_shared.png", |
334 IDR_PRINT_PREVIEW_IMAGES_MOBILE_SHARED); | 334 IDR_PRINT_PREVIEW_IMAGES_MOBILE_SHARED); |
335 source->SetDefaultResource(IDR_PRINT_PREVIEW_HTML); | 335 source->SetDefaultResource(IDR_PRINT_PREVIEW_HTML); |
336 source->SetRequestFilter(base::Bind(&HandleRequestCallback)); | 336 source->SetRequestFilter(base::Bind(&HandleRequestCallback)); |
337 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';"); | 337 source->OverrideContentSecurityPolicyObjectSrc("object-src 'self';"); |
338 return source; | 338 return source; |
339 } | 339 } |
340 | 340 |
| 341 int g_auto_cancel_count_for_testing_ = -1; // Disabled if count < 0. |
| 342 |
| 343 void EnableAutoCancelAndResetCountForTesting() { |
| 344 g_auto_cancel_count_for_testing_ = 0; |
| 345 } |
| 346 |
| 347 void DisableAutoCancelForTesting() { |
| 348 g_auto_cancel_count_for_testing_ = -1; |
| 349 } |
| 350 |
| 351 bool IsAutoCancelEnabledForTesting() { |
| 352 return (g_auto_cancel_count_for_testing_ >= 0); |
| 353 } |
| 354 |
| 355 void IncrementAutoCancelCountForTesting() { |
| 356 if (g_auto_cancel_count_for_testing_ >= 0) |
| 357 ++g_auto_cancel_count_for_testing_; |
| 358 } |
| 359 |
| 360 int GetAutoCancelCountForTesting() { |
| 361 return std::max(g_auto_cancel_count_for_testing_, -1); |
| 362 } |
| 363 |
341 } // namespace | 364 } // namespace |
342 | 365 |
343 PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) | 366 PrintPreviewUI::PrintPreviewUI(content::WebUI* web_ui) |
344 : ConstrainedWebDialogUI(web_ui), | 367 : ConstrainedWebDialogUI(web_ui), |
345 initial_preview_start_time_(base::TimeTicks::Now()), | 368 initial_preview_start_time_(base::TimeTicks::Now()), |
346 id_(g_print_preview_ui_id_map.Get().Add(this)), | 369 id_(g_print_preview_ui_id_map.Get().Add(this)), |
347 handler_(NULL), | 370 handler_(NULL), |
348 source_is_modifiable_(true), | 371 source_is_modifiable_(true), |
349 source_has_selection_(false), | 372 source_has_selection_(false), |
350 dialog_closed_(false) { | 373 dialog_closed_(false) { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 | 536 |
514 if (!initial_preview_start_time_.is_null()) { | 537 if (!initial_preview_start_time_.is_null()) { |
515 UMA_HISTOGRAM_TIMES("PrintPreview.InitialDisplayTime", | 538 UMA_HISTOGRAM_TIMES("PrintPreview.InitialDisplayTime", |
516 base::TimeTicks::Now() - initial_preview_start_time_); | 539 base::TimeTicks::Now() - initial_preview_start_time_); |
517 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.Initial", | 540 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.Initial", |
518 expected_pages_count); | 541 expected_pages_count); |
519 initial_preview_start_time_ = base::TimeTicks(); | 542 initial_preview_start_time_ = base::TimeTicks(); |
520 } | 543 } |
521 base::FundamentalValue ui_identifier(id_); | 544 base::FundamentalValue ui_identifier(id_); |
522 base::FundamentalValue ui_preview_request_id(preview_request_id); | 545 base::FundamentalValue ui_preview_request_id(preview_request_id); |
523 if (ScopedAutoCancelForTesting::IsEnabledForTesting()) { | 546 if (IsAutoCancelEnabledForTesting()) { |
524 ScopedAutoCancelForTesting::IncrementCountForTesting(); | 547 IncrementAutoCancelCountForTesting(); |
525 OnClosePrintPreviewDialog(); | 548 OnClosePrintPreviewDialog(); |
526 } else { | 549 } else { |
527 web_ui()->CallJavascriptFunction("updatePrintPreview", ui_identifier, | 550 web_ui()->CallJavascriptFunction("updatePrintPreview", ui_identifier, |
528 ui_preview_request_id); | 551 ui_preview_request_id); |
529 } | 552 } |
530 } | 553 } |
531 | 554 |
532 void PrintPreviewUI::OnPrintPreviewDialogDestroyed() { | 555 void PrintPreviewUI::OnPrintPreviewDialogDestroyed() { |
533 handler_->OnPrintPreviewDialogDestroyed(); | 556 handler_->OnPrintPreviewDialogDestroyed(); |
534 } | 557 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
581 } | 604 } |
582 | 605 |
583 void PrintPreviewUI::OnReloadPrintersList() { | 606 void PrintPreviewUI::OnReloadPrintersList() { |
584 web_ui()->CallJavascriptFunction("reloadPrintersList"); | 607 web_ui()->CallJavascriptFunction("reloadPrintersList"); |
585 } | 608 } |
586 | 609 |
587 void PrintPreviewUI::OnPrintPreviewScalingDisabled() { | 610 void PrintPreviewUI::OnPrintPreviewScalingDisabled() { |
588 web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF"); | 611 web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF"); |
589 } | 612 } |
590 | 613 |
591 static int g_auto_cancel_count_for_testing_ = -1; // Disabled if count < 0. | |
592 | |
593 PrintPreviewUI::ScopedAutoCancelForTesting::ScopedAutoCancelForTesting() { | 614 PrintPreviewUI::ScopedAutoCancelForTesting::ScopedAutoCancelForTesting() { |
594 g_auto_cancel_count_for_testing_ = 0; | 615 EnableAutoCancelAndResetCountForTesting(); |
595 } | 616 } |
596 | 617 |
597 PrintPreviewUI::ScopedAutoCancelForTesting::~ScopedAutoCancelForTesting() { | 618 PrintPreviewUI::ScopedAutoCancelForTesting::~ScopedAutoCancelForTesting() { |
598 g_auto_cancel_count_for_testing_ = -1; | 619 DisableAutoCancelForTesting(); |
599 } | |
600 | |
601 bool PrintPreviewUI::ScopedAutoCancelForTesting::IsEnabledForTesting() { | |
602 return (g_auto_cancel_count_for_testing_ >= 0); | |
603 } | |
604 | |
605 void PrintPreviewUI::ScopedAutoCancelForTesting::IncrementCountForTesting() { | |
606 if (g_auto_cancel_count_for_testing_ >= 0) | |
607 ++g_auto_cancel_count_for_testing_; | |
608 } | 620 } |
609 | 621 |
610 int PrintPreviewUI::ScopedAutoCancelForTesting::GetCountForTesting() { | 622 int PrintPreviewUI::ScopedAutoCancelForTesting::GetCountForTesting() { |
611 return std::max(g_auto_cancel_count_for_testing_, -1); | 623 return GetAutoCancelCountForTesting(); |
612 } | 624 } |
OLD | NEW |