| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "content/browser/renderer_host/clipboard_message_filter.h" | 5 #include "content/browser/renderer_host/clipboard_message_filter.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 base::SharedMemoryCreateOptions options; | 45 base::SharedMemoryCreateOptions options; |
| 46 options.size = size; | 46 options.size = size; |
| 47 options.share_read_only = true; | 47 options.share_read_only = true; |
| 48 if (!m->Create(options)) | 48 if (!m->Create(options)) |
| 49 return nullptr; | 49 return nullptr; |
| 50 return m; | 50 return m; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void CallWriteImage(const gfx::Size& size, | 53 void CallWriteImage(const gfx::Size& size, |
| 54 base::SharedMemory* shared_memory) { | 54 base::SharedMemory* shared_memory) { |
| 55 base::SharedMemoryHandle handle; | 55 base::SharedMemoryHandle handle = shared_memory->GetReadOnlyHandle(); |
| 56 ASSERT_TRUE(shared_memory->GiveReadOnlyToProcess( | 56 shared_memory->Unmap(); |
| 57 base::GetCurrentProcessHandle(), &handle)); | 57 shared_memory->Close(); |
| 58 ASSERT_TRUE(handle.IsValid()); |
| 58 CallWriteImageDirectly(size, handle); | 59 CallWriteImageDirectly(size, handle); |
| 59 } | 60 } |
| 60 | 61 |
| 61 // Prefer to use CallWriteImage() in tests. | 62 // Prefer to use CallWriteImage() in tests. |
| 62 void CallWriteImageDirectly(const gfx::Size& size, | 63 void CallWriteImageDirectly(const gfx::Size& size, |
| 63 base::SharedMemoryHandle handle) { | 64 base::SharedMemoryHandle handle) { |
| 64 filter_->OnWriteImage(ui::CLIPBOARD_TYPE_COPY_PASTE, size, handle); | 65 filter_->OnWriteImage(ui::CLIPBOARD_TYPE_COPY_PASTE, size, handle); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void CallCommitWrite() { | 68 void CallCommitWrite() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 CallWriteImageDirectly(gfx::Size(5, 5), base::SharedMemoryHandle()); | 127 CallWriteImageDirectly(gfx::Size(5, 5), base::SharedMemoryHandle()); |
| 127 uint64_t sequence_number = | 128 uint64_t sequence_number = |
| 128 clipboard()->GetSequenceNumber(ui::CLIPBOARD_TYPE_COPY_PASTE); | 129 clipboard()->GetSequenceNumber(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| 129 CallCommitWrite(); | 130 CallCommitWrite(); |
| 130 | 131 |
| 131 EXPECT_EQ(sequence_number, | 132 EXPECT_EQ(sequence_number, |
| 132 clipboard()->GetSequenceNumber(ui::CLIPBOARD_TYPE_COPY_PASTE)); | 133 clipboard()->GetSequenceNumber(ui::CLIPBOARD_TYPE_COPY_PASTE)); |
| 133 } | 134 } |
| 134 | 135 |
| 135 } // namespace content | 136 } // namespace content |
| OLD | NEW |