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

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: Addressing comments 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 if (!tab_controller) 75 if (!tab_controller)
76 return NULL; 76 return NULL;
77 77
78 return tab_controller->GetPrintPreviewForTab(tab_contents()); 78 return tab_controller->GetPrintPreviewForTab(tab_contents());
79 } 79 }
80 80
81 void PrintPreviewMessageHandler::OnRequestPrintPreview() { 81 void PrintPreviewMessageHandler::OnRequestPrintPreview() {
82 PrintPreviewTabController::PrintPreview(tab_contents()); 82 PrintPreviewTabController::PrintPreview(tab_contents());
83 } 83 }
84 84
85 void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(int document_cookie, 85 void PrintPreviewMessageHandler::OnDidGetPreviewPageCount(
86 int page_count, 86 const PrintHostMsg_DidGetPreviewPageCount_Params& params) {
87 bool is_modifiable) { 87 if (params.page_count <= 0)
88 if (page_count <= 0)
89 return; 88 return;
90 89
91 TabContents* print_preview_tab = GetPrintPreviewTab(); 90 TabContents* print_preview_tab = GetPrintPreviewTab();
92 if (!print_preview_tab || !print_preview_tab->web_ui()) 91 if (!print_preview_tab || !print_preview_tab->web_ui())
93 return; 92 return;
94 93
95 PrintPreviewUI* print_preview_ui = 94 PrintPreviewUI* print_preview_ui =
96 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); 95 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
97 print_preview_ui->OnDidGetPreviewPageCount( 96 print_preview_ui->OnDidGetPreviewPageCount(params);
98 document_cookie, page_count, is_modifiable);
99 } 97 }
100 98
101 void PrintPreviewMessageHandler::OnDidPreviewPage( 99 void PrintPreviewMessageHandler::OnDidPreviewPage(
102 const PrintHostMsg_DidPreviewPage_Params& params) { 100 const PrintHostMsg_DidPreviewPage_Params& params) {
103 RenderViewHost* rvh = tab_contents()->render_view_host(); 101 RenderViewHost* rvh = tab_contents()->render_view_host();
104 TabContents* print_preview_tab = GetPrintPreviewTab(); 102 TabContents* print_preview_tab = GetPrintPreviewTab();
105 if (!print_preview_tab || !print_preview_tab->web_ui()) { 103 if (!print_preview_tab || !print_preview_tab->web_ui()) {
106 // Can't find print preview tab means we should abort. 104 // Can't find print preview tab means we should abort.
107 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id())); 105 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id()));
108 return; 106 return;
(...skipping 15 matching lines...) Expand all
124 122
125 if (page_number == FIRST_PAGE_INDEX) 123 if (page_number == FIRST_PAGE_INDEX)
126 print_preview_ui->ClearAllPreviewData(); 124 print_preview_ui->ClearAllPreviewData();
127 125
128 if (page_number >= FIRST_PAGE_INDEX && params.data_size) { 126 if (page_number >= FIRST_PAGE_INDEX && params.data_size) {
129 RefCountedBytes* data_bytes = 127 RefCountedBytes* data_bytes =
130 GetDataFromHandle(params.metafile_data_handle, params.data_size); 128 GetDataFromHandle(params.metafile_data_handle, params.data_size);
131 DCHECK(data_bytes); 129 DCHECK(data_bytes);
132 130
133 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes); 131 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes);
134 print_preview_ui->OnDidPreviewPage(page_number); 132 print_preview_ui->OnDidPreviewPage(page_number, params.preview_request_id);
135 // TODO(kmadhusu): Query |PrintPreviewUI| and update 133 // TODO(kmadhusu): Query |PrintPreviewUI| and update
136 // |requested_preview_page_index| accordingly. 134 // |requested_preview_page_index| accordingly.
137 } 135 }
138 136
139 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id(), 137 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id(),
140 requested_preview_page_index)); 138 requested_preview_page_index));
141 } 139 }
142 140
143 void PrintPreviewMessageHandler::OnPagesReadyForPreview( 141 void PrintPreviewMessageHandler::OnPagesReadyForPreview(
144 const PrintHostMsg_DidPreviewDocument_Params& params) { 142 const PrintHostMsg_DidPreviewDocument_Params& params) {
145 StopWorker(params.document_cookie); 143 StopWorker(params.document_cookie);
146 144
147 // Get the print preview tab. 145 // Get the print preview tab.
148 TabContents* print_preview_tab = GetPrintPreviewTab(); 146 TabContents* print_preview_tab = GetPrintPreviewTab();
149 // User might have closed it already. 147 // User might have closed it already.
150 if (!print_preview_tab) 148 if (!print_preview_tab)
151 return; 149 return;
152 150
153 PrintPreviewUI* print_preview_ui = 151 PrintPreviewUI* print_preview_ui =
154 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); 152 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
155 153
156 TabContentsWrapper* wrapper = 154 TabContentsWrapper* wrapper =
157 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); 155 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab);
158 156
159 if (params.reuse_existing_data) { 157 if (params.reuse_existing_data) {
160 // Need to match normal rendering where we are expected to send this. 158 // Need to match normal rendering where we are expected to send this.
161 print_preview_ui->OnDidGetPreviewPageCount(params.document_cookie, 159 PrintHostMsg_DidGetPreviewPageCount_Params temp_params;
162 params.expected_pages_count, 160 temp_params.page_count = params.expected_pages_count;
163 params.modifiable); 161 temp_params.document_cookie = params.document_cookie;
164 162 temp_params.is_modifiable = params.modifiable;
163 temp_params.preview_request_id = params.preview_request_id;
164 print_preview_ui->OnDidGetPreviewPageCount(temp_params);
165 print_preview_ui->OnReusePreviewData(params.preview_request_id); 165 print_preview_ui->OnReusePreviewData(params.preview_request_id);
166 return; 166 return;
167 } 167 }
168 168
169 wrapper->print_view_manager()->OverrideTitle(tab_contents()); 169 wrapper->print_view_manager()->OverrideTitle(tab_contents());
170 170
171 // TODO(joth): This seems like a good match for using RefCountedStaticMemory 171 // TODO(joth): This seems like a good match for using RefCountedStaticMemory
172 // to avoid the memory copy, but the SetPrintPreviewData call chain below 172 // to avoid the memory copy, but the SetPrintPreviewData call chain below
173 // needs updating to accept the RefCountedMemory* base class. 173 // needs updating to accept the RefCountedMemory* base class.
174 RefCountedBytes* data_bytes = 174 RefCountedBytes* data_bytes =
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 228 }
229 229
230 void PrintPreviewMessageHandler::DidStartLoading() { 230 void PrintPreviewMessageHandler::DidStartLoading() {
231 if (tab_contents()->delegate() && 231 if (tab_contents()->delegate() &&
232 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { 232 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) {
233 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); 233 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT);
234 } 234 }
235 } 235 }
236 236
237 } // namespace printing 237 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_preview_message_handler.h ('k') | chrome/browser/resources/print_preview/color_settings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698