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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return false; | 131 return false; |
132 | 132 |
133 base::CheckedNumeric<uint32_t> checked_buf_size = 4; | 133 base::CheckedNumeric<uint32_t> checked_buf_size = 4; |
134 checked_buf_size *= size.width(); | 134 checked_buf_size *= size.width(); |
135 checked_buf_size *= size.height(); | 135 checked_buf_size *= size.height(); |
136 if (!checked_buf_size.IsValid()) | 136 if (!checked_buf_size.IsValid()) |
137 return false; | 137 return false; |
138 | 138 |
139 // Allocate a shared memory buffer to hold the bitmap bits. | 139 // Allocate a shared memory buffer to hold the bitmap bits. |
140 uint32_t buf_size = checked_buf_size.ValueOrDie(); | 140 uint32_t buf_size = checked_buf_size.ValueOrDie(); |
141 shared_buf = ChildThreadImpl::current()->AllocateSharedMemory(buf_size); | 141 shared_buf = ChildThreadImpl::AllocateSharedMemory(buf_size); |
142 if (!shared_buf) | 142 if (!shared_buf) |
143 return false; | 143 return false; |
144 if (!shared_buf->Map(buf_size)) | 144 if (!shared_buf->Map(buf_size)) |
145 return false; | 145 return false; |
146 // Copy the bits into shared memory | 146 // Copy the bits into shared memory |
147 DCHECK(shared_buf->memory()); | 147 DCHECK(shared_buf->memory()); |
148 memcpy(shared_buf->memory(), pixels, buf_size); | 148 memcpy(shared_buf->memory(), pixels, buf_size); |
149 shared_buf->Unmap(); | 149 shared_buf->Unmap(); |
150 } | 150 } |
151 | 151 |
152 RenderThreadImpl::current()->Send(new ClipboardHostMsg_WriteImage( | 152 RenderThreadImpl::current()->Send(new ClipboardHostMsg_WriteImage( |
153 clipboard_type, size, shared_buf->handle())); | 153 clipboard_type, size, shared_buf->handle())); |
154 return true; | 154 return true; |
155 } | 155 } |
156 | 156 |
157 void RendererClipboardDelegate::CommitWrite(ui::ClipboardType clipboard_type) { | 157 void RendererClipboardDelegate::CommitWrite(ui::ClipboardType clipboard_type) { |
158 RenderThreadImpl::current()->Send( | 158 RenderThreadImpl::current()->Send( |
159 new ClipboardHostMsg_CommitWrite(clipboard_type)); | 159 new ClipboardHostMsg_CommitWrite(clipboard_type)); |
160 } | 160 } |
161 | 161 |
162 } // namespace content | 162 } // namespace content |
OLD | NEW |