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 // This file provides the embedder's side of the Clipboard interface. | 5 // This file provides the embedder's side of the Clipboard interface. |
6 | 6 |
7 #include "content/renderer/renderer_clipboard_delegate.h" | 7 #include "content/renderer/renderer_clipboard_delegate.h" |
8 | 8 |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/numerics/safe_math.h" | 10 #include "base/numerics/safe_math.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 return false; | 136 return false; |
137 | 137 |
138 base::CheckedNumeric<uint32> checked_buf_size = 4; | 138 base::CheckedNumeric<uint32> checked_buf_size = 4; |
139 checked_buf_size *= size.width(); | 139 checked_buf_size *= size.width(); |
140 checked_buf_size *= size.height(); | 140 checked_buf_size *= size.height(); |
141 if (!checked_buf_size.IsValid()) | 141 if (!checked_buf_size.IsValid()) |
142 return false; | 142 return false; |
143 | 143 |
144 // Allocate a shared memory buffer to hold the bitmap bits. | 144 // Allocate a shared memory buffer to hold the bitmap bits. |
145 uint32 buf_size = checked_buf_size.ValueOrDie(); | 145 uint32 buf_size = checked_buf_size.ValueOrDie(); |
146 shared_buf = ChildThread::current()->AllocateSharedMemory(buf_size); | 146 shared_buf = ChildThreadImpl::current()->AllocateSharedMemory(buf_size); |
147 if (!shared_buf) | 147 if (!shared_buf) |
148 return false; | 148 return false; |
149 if (!shared_buf->Map(buf_size)) | 149 if (!shared_buf->Map(buf_size)) |
150 return false; | 150 return false; |
151 // Copy the bits into shared memory | 151 // Copy the bits into shared memory |
152 DCHECK(shared_buf->memory()); | 152 DCHECK(shared_buf->memory()); |
153 memcpy(shared_buf->memory(), pixels, buf_size); | 153 memcpy(shared_buf->memory(), pixels, buf_size); |
154 shared_buf->Unmap(); | 154 shared_buf->Unmap(); |
155 } | 155 } |
156 | 156 |
157 RenderThreadImpl::current()->Send(new ClipboardHostMsg_WriteImage( | 157 RenderThreadImpl::current()->Send(new ClipboardHostMsg_WriteImage( |
158 clipboard_type, size, shared_buf->handle())); | 158 clipboard_type, size, shared_buf->handle())); |
159 return true; | 159 return true; |
160 } | 160 } |
161 | 161 |
162 void RendererClipboardDelegate::CommitWrite(ui::ClipboardType clipboard_type) { | 162 void RendererClipboardDelegate::CommitWrite(ui::ClipboardType clipboard_type) { |
163 RenderThreadImpl::current()->Send( | 163 RenderThreadImpl::current()->Send( |
164 new ClipboardHostMsg_CommitWrite(clipboard_type)); | 164 new ClipboardHostMsg_CommitWrite(clipboard_type)); |
165 } | 165 } |
166 | 166 |
167 } // namespace content | 167 } // namespace content |
OLD | NEW |