|
1 | | -// Copyright 2013 The Flutter 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. |
4 | | - |
5 | | -#include "flutter/shell/platform/windows/platform_handler.h" |
6 | | - |
7 | | -#include "flutter/shell/platform/common/json_method_codec.h" |
8 | | - |
9 | | -static constexpr char kChannelName[] = "flutter/platform"; |
10 | | - |
11 | | -static constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"; |
12 | | -static constexpr char kHasStringsClipboardMethod[] = "Clipboard.hasStrings"; |
13 | | -static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"; |
14 | | - |
15 | | -static constexpr char kTextPlainFormat[] = "text/plain"; |
16 | | -static constexpr char kTextKey[] = "text"; |
17 | | - |
18 | | -static constexpr char kUnknownClipboardFormatMessage[] = |
19 | | - "Unknown clipboard format"; |
20 | | - |
21 | | -namespace flutter { |
22 | | - |
23 | | -PlatformHandler::PlatformHandler(BinaryMessenger* messenger) |
24 | | - : channel_(std::make_unique<MethodChannel<rapidjson::Document>>( |
25 | | - messenger, |
26 | | - kChannelName, |
27 | | - &JsonMethodCodec::GetInstance())) { |
28 | | - channel_->SetMethodCallHandler( |
29 | | - [this](const MethodCall<rapidjson::Document>& call, |
30 | | - std::unique_ptr<MethodResult<rapidjson::Document>> result) { |
31 | | - HandleMethodCall(call, std::move(result)); |
32 | | - }); |
33 | | -} |
34 | | - |
35 | | -PlatformHandler::~PlatformHandler() = default; |
36 | | - |
37 | | -void PlatformHandler::HandleMethodCall( |
38 | | - const MethodCall<rapidjson::Document>& method_call, |
39 | | - std::unique_ptr<MethodResult<rapidjson::Document>> result) { |
40 | | - const std::string& method = method_call.method_name(); |
41 | | - if (method.compare(kGetClipboardDataMethod) == 0) { |
42 | | - // Only one string argument is expected. |
43 | | - const rapidjson::Value& format = method_call.arguments()[0]; |
44 | | - |
45 | | - if (strcmp(format.GetString(), kTextPlainFormat) != 0) { |
46 | | - result->Error(kClipboardError, kUnknownClipboardFormatMessage); |
47 | | - return; |
48 | | - } |
49 | | - GetPlainText(std::move(result), kTextKey); |
50 | | - } else if (method.compare(kHasStringsClipboardMethod) == 0) { |
51 | | - // Only one string argument is expected. |
52 | | - const rapidjson::Value& format = method_call.arguments()[0]; |
53 | | - |
54 | | - if (strcmp(format.GetString(), kTextPlainFormat) != 0) { |
55 | | - result->Error(kClipboardError, kUnknownClipboardFormatMessage); |
56 | | - return; |
57 | | - } |
58 | | - HasStrings(std::move(result)); |
59 | | - } else if (method.compare(kSetClipboardDataMethod) == 0) { |
60 | | - const rapidjson::Value& document = *method_call.arguments(); |
61 | | - rapidjson::Value::ConstMemberIterator itr = document.FindMember(kTextKey); |
62 | | - if (itr == document.MemberEnd()) { |
63 | | - result->Error(kClipboardError, kUnknownClipboardFormatMessage); |
64 | | - return; |
65 | | - } |
66 | | - SetPlainText(itr->value.GetString(), std::move(result)); |
67 | | - } else { |
68 | | - result->NotImplemented(); |
69 | | - } |
70 | | -} |
71 | | - |
72 | | -} // namespace flutter |
| 1 | +// Copyright 2013 The Flutter 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. |
| 4 | + |
| 5 | +#include "flutter/shell/platform/windows/platform_handler.h" |
| 6 | + |
| 7 | +#include "flutter/shell/platform/common/json_method_codec.h" |
| 8 | + |
| 9 | +static constexpr char kChannelName[] = "flutter/platform"; |
| 10 | + |
| 11 | +static constexpr char kGetClipboardDataMethod[] = "Clipboard.getData"; |
| 12 | +static constexpr char kHasStringsClipboardMethod[] = "Clipboard.hasStrings"; |
| 13 | +static constexpr char kSetClipboardDataMethod[] = "Clipboard.setData"; |
| 14 | + |
| 15 | +static constexpr char kTextPlainFormat[] = "text/plain"; |
| 16 | +static constexpr char kTextKey[] = "text"; |
| 17 | + |
| 18 | +static constexpr char kUnknownClipboardFormatMessage[] = |
| 19 | + "Unknown clipboard format"; |
| 20 | + |
| 21 | +namespace flutter { |
| 22 | + |
| 23 | +PlatformHandler::PlatformHandler(BinaryMessenger* messenger) |
| 24 | + : channel_(std::make_unique<MethodChannel<rapidjson::Document>>( |
| 25 | + messenger, |
| 26 | + kChannelName, |
| 27 | + &JsonMethodCodec::GetInstance())) { |
| 28 | + channel_->SetMethodCallHandler( |
| 29 | + [this](const MethodCall<rapidjson::Document>& call, |
| 30 | + std::unique_ptr<MethodResult<rapidjson::Document>> result) { |
| 31 | + HandleMethodCall(call, std::move(result)); |
| 32 | + }); |
| 33 | +} |
| 34 | + |
| 35 | +PlatformHandler::~PlatformHandler() = default; |
| 36 | + |
| 37 | +void PlatformHandler::HandleMethodCall( |
| 38 | + const MethodCall<rapidjson::Document>& method_call, |
| 39 | + std::unique_ptr<MethodResult<rapidjson::Document>> result) { |
| 40 | + const std::string& method = method_call.method_name(); |
| 41 | + if (method.compare(kGetClipboardDataMethod) == 0) { |
| 42 | + // Only one string argument is expected. |
| 43 | + const rapidjson::Value& format = method_call.arguments()[0]; |
| 44 | + |
| 45 | + if (strcmp(format.GetString(), kTextPlainFormat) != 0) { |
| 46 | + result->Error(kClipboardError, kUnknownClipboardFormatMessage); |
| 47 | + return; |
| 48 | + } |
| 49 | + GetPlainText(std::move(result), kTextKey); |
| 50 | + } else if (method.compare(kHasStringsClipboardMethod) == 0) { |
| 51 | + // Only one string argument is expected. |
| 52 | + const rapidjson::Value& format = method_call.arguments()[0]; |
| 53 | + |
| 54 | + if (strcmp(format.GetString(), kTextPlainFormat) != 0) { |
| 55 | + result->Error(kClipboardError, kUnknownClipboardFormatMessage); |
| 56 | + return; |
| 57 | + } |
| 58 | + HasStrings(std::move(result)); |
| 59 | + } else if (method.compare(kSetClipboardDataMethod) == 0) { |
| 60 | + const rapidjson::Value& document = *method_call.arguments(); |
| 61 | + rapidjson::Value::ConstMemberIterator itr = document.FindMember(kTextKey); |
| 62 | + if (itr == document.MemberEnd()) { |
| 63 | + result->Error(kClipboardError, kUnknownClipboardFormatMessage); |
| 64 | + return; |
| 65 | + } |
| 66 | + SetPlainText(itr->value.GetString(), std::move(result)); |
| 67 | + } else { |
| 68 | + result->NotImplemented(); |
| 69 | + } |
| 70 | +} |
| 71 | + |
| 72 | +} // namespace flutter |
0 commit comments