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

Side by Side Diff: content/browser/renderer_host/render_message_filter.cc

Issue 6533006: Print Preview: Hook up the print button to initiate printing without displaying a print dialog. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: '' Created 9 years, 10 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 "content/browser/renderer_host/render_message_filter.h" 5 #include "content/browser/renderer_host/render_message_filter.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 OnAllocateTempFileForPrinting) 455 OnAllocateTempFileForPrinting)
456 IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten, 456 IPC_MESSAGE_HANDLER(ViewHostMsg_TempFileForPrintingWritten,
457 OnTempFileForPrintingWritten) 457 OnTempFileForPrintingWritten)
458 #endif 458 #endif
459 IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats) 459 IPC_MESSAGE_HANDLER(ViewHostMsg_ResourceTypeStats, OnResourceTypeStats)
460 IPC_MESSAGE_HANDLER(ViewHostMsg_V8HeapStats, OnV8HeapStats) 460 IPC_MESSAGE_HANDLER(ViewHostMsg_V8HeapStats, OnV8HeapStats)
461 IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL) 461 IPC_MESSAGE_HANDLER(ViewHostMsg_DidZoomURL, OnDidZoomURL)
462 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy) 462 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ResolveProxy, OnResolveProxy)
463 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings, 463 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetDefaultPrintSettings,
464 OnGetDefaultPrintSettings) 464 OnGetDefaultPrintSettings)
465 IPC_MESSAGE_HANDLER(ViewHostMsg_GetCurrentPrintSettings,
466 OnGetCurrentPrintSettings)
465 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint, OnScriptedPrint) 467 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_ScriptedPrint, OnScriptedPrint)
468 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_UpdatePrintSettings,
469 OnUpdatePrintSettings)
466 #if defined(OS_MACOSX) 470 #if defined(OS_MACOSX)
467 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB, OnAllocTransportDIB) 471 IPC_MESSAGE_HANDLER(ViewHostMsg_AllocTransportDIB, OnAllocTransportDIB)
468 IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB, OnFreeTransportDIB) 472 IPC_MESSAGE_HANDLER(ViewHostMsg_FreeTransportDIB, OnFreeTransportDIB)
469 #endif 473 #endif
470 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension, 474 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToExtension,
471 OnOpenChannelToExtension) 475 OnOpenChannelToExtension)
472 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToTab, OnOpenChannelToTab) 476 IPC_MESSAGE_HANDLER(ViewHostMsg_OpenChannelToTab, OnOpenChannelToTab)
473 IPC_MESSAGE_HANDLER(ViewHostMsg_CloseCurrentConnections, 477 IPC_MESSAGE_HANDLER(ViewHostMsg_CloseCurrentConnections,
474 OnCloseCurrentConnections) 478 OnCloseCurrentConnections)
475 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode, OnSetCacheMode) 479 IPC_MESSAGE_HANDLER(ViewHostMsg_SetCacheMode, OnSetCacheMode)
(...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 if (printer_query.get()) { 1160 if (printer_query.get()) {
1157 // If user hasn't cancelled. 1161 // If user hasn't cancelled.
1158 if (printer_query->cookie() && printer_query->settings().dpi()) { 1162 if (printer_query->cookie() && printer_query->settings().dpi()) {
1159 print_job_manager_->QueuePrinterQuery(printer_query.get()); 1163 print_job_manager_->QueuePrinterQuery(printer_query.get());
1160 } else { 1164 } else {
1161 printer_query->StopWorker(); 1165 printer_query->StopWorker();
1162 } 1166 }
1163 } 1167 }
1164 } 1168 }
1165 1169
1170 void RenderMessageFilter::OnGetCurrentPrintSettings(int document_cookie,
1171 ViewMsg_Print_Params* params) {
1172 scoped_refptr<printing::PrinterQuery> printer_query;
1173 print_job_manager_->PopPrinterQuery(document_cookie, &printer_query);
1174 if (!printer_query.get()) {
1175 memset(params, 0, sizeof(ViewMsg_Print_Params));
1176 } else {
1177 RenderParamsFromPrintSettings(printer_query->settings(), params);
1178 params->document_cookie = printer_query->cookie();
1179 }
1180 // If printing was enabled.
1181 if (printer_query.get()) {
1182 // If user hasn't cancelled.
1183 if (printer_query->cookie() && printer_query->settings().dpi()) {
1184 print_job_manager_->QueuePrinterQuery(printer_query.get());
1185 } else {
1186 printer_query->StopWorker();
1187 }
1188 }
1189 }
1190
1191 void RenderMessageFilter::OnUpdatePrintSettings(int document_cookie,
1192 const std::string& job_settings, IPC::Message* reply_msg) {
1193 scoped_refptr<printing::PrinterQuery> printer_query;
1194 print_job_manager_->PopPrinterQuery(document_cookie, &printer_query);
1195 if (printer_query.get()) {
1196 CancelableTask* task = NewRunnableMethod(
1197 this,
1198 &RenderMessageFilter::OnUpdatePrintSettingsReply,
1199 printer_query,
1200 reply_msg);
1201 printer_query->SetSettings(job_settings, task);
1202 }
1203 }
1204
1205 void RenderMessageFilter::OnUpdatePrintSettingsReply(
1206 scoped_refptr<printing::PrinterQuery> printer_query,
1207 IPC::Message* reply_msg) {
1208 ViewMsg_Print_Params params;
1209 if (!printer_query.get() ||
1210 printer_query->last_status() != printing::PrintingContext::OK) {
1211 memset(&params, 0, sizeof(params));
1212 } else {
1213 RenderParamsFromPrintSettings(printer_query->settings(), &params);
1214 params.document_cookie = printer_query->cookie();
1215 }
1216 ViewHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params);
1217 Send(reply_msg);
1218 // If printing was enabled.
1219 if (printer_query.get()) {
1220 // If user hasn't cancelled.
1221 if (printer_query->cookie() && printer_query->settings().dpi()) {
1222 print_job_manager_->QueuePrinterQuery(printer_query.get());
1223 } else {
1224 printer_query->StopWorker();
1225 }
1226 }
1227 }
1228
1166 void RenderMessageFilter::OnScriptedPrint( 1229 void RenderMessageFilter::OnScriptedPrint(
1167 const ViewHostMsg_ScriptedPrint_Params& params, 1230 const ViewHostMsg_ScriptedPrint_Params& params,
1168 IPC::Message* reply_msg) { 1231 IPC::Message* reply_msg) {
1169 gfx::NativeView host_view = 1232 gfx::NativeView host_view =
1170 gfx::NativeViewFromIdInBrowser(params.host_window_id); 1233 gfx::NativeViewFromIdInBrowser(params.host_window_id);
1171 1234
1172 scoped_refptr<printing::PrinterQuery> printer_query; 1235 scoped_refptr<printing::PrinterQuery> printer_query;
1173 print_job_manager_->PopPrinterQuery(params.cookie, &printer_query); 1236 print_job_manager_->PopPrinterQuery(params.cookie, &printer_query);
1174 if (!printer_query.get()) { 1237 if (!printer_query.get()) {
1175 printer_query = new printing::PrinterQuery; 1238 printer_query = new printing::PrinterQuery;
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
1709 } 1772 }
1710 1773
1711 CookiesEnabledCompletion::~CookiesEnabledCompletion() {} 1774 CookiesEnabledCompletion::~CookiesEnabledCompletion() {}
1712 1775
1713 void CookiesEnabledCompletion::RunWithParams(const Tuple1<int>& params) { 1776 void CookiesEnabledCompletion::RunWithParams(const Tuple1<int>& params) {
1714 bool result = params.a != net::ERR_ACCESS_DENIED; 1777 bool result = params.a != net::ERR_ACCESS_DENIED;
1715 ViewHostMsg_CookiesEnabled::WriteReplyParams(reply_msg_, result); 1778 ViewHostMsg_CookiesEnabled::WriteReplyParams(reply_msg_, result);
1716 filter_->Send(reply_msg_); 1779 filter_->Send(reply_msg_);
1717 delete this; 1780 delete this;
1718 } 1781 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698