Clean up extension confirmation prompts and make them consistent between Views and...
[chromium-blink-merge.git] / components / clipboard / clipboard_standalone_impl.cc
blob2cf03c295a209df2294436027f3213b85bebec27
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
3 // found in the LICENSE file.
5 #include "components/clipboard/clipboard_standalone_impl.h"
7 #include <string.h>
9 #include "third_party/mojo/src/mojo/public/cpp/bindings/array.h"
10 #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
11 #include "third_party/mojo/src/mojo/public/cpp/bindings/string.h"
13 using mojo::Array;
14 using mojo::Map;
15 using mojo::String;
17 namespace clipboard {
19 // ClipboardData contains data copied to the Clipboard for a variety of formats.
20 // It mostly just provides APIs to cleanly access and manipulate this data.
21 class ClipboardStandaloneImpl::ClipboardData {
22 public:
23 ClipboardData() {}
24 ~ClipboardData() {}
26 Array<String> GetMimeTypes() const {
27 Array<String> types(data_types_.size());
28 int i = 0;
29 for (auto it = data_types_.begin(); it != data_types_.end(); ++it, ++i)
30 types[i] = it.GetKey();
32 return types.Pass();
35 void SetData(Map<String, Array<uint8_t>> data) { data_types_ = data.Pass(); }
37 void GetData(const String& mime_type, Array<uint8_t>* data) const {
38 auto it = data_types_.find(mime_type);
39 if (it != data_types_.end())
40 *data = it.GetValue().Clone();
43 private:
44 Map<String, Array<uint8_t>> data_types_;
46 DISALLOW_COPY_AND_ASSIGN(ClipboardData);
49 ClipboardStandaloneImpl::ClipboardStandaloneImpl(
50 mojo::InterfaceRequest<mojo::Clipboard> request)
51 : binding_(this, request.Pass()) {
52 for (int i = 0; i < kNumClipboards; ++i) {
53 sequence_number_[i] = 0;
54 clipboard_state_[i].reset(new ClipboardData);
58 ClipboardStandaloneImpl::~ClipboardStandaloneImpl() {
61 void ClipboardStandaloneImpl::GetSequenceNumber(
62 Clipboard::Type clipboard_type,
63 const mojo::Callback<void(uint64_t)>& callback) {
64 callback.Run(sequence_number_[clipboard_type]);
67 void ClipboardStandaloneImpl::GetAvailableMimeTypes(
68 Clipboard::Type clipboard_type,
69 const mojo::Callback<void(Array<String>)>& callback) {
70 callback.Run(clipboard_state_[clipboard_type]->GetMimeTypes().Pass());
73 void ClipboardStandaloneImpl::ReadMimeType(
74 Clipboard::Type clipboard_type,
75 const String& mime_type,
76 const mojo::Callback<void(Array<uint8_t>)>& callback) {
77 Array<uint8_t> mime_data;
78 clipboard_state_[clipboard_type]->GetData(mime_type, &mime_data);
79 callback.Run(mime_data.Pass());
82 void ClipboardStandaloneImpl::WriteClipboardData(
83 Clipboard::Type clipboard_type,
84 Map<String, Array<uint8_t>> data) {
85 sequence_number_[clipboard_type]++;
86 clipboard_state_[clipboard_type]->SetData(data.Pass());
89 } // namespace clipboard