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/printing/print_preview_message_handler.h" | 5 #include "chrome/browser/printing/print_preview_message_handler.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
10 #include "base/memory/ref_counted_memory.h" | 10 #include "base/memory/ref_counted_memory.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 printing::PrintPreviewTabController::GetInstance(); | 73 printing::PrintPreviewTabController::GetInstance(); |
74 if (!tab_controller) | 74 if (!tab_controller) |
75 return NULL; | 75 return NULL; |
76 return tab_controller->GetPrintPreviewForTab(tab_contents()); | 76 return tab_controller->GetPrintPreviewForTab(tab_contents()); |
77 } | 77 } |
78 | 78 |
79 void PrintPreviewMessageHandler::OnRequestPrintPreview() { | 79 void PrintPreviewMessageHandler::OnRequestPrintPreview() { |
80 PrintPreviewTabController::PrintPreview(tab_contents()); | 80 PrintPreviewTabController::PrintPreview(tab_contents()); |
81 } | 81 } |
82 | 82 |
83 void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(int document_cookie, | 83 void PrintPreviewMessageHandler::OnDidGetPreviewPageCount( |
84 int page_count, | 84 int document_cookie, |
85 bool is_modifiable) { | 85 int page_count, |
| 86 bool is_modifiable, |
| 87 bool clear_preview_data) { |
86 if (page_count <= 0) | 88 if (page_count <= 0) |
87 return; | 89 return; |
88 TabContents* print_preview_tab = GetPrintPreviewTab(); | 90 TabContents* print_preview_tab = GetPrintPreviewTab(); |
89 if (!print_preview_tab) | 91 if (!print_preview_tab) |
90 return; | 92 return; |
91 | 93 |
92 PrintPreviewUI* print_preview_ui = | 94 PrintPreviewUI* print_preview_ui = |
93 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | 95 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
| 96 |
| 97 if (!is_modifiable || clear_preview_data) |
| 98 print_preview_ui->ClearAllPreviewData(); |
| 99 |
94 print_preview_ui->OnDidGetPreviewPageCount( | 100 print_preview_ui->OnDidGetPreviewPageCount( |
95 document_cookie, page_count, is_modifiable); | 101 document_cookie, page_count, is_modifiable); |
96 } | 102 } |
97 | 103 |
98 void PrintPreviewMessageHandler::OnDidPreviewPage( | 104 void PrintPreviewMessageHandler::OnDidPreviewPage( |
99 const PrintHostMsg_DidPreviewPage_Params& params) { | 105 const PrintHostMsg_DidPreviewPage_Params& params) { |
100 RenderViewHost* rvh = tab_contents()->render_view_host(); | 106 RenderViewHost* rvh = tab_contents()->render_view_host(); |
101 TabContents* print_preview_tab = GetPrintPreviewTab(); | 107 TabContents* print_preview_tab = GetPrintPreviewTab(); |
102 if (!(print_preview_tab && print_preview_tab->web_ui())) { | 108 if (!(print_preview_tab && print_preview_tab->web_ui())) { |
103 // Can't find print preview tab means we should abort. | 109 // Can't find print preview tab means we should abort. |
104 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id())); | 110 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id())); |
105 return; | 111 return; |
106 } | 112 } |
107 | 113 |
108 PrintPreviewUI* print_preview_ui = | 114 PrintPreviewUI* print_preview_ui = |
109 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | 115 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
110 bool has_pending = print_preview_ui->HasPendingRequests(); | 116 bool has_pending = print_preview_ui->HasPendingRequests(); |
111 if (has_pending) { | 117 if (has_pending) { |
112 // Cancel. Next print preview request will cancel the current one. | 118 // Cancel. Next print preview request will cancel the current one. |
113 // Just do the required maintainance work here. | 119 // Just do the required maintainance work here. |
114 StopWorker(print_preview_ui->document_cookie()); | 120 StopWorker(print_preview_ui->document_cookie()); |
115 print_preview_ui->OnPrintPreviewCancelled(); | 121 print_preview_ui->OnPrintPreviewCancelled(); |
116 return; | 122 return; |
117 } | 123 } |
118 | 124 |
119 int requested_preview_page_index = INVALID_PAGE_INDEX; | |
120 int page_number = params.page_number; | 125 int page_number = params.page_number; |
121 | |
122 if (page_number == FIRST_PAGE_INDEX) | |
123 print_preview_ui->ClearAllPreviewData(); | |
124 | |
125 if (page_number >= FIRST_PAGE_INDEX && params.data_size) { | 126 if (page_number >= FIRST_PAGE_INDEX && params.data_size) { |
126 RefCountedBytes* data_bytes = | 127 RefCountedBytes* data_bytes = |
127 GetDataFromHandle(params.metafile_data_handle, params.data_size); | 128 GetDataFromHandle(params.metafile_data_handle, params.data_size); |
128 DCHECK(data_bytes); | 129 DCHECK(data_bytes); |
129 | 130 |
130 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes); | 131 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes); |
131 print_preview_ui->OnDidPreviewPage(page_number); | 132 print_preview_ui->OnDidPreviewPage(page_number); |
132 // TODO(kmadhusu): Query |PrintPreviewUI| and update | |
133 // |requested_preview_page_index| accordingly. | |
134 } | 133 } |
135 | 134 |
136 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id(), | 135 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id())); |
137 requested_preview_page_index)); | |
138 } | 136 } |
139 | 137 |
140 void PrintPreviewMessageHandler::OnPagesReadyForPreview( | 138 void PrintPreviewMessageHandler::OnPagesReadyForPreview( |
141 const PrintHostMsg_DidPreviewDocument_Params& params) { | 139 const PrintHostMsg_DidPreviewDocument_Params& params) { |
142 StopWorker(params.document_cookie); | 140 StopWorker(params.document_cookie); |
143 | 141 |
144 // Get the print preview tab. | 142 // Get the print preview tab. |
145 TabContents* print_preview_tab = GetPrintPreviewTab(); | 143 TabContents* print_preview_tab = GetPrintPreviewTab(); |
146 // User might have closed it already. | 144 // User might have closed it already. |
147 if (!print_preview_tab) | 145 if (!print_preview_tab) |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 } | 223 } |
226 | 224 |
227 void PrintPreviewMessageHandler::DidStartLoading() { | 225 void PrintPreviewMessageHandler::DidStartLoading() { |
228 if (tab_contents()->delegate() && | 226 if (tab_contents()->delegate() && |
229 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 227 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
230 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 228 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
231 } | 229 } |
232 } | 230 } |
233 | 231 |
234 } // namespace printing | 232 } // namespace printing |
OLD | NEW |