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

Side by Side Diff: chrome/browser/printing/print_preview_message_handler.cc

Issue 7056070: PrintPreview: Preview generation should not block print button. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 9 years, 6 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 "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
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 RenderViewHost* rvh = tab_contents()->render_view_host();
126 rvh->Send(new PrintMsg_PrintingDone(rvh->routing_id(), false));
127 delete print_preview_tab;
128 return;
129 } else {
130 PrintPreviewUI* print_preview_ui =
131 static_cast<PrintPreviewUI*>(print_preview_tab->web_ui());
132 print_preview_ui->CallJavascriptFunction("printPreviewFailed");
133 }
118 } 134 }
119 135
120 bool PrintPreviewMessageHandler::OnMessageReceived( 136 bool PrintPreviewMessageHandler::OnMessageReceived(
121 const IPC::Message& message) { 137 const IPC::Message& message) {
122 bool handled = true; 138 bool handled = true;
123 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message) 139 IPC_BEGIN_MESSAGE_MAP(PrintPreviewMessageHandler, message)
124 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview, 140 IPC_MESSAGE_HANDLER(PrintHostMsg_RequestPrintPreview,
125 OnRequestPrintPreview) 141 OnRequestPrintPreview)
126 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview, 142 IPC_MESSAGE_HANDLER(PrintHostMsg_PagesReadyForPreview,
127 OnPagesReadyForPreview) 143 OnPagesReadyForPreview)
128 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, 144 IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed,
129 OnPrintPreviewFailed) 145 OnPrintPreviewFailed)
130 IPC_MESSAGE_UNHANDLED(handled = false) 146 IPC_MESSAGE_UNHANDLED(handled = false)
131 IPC_END_MESSAGE_MAP() 147 IPC_END_MESSAGE_MAP()
132 return handled; 148 return handled;
133 } 149 }
134 150
135 void PrintPreviewMessageHandler::DidStartLoading() { 151 void PrintPreviewMessageHandler::DidStartLoading() {
136 if (tab_contents()->delegate() && 152 if (tab_contents()->delegate() &&
137 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) { 153 printing::PrintPreviewTabController::IsPrintPreviewTab(tab_contents())) {
138 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT); 154 tab_contents()->SetContentRestrictions(CONTENT_RESTRICTION_PRINT);
139 } 155 }
140 } 156 }
141 157
142 } // namespace printing 158 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698