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" |
11 #include "content/common/clipboard_messages.h" | 11 #include "content/common/clipboard_messages.h" |
12 #include "content/public/renderer/content_renderer_client.h" | 12 #include "content/public/renderer/content_renderer_client.h" |
13 #include "content/renderer/render_thread_impl.h" | 13 #include "content/renderer/render_thread_impl.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 14 #include "third_party/skia/include/core/SkBitmap.h" |
15 #include "ui/base/clipboard/clipboard.h" | 15 #include "ui/base/clipboard/clipboard.h" |
16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 RendererClipboardDelegate::RendererClipboardDelegate() { | 20 RendererClipboardDelegate::RendererClipboardDelegate() { |
21 } | 21 } |
22 | 22 |
23 uint64 RendererClipboardDelegate::GetSequenceNumber(ui::ClipboardType type) { | 23 uint64_t RendererClipboardDelegate::GetSequenceNumber(ui::ClipboardType type) { |
24 uint64 sequence_number = 0; | 24 uint64_t sequence_number = 0; |
25 RenderThreadImpl::current()->Send( | 25 RenderThreadImpl::current()->Send( |
26 new ClipboardHostMsg_GetSequenceNumber(type, &sequence_number)); | 26 new ClipboardHostMsg_GetSequenceNumber(type, &sequence_number)); |
27 return sequence_number; | 27 return sequence_number; |
28 } | 28 } |
29 | 29 |
30 bool RendererClipboardDelegate::IsFormatAvailable( | 30 bool RendererClipboardDelegate::IsFormatAvailable( |
31 content::ClipboardFormat format, | 31 content::ClipboardFormat format, |
32 ui::ClipboardType type) { | 32 ui::ClipboardType type) { |
33 bool result = false; | 33 bool result = false; |
34 RenderThreadImpl::current()->Send( | 34 RenderThreadImpl::current()->Send( |
(...skipping 15 matching lines...) Expand all Loading... |
50 | 50 |
51 void RendererClipboardDelegate::ReadText(ui::ClipboardType type, | 51 void RendererClipboardDelegate::ReadText(ui::ClipboardType type, |
52 base::string16* result) { | 52 base::string16* result) { |
53 RenderThreadImpl::current()->Send( | 53 RenderThreadImpl::current()->Send( |
54 new ClipboardHostMsg_ReadText(type, result)); | 54 new ClipboardHostMsg_ReadText(type, result)); |
55 } | 55 } |
56 | 56 |
57 void RendererClipboardDelegate::ReadHTML(ui::ClipboardType type, | 57 void RendererClipboardDelegate::ReadHTML(ui::ClipboardType type, |
58 base::string16* markup, | 58 base::string16* markup, |
59 GURL* url, | 59 GURL* url, |
60 uint32* fragment_start, | 60 uint32_t* fragment_start, |
61 uint32* fragment_end) { | 61 uint32_t* fragment_end) { |
62 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadHTML( | 62 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadHTML( |
63 type, markup, url, fragment_start, fragment_end)); | 63 type, markup, url, fragment_start, fragment_end)); |
64 } | 64 } |
65 | 65 |
66 void RendererClipboardDelegate::ReadRTF(ui::ClipboardType type, | 66 void RendererClipboardDelegate::ReadRTF(ui::ClipboardType type, |
67 std::string* result) { | 67 std::string* result) { |
68 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadRTF(type, result)); | 68 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadRTF(type, result)); |
69 } | 69 } |
70 | 70 |
71 void RendererClipboardDelegate::ReadImage(ui::ClipboardType type, | 71 void RendererClipboardDelegate::ReadImage(ui::ClipboardType type, |
72 std::string* data) { | 72 std::string* data) { |
73 base::SharedMemoryHandle image_handle; | 73 base::SharedMemoryHandle image_handle; |
74 uint32 image_size = 0; | 74 uint32_t image_size = 0; |
75 RenderThreadImpl::current()->Send( | 75 RenderThreadImpl::current()->Send( |
76 new ClipboardHostMsg_ReadImage(type, &image_handle, &image_size)); | 76 new ClipboardHostMsg_ReadImage(type, &image_handle, &image_size)); |
77 if (base::SharedMemory::IsHandleValid(image_handle)) { | 77 if (base::SharedMemory::IsHandleValid(image_handle)) { |
78 base::SharedMemory buffer(image_handle, true); | 78 base::SharedMemory buffer(image_handle, true); |
79 buffer.Map(image_size); | 79 buffer.Map(image_size); |
80 data->append(static_cast<char*>(buffer.memory()), image_size); | 80 data->append(static_cast<char*>(buffer.memory()), image_size); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void RendererClipboardDelegate::ReadCustomData(ui::ClipboardType clipboard_type, | 84 void RendererClipboardDelegate::ReadCustomData(ui::ClipboardType clipboard_type, |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 const gfx::Size size(bitmap.width(), bitmap.height()); | 129 const gfx::Size size(bitmap.width(), bitmap.height()); |
130 scoped_ptr<base::SharedMemory> shared_buf; | 130 scoped_ptr<base::SharedMemory> shared_buf; |
131 { | 131 { |
132 SkAutoLockPixels locked(bitmap); | 132 SkAutoLockPixels locked(bitmap); |
133 void* pixels = bitmap.getPixels(); | 133 void* pixels = bitmap.getPixels(); |
134 // TODO(piman): this should not be NULL, but it is. crbug.com/369621 | 134 // TODO(piman): this should not be NULL, but it is. crbug.com/369621 |
135 if (!pixels) | 135 if (!pixels) |
136 return false; | 136 return false; |
137 | 137 |
138 base::CheckedNumeric<uint32> checked_buf_size = 4; | 138 base::CheckedNumeric<uint32_t> 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_t buf_size = checked_buf_size.ValueOrDie(); |
146 shared_buf = ChildThreadImpl::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 |