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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 1793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1804 } | 1804 } |
1805 #endif // !defined(OS_MACOSX) | 1805 #endif // !defined(OS_MACOSX) |
1806 | 1806 |
1807 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 1807 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
1808 const PdfMetafileSkia& metafile, | 1808 const PdfMetafileSkia& metafile, |
1809 base::SharedMemoryHandle* shared_mem_handle) { | 1809 base::SharedMemoryHandle* shared_mem_handle) { |
1810 uint32_t buf_size = metafile.GetDataSize(); | 1810 uint32_t buf_size = metafile.GetDataSize(); |
1811 if (buf_size == 0) | 1811 if (buf_size == 0) |
1812 return false; | 1812 return false; |
1813 | 1813 |
1814 #if defined(OS_WIN) | |
1815 base::SharedMemory shared_buf; | |
1816 // Allocate a shared memory buffer to hold the generated metafile data. | |
1817 if (!shared_buf.CreateAndMapAnonymous(buf_size)) | |
1818 return false; | |
1819 | |
1820 // Copy the bits into shared memory. | |
1821 if (!metafile.GetData(shared_buf.memory(), buf_size)) | |
1822 return false; | |
1823 | |
1824 *shared_mem_handle = base::SharedMemory::DuplicateHandle(shared_buf.handle()); | |
1825 return true; | |
1826 #else | |
1827 scoped_ptr<base::SharedMemory> shared_buf( | 1814 scoped_ptr<base::SharedMemory> shared_buf( |
1828 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size)); | 1815 content::RenderThread::Get()->HostAllocateSharedMemoryBuffer(buf_size)); |
1829 if (!shared_buf) | 1816 if (!shared_buf) |
1830 return false; | 1817 return false; |
1831 | 1818 |
1832 if (!shared_buf->Map(buf_size)) | 1819 if (!shared_buf->Map(buf_size)) |
1833 return false; | 1820 return false; |
1834 | 1821 |
1835 if (!metafile.GetData(shared_buf->memory(), buf_size)) | 1822 if (!metafile.GetData(shared_buf->memory(), buf_size)) |
1836 return false; | 1823 return false; |
1837 | 1824 |
1838 return shared_buf->GiveToProcess(base::GetCurrentProcessHandle(), | 1825 *shared_mem_handle = |
1839 shared_mem_handle); | 1826 base::SharedMemory::DuplicateHandle(shared_buf->handle()); |
1840 #endif // defined(OS_WIN) | 1827 return true; |
1841 } | 1828 } |
1842 | 1829 |
1843 #if defined(ENABLE_PRINT_PREVIEW) | 1830 #if defined(ENABLE_PRINT_PREVIEW) |
1844 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1831 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
1845 if (is_scripted_preview_delayed_) { | 1832 if (is_scripted_preview_delayed_) { |
1846 is_scripted_preview_delayed_ = false; | 1833 is_scripted_preview_delayed_ = false; |
1847 Send(new PrintHostMsg_ShowScriptedPrintPreview( | 1834 Send(new PrintHostMsg_ShowScriptedPrintPreview( |
1848 routing_id(), print_preview_context_.IsModifiable())); | 1835 routing_id(), print_preview_context_.IsModifiable())); |
1849 } | 1836 } |
1850 } | 1837 } |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2253 blink::WebConsoleMessage::LevelWarning, message)); | 2240 blink::WebConsoleMessage::LevelWarning, message)); |
2254 return false; | 2241 return false; |
2255 } | 2242 } |
2256 | 2243 |
2257 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2244 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2258 // Reset counter on successful print. | 2245 // Reset counter on successful print. |
2259 count_ = 0; | 2246 count_ = 0; |
2260 } | 2247 } |
2261 | 2248 |
2262 } // namespace printing | 2249 } // namespace printing |
OLD | NEW |