|
| 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/linux/fl_accessibility_channel.h" |
| 6 | +#include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h" |
| 7 | +#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h" |
| 8 | + |
| 9 | +struct _FlAccessibilityChannel { |
| 10 | + GObject parent_instance; |
| 11 | + |
| 12 | + FlBasicMessageChannel* channel; |
| 13 | +}; |
| 14 | + |
| 15 | +G_DEFINE_TYPE(FlAccessibilityChannel, fl_accessibility_channel, G_TYPE_OBJECT) |
| 16 | + |
| 17 | +// Called when a message is received on this channel |
| 18 | +static void message_cb(FlBasicMessageChannel* channel, |
| 19 | + FlValue* message, |
| 20 | + FlBasicMessageChannelResponseHandle* response_handle, |
| 21 | + gpointer user_data) { |
| 22 | + if (fl_value_get_type(message) != FL_VALUE_TYPE_MAP) { |
| 23 | + g_warning("Ignoring unknown flutter/accessibility message type"); |
| 24 | + fl_basic_message_channel_respond(channel, response_handle, nullptr, |
| 25 | + nullptr); |
| 26 | + return; |
| 27 | + } |
| 28 | + |
| 29 | + FlValue* type_value = fl_value_lookup_string(message, "type"); |
| 30 | + if (type_value == nullptr || |
| 31 | + fl_value_get_type(type_value) != FL_VALUE_TYPE_STRING) { |
| 32 | + g_warning( |
| 33 | + "Ignoring unknown flutter/accessibility message with unknown type"); |
| 34 | + fl_basic_message_channel_respond(channel, response_handle, nullptr, |
| 35 | + nullptr); |
| 36 | + return; |
| 37 | + } |
| 38 | + const gchar* type = fl_value_get_string(type_value); |
| 39 | + |
| 40 | + if (strcmp(type, "tooltip") == 0) { |
| 41 | + g_debug("Got tooltip"); |
| 42 | + // FIXME: Make a callback |
| 43 | + fl_basic_message_channel_respond(channel, response_handle, nullptr, |
| 44 | + nullptr); |
| 45 | + } else { |
| 46 | + g_debug("Got unknown accessibility message: %s", type); |
| 47 | + fl_basic_message_channel_respond(channel, response_handle, nullptr, |
| 48 | + nullptr); |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +static void fl_accessibility_channel_dispose(GObject* object) { |
| 53 | + FlAccessibilityChannel* self = FL_ACCESSIBILITY_CHANNEL(object); |
| 54 | + |
| 55 | + g_clear_object(&self->channel); |
| 56 | + |
| 57 | + G_OBJECT_CLASS(fl_accessibility_channel_parent_class)->dispose(object); |
| 58 | +} |
| 59 | + |
| 60 | +static void fl_accessibility_channel_class_init( |
| 61 | + FlAccessibilityChannelClass* klass) { |
| 62 | + G_OBJECT_CLASS(klass)->dispose = fl_accessibility_channel_dispose; |
| 63 | +} |
| 64 | + |
| 65 | +static void fl_accessibility_channel_init(FlAccessibilityChannel* self) {} |
| 66 | + |
| 67 | +FlAccessibilityChannel* fl_accessibility_channel_new( |
| 68 | + FlBinaryMessenger* messenger) { |
| 69 | + g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr); |
| 70 | + |
| 71 | + FlAccessibilityChannel* self = FL_ACCESSIBILITY_CHANNEL( |
| 72 | + g_object_new(fl_accessibility_channel_get_type(), nullptr)); |
| 73 | + |
| 74 | + g_autoptr(FlStandardMessageCodec) codec = fl_standard_message_codec_new(); |
| 75 | + self->channel = fl_basic_message_channel_new( |
| 76 | + messenger, "flutter/accessibility", FL_MESSAGE_CODEC(codec)); |
| 77 | + fl_basic_message_channel_set_message_handler(self->channel, message_cb, self, |
| 78 | + nullptr); |
| 79 | + |
| 80 | + return self; |
| 81 | +} |
0 commit comments