| 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_client.h" | 7 #include "content/renderer/renderer_clipboard_client.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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 | 109 |
| 110 uint64 RendererClipboardClient::GetSequenceNumber(ui::ClipboardType type) { | 110 uint64 RendererClipboardClient::GetSequenceNumber(ui::ClipboardType type) { |
| 111 uint64 sequence_number = 0; | 111 uint64 sequence_number = 0; |
| 112 RenderThreadImpl::current()->Send( | 112 RenderThreadImpl::current()->Send( |
| 113 new ClipboardHostMsg_GetSequenceNumber(type, &sequence_number)); | 113 new ClipboardHostMsg_GetSequenceNumber(type, &sequence_number)); |
| 114 return sequence_number; | 114 return sequence_number; |
| 115 } | 115 } |
| 116 | 116 |
| 117 bool RendererClipboardClient::IsFormatAvailable(content::ClipboardFormat format, | 117 bool RendererClipboardClient::IsFormatAvailable(content::ClipboardFormat format, |
| 118 ui::ClipboardType type) { | 118 ui::ClipboardType type) { |
| 119 bool result; | 119 bool result = false; |
| 120 RenderThreadImpl::current()->Send( | 120 RenderThreadImpl::current()->Send( |
| 121 new ClipboardHostMsg_IsFormatAvailable(format, type, &result)); | 121 new ClipboardHostMsg_IsFormatAvailable(format, type, &result)); |
| 122 return result; | 122 return result; |
| 123 } | 123 } |
| 124 | 124 |
| 125 void RendererClipboardClient::Clear(ui::ClipboardType type) { | 125 void RendererClipboardClient::Clear(ui::ClipboardType type) { |
| 126 RenderThreadImpl::current()->Send(new ClipboardHostMsg_Clear(type)); | 126 RenderThreadImpl::current()->Send(new ClipboardHostMsg_Clear(type)); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void RendererClipboardClient::ReadAvailableTypes( | 129 void RendererClipboardClient::ReadAvailableTypes( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 149 } | 149 } |
| 150 | 150 |
| 151 void RendererClipboardClient::ReadRTF(ui::ClipboardType type, | 151 void RendererClipboardClient::ReadRTF(ui::ClipboardType type, |
| 152 std::string* result) { | 152 std::string* result) { |
| 153 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadRTF(type, result)); | 153 RenderThreadImpl::current()->Send(new ClipboardHostMsg_ReadRTF(type, result)); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void RendererClipboardClient::ReadImage(ui::ClipboardType type, | 156 void RendererClipboardClient::ReadImage(ui::ClipboardType type, |
| 157 std::string* data) { | 157 std::string* data) { |
| 158 base::SharedMemoryHandle image_handle; | 158 base::SharedMemoryHandle image_handle; |
| 159 uint32 image_size; | 159 uint32 image_size = 0; |
| 160 RenderThreadImpl::current()->Send( | 160 RenderThreadImpl::current()->Send( |
| 161 new ClipboardHostMsg_ReadImage(type, &image_handle, &image_size)); | 161 new ClipboardHostMsg_ReadImage(type, &image_handle, &image_size)); |
| 162 if (base::SharedMemory::IsHandleValid(image_handle)) { | 162 if (base::SharedMemory::IsHandleValid(image_handle)) { |
| 163 base::SharedMemory buffer(image_handle, true); | 163 base::SharedMemory buffer(image_handle, true); |
| 164 buffer.Map(image_size); | 164 buffer.Map(image_size); |
| 165 data->append(static_cast<char*>(buffer.memory()), image_size); | 165 data->append(static_cast<char*>(buffer.memory()), image_size); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 void RendererClipboardClient::ReadCustomData(ui::ClipboardType clipboard_type, | 169 void RendererClipboardClient::ReadCustomData(ui::ClipboardType clipboard_type, |
| 170 const base::string16& type, | 170 const base::string16& type, |
| 171 base::string16* data) { | 171 base::string16* data) { |
| 172 RenderThreadImpl::current()->Send( | 172 RenderThreadImpl::current()->Send( |
| 173 new ClipboardHostMsg_ReadCustomData(clipboard_type, type, data)); | 173 new ClipboardHostMsg_ReadCustomData(clipboard_type, type, data)); |
| 174 } | 174 } |
| 175 | 175 |
| 176 ClipboardClient::WriteContext* RendererClipboardClient::CreateWriteContext() { | 176 ClipboardClient::WriteContext* RendererClipboardClient::CreateWriteContext() { |
| 177 return new RendererClipboardWriteContext; | 177 return new RendererClipboardWriteContext; |
| 178 } | 178 } |
| 179 | 179 |
| 180 } // namespace content | 180 } // namespace content |
| OLD | NEW |