Chromium Code Reviews| 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/print_job_manager.h" | 9 #include "chrome/browser/printing/print_job_manager.h" |
| 10 #include "chrome/browser/printing/print_preview_tab_controller.h" | 10 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 | 107 |
| 108 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { | 108 void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { |
| 109 // Always need to stop the worker. | 109 // Always need to stop the worker. |
| 110 StopWorker(document_cookie); | 110 StopWorker(document_cookie); |
| 111 | 111 |
| 112 // Inform the print preview tab of the failure. | 112 // Inform the print preview tab of the failure. |
| 113 TabContents* print_preview_tab = GetPrintPreviewTab(); | 113 TabContents* print_preview_tab = GetPrintPreviewTab(); |
| 114 // User might have closed it already. | 114 // User might have closed it already. |
| 115 if (!print_preview_tab) | 115 if (!print_preview_tab) |
| 116 return; | 116 return; |
| 117 print_preview_tab->web_ui()->CallJavascriptFunction("printPreviewFailed"); | 117 |
| 118 PrintPreviewUI* print_preview_ui = | |
| 119 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | |
| 120 | |
| 121 if (print_preview_ui->isHidden()) { | |
| 122 // Preview tab was hidden to serve the print request. | |
| 123 RenderViewHost* rvh = tab_contents()->render_view_host(); | |
| 124 rvh->Send(new PrintMsg_PrintingDone(rvh->routing_id(), false)); | |
|
Lei Zhang
2011/06/09 09:54:55
Why do you need this? If we failed to generate a p
kmadhusu
2011/06/09 18:11:44
I am sending this message for 2 reasons.
(1) To di
| |
| 125 delete print_preview_tab; | |
| 126 return; | |
| 127 } else { | |
| 128 print_preview_ui->CallJavascriptFunction("printPreviewFailed"); | |
| 129 } | |
| 118 } | 130 } |
| 119 | 131 |
| 120 bool PrintPreviewMessageHandler::OnMessageReceived( | 132 bool PrintPreviewMessageHandler::OnMessageReceived( |
| 121 const IPC::Message& message) { | 133 const IPC::Message& message) { |
| 122 bool handled = true; | 134 bool handled = true; |
| 123 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message) | 135 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message) |
| 124 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, | 136 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, |
| 125 OnRequestPrintPreview) | 137 OnRequestPrintPreview) |
| 126 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview, | 138 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview, |
| 127 OnPagesReadyForPreview) | 139 OnPagesReadyForPreview) |
| 128 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, | 140 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, |
| 129 OnPrintPreviewFailed) | 141 OnPrintPreviewFailed) |
| 130 IPC_MESSAGE_UNHANDLED(handled = false) | 142 IPC_MESSAGE_UNHANDLED(handled = false) |
| 131 IPC_END_MESSAGE_MAP() | 143 IPC_END_MESSAGE_MAP() |
| 132 return handled; | 144 return handled; |
| 133 } | 145 } |
| 134 | 146 |
| 135 void PrintPreviewMessageHandler::DidStartLoading() { | 147 void PrintPreviewMessageHandler::DidStartLoading() { |
| 136 if (tab_contents()->delegate() && | 148 if (tab_contents()->delegate() && |
| 137 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 149 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
| 138 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 150 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
| 139 } | 151 } |
| 140 } | 152 } |
| 141 | 153 |
| 142 } // namespace printing | 154 } // namespace printing |
| OLD | NEW |