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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 TabContents* print_preview_tab = GetPrintPreviewTab(); | 69 TabContents* print_preview_tab = GetPrintPreviewTab(); |
| 70 if (!print_preview_tab) | 70 if (!print_preview_tab) |
| 71 return; | 71 return; |
| 72 | 72 |
| 73 PrintPreviewUI* print_preview_ui = | 73 PrintPreviewUI* print_preview_ui = |
| 74 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | 74 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
| 75 print_preview_ui->OnDidGetPreviewPageCount(page_count); | 75 print_preview_ui->OnDidGetPreviewPageCount(page_count); |
| 76 } | 76 } |
| 77 | 77 |
| 78 void PrintPreviewMessageHandler::OnDidPreviewPage(int page_number, | 78 void PrintPreviewMessageHandler::OnDidPreviewPage(int page_number, |
| 79 bool* cancel) { | 79 int document_cookie) { |
| 80 RenderViewHost* rvh = tab_contents()->render_view_host(); | |
| 80 TabContents* print_preview_tab = GetPrintPreviewTab(); | 81 TabContents* print_preview_tab = GetPrintPreviewTab(); |
| 81 if (!print_preview_tab) { | 82 if (!print_preview_tab) { |
|
kmadhusu
2011/07/15 01:22:46
Can you make this if condition (!print_preview_tab
Lei Zhang
2011/07/15 01:48:02
I don't think we need it. I've never seen a crash
kmadhusu
2011/07/15 19:25:46
As we discussed, it can happen. So, modify the if
Lei Zhang
2011/07/15 20:23:35
Done.
| |
| 82 // Can't find print preview tab means we should cancel. | 83 // Can't find print preview tab means we should abort. |
| 83 *cancel = true; | 84 StopWorker(document_cookie); |
| 85 rvh->Send(new PrintMsg_AbortPreview(rvh->routing_id())); | |
| 84 return; | 86 return; |
| 85 } | 87 } |
| 86 | 88 |
| 87 PrintPreviewUI* print_preview_ui = | 89 PrintPreviewUI* print_preview_ui = |
| 88 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | 90 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
| 89 bool has_pending = print_preview_ui->HasPendingRequests(); | 91 bool has_pending = print_preview_ui->HasPendingRequests(); |
| 90 if (!has_pending && page_number >= 0) | 92 if (has_pending) { |
| 93 // Cancel. Next print preview request will cancel the current one. | |
| 94 // Just do the required maintainance work here. | |
| 95 StopWorker(document_cookie); | |
| 96 print_preview_ui->OnPrintPreviewCancelled(); | |
| 97 return; | |
| 98 } | |
| 99 | |
| 100 // Continue | |
| 101 if (page_number >= 0) | |
| 91 print_preview_ui->OnDidPreviewPage(page_number); | 102 print_preview_ui->OnDidPreviewPage(page_number); |
| 92 *cancel = has_pending; | 103 rvh->Send(new PrintMsg_ContinuePreview(rvh->routing_id())); |
| 93 } | 104 } |
| 94 | 105 |
| 95 void PrintPreviewMessageHandler::OnPagesReadyForPreview( | 106 void PrintPreviewMessageHandler::OnPagesReadyForPreview( |
| 96 const PrintHostMsg_DidPreviewDocument_Params& params) { | 107 const PrintHostMsg_DidPreviewDocument_Params& params) { |
| 97 // Always need to stop the worker and send PrintMsg_PrintingDone. | 108 // Always need to stop the worker and send PrintMsg_PrintingDone. |
| 98 StopWorker(params.document_cookie); | 109 StopWorker(params.document_cookie); |
| 99 | 110 |
| 100 RenderViewHost* rvh = tab_contents()->render_view_host(); | 111 RenderViewHost* rvh = tab_contents()->render_view_host(); |
| 101 rvh->Send(new PrintMsg_PrintingDone(rvh->routing_id(), true)); | 112 rvh->Send(new PrintMsg_PrintingDone(rvh->routing_id(), true)); |
| 102 | 113 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 HasTabContents(wrapper)) { | 179 HasTabContents(wrapper)) { |
| 169 // Preview tab was hidden to serve the print request. | 180 // Preview tab was hidden to serve the print request. |
| 170 delete wrapper; | 181 delete wrapper; |
| 171 } else { | 182 } else { |
| 172 PrintPreviewUI* print_preview_ui = | 183 PrintPreviewUI* print_preview_ui = |
| 173 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | 184 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); |
| 174 print_preview_ui->OnPrintPreviewFailed(); | 185 print_preview_ui->OnPrintPreviewFailed(); |
| 175 } | 186 } |
| 176 } | 187 } |
| 177 | 188 |
| 178 void PrintPreviewMessageHandler::OnPrintPreviewCancelled(int document_cookie) { | |
| 179 // Always need to stop the worker. | |
| 180 StopWorker(document_cookie); | |
| 181 | |
| 182 TabContents* print_preview_tab = GetPrintPreviewTab(); | |
| 183 if (!print_preview_tab) | |
| 184 return; | |
| 185 | |
| 186 PrintPreviewUI* print_preview_ui = | |
| 187 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui()); | |
| 188 print_preview_ui->OnPrintPreviewCancelled(); | |
| 189 } | |
| 190 | |
| 191 bool PrintPreviewMessageHandler::OnMessageReceived( | 189 bool PrintPreviewMessageHandler::OnMessageReceived( |
| 192 const IPC::Message& message) { | 190 const IPC::Message& message) { |
| 193 bool handled = true; | 191 bool handled = true; |
| 194 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message) | 192 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message) |
| 195 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, | 193 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, |
| 196 OnRequestPrintPreview) | 194 OnRequestPrintPreview) |
| 197 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount, | 195 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPreviewPageCount, |
| 198 OnDidGetPreviewPageCount) | 196 OnDidGetPreviewPageCount) |
| 199 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, | 197 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPreviewPage, |
| 200 OnDidPreviewPage) | 198 OnDidPreviewPage) |
| 201 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview, | 199 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview, |
| 202 OnPagesReadyForPreview) | 200 OnPagesReadyForPreview) |
| 203 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, | 201 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, |
| 204 OnPrintPreviewFailed) | 202 OnPrintPreviewFailed) |
| 205 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewCancelled, | |
| 206 OnPrintPreviewCancelled) | |
| 207 IPC_MESSAGE_UNHANDLED(handled = false) | 203 IPC_MESSAGE_UNHANDLED(handled = false) |
| 208 IPC_END_MESSAGE_MAP() | 204 IPC_END_MESSAGE_MAP() |
| 209 return handled; | 205 return handled; |
| 210 } | 206 } |
| 211 | 207 |
| 212 void PrintPreviewMessageHandler::DidStartLoading() { | 208 void PrintPreviewMessageHandler::DidStartLoading() { |
| 213 if (tab_contents()->delegate() && | 209 if (tab_contents()->delegate() && |
| 214 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { | 210 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { |
| 215 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); | 211 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); |
| 216 } | 212 } |
| 217 } | 213 } |
| 218 | 214 |
| 219 } // namespace printing | 215 } // namespace printing |
| OLD | NEW |