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

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 responseID to onDidPreviewPage 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 int document_cookie,
85 bool is_modifiable) { 85 int page_count,
86 bool is_modifiable,
kmadhusu 2011/08/03 18:39:45 I think its worth to create a new Struct for this
dpapad 2011/08/08 18:25:36 Done.
87 int preview_request_id) {
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());
94 print_preview_ui->OnDidGetPreviewPageCount( 96 print_preview_ui->OnDidGetPreviewPageCount(
95 document_cookie, page_count, is_modifiable); 97 document_cookie, page_count, is_modifiable, preview_request_id);
96 } 98 }
97 99
98 void PrintPreviewMessageHandler::OnDidPreviewPage( 100 void PrintPreviewMessageHandler::OnDidPreviewPage(
99 const PrintHostMsg_DidPreviewPage_Params& params) { 101 const PrintHostMsg_DidPreviewPage_Params& params) {
100 RenderViewHost* rvh = tab_contents()->render_view_host(); 102 RenderViewHost* rvh = tab_contents()->render_view_host();
101 TabContents* print_preview_tab = GetPrintPreviewTab(); 103 TabContents* print_preview_tab = GetPrintPreviewTab();
102 if (!(print_preview_tab && print_preview_tab->web_ui())) { 104 if (!(print_preview_tab && print_preview_tab->web_ui())) {
103 // Can't find print preview tab means we should abort. 105 // Can't find print preview tab means we should abort.
104 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id())); 106 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id()));
105 return; 107 return;
(...skipping 15 matching lines...) Expand all
121 123
122 if (page_number == FIRST_PAGE_INDEX) 124 if (page_number == FIRST_PAGE_INDEX)
123 print_preview_ui->ClearAllPreviewData(); 125 print_preview_ui->ClearAllPreviewData();
124 126
125 if (page_number >= FIRST_PAGE_INDEX && params.data_size) { 127 if (page_number >= FIRST_PAGE_INDEX && params.data_size) {
126 RefCountedBytes* data_bytes = 128 RefCountedBytes* data_bytes =
127 GetDataFromHandle(params.metafile_data_handle, params.data_size); 129 GetDataFromHandle(params.metafile_data_handle, params.data_size);
128 DCHECK(data_bytes); 130 DCHECK(data_bytes);
129 131
130 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes); 132 print_preview_ui->SetPrintPreviewDataForIndex(page_number, data_bytes);
131 print_preview_ui->OnDidPreviewPage(page_number); 133 print_preview_ui->OnDidPreviewPage(page_number, params.preview_request_id);
132 // TODO(kmadhusu): Query |PrintPreviewUI| and update 134 // TODO(kmadhusu): Query |PrintPreviewUI| and update
133 // |requested_preview_page_index| accordingly. 135 // |requested_preview_page_index| accordingly.
134 } 136 }
135 137
136 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id(), 138 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id(),
137 requested_preview_page_index)); 139 requested_preview_page_index));
138 } 140 }
139 141
140 void PrintPreviewMessageHandler::OnPagesReadyForPreview( 142 void PrintPreviewMessageHandler::OnPagesReadyForPreview(
141 const PrintHostMsg_DidPreviewDocument_Params& params) { 143 const PrintHostMsg_DidPreviewDocument_Params& params) {
142 StopWorker(params.document_cookie); 144 StopWorker(params.document_cookie);
143 145
144 // Get the print preview tab. 146 // Get the print preview tab.
145 TabContents* print_preview_tab = GetPrintPreviewTab(); 147 TabContents* print_preview_tab = GetPrintPreviewTab();
146 // User might have closed it already. 148 // User might have closed it already.
147 if (!print_preview_tab) 149 if (!print_preview_tab)
148 return; 150 return;
149 151
150 PrintPreviewUI* print_preview_ui = 152 PrintPreviewUI* print_preview_ui =
151 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); 153 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
152 154
153 TabContentsWrapper* wrapper = 155 TabContentsWrapper* wrapper =
154 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); 156 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab);
155 157
156 if (params.reuse_existing_data) { 158 if (params.reuse_existing_data) {
157 // Need to match normal rendering where we are expected to send this. 159 // Need to match normal rendering where we are expected to send this.
158 print_preview_ui->OnDidGetPreviewPageCount(params.document_cookie, 160 print_preview_ui->OnDidGetPreviewPageCount(params.document_cookie,
159 params.expected_pages_count, 161 params.expected_pages_count,
160 params.modifiable); 162 params.modifiable,
163 params.preview_request_id);
161 164
162 print_preview_ui->OnReusePreviewData(params.preview_request_id); 165 print_preview_ui->OnReusePreviewData(params.preview_request_id);
163 return; 166 return;
164 } 167 }
165 168
166 wrapper->print_view_manager()->OverrideTitle(tab_contents()); 169 wrapper->print_view_manager()->OverrideTitle(tab_contents());
167 170
168 // TODO(joth): This seems like a good match for using RefCountedStaticMemory 171 // TODO(joth): This seems like a good match for using RefCountedStaticMemory
169 // to avoid the memory copy, but the SetPrintPreviewData call chain below 172 // to avoid the memory copy, but the SetPrintPreviewData call chain below
170 // needs updating to accept the RefCountedMemory* base class. 173 // needs updating to accept the RefCountedMemory* base class.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 } 228 }
226 229
227 void PrintPreviewMessageHandler::DidStartLoading() { 230 void PrintPreviewMessageHandler::DidStartLoading() {
228 if (tab_contents()->delegate() && 231 if (tab_contents()->delegate() &&
229 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { 232 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) {
230 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); 233 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT);
231 } 234 }
232 } 235 }
233 236
234 } // 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/layout_settings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698