Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: chrome/browser/printing/print_preview_message_handler.cc

Issue 7550022: Print Preview: Fixing behavior of event listeners. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding new struct PrintHostMsg_DidGetPreviewPageCount_Params. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
85 bool is_modifiable) { 85 if (params.page_count <= 0)
86 if (page_count <= 0)
87 return; 86 return;
88 TabContents* print_preview_tab = GetPrintPreviewTab(); 87 TabContents* print_preview_tab = GetPrintPreviewTab();
89 if (!print_preview_tab) 88 if (!print_preview_tab)
90 return; 89 return;
91 90
92 PrintPreviewUI* print_preview_ui = 91 PrintPreviewUI* print_preview_ui =
93 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); 92 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
94 print_preview_ui->OnDidGetPreviewPageCount( 93 print_preview_ui->OnDidGetPreviewPageCount(
kmadhusu 2011/08/08 22:20:45 You can change PrintPreviewUI::OnDidGetPreviewPage
dpapad 2011/08/08 23:41:43 I could, but I did not do it for consistency. None
kmadhusu 2011/08/09 22:30:40 No other method in PrintPreviewUI uses all of the
dpapad 2011/08/10 00:17:10 Done.
95 document_cookie, page_count, is_modifiable); 94 params.document_cookie, params.page_count, params.is_modifiable,
95 params.preview_request_id);
96 } 96 }
97 97
98 void PrintPreviewMessageHandler::OnDidPreviewPage( 98 void PrintPreviewMessageHandler::OnDidPreviewPage(
99 const PrintHostMsg_DidPreviewPage_Params& params) { 99 const PrintHostMsg_DidPreviewPage_Params& params) {
100 RenderViewHost* rvh = tab_contents()->render_view_host(); 100 RenderViewHost* rvh = tab_contents()->render_view_host();
101 TabContents* print_preview_tab = GetPrintPreviewTab(); 101 TabContents* print_preview_tab = GetPrintPreviewTab();
102 if (!(print_preview_tab && print_preview_tab->web_ui())) { 102 if (!(print_preview_tab && print_preview_tab->web_ui())) {
103 // Can't find print preview tab means we should abort. 103 // Can't find print preview tab means we should abort.
104 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id())); 104 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id()));
105 return; 105 return;
(...skipping 15 matching lines...) Expand all
121 121
122 if (page_number == FIRST_PAGE_INDEX) 122 if (page_number == FIRST_PAGE_INDEX)
123 print_preview_ui->ClearAllPreviewData(); 123 print_preview_ui->ClearAllPreviewData();
124 124
125 if (page_number >= FIRST_PAGE_INDEX && params.data_size) { 125 if (page_number >= FIRST_PAGE_INDEX && params.data_size) {
126 RefCountedBytes* data_bytes = 126 RefCountedBytes* data_bytes =
127 GetDataFromHandle(params.metafile_data_handle, params.data_size); 127 GetDataFromHandle(params.metafile_data_handle, params.data_size);
128 DCHECK(data_bytes); 128 DCHECK(data_bytes);
129 129
130 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes); 130 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes);
131 print_preview_ui->OnDidPreviewPage(page_number); 131 print_preview_ui->OnDidPreviewPage(page_number, params.preview_request_id);
132 // TODO(kmadhusu): Query |PrintPreviewUI| and update 132 // TODO(kmadhusu): Query |PrintPreviewUI| and update
133 // |requested_preview_page_index| accordingly. 133 // |requested_preview_page_index| accordingly.
134 } 134 }
135 135
136 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id(), 136 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id(),
137 requested_preview_page_index)); 137 requested_preview_page_index));
138 } 138 }
139 139
140 void PrintPreviewMessageHandler::OnPagesReadyForPreview( 140 void PrintPreviewMessageHandler::OnPagesReadyForPreview(
141 const PrintHostMsg_DidPreviewDocument_Params& params) { 141 const PrintHostMsg_DidPreviewDocument_Params& params) {
142 StopWorker(params.document_cookie); 142 StopWorker(params.document_cookie);
143 143
144 // Get the print preview tab. 144 // Get the print preview tab.
145 TabContents* print_preview_tab = GetPrintPreviewTab(); 145 TabContents* print_preview_tab = GetPrintPreviewTab();
146 // User might have closed it already. 146 // User might have closed it already.
147 if (!print_preview_tab) 147 if (!print_preview_tab)
148 return; 148 return;
149 149
150 PrintPreviewUI* print_preview_ui = 150 PrintPreviewUI* print_preview_ui =
151 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); 151 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
152 152
153 TabContentsWrapper* wrapper = 153 TabContentsWrapper* wrapper =
154 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); 154 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab);
155 155
156 if (params.reuse_existing_data) { 156 if (params.reuse_existing_data) {
157 // Need to match normal rendering where we are expected to send this. 157 // Need to match normal rendering where we are expected to send this.
158 print_preview_ui->OnDidGetPreviewPageCount(params.document_cookie, 158 print_preview_ui->OnDidGetPreviewPageCount(params.document_cookie,
159 params.expected_pages_count, 159 params.expected_pages_count,
160 params.modifiable); 160 params.modifiable,
kmadhusu 2011/08/08 22:20:45 nit: Can you make this line style similar to line
dpapad 2011/08/08 23:41:43 Done.
161 params.preview_request_id);
161 162
162 print_preview_ui->OnReusePreviewData(params.preview_request_id); 163 print_preview_ui->OnReusePreviewData(params.preview_request_id);
163 return; 164 return;
164 } 165 }
165 166
166 wrapper->print_view_manager()->OverrideTitle(tab_contents()); 167 wrapper->print_view_manager()->OverrideTitle(tab_contents());
167 168
168 // TODO(joth): This seems like a good match for using RefCountedStaticMemory 169 // TODO(joth): This seems like a good match for using RefCountedStaticMemory
169 // to avoid the memory copy, but the SetPrintPreviewData call chain below 170 // to avoid the memory copy, but the SetPrintPreviewData call chain below
170 // needs updating to accept the RefCountedMemory* base class. 171 // needs updating to accept the RefCountedMemory* base class.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 226 }
226 227
227 void PrintPreviewMessageHandler::DidStartLoading() { 228 void PrintPreviewMessageHandler::DidStartLoading() {
228 if (tab_contents()->delegate() && 229 if (tab_contents()->delegate() &&
229 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { 230 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) {
230 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); 231 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT);
231 } 232 }
232 } 233 }
233 234
234 } // namespace printing 235 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698