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

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

Issue 2508923003: Make printing work better with OOPIF. (try 2) (Closed)
Patch Set: Fix android_webview Created 4 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/printing_message_filter.h" 5 #include "chrome/browser/printing/printing_message_filter.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/printing/print_job_manager.h" 14 #include "chrome/browser/printing/print_job_manager.h"
15 #include "chrome/browser/printing/printer_query.h" 15 #include "chrome/browser/printing/printer_query.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/pref_names.h" 17 #include "chrome/common/pref_names.h"
18 #include "components/printing/browser/print_manager_utils.h" 18 #include "components/printing/browser/print_manager_utils.h"
19 #include "components/printing/common/print_messages.h" 19 #include "components/printing/common/print_messages.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "content/public/browser/render_view_host.h" 21 #include "content/public/browser/render_frame_host.h"
22 #include "content/public/browser/web_contents.h" 22 #include "content/public/browser/web_contents.h"
23 #include "content/public/common/child_process_host.h" 23 #include "content/public/common/child_process_host.h"
24 #include "printing/features/features.h" 24 #include "printing/features/features.h"
25 25
26 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 26 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
27 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h" 27 #include "chrome/browser/ui/webui/print_preview/print_preview_ui.h"
28 #endif 28 #endif
29 29
30 #if defined(OS_ANDROID) 30 #if defined(OS_ANDROID)
31 #include "base/file_descriptor_posix.h" 31 #include "base/file_descriptor_posix.h"
32 #include "base/strings/string_number_conversions.h" 32 #include "base/strings/string_number_conversions.h"
33 #include "chrome/browser/printing/print_view_manager_basic.h" 33 #include "chrome/browser/printing/print_view_manager_basic.h"
34 #endif 34 #endif
35 35
36 using content::BrowserThread; 36 using content::BrowserThread;
37 37
38 namespace printing { 38 namespace printing {
39 39
40 namespace { 40 namespace {
41 41
42 #if defined(OS_ANDROID) 42 #if defined(OS_ANDROID)
43 content::WebContents* GetWebContentsForRenderView(int render_process_id, 43 content::WebContents* GetWebContentsForRenderFrame(int render_process_id,
44 int render_view_id) { 44 int render_frame_id) {
45 DCHECK_CURRENTLY_ON(BrowserThread::UI); 45 DCHECK_CURRENTLY_ON(BrowserThread::UI);
46 content::RenderViewHost* view = content::RenderViewHost::FromID( 46 content::RenderFrameHost* frame =
47 render_process_id, render_view_id); 47 content::RenderFrameHost::FromID(render_process_id, render_frame_id);
48 return view ? content::WebContents::FromRenderViewHost(view) : nullptr; 48 return frame ? content::WebContents::FromRenderFrameHost(frame) : nullptr;
49 } 49 }
50 50
51 PrintViewManagerBasic* GetPrintManager(int render_process_id, 51 PrintViewManagerBasic* GetPrintManager(int render_process_id,
52 int render_view_id) { 52 int render_frame_id) {
53 DCHECK_CURRENTLY_ON(BrowserThread::UI); 53 DCHECK_CURRENTLY_ON(BrowserThread::UI);
54 content::WebContents* web_contents = 54 content::WebContents* web_contents =
55 GetWebContentsForRenderView(render_process_id, render_view_id); 55 GetWebContentsForRenderFrame(render_process_id, render_frame_id);
56 return web_contents ? PrintViewManagerBasic::FromWebContents(web_contents) 56 return web_contents ? PrintViewManagerBasic::FromWebContents(web_contents)
57 : nullptr; 57 : nullptr;
58 } 58 }
59 #endif 59 #endif
60 60
61 } // namespace 61 } // namespace
62 62
63 PrintingMessageFilter::PrintingMessageFilter(int render_process_id, 63 PrintingMessageFilter::PrintingMessageFilter(int render_process_id,
64 Profile* profile) 64 Profile* profile)
65 : BrowserMessageFilter(PrintMsgStart), 65 : BrowserMessageFilter(PrintMsgStart),
(...skipping 21 matching lines...) Expand all
87 87
88 bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message) { 88 bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message) {
89 bool handled = true; 89 bool handled = true;
90 IPC_BEGIN_MESSAGE_MAP(PrintingMessageFilter, message) 90 IPC_BEGIN_MESSAGE_MAP(PrintingMessageFilter, message)
91 #if defined(OS_ANDROID) 91 #if defined(OS_ANDROID)
92 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, 92 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting,
93 OnAllocateTempFileForPrinting) 93 OnAllocateTempFileForPrinting)
94 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, 94 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten,
95 OnTempFileForPrintingWritten) 95 OnTempFileForPrintingWritten)
96 #endif 96 #endif
97 IPC_MESSAGE_HANDLER(PrintHostMsg_IsPrintingEnabled, OnIsPrintingEnabled)
98 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, 97 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings,
99 OnGetDefaultPrintSettings) 98 OnGetDefaultPrintSettings)
100 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint) 99 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint)
101 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_UpdatePrintSettings, 100 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_UpdatePrintSettings,
102 OnUpdatePrintSettings) 101 OnUpdatePrintSettings)
103 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 102 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
104 IPC_MESSAGE_HANDLER(PrintHostMsg_CheckForCancel, OnCheckForCancel) 103 IPC_MESSAGE_HANDLER(PrintHostMsg_CheckForCancel, OnCheckForCancel)
105 #endif 104 #endif
106 IPC_MESSAGE_UNHANDLED(handled = false) 105 IPC_MESSAGE_UNHANDLED(handled = false)
107 IPC_END_MESSAGE_MAP() 106 IPC_END_MESSAGE_MAP()
108 return handled; 107 return handled;
109 } 108 }
110 109
111 #if defined(OS_ANDROID) 110 #if defined(OS_ANDROID)
112 void PrintingMessageFilter::OnAllocateTempFileForPrinting( 111 void PrintingMessageFilter::OnAllocateTempFileForPrinting(
113 int render_view_id, 112 int render_frame_id,
114 base::FileDescriptor* temp_file_fd, 113 base::FileDescriptor* temp_file_fd,
115 int* sequence_number) { 114 int* sequence_number) {
116 DCHECK_CURRENTLY_ON(BrowserThread::UI); 115 DCHECK_CURRENTLY_ON(BrowserThread::UI);
117 PrintViewManagerBasic* print_view_manager = 116 PrintViewManagerBasic* print_view_manager =
118 GetPrintManager(render_process_id_, render_view_id); 117 GetPrintManager(render_process_id_, render_frame_id);
119 if (!print_view_manager) 118 if (!print_view_manager)
120 return; 119 return;
120
121 // The file descriptor is originally created in & passed from the Android 121 // The file descriptor is originally created in & passed from the Android
122 // side, and it will handle the closing. 122 // side, and it will handle the closing.
123 temp_file_fd->fd = print_view_manager->file_descriptor().fd; 123 temp_file_fd->fd = print_view_manager->file_descriptor().fd;
124 temp_file_fd->auto_close = false; 124 temp_file_fd->auto_close = false;
125 } 125 }
126 126
127 void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_view_id, 127 void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_frame_id,
128 int sequence_number) { 128 int sequence_number) {
129 DCHECK_CURRENTLY_ON(BrowserThread::UI); 129 DCHECK_CURRENTLY_ON(BrowserThread::UI);
130 PrintViewManagerBasic* print_view_manager = 130 PrintViewManagerBasic* print_view_manager =
131 GetPrintManager(render_process_id_, render_view_id); 131 GetPrintManager(render_process_id_, render_frame_id);
132 if (print_view_manager) 132 if (print_view_manager)
133 print_view_manager->PdfWritingDone(true); 133 print_view_manager->PdfWritingDone(true);
134 } 134 }
135 #endif // defined(OS_ANDROID) 135 #endif // defined(OS_ANDROID)
136 136
137 void PrintingMessageFilter::OnIsPrintingEnabled(bool* is_enabled) {
138 DCHECK_CURRENTLY_ON(BrowserThread::IO);
139 *is_enabled = is_printing_enabled_->GetValue();
140 }
141
142 void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) { 137 void PrintingMessageFilter::OnGetDefaultPrintSettings(IPC::Message* reply_msg) {
143 DCHECK_CURRENTLY_ON(BrowserThread::IO); 138 DCHECK_CURRENTLY_ON(BrowserThread::IO);
144 scoped_refptr<PrinterQuery> printer_query; 139 scoped_refptr<PrinterQuery> printer_query;
145 if (!is_printing_enabled_->GetValue()) { 140 if (!is_printing_enabled_->GetValue()) {
146 // Reply with NULL query. 141 // Reply with NULL query.
147 OnGetDefaultPrintSettingsReply(printer_query, reply_msg); 142 OnGetDefaultPrintSettingsReply(printer_query, reply_msg);
148 return; 143 return;
149 } 144 }
150 printer_query = queue_->PopPrinterQuery(0); 145 printer_query = queue_->PopPrinterQuery(0);
151 if (!printer_query.get()) { 146 if (!printer_query.get()) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 routing_id, file_descriptor)); 228 routing_id, file_descriptor));
234 } 229 }
235 #endif 230 #endif
236 queue_->QueuePrinterQuery(printer_query.get()); 231 queue_->QueuePrinterQuery(printer_query.get());
237 } else { 232 } else {
238 printer_query->StopWorker(); 233 printer_query->StopWorker();
239 } 234 }
240 } 235 }
241 236
242 #if defined(OS_ANDROID) 237 #if defined(OS_ANDROID)
243 void PrintingMessageFilter::UpdateFileDescriptor(int render_view_id, int fd) { 238 void PrintingMessageFilter::UpdateFileDescriptor(int render_frame_id, int fd) {
244 DCHECK_CURRENTLY_ON(BrowserThread::UI); 239 DCHECK_CURRENTLY_ON(BrowserThread::UI);
245 PrintViewManagerBasic* print_view_manager = 240 PrintViewManagerBasic* print_view_manager =
246 GetPrintManager(render_process_id_, render_view_id); 241 GetPrintManager(render_process_id_, render_frame_id);
247 if (print_view_manager) 242 if (print_view_manager)
248 print_view_manager->set_file_descriptor(base::FileDescriptor(fd, false)); 243 print_view_manager->set_file_descriptor(base::FileDescriptor(fd, false));
249 } 244 }
250 #endif 245 #endif
251 246
252 void PrintingMessageFilter::OnUpdatePrintSettings( 247 void PrintingMessageFilter::OnUpdatePrintSettings(
253 int document_cookie, const base::DictionaryValue& job_settings, 248 int document_cookie, const base::DictionaryValue& job_settings,
254 IPC::Message* reply_msg) { 249 IPC::Message* reply_msg) {
255 std::unique_ptr<base::DictionaryValue> new_settings(job_settings.DeepCopy()); 250 std::unique_ptr<base::DictionaryValue> new_settings(job_settings.DeepCopy());
256 251
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 void PrintingMessageFilter::OnCheckForCancel(int32_t preview_ui_id, 306 void PrintingMessageFilter::OnCheckForCancel(int32_t preview_ui_id,
312 int preview_request_id, 307 int preview_request_id,
313 bool* cancel) { 308 bool* cancel) {
314 PrintPreviewUI::GetCurrentPrintPreviewStatus(preview_ui_id, 309 PrintPreviewUI::GetCurrentPrintPreviewStatus(preview_ui_id,
315 preview_request_id, 310 preview_request_id,
316 cancel); 311 cancel);
317 } 312 }
318 #endif 313 #endif
319 314
320 } // namespace printing 315 } // namespace printing
OLDNEW
« no previous file with comments | « chrome/browser/printing/printing_message_filter.h ('k') | chrome/browser/ui/browser_commands.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698