| 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" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/webui/print_preview_data_source.h" | 12 #include "chrome/browser/ui/webui/print_preview_data_source.h" |
| 13 #include "chrome/browser/ui/webui/print_preview_handler.h" | 13 #include "chrome/browser/ui/webui/print_preview_handler.h" |
| 14 #include "chrome/common/print_messages.h" |
| 14 #include "content/browser/tab_contents/tab_contents.h" | 15 #include "content/browser/tab_contents/tab_contents.h" |
| 15 | 16 |
| 16 PrintPreviewUI::PrintPreviewUI(TabContents* contents) | 17 PrintPreviewUI::PrintPreviewUI(TabContents* contents) |
| 17 : ChromeWebUI(contents), | 18 : ChromeWebUI(contents), |
| 18 initial_preview_start_time_(base::TimeTicks::Now()), | 19 initial_preview_start_time_(base::TimeTicks::Now()), |
| 19 request_count_(0U), | 20 request_count_(0U), |
| 20 document_cookie_(0) { | 21 document_cookie_(0) { |
| 21 // WebUI owns |handler_|. | 22 // WebUI owns |handler_|. |
| 22 handler_ = new PrintPreviewHandler(); | 23 handler_ = new PrintPreviewHandler(); |
| 23 AddMessageHandler(handler_->Attach(this)); | 24 AddMessageHandler(handler_->Attach(this)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 void PrintPreviewUI::OnInitiatorTabClosed( | 57 void PrintPreviewUI::OnInitiatorTabClosed( |
| 57 const std::string& initiator_url) { | 58 const std::string& initiator_url) { |
| 58 StringValue initiator_tab_url(initiator_url); | 59 StringValue initiator_tab_url(initiator_url); |
| 59 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); | 60 CallJavascriptFunction("onInitiatorTabClosed", initiator_tab_url); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void PrintPreviewUI::OnPrintPreviewRequest() { | 63 void PrintPreviewUI::OnPrintPreviewRequest() { |
| 63 request_count_++; | 64 request_count_++; |
| 64 } | 65 } |
| 65 | 66 |
| 66 void PrintPreviewUI::OnDidGetPreviewPageCount(int document_cookie, | 67 void PrintPreviewUI::OnDidGetPreviewPageCount( |
| 67 int page_count, | 68 const PrintHostMsg_DidGetPreviewPageCount_Params& params) { |
| 68 bool is_modifiable) { | 69 DCHECK_GT(params.page_count, 0); |
| 69 DCHECK_GT(page_count, 0); | 70 document_cookie_ = params.document_cookie; |
| 70 document_cookie_ = document_cookie; | 71 base::FundamentalValue count(params.page_count); |
| 71 base::FundamentalValue count(page_count); | 72 base::FundamentalValue modifiable(params.is_modifiable); |
| 72 base::FundamentalValue modifiable(is_modifiable); | 73 base::FundamentalValue request_id(params.preview_request_id); |
| 73 CallJavascriptFunction("onDidGetPreviewPageCount", count, modifiable); | 74 CallJavascriptFunction("onDidGetPreviewPageCount", count, modifiable, |
| 75 request_id); |
| 74 } | 76 } |
| 75 | 77 |
| 76 void PrintPreviewUI::OnDidPreviewPage(int page_number) { | 78 void PrintPreviewUI::OnDidPreviewPage(int page_number, |
| 79 int preview_request_id) { |
| 77 DCHECK_GE(page_number, 0); | 80 DCHECK_GE(page_number, 0); |
| 78 base::FundamentalValue number(page_number); | 81 base::FundamentalValue number(page_number); |
| 79 base::StringValue ui_identifier(preview_ui_addr_str_); | 82 StringValue ui_identifier(preview_ui_addr_str_); |
| 80 CallJavascriptFunction("onDidPreviewPage", number, ui_identifier); | 83 base::FundamentalValue request_id(preview_request_id); |
| 84 CallJavascriptFunction("onDidPreviewPage", number, ui_identifier, request_id); |
| 81 } | 85 } |
| 82 | 86 |
| 83 void PrintPreviewUI::OnReusePreviewData(int preview_request_id) { | 87 void PrintPreviewUI::OnReusePreviewData(int preview_request_id) { |
| 84 DecrementRequestCount(); | 88 DecrementRequestCount(); |
| 85 | 89 |
| 86 base::StringValue ui_identifier(preview_ui_addr_str_); | 90 base::StringValue ui_identifier(preview_ui_addr_str_); |
| 87 base::FundamentalValue ui_preview_request_id(preview_request_id); | 91 base::FundamentalValue ui_preview_request_id(preview_request_id); |
| 88 CallJavascriptFunction("reloadPreviewPages", ui_identifier, | 92 CallJavascriptFunction("reloadPreviewPages", ui_identifier, |
| 89 ui_preview_request_id); | 93 ui_preview_request_id); |
| 90 } | 94 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 140 } |
| 137 | 141 |
| 138 void PrintPreviewUI::DecrementRequestCount() { | 142 void PrintPreviewUI::DecrementRequestCount() { |
| 139 if (request_count_ > 0) | 143 if (request_count_ > 0) |
| 140 request_count_--; | 144 request_count_--; |
| 141 } | 145 } |
| 142 | 146 |
| 143 int PrintPreviewUI::document_cookie() { | 147 int PrintPreviewUI::document_cookie() { |
| 144 return document_cookie_; | 148 return document_cookie_; |
| 145 } | 149 } |
| OLD | NEW |