Chromium Code Reviews| Index: components/arc/clipboard/clipboard_bridge_impl.cc |
| diff --git a/components/arc/clipboard/clipboard_bridge_impl.cc b/components/arc/clipboard/clipboard_bridge_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e64c7557a7aa562815edc79f40f840ee4cb931dd |
| --- /dev/null |
| +++ b/components/arc/clipboard/clipboard_bridge_impl.cc |
| @@ -0,0 +1,48 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "components/arc/clipboard/clipboard_bridge_impl.h" |
| + |
| +#include "base/logging.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "components/arc/arc_bridge_service.h" |
| +#include "ui/base/clipboard/clipboard.h" |
| +#include "ui/base/clipboard/clipboard_types.h" |
| +#include "ui/base/clipboard/scoped_clipboard_writer.h" |
| + |
| +namespace arc { |
| + |
| +ClipboardBridgeImpl::ClipboardBridgeImpl(ArcBridgeService* bridge_service) |
| + : bridge_service_(bridge_service) { |
| + DCHECK(bridge_service_->state() == ArcBridgeService::State::STOPPED); |
|
elijahtaylor1
2015/12/15 01:17:05
is this required?
Luis Héctor Chávez
2015/12/16 23:16:23
Shouldn't be. It was required by input, but is not
cnwan
2015/12/21 11:18:00
Done.
|
| + |
| + bridge_service_->AddClipboardObserver(this); |
| +} |
| + |
| +ClipboardBridgeImpl::~ClipboardBridgeImpl() { |
| + bridge_service_->RemoveClipboardObserver(this); |
| +} |
| + |
| +void ClipboardBridgeImpl::OnSetClipboardContent(const std::string& text) { |
| + base::string16 result = base::UTF8ToUTF16(text); |
| + |
| + ui::ScopedClipboardWriter writer(ui::CLIPBOARD_TYPE_COPY_PASTE); |
| + writer.WriteText(result); |
| +} |
| + |
| +void ClipboardBridgeImpl::OnGetClipboardContent() { |
| + base::string16 text; |
| + ui::Clipboard* clipboard = ui::Clipboard::GetForCurrentThread(); |
|
elijahtaylor1
2015/12/15 01:17:05
do we need to check which thread we're on to get a
cnwan
2015/12/21 11:18:00
Done.
|
| + clipboard->ReadText(ui::CLIPBOARD_TYPE_COPY_PASTE, &text); |
| + |
| + std::string result = base::UTF16ToUTF8(text); |
| + bridge_service_->SendClipboardContentToAndroid(result); |
| +} |
| + |
| +scoped_ptr<ClipboardBridge> ClipboardBridge::Create( |
| + ArcBridgeService* bridge_service) { |
| + return make_scoped_ptr(new ClipboardBridgeImpl(bridge_service)); |
| +} |
| + |
| +} // namespace arc |