| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #if !defined(OS_CHROMEOS) | 10 #if !defined(OS_CHROMEOS) |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 #endif | 69 #endif |
| 70 | 70 |
| 71 enum UserActionBuckets { | 71 enum UserActionBuckets { |
| 72 PRINT_TO_PRINTER, | 72 PRINT_TO_PRINTER, |
| 73 PRINT_TO_PDF, | 73 PRINT_TO_PDF, |
| 74 CANCEL, | 74 CANCEL, |
| 75 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, | 75 FALLBACK_TO_ADVANCED_SETTINGS_DIALOG, |
| 76 PREVIEW_FAILED, | 76 PREVIEW_FAILED, |
| 77 PREVIEW_STARTED, | 77 PREVIEW_STARTED, |
| 78 INITIATOR_TAB_CRASHED, | 78 INITIATOR_TAB_CRASHED, |
| 79 INITIATOR_TAB_CLOSED, |
| 79 USERACTION_BUCKET_BOUNDARY | 80 USERACTION_BUCKET_BOUNDARY |
| 80 }; | 81 }; |
| 81 | 82 |
| 82 enum PrintSettingsBuckets { | 83 enum PrintSettingsBuckets { |
| 83 LANDSCAPE, | 84 LANDSCAPE, |
| 84 PORTRAIT, | 85 PORTRAIT, |
| 85 COLOR, | 86 COLOR, |
| 86 BLACK_AND_WHITE, | 87 BLACK_AND_WHITE, |
| 87 COLLATE, | 88 COLLATE, |
| 88 SIMPLEX, | 89 SIMPLEX, |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO | 489 // when calling PrintPreviewUI::GetCurrentPrintPreviewStatus() on the IO |
| 489 // thread. | 490 // thread. |
| 490 settings->SetString(printing::kPreviewUIAddr, | 491 settings->SetString(printing::kPreviewUIAddr, |
| 491 print_preview_ui->GetPrintPreviewUIAddress()); | 492 print_preview_ui->GetPrintPreviewUIAddress()); |
| 492 | 493 |
| 493 // Increment request count. | 494 // Increment request count. |
| 494 ++regenerate_preview_request_count_; | 495 ++regenerate_preview_request_count_; |
| 495 | 496 |
| 496 TabContents* initiator_tab = GetInitiatorTab(); | 497 TabContents* initiator_tab = GetInitiatorTab(); |
| 497 if (!initiator_tab) { | 498 if (!initiator_tab) { |
| 498 if (!reported_failed_preview_) { | 499 ReportUserActionHistogram(INITIATOR_TAB_CLOSED); |
| 499 ReportUserActionHistogram(PREVIEW_FAILED); | 500 print_preview_ui->OnInitiatorTabClosed(); |
| 500 reported_failed_preview_ = true; | |
| 501 } | |
| 502 print_preview_ui->OnPrintPreviewFailed(); | |
| 503 return; | 501 return; |
| 504 } | 502 } |
| 505 | 503 |
| 506 // Retrieve the page title and url and send it to the renderer process if | 504 // Retrieve the page title and url and send it to the renderer process if |
| 507 // headers and footers are to be displayed. | 505 // headers and footers are to be displayed. |
| 508 bool display_header_footer = false; | 506 bool display_header_footer = false; |
| 509 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, | 507 if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled, |
| 510 &display_header_footer)) { | 508 &display_header_footer)) { |
| 511 NOTREACHED(); | 509 NOTREACHED(); |
| 512 } | 510 } |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 void PrintPreviewHandler::OnTabDestroyed() { | 877 void PrintPreviewHandler::OnTabDestroyed() { |
| 880 TabContents* initiator_tab = GetInitiatorTab(); | 878 TabContents* initiator_tab = GetInitiatorTab(); |
| 881 if (!initiator_tab) | 879 if (!initiator_tab) |
| 882 return; | 880 return; |
| 883 | 881 |
| 884 TabContentsWrapper* wrapper = | 882 TabContentsWrapper* wrapper = |
| 885 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); | 883 TabContentsWrapper::GetCurrentWrapperForContents(initiator_tab); |
| 886 wrapper->print_view_manager()->set_observer(NULL); | 884 wrapper->print_view_manager()->set_observer(NULL); |
| 887 } | 885 } |
| 888 | 886 |
| 887 void PrintPreviewHandler::OnPrintPreviewFailed() { |
| 888 if (reported_failed_preview_) |
| 889 return; |
| 890 reported_failed_preview_ = true; |
| 891 ReportUserActionHistogram(PREVIEW_FAILED); |
| 892 } |
| 893 |
| 889 void PrintPreviewHandler::FileSelected(const FilePath& path, | 894 void PrintPreviewHandler::FileSelected(const FilePath& path, |
| 890 int index, void* params) { | 895 int index, void* params) { |
| 891 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); | 896 PrintPreviewUI* print_preview_ui = static_cast<PrintPreviewUI*>(web_ui_); |
| 892 scoped_refptr<RefCountedBytes> data; | 897 scoped_refptr<RefCountedBytes> data; |
| 893 print_preview_ui->GetPrintPreviewDataForIndex( | 898 print_preview_ui->GetPrintPreviewDataForIndex( |
| 894 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); | 899 printing::COMPLETE_PREVIEW_DOCUMENT_INDEX, &data); |
| 895 if (!data.get()) { | 900 if (!data.get()) { |
| 896 NOTREACHED(); | 901 NOTREACHED(); |
| 897 return; | 902 return; |
| 898 } | 903 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 928 return; | 933 return; |
| 929 | 934 |
| 930 // We no longer require the initiator tab details. Remove those details | 935 // We no longer require the initiator tab details. Remove those details |
| 931 // associated with the preview tab to allow the initiator tab to create | 936 // associated with the preview tab to allow the initiator tab to create |
| 932 // another preview tab. | 937 // another preview tab. |
| 933 printing::PrintPreviewTabController* tab_controller = | 938 printing::PrintPreviewTabController* tab_controller = |
| 934 printing::PrintPreviewTabController::GetInstance(); | 939 printing::PrintPreviewTabController::GetInstance(); |
| 935 if (tab_controller) | 940 if (tab_controller) |
| 936 tab_controller->EraseInitiatorTabInfo(preview_tab()); | 941 tab_controller->EraseInitiatorTabInfo(preview_tab()); |
| 937 } | 942 } |
| OLD | NEW |