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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/memory/ref_counted_memory.h" | 11 #include "base/memory/ref_counted_memory.h" |
12 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/printing/print_job_manager.h" | 14 #include "chrome/browser/printing/print_job_manager.h" |
15 #include "chrome/browser/printing/print_preview_tab_controller.h" | 15 #include "chrome/browser/printing/print_preview_tab_controller.h" |
16 #include "chrome/browser/printing/print_view_manager.h" | |
17 #include "chrome/browser/printing/printer_query.h" | 16 #include "chrome/browser/printing/printer_query.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
19 #include "chrome/browser/ui/webui/print_preview_handler.h" | |
20 #include "chrome/browser/ui/webui/print_preview_ui.h" | 18 #include "chrome/browser/ui/webui/print_preview_ui.h" |
21 #include "chrome/common/print_messages.h" | 19 #include "chrome/common/print_messages.h" |
22 #include "content/browser/renderer_host/render_view_host.h" | 20 #include "content/browser/renderer_host/render_view_host.h" |
23 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
24 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/common/content_restriction.h" | |
26 #include "printing/page_size_margins.h" | 23 #include "printing/page_size_margins.h" |
27 #include "printing/print_job_constants.h" | 24 #include "printing/print_job_constants.h" |
28 | 25 |
29 using content::BrowserThread; | 26 using content::BrowserThread; |
30 | 27 |
31 namespace { | 28 namespace { |
32 | 29 |
33 void StopWorker(int document_cookie) { | 30 void StopWorker(int document_cookie) { |
34 if (document_cookie <= 0) | 31 if (document_cookie <= 0) |
35 return; | 32 return; |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 PrintHostMsg_DidGetPreviewPageCount_Params temp_params; | 171 PrintHostMsg_DidGetPreviewPageCount_Params temp_params; |
175 temp_params.page_count = params.expected_pages_count; | 172 temp_params.page_count = params.expected_pages_count; |
176 temp_params.document_cookie = params.document_cookie; | 173 temp_params.document_cookie = params.document_cookie; |
177 temp_params.is_modifiable = params.modifiable; | 174 temp_params.is_modifiable = params.modifiable; |
178 temp_params.preview_request_id = params.preview_request_id; | 175 temp_params.preview_request_id = params.preview_request_id; |
179 print_preview_ui->OnDidGetPreviewPageCount(temp_params); | 176 print_preview_ui->OnDidGetPreviewPageCount(temp_params); |
180 print_preview_ui->OnReusePreviewData(params.preview_request_id); | 177 print_preview_ui->OnReusePreviewData(params.preview_request_id); |
181 return; | 178 return; |
182 } | 179 } |
183 | 180 |
184 print_preview_tab->print_view_manager()->OverrideTitle(tab_contents()); | |
185 | |
186 // TODO(joth): This seems like a good match for using RefCountedStaticMemory | 181 // TODO(joth): This seems like a good match for using RefCountedStaticMemory |
187 // to avoid the memory copy, but the SetPrintPreviewData call chain below | 182 // to avoid the memory copy, but the SetPrintPreviewData call chain below |
188 // needs updating to accept the RefCountedMemory* base class. | 183 // needs updating to accept the RefCountedMemory* base class. |
189 RefCountedBytes* data_bytes = | 184 RefCountedBytes* data_bytes = |
190 GetDataFromHandle(params.metafile_data_handle, params.data_size); | 185 GetDataFromHandle(params.metafile_data_handle, params.data_size); |
191 if (!data_bytes) | 186 if (!data_bytes) |
192 return; | 187 return; |
193 | 188 |
194 print_preview_ui->SetPrintPreviewDataForIndex(COMPLETE_PREVIEW_DOCUMENT_INDEX, | 189 print_preview_ui->SetPrintPreviewDataForIndex(COMPLETE_PREVIEW_DOCUMENT_INDEX, |
195 data_bytes); | 190 data_bytes); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 OnDidGetDefaultPageLayout) | 240 OnDidGetDefaultPageLayout) |
246 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewCancelled, | 241 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewCancelled, |
247 OnPrintPreviewCancelled) | 242 OnPrintPreviewCancelled) |
248 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewInvalidPrinterSettings, | 243 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewInvalidPrinterSettings, |
249 OnInvalidPrinterSettings) | 244 OnInvalidPrinterSettings) |
250 IPC_MESSAGE_UNHANDLED(handled = false) | 245 IPC_MESSAGE_UNHANDLED(handled = false) |
251 IPC_END_MESSAGE_MAP() | 246 IPC_END_MESSAGE_MAP() |
252 return handled; | 247 return handled; |
253 } | 248 } |
254 | 249 |
255 void PrintPreviewMessageHandler::DidStartLoading() { | 250 void PrintPreviewMessageHandler::NavigateToPendingEntry( |
256 if (tab_contents()->delegate() && | 251 const GURL& url, |
257 PrintPreviewTabController::IsPrintPreviewTab(tab_contents_wrapper())) { | 252 NavigationController::ReloadType reload_type) { |
258 tab_contents()->SetContentRestrictions(content::CONTENT_RESTRICTION_PRINT); | 253 TabContentsWrapper* tab = tab_contents_wrapper(); |
| 254 TabContentsWrapper* preview_tab = GetPrintPreviewTab(); |
| 255 if (tab == preview_tab) { |
| 256 // Cloud print sign-in reloads the page. |
| 257 DCHECK(PrintPreviewTabController::IsPrintPreviewURL(url)); |
| 258 DCHECK_EQ(NavigationController::RELOAD, reload_type); |
| 259 return; |
259 } | 260 } |
260 } | 261 } |
261 | 262 |
262 } // namespace printing | 263 } // namespace printing |
OLD | NEW |