OLD | NEW |
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 // This file provides the embedder's side of random webkit glue functions. | 5 // This file provides the embedder's side of random webkit glue functions. |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 | 8 |
9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // across processes. | 44 // across processes. |
45 void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels, | 45 void ScopedClipboardWriterGlue::WriteBitmapFromPixels(const void* pixels, |
46 const gfx::Size& size) { | 46 const gfx::Size& size) { |
47 // Do not try to write a bitmap more than once | 47 // Do not try to write a bitmap more than once |
48 if (shared_buf_) | 48 if (shared_buf_) |
49 return; | 49 return; |
50 | 50 |
51 uint32 buf_size = 4 * size.width() * size.height(); | 51 uint32 buf_size = 4 * size.width() * size.height(); |
52 | 52 |
53 // Allocate a shared memory buffer to hold the bitmap bits. | 53 // Allocate a shared memory buffer to hold the bitmap bits. |
54 #if defined(OS_POSIX) | 54 shared_buf_ = ChildThread::current()->AllocateSharedMemory(buf_size); |
55 // On POSIX, we need to ask the browser to create the shared memory for us, | 55 if (!shared_buf_) |
56 // since this is blocked by the sandbox. | |
57 base::SharedMemoryHandle shared_mem_handle; | |
58 ViewHostMsg_AllocateSharedMemoryBuffer *msg = | |
59 new ViewHostMsg_AllocateSharedMemoryBuffer(buf_size, | |
60 &shared_mem_handle); | |
61 if (RenderThreadImpl::current()->Send(msg)) { | |
62 if (base::SharedMemory::IsHandleValid(shared_mem_handle)) { | |
63 shared_buf_ = new base::SharedMemory(shared_mem_handle, false); | |
64 if (!shared_buf_ || !shared_buf_->Map(buf_size)) { | |
65 NOTREACHED() << "Map failed"; | |
66 return; | |
67 } | |
68 } else { | |
69 NOTREACHED() << "Browser failed to allocate shared memory"; | |
70 return; | |
71 } | |
72 } else { | |
73 NOTREACHED() << "Browser allocation request message failed"; | |
74 return; | 56 return; |
75 } | |
76 #else // !OS_POSIX | |
77 shared_buf_ = new base::SharedMemory; | |
78 if (!shared_buf_->CreateAndMapAnonymous(buf_size)) { | |
79 NOTREACHED(); | |
80 return; | |
81 } | |
82 #endif | |
83 | 57 |
84 // Copy the bits into shared memory | 58 // Copy the bits into shared memory |
| 59 DCHECK(shared_buf_->memory()); |
85 memcpy(shared_buf_->memory(), pixels, buf_size); | 60 memcpy(shared_buf_->memory(), pixels, buf_size); |
86 shared_buf_->Unmap(); | 61 shared_buf_->Unmap(); |
87 | 62 |
88 ui::Clipboard::ObjectMapParam size_param; | 63 ui::Clipboard::ObjectMapParam size_param; |
89 const char* size_data = reinterpret_cast<const char*>(&size); | 64 const char* size_data = reinterpret_cast<const char*>(&size); |
90 for (size_t i = 0; i < sizeof(gfx::Size); ++i) | 65 for (size_t i = 0; i < sizeof(gfx::Size); ++i) |
91 size_param.push_back(size_data[i]); | 66 size_param.push_back(size_data[i]); |
92 | 67 |
93 ui::Clipboard::ObjectMapParams params; | 68 ui::Clipboard::ObjectMapParams params; |
94 | 69 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 221 |
247 string16 GetLocalizedString(int message_id) { | 222 string16 GetLocalizedString(int message_id) { |
248 return content::GetContentClient()->GetLocalizedString(message_id); | 223 return content::GetContentClient()->GetLocalizedString(message_id); |
249 } | 224 } |
250 | 225 |
251 base::StringPiece GetDataResource(int resource_id) { | 226 base::StringPiece GetDataResource(int resource_id) { |
252 return content::GetContentClient()->GetDataResource(resource_id); | 227 return content::GetContentClient()->GetDataResource(resource_id); |
253 } | 228 } |
254 | 229 |
255 } // namespace webkit_glue | 230 } // namespace webkit_glue |
OLD | NEW |