OLD | NEW |
---|---|
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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
25 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
26 #include <fcntl.h> | 26 #include <fcntl.h> |
27 | 27 |
28 #include <map> | 28 #include <map> |
29 | 29 |
30 #include "base/file_util.h" | 30 #include "base/file_util.h" |
31 #include "base/lazy_instance.h" | 31 #include "base/lazy_instance.h" |
32 #include "chrome/browser/printing/print_dialog_cloud.h" | 32 #include "chrome/browser/printing/print_dialog_cloud.h" |
33 #endif | 33 #endif |
34 | 34 |
35 #if defined(OS_ANDROID) | |
36 #include "chrome/browser/printing/print_view_manager_basic.h" | |
37 #endif | |
38 | |
35 using content::BrowserThread; | 39 using content::BrowserThread; |
36 | 40 |
37 namespace { | 41 namespace { |
38 | 42 |
39 #if defined(OS_CHROMEOS) | 43 #if defined(OS_CHROMEOS) |
40 typedef std::map<int, base::FilePath> SequenceToPathMap; | 44 typedef std::map<int, base::FilePath> SequenceToPathMap; |
41 | 45 |
42 struct PrintingSequencePathMap { | 46 struct PrintingSequencePathMap { |
43 SequenceToPathMap map; | 47 SequenceToPathMap map; |
44 int sequence; | 48 int sequence; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 PrintingMessageFilter::~PrintingMessageFilter() { | 97 PrintingMessageFilter::~PrintingMessageFilter() { |
94 } | 98 } |
95 | 99 |
96 void PrintingMessageFilter::OverrideThreadForMessage( | 100 void PrintingMessageFilter::OverrideThreadForMessage( |
97 const IPC::Message& message, BrowserThread::ID* thread) { | 101 const IPC::Message& message, BrowserThread::ID* thread) { |
98 #if defined(OS_CHROMEOS) | 102 #if defined(OS_CHROMEOS) |
99 if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID || | 103 if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID || |
100 message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) { | 104 message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) { |
101 *thread = BrowserThread::FILE; | 105 *thread = BrowserThread::FILE; |
102 } | 106 } |
107 #elif defined(OS_ANDROID) | |
108 if (message.type() == PrintHostMsg_AllocateTempFileForPrinting::ID || | |
109 message.type() == PrintHostMsg_TempFileForPrintingWritten::ID) { | |
110 *thread = BrowserThread::UI; | |
111 } | |
103 #endif | 112 #endif |
104 } | 113 } |
105 | 114 |
106 bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message, | 115 bool PrintingMessageFilter::OnMessageReceived(const IPC::Message& message, |
107 bool* message_was_ok) { | 116 bool* message_was_ok) { |
108 bool handled = true; | 117 bool handled = true; |
109 IPC_BEGIN_MESSAGE_MAP_EX(PrintingMessageFilter, message, *message_was_ok) | 118 IPC_BEGIN_MESSAGE_MAP_EX(PrintingMessageFilter, message, *message_was_ok) |
110 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
111 IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) | 120 IPC_MESSAGE_HANDLER(PrintHostMsg_DuplicateSection, OnDuplicateSection) |
112 #endif | 121 #endif |
113 #if defined(OS_CHROMEOS) | 122 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
114 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, | 123 IPC_MESSAGE_HANDLER(PrintHostMsg_AllocateTempFileForPrinting, |
115 OnAllocateTempFileForPrinting) | 124 OnAllocateTempFileForPrinting) |
116 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, | 125 IPC_MESSAGE_HANDLER(PrintHostMsg_TempFileForPrintingWritten, |
117 OnTempFileForPrintingWritten) | 126 OnTempFileForPrintingWritten) |
118 #endif | 127 #endif |
119 IPC_MESSAGE_HANDLER(PrintHostMsg_IsPrintingEnabled, OnIsPrintingEnabled) | 128 IPC_MESSAGE_HANDLER(PrintHostMsg_IsPrintingEnabled, OnIsPrintingEnabled) |
120 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, | 129 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_GetDefaultPrintSettings, |
121 OnGetDefaultPrintSettings) | 130 OnGetDefaultPrintSettings) |
122 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint) | 131 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_ScriptedPrint, OnScriptedPrint) |
123 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_UpdatePrintSettings, | 132 IPC_MESSAGE_HANDLER_DELAY_REPLY(PrintHostMsg_UpdatePrintSettings, |
(...skipping 10 matching lines...) Expand all Loading... | |
134 void PrintingMessageFilter::OnDuplicateSection( | 143 void PrintingMessageFilter::OnDuplicateSection( |
135 base::SharedMemoryHandle renderer_handle, | 144 base::SharedMemoryHandle renderer_handle, |
136 base::SharedMemoryHandle* browser_handle) { | 145 base::SharedMemoryHandle* browser_handle) { |
137 // Duplicate the handle in this process right now so the memory is kept alive | 146 // Duplicate the handle in this process right now so the memory is kept alive |
138 // (even if it is not mapped) | 147 // (even if it is not mapped) |
139 base::SharedMemory shared_buf(renderer_handle, true, PeerHandle()); | 148 base::SharedMemory shared_buf(renderer_handle, true, PeerHandle()); |
140 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle); | 149 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), browser_handle); |
141 } | 150 } |
142 #endif | 151 #endif |
143 | 152 |
153 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) | |
154 void PrintingMessageFilter::OnAllocateTempFileForPrinting( | |
155 int render_view_id, | |
156 base::FileDescriptor* temp_file_fd, | |
157 int* sequence_number) { | |
144 #if defined(OS_CHROMEOS) | 158 #if defined(OS_CHROMEOS) |
145 void PrintingMessageFilter::OnAllocateTempFileForPrinting( | |
146 base::FileDescriptor* temp_file_fd, int* sequence_number) { | |
147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 159 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
148 temp_file_fd->fd = *sequence_number = -1; | 160 temp_file_fd->fd = *sequence_number = -1; |
149 temp_file_fd->auto_close = false; | 161 temp_file_fd->auto_close = false; |
150 | 162 |
151 SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map; | 163 SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map; |
152 *sequence_number = g_printing_file_descriptor_map.Get().sequence++; | 164 *sequence_number = g_printing_file_descriptor_map.Get().sequence++; |
153 | 165 |
154 base::FilePath path; | 166 base::FilePath path; |
155 if (file_util::CreateTemporaryFile(&path)) { | 167 if (file_util::CreateTemporaryFile(&path)) { |
156 int fd = open(path.value().c_str(), O_WRONLY); | 168 int fd = open(path.value().c_str(), O_WRONLY); |
157 if (fd >= 0) { | 169 if (fd >= 0) { |
158 SequenceToPathMap::iterator it = map->find(*sequence_number); | 170 SequenceToPathMap::iterator it = map->find(*sequence_number); |
159 if (it != map->end()) { | 171 if (it != map->end()) { |
160 NOTREACHED() << "Sequence number already in use. seq=" << | 172 NOTREACHED() << "Sequence number already in use. seq=" << |
161 *sequence_number; | 173 *sequence_number; |
162 } else { | 174 } else { |
163 (*map)[*sequence_number] = path; | 175 (*map)[*sequence_number] = path; |
164 temp_file_fd->fd = fd; | 176 temp_file_fd->fd = fd; |
165 temp_file_fd->auto_close = true; | 177 temp_file_fd->auto_close = true; |
166 } | 178 } |
167 } | 179 } |
168 } | 180 } |
181 #elif defined(OS_ANDROID) | |
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
183 content::WebContents* wc = GetWebContentsForRenderView(render_view_id); | |
184 printing::PrintViewManagerBasic* print_view_manager = | |
185 printing::PrintViewManagerBasic::FromWebContents(wc); | |
186 temp_file_fd->auto_close = false; | |
187 temp_file_fd->fd = print_view_manager->GetFileDescriptor().fd; | |
whywhat
2013/08/15 20:19:56
Check that GetFileDescritor() is not NULL?
| |
188 #endif | |
169 } | 189 } |
170 | 190 |
171 void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_view_id, | 191 void PrintingMessageFilter::OnTempFileForPrintingWritten(int render_view_id, |
172 int sequence_number) { | 192 int sequence_number) { |
193 #if defined(OS_CHROMEOS) | |
173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
174 SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map; | 195 SequenceToPathMap* map = &g_printing_file_descriptor_map.Get().map; |
175 SequenceToPathMap::iterator it = map->find(sequence_number); | 196 SequenceToPathMap::iterator it = map->find(sequence_number); |
176 if (it == map->end()) { | 197 if (it == map->end()) { |
177 NOTREACHED() << "Got a sequence that we didn't pass to the " | 198 NOTREACHED() << "Got a sequence that we didn't pass to the " |
178 "renderer: " << sequence_number; | 199 "renderer: " << sequence_number; |
179 return; | 200 return; |
180 } | 201 } |
181 BrowserThread::PostTask( | 202 BrowserThread::PostTask( |
182 BrowserThread::UI, FROM_HERE, | 203 BrowserThread::UI, FROM_HERE, |
183 base::Bind(&PrintingMessageFilter::CreatePrintDialogForFile, | 204 base::Bind(&PrintingMessageFilter::CreatePrintDialogForFile, |
184 this, render_view_id, it->second)); | 205 this, render_view_id, it->second)); |
185 | 206 |
186 // Erase the entry in the map. | 207 // Erase the entry in the map. |
187 map->erase(it); | 208 map->erase(it); |
209 #endif | |
188 } | 210 } |
211 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) | |
189 | 212 |
213 #if defined(OS_CHROMEOS) | |
190 void PrintingMessageFilter::CreatePrintDialogForFile( | 214 void PrintingMessageFilter::CreatePrintDialogForFile( |
191 int render_view_id, | 215 int render_view_id, |
192 const base::FilePath& path) { | 216 const base::FilePath& path) { |
193 content::WebContents* wc = GetWebContentsForRenderView(render_view_id); | 217 content::WebContents* wc = GetWebContentsForRenderView(render_view_id); |
194 print_dialog_cloud::CreatePrintDialogForFile( | 218 print_dialog_cloud::CreatePrintDialogForFile( |
195 wc->GetBrowserContext(), | 219 wc->GetBrowserContext(), |
196 wc->GetView()->GetTopLevelNativeWindow(), | 220 wc->GetView()->GetTopLevelNativeWindow(), |
197 path, | 221 path, |
198 wc->GetTitle(), | 222 wc->GetTitle(), |
199 string16(), | 223 string16(), |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 | 409 |
386 #if defined(ENABLE_FULL_PRINTING) | 410 #if defined(ENABLE_FULL_PRINTING) |
387 void PrintingMessageFilter::OnCheckForCancel(int32 preview_ui_id, | 411 void PrintingMessageFilter::OnCheckForCancel(int32 preview_ui_id, |
388 int preview_request_id, | 412 int preview_request_id, |
389 bool* cancel) { | 413 bool* cancel) { |
390 PrintPreviewUI::GetCurrentPrintPreviewStatus(preview_ui_id, | 414 PrintPreviewUI::GetCurrentPrintPreviewStatus(preview_ui_id, |
391 preview_request_id, | 415 preview_request_id, |
392 cancel); | 416 cancel); |
393 } | 417 } |
394 #endif | 418 #endif |
OLD | NEW |