| 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_ui.h" | 5 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 6 | 6 |
| 7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/printing/print_preview_data_service.h" | 10 #include "chrome/browser/printing/print_preview_data_service.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 | 61 |
| 62 void PrintPreviewUI::OnPrintPreviewRequest() { | 62 void PrintPreviewUI::OnPrintPreviewRequest() { |
| 63 request_count_++; | 63 request_count_++; |
| 64 } | 64 } |
| 65 | 65 |
| 66 void PrintPreviewUI::OnDidGetPreviewPageCount(int document_cookie, | 66 void PrintPreviewUI::OnDidGetPreviewPageCount(int document_cookie, |
| 67 int page_count, | 67 int page_count, |
| 68 bool is_modifiable) { | 68 bool is_modifiable) { |
| 69 DCHECK_GT(page_count, 0); | 69 DCHECK_GT(page_count, 0); |
| 70 document_cookie_ = document_cookie; | 70 document_cookie_ = document_cookie; |
| 71 FundamentalValue count(page_count); | 71 base::FundamentalValue count(page_count); |
| 72 FundamentalValue modifiable(is_modifiable); | 72 base::FundamentalValue modifiable(is_modifiable); |
| 73 CallJavascriptFunction("onDidGetPreviewPageCount", count, modifiable); | 73 CallJavascriptFunction("onDidGetPreviewPageCount", count, modifiable); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void PrintPreviewUI::OnDidPreviewPage(int page_number) { | 76 void PrintPreviewUI::OnDidPreviewPage(int page_number) { |
| 77 DCHECK_GE(page_number, 0); | 77 DCHECK_GE(page_number, 0); |
| 78 FundamentalValue number(page_number); | 78 base::FundamentalValue number(page_number); |
| 79 StringValue ui_identifier(preview_ui_addr_str_); | 79 base::StringValue ui_identifier(preview_ui_addr_str_); |
| 80 CallJavascriptFunction("onDidPreviewPage", number, ui_identifier); | 80 CallJavascriptFunction("onDidPreviewPage", number, ui_identifier); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void PrintPreviewUI::OnReusePreviewData(int preview_request_id) { | 83 void PrintPreviewUI::OnReusePreviewData(int preview_request_id) { |
| 84 DecrementRequestCount(); | 84 DecrementRequestCount(); |
| 85 | 85 |
| 86 StringValue ui_identifier(preview_ui_addr_str_); | 86 base::StringValue ui_identifier(preview_ui_addr_str_); |
| 87 FundamentalValue ui_preview_request_id(preview_request_id); | 87 base::FundamentalValue ui_preview_request_id(preview_request_id); |
| 88 CallJavascriptFunction("reloadPreviewPages", ui_identifier, | 88 CallJavascriptFunction("reloadPreviewPages", ui_identifier, |
| 89 ui_preview_request_id); | 89 ui_preview_request_id); |
| 90 } | 90 } |
| 91 | 91 |
| 92 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, | 92 void PrintPreviewUI::OnPreviewDataIsAvailable(int expected_pages_count, |
| 93 const string16& job_title, | 93 const string16& job_title, |
| 94 int preview_request_id) { | 94 int preview_request_id) { |
| 95 VLOG(1) << "Print preview request finished with " | 95 VLOG(1) << "Print preview request finished with " |
| 96 << expected_pages_count << " pages"; | 96 << expected_pages_count << " pages"; |
| 97 DecrementRequestCount(); | 97 DecrementRequestCount(); |
| 98 | 98 |
| 99 if (!initial_preview_start_time_.is_null()) { | 99 if (!initial_preview_start_time_.is_null()) { |
| 100 UMA_HISTOGRAM_TIMES("PrintPreview.InitalDisplayTime", | 100 UMA_HISTOGRAM_TIMES("PrintPreview.InitalDisplayTime", |
| 101 base::TimeTicks::Now() - initial_preview_start_time_); | 101 base::TimeTicks::Now() - initial_preview_start_time_); |
| 102 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.Initial", | 102 UMA_HISTOGRAM_COUNTS("PrintPreview.PageCount.Initial", |
| 103 expected_pages_count); | 103 expected_pages_count); |
| 104 initial_preview_start_time_ = base::TimeTicks(); | 104 initial_preview_start_time_ = base::TimeTicks(); |
| 105 } | 105 } |
| 106 StringValue title(job_title); | 106 base::StringValue title(job_title); |
| 107 StringValue ui_identifier(preview_ui_addr_str_); | 107 base::StringValue ui_identifier(preview_ui_addr_str_); |
| 108 FundamentalValue ui_preview_request_id(preview_request_id); | 108 base::FundamentalValue ui_preview_request_id(preview_request_id); |
| 109 CallJavascriptFunction("updatePrintPreview", title, ui_identifier, | 109 CallJavascriptFunction("updatePrintPreview", title, ui_identifier, |
| 110 ui_preview_request_id); | 110 ui_preview_request_id); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void PrintPreviewUI::OnNavigation() { | 113 void PrintPreviewUI::OnNavigation() { |
| 114 handler_->OnNavigation(); | 114 handler_->OnNavigation(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void PrintPreviewUI::OnFileSelectionCancelled() { | 117 void PrintPreviewUI::OnFileSelectionCancelled() { |
| 118 CallJavascriptFunction("fileSelectionCancelled"); | 118 CallJavascriptFunction("fileSelectionCancelled"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 void PrintPreviewUI::DecrementRequestCount() { | 138 void PrintPreviewUI::DecrementRequestCount() { |
| 139 if (request_count_ > 0) | 139 if (request_count_ > 0) |
| 140 request_count_--; | 140 request_count_--; |
| 141 } | 141 } |
| 142 | 142 |
| 143 int PrintPreviewUI::document_cookie() { | 143 int PrintPreviewUI::document_cookie() { |
| 144 return document_cookie_; | 144 return document_cookie_; |
| 145 } | 145 } |
| OLD | NEW |