| 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 "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/printing/background_printing_manager.h" |
| 9 #include "chrome/browser/printing/print_job_manager.h" | 10 #include "chrome/browser/printing/print_job_manager.h" |
| 10 #include "chrome/browser/printing/print_preview_tab_controller.h" | 11 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 11 #include "chrome/browser/printing/print_view_manager.h" | 12 #include "chrome/browser/printing/print_view_manager.h" |
| 12 #include "chrome/browser/printing/printer_query.h" | 13 #include "chrome/browser/printing/printer_query.h" |
| 13 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 14 #include "chrome/browser/ui/webui/print_preview_handler.h" | 15 #include "chrome/browser/ui/webui/print_preview_handler.h" |
| 15 #include "chrome/browser/ui/webui/print_preview_ui.h" | 16 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 16 #include "chrome/common/print_messages.h" | 17 #include "chrome/common/print_messages.h" |
| 17 #include "content/browser/browser_thread.h" | 18 #include "content/browser/browser_thread.h" |
| 18 #include "content/browser/renderer_host/render_view_host.h" | 19 #include "content/browser/renderer_host/render_view_host.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { | 109 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { |
| 109 // Always need to stop the worker. | 110 // Always need to stop the worker. |
| 110 StopWorker(document_cookie); | 111 StopWorker(document_cookie); |
| 111 | 112 |
| 112 // Inform the print preview tab of the failure. | 113 // Inform the print preview tab of the failure. |
| 113 TabContents* print_preview_tab = GetPrintPreviewTab(); | 114 TabContents* print_preview_tab = GetPrintPreviewTab(); |
| 114 // User might have closed it already. | 115 // User might have closed it already. |
| 115 if (!print_preview_tab) | 116 if (!print_preview_tab) |
| 116 return; | 117 return; |
| 117 print_preview_tab->web_ui()->CallJavascriptFunction("printPreviewFailed"); | 118 |
| 119 TabContentsWrapper* wrapper = |
| 120 TabContentsWrapper::GetCurrentWrapperForContents(print_preview_tab); |
| 121 |
| 122 if (g_browser_process->background_printing_manager()-> |
| 123 HasTabContents(wrapper)) { |
| 124 // Preview tab was hidden to serve the print request. |
| 125 delete wrapper; |
| 126 } else { |
| 127 PrintPreviewUI* print_preview_ui = |
| 128 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
| 129 print_preview_ui->CallJavascriptFunction("printPreviewFailed"); |
| 130 } |
| 118 } | 131 } |
| 119 | 132 |
| 120 bool PrintPreviewMessageHandler::OnMessageReceived( | 133 bool PrintPreviewMessageHandler::OnMessageReceived( |
| 121 const IPC::Message& message) { | 134 const IPC::Message& message) { |
| 122 bool handled = true; | 135 bool handled = true; |
| 123 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message) | 136 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message) |
| 124 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, | 137 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, |
| 125 OnRequestPrintPreview) | 138 OnRequestPrintPreview) |
| 126 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview, | 139 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview, |
| 127 OnPagesReadyForPreview) | 140 OnPagesReadyForPreview) |
| 128 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, | 141 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, |
| 129 OnPrintPreviewFailed) | 142 OnPrintPreviewFailed) |
| 130 IPC_MESSAGE_UNHANDLED(handled = false) | 143 IPC_MESSAGE_UNHANDLED(handled = false) |
| 131 IPC_END_MESSAGE_MAP() | 144 IPC_END_MESSAGE_MAP() |
| 132 return handled; | 145 return handled; |
| 133 } | 146 } |
| 134 | 147 |
| 135 void PrintPreviewMessageHandler::DidStartLoading() { | 148 void PrintPreviewMessageHandler::DidStartLoading() { |
| 136 if (tab_contents()->delegate() && | 149 if (tab_contents()->delegate() && |
| 137 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 150 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
| 138 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 151 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
| 139 } | 152 } |
| 140 } | 153 } |
| 141 | 154 |
| 142 } // namespace printing | 155 } // namespace printing |
| OLD | NEW |