Flutter Engine
 
Loading...
Searching...
No Matches
fl_platform_handler.cc File Reference

Go to the source code of this file.

Classes

struct  _FlPlatformHandler
 

Functions

static void clipboard_text_cb (GtkClipboard *clipboard, const gchar *text, gpointer user_data)
 
static void clipboard_text_has_strings_cb (GtkClipboard *clipboard, const gchar *text, gpointer user_data)
 
static FlMethodResponse * clipboard_set_data (FlMethodCall *method_call, const gchar *text, gpointer user_data)
 
static FlMethodResponse * clipboard_get_data (FlMethodCall *method_call, const gchar *format, gpointer user_data)
 
static FlMethodResponse * clipboard_has_strings (FlMethodCall *method_call, gpointer user_data)
 
static void quit_application ()
 
static void request_app_exit_response_cb (GObject *object, GAsyncResult *result, gpointer user_data)
 
static void request_app_exit (FlPlatformHandler *self, FlPlatformChannelExitType type)
 
static void system_initialization_complete (gpointer user_data)
 
static FlMethodResponse * system_exit_application (FlMethodCall *method_call, FlPlatformChannelExitType type, gpointer user_data)
 
static void system_sound_play (const gchar *type, gpointer user_data)
 
static void system_navigator_pop (gpointer user_data)
 
static void fl_platform_handler_dispose (GObject *object)
 
static void fl_platform_handler_class_init (FlPlatformHandlerClass *klass)
 
static void fl_platform_handler_init (FlPlatformHandler *self)
 
FlPlatformHandler * fl_platform_handler_new (FlBinaryMessenger *messenger)
 
void fl_platform_handler_request_app_exit (FlPlatformHandler *self)
 

Variables

static constexpr char kInProgressError [] = "In Progress"
 
static constexpr char kUnknownClipboardFormatError []
 
static constexpr char kTextPlainFormat [] = "text/plain"
 
static constexpr char kSoundTypeAlert [] = "SystemSoundType.alert"
 
static constexpr char kSoundTypeClick [] = "SystemSoundType.click"
 
static constexpr char kSoundTypeTick [] = "SystemSoundType.tick"
 
static FlPlatformChannelVTable platform_channel_vtable
 

Function Documentation

◆ clipboard_get_data()

static FlMethodResponse * clipboard_get_data ( FlMethodCall *  method_call,
const gchar *  format,
gpointer  user_data 
)
static

Definition at line 66 of file fl_platform_handler.cc.

68 {
69 if (strcmp(format, kTextPlainFormat) != 0) {
70 return FL_METHOD_RESPONSE(fl_method_error_response_new(
71 kUnknownClipboardFormatError, "GTK clipboard API only supports text",
72 nullptr));
73 }
74
75 GtkClipboard* clipboard =
78 g_object_ref(method_call));
79
80 // Will respond later.
81 return nullptr;
82}
G_BEGIN_DECLS G_MODULE_EXPORT FlMethodCall * method_call
G_MODULE_EXPORT FlMethodErrorResponse * fl_method_error_response_new(const gchar *code, const gchar *message, FlValue *details)
static constexpr char kUnknownClipboardFormatError[]
static void clipboard_text_cb(GtkClipboard *clipboard, const gchar *text, gpointer user_data)
static constexpr char kTextPlainFormat[]
GdkDisplay * gdk_display_get_default()
Definition mock_gtk.cc:65
GtkClipboard * gtk_clipboard_get_default(GdkDisplay *display)
Definition mock_gtk.cc:363
void gtk_clipboard_request_text(GtkClipboard *clipboard, GtkClipboardTextReceivedFunc callback, gpointer user_data)
Definition mock_gtk.cc:374

References clipboard_text_cb(), fl_method_error_response_new(), format, gdk_display_get_default(), gtk_clipboard_get_default(), gtk_clipboard_request_text(), kTextPlainFormat, kUnknownClipboardFormatError, and method_call.

◆ clipboard_has_strings()

static FlMethodResponse * clipboard_has_strings ( FlMethodCall *  method_call,
gpointer  user_data 
)
static

Definition at line 86 of file fl_platform_handler.cc.

87 {
88 GtkClipboard* clipboard =
91 g_object_ref(method_call));
92
93 // Will respond later.
94 return nullptr;
95}
static void clipboard_text_has_strings_cb(GtkClipboard *clipboard, const gchar *text, gpointer user_data)

References clipboard_text_has_strings_cb(), gdk_display_get_default(), gtk_clipboard_get_default(), gtk_clipboard_request_text(), and method_call.

◆ clipboard_set_data()

static FlMethodResponse * clipboard_set_data ( FlMethodCall *  method_call,
const gchar *  text,
gpointer  user_data 
)
static

Definition at line 55 of file fl_platform_handler.cc.

57 {
58 GtkClipboard* clipboard =
60 gtk_clipboard_set_text(clipboard, text, -1);
61
62 return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
63}
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
std::u16string text
void gtk_clipboard_set_text(GtkClipboard *clipboard, const gchar *text, gint len)
Definition mock_gtk.cc:368

References fl_method_success_response_new(), gdk_display_get_default(), gtk_clipboard_get_default(), gtk_clipboard_set_text(), and text.

◆ clipboard_text_cb()

static void clipboard_text_cb ( GtkClipboard *  clipboard,
const gchar *  text,
gpointer  user_data 
)
static

Definition at line 38 of file fl_platform_handler.cc.

40 {
41 g_autoptr(FlMethodCall) method_call = FL_METHOD_CALL(user_data);
43}
g_autoptr(GMutexLocker) locker
void fl_platform_channel_respond_clipboard_get_data(FlMethodCall *method_call, const gchar *text)

References fl_platform_channel_respond_clipboard_get_data(), g_autoptr(), method_call, text, and user_data.

Referenced by clipboard_get_data().

◆ clipboard_text_has_strings_cb()

static void clipboard_text_has_strings_cb ( GtkClipboard *  clipboard,
const gchar *  text,
gpointer  user_data 
)
static

Definition at line 46 of file fl_platform_handler.cc.

48 {
49 g_autoptr(FlMethodCall) method_call = FL_METHOD_CALL(user_data);
51 method_call, text != nullptr && strlen(text) > 0);
52}
void fl_platform_channel_respond_clipboard_has_strings(FlMethodCall *method_call, gboolean has_strings)

References fl_platform_channel_respond_clipboard_has_strings(), g_autoptr(), method_call, text, and user_data.

Referenced by clipboard_has_strings().

◆ fl_platform_handler_class_init()

static void fl_platform_handler_class_init ( FlPlatformHandlerClass *  klass)
static

Definition at line 236 of file fl_platform_handler.cc.

236 {
237 G_OBJECT_CLASS(klass)->dispose = fl_platform_handler_dispose;
238}
static void fl_platform_handler_dispose(GObject *object)

References fl_platform_handler_dispose().

◆ fl_platform_handler_dispose()

static void fl_platform_handler_dispose ( GObject *  object)
static

Definition at line 224 of file fl_platform_handler.cc.

224 {
225 FlPlatformHandler* self = FL_PLATFORM_HANDLER(object);
226
227 g_cancellable_cancel(self->cancellable);
228
229 g_clear_object(&self->channel);
230 g_clear_object(&self->exit_application_method_call);
231 g_clear_object(&self->cancellable);
232
233 G_OBJECT_CLASS(fl_platform_handler_parent_class)->dispose(object);
234}

References self.

Referenced by fl_platform_handler_class_init().

◆ fl_platform_handler_init()

static void fl_platform_handler_init ( FlPlatformHandler *  self)
static

Definition at line 240 of file fl_platform_handler.cc.

240 {
241 self->cancellable = g_cancellable_new();
242}

References self.

◆ fl_platform_handler_new()

FlPlatformHandler * fl_platform_handler_new ( FlBinaryMessenger *  messenger)

FlPlatformHandler:

#FlPlatformHandler is a handler that implements the shell side of SystemChannels.platform from the Flutter services library. fl_platform_handler_new: @messenger: an #FlBinaryMessenger

Creates a new handler that implements SystemChannels.platform from the Flutter services library.

Returns: a new #FlPlatformHandler

Definition at line 254 of file fl_platform_handler.cc.

254 {
255 g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);
256
257 FlPlatformHandler* self = FL_PLATFORM_HANDLER(
258 g_object_new(fl_platform_handler_get_type(), nullptr));
259
260 self->channel =
262 self->app_initialization_complete = FALSE;
263
264 return self;
265}
FlPlatformChannel * fl_platform_channel_new(FlBinaryMessenger *messenger, FlPlatformChannelVTable *vtable, gpointer user_data)
static FlPlatformChannelVTable platform_channel_vtable

References fl_platform_channel_new(), platform_channel_vtable, and self.

Referenced by fl_engine_start(), fl_test_application_activate(), TEST(), and TEST().

◆ fl_platform_handler_request_app_exit()

void fl_platform_handler_request_app_exit ( FlPlatformHandler *  handler)

fl_platform_handler_request_app_exit: @handler: an #FlPlatformHandler

Request the application exits (i.e. due to the window being requested to be closed).

Calling this will only send an exit request to the framework if the framework has already indicated that it is ready to receive requests by sending a "System.initializationComplete" method call on the platform channel. Calls before initialization is complete will result in an immediate exit.

Definition at line 267 of file fl_platform_handler.cc.

267 {
268 g_return_if_fail(FL_IS_PLATFORM_HANDLER(self));
269 // Request a cancellable exit.
271}
@ FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE
static void request_app_exit(FlPlatformHandler *self, FlPlatformChannelExitType type)

References FL_PLATFORM_CHANNEL_EXIT_TYPE_CANCELABLE, request_app_exit(), and self.

Referenced by fl_engine_request_app_exit().

◆ quit_application()

static void quit_application ( )
static

Definition at line 98 of file fl_platform_handler.cc.

98 {
99 GApplication* app = g_application_get_default();
100 if (app == nullptr) {
101 // Unable to gracefully quit, so just exit the process.
102 exit(0);
103 }
104
105 // GtkApplication windows contain a reference back to the application.
106 // Break them so the application object can cleanup.
107 // See https://gitlab.gnome.org/GNOME/gtk/-/issues/6190
108 if (GTK_IS_APPLICATION(app)) {
109 // List is copied as it will be modified as windows are disconnected from
110 // the application.
111 g_autoptr(GList) windows =
112 g_list_copy(gtk_application_get_windows(GTK_APPLICATION(app)));
113 for (GList* link = windows; link != NULL; link = link->next) {
114 GtkWidget* window = GTK_WIDGET(link->data);
115 gtk_window_set_application(GTK_WINDOW(window), NULL);
116 }
117 }
118
119 g_application_quit(app);
120}
GLFWwindow * window
Definition main.cc:60

References g_autoptr(), and window.

Referenced by request_app_exit(), request_app_exit_response_cb(), system_exit_application(), and system_navigator_pop().

◆ request_app_exit()

static void request_app_exit ( FlPlatformHandler *  self,
FlPlatformChannelExitType  type 
)
static

Definition at line 153 of file fl_platform_handler.cc.

154 {
155 if (!self->app_initialization_complete ||
158 return;
159 }
160
162 self->channel, type, self->cancellable, request_app_exit_response_cb,
163 self);
164}
GLenum type
void fl_platform_channel_system_request_app_exit(FlPlatformChannel *self, FlPlatformChannelExitType type, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
@ FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED
static void quit_application()
static void request_app_exit_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)

References FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED, fl_platform_channel_system_request_app_exit(), quit_application(), request_app_exit_response_cb(), self, and type.

Referenced by fl_platform_handler_request_app_exit(), and system_exit_application().

◆ request_app_exit_response_cb()

static void request_app_exit_response_cb ( GObject *  object,
GAsyncResult *  result,
gpointer  user_data 
)
static

Definition at line 123 of file fl_platform_handler.cc.

125 {
126 FlPlatformHandler* self = FL_PLATFORM_HANDLER(user_data);
127
128 g_autoptr(GError) error = nullptr;
129 FlPlatformChannelExitResponse exit_response;
131 object, result, &exit_response, &error)) {
132 if (g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
133 return;
134 }
135 g_warning("Failed to complete System.requestAppExit: %s", error->message);
137 return;
138 }
139
140 if (exit_response == FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT) {
142 }
143
144 // If request was due to a request from Flutter, pass result back.
145 if (self->exit_application_method_call != nullptr) {
147 self->exit_application_method_call, exit_response);
148 }
149}
const uint8_t uint32_t uint32_t GError ** error
gboolean fl_platform_channel_system_request_app_exit_finish(GObject *object, GAsyncResult *result, FlPlatformChannelExitResponse *exit_response, GError **error)
void fl_platform_channel_respond_system_exit_application(FlMethodCall *method_call, FlPlatformChannelExitResponse exit_response)
FlPlatformChannelExitResponse
@ FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT

References error, FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT, fl_platform_channel_respond_system_exit_application(), fl_platform_channel_system_request_app_exit_finish(), g_autoptr(), quit_application(), self, and user_data.

Referenced by request_app_exit().

◆ system_exit_application()

static FlMethodResponse * system_exit_application ( FlMethodCall *  method_call,
FlPlatformChannelExitType  type,
gpointer  user_data 
)
static

Definition at line 175 of file fl_platform_handler.cc.

177 {
178 FlPlatformHandler* self = FL_PLATFORM_HANDLER(user_data);
179 // Save method call to respond to when our request to Flutter completes.
180 if (self->exit_application_method_call != nullptr) {
181 return FL_METHOD_RESPONSE(fl_method_error_response_new(
182 kInProgressError, "Request already in progress", nullptr));
183 }
184 self->exit_application_method_call =
185 FL_METHOD_CALL(g_object_ref(method_call));
186
187 // Requested to immediately quit if the app hasn't yet signaled that it is
188 // ready to handle requests, or if the type of exit requested is "required".
189 if (!self->app_initialization_complete ||
194 }
195
196 // Send the request back to Flutter to follow the standard process.
198
199 // Will respond later.
200 return nullptr;
201}
FlMethodResponse * fl_platform_channel_make_system_request_app_exit_response(FlPlatformChannelExitResponse exit_response)
static constexpr char kInProgressError[]

References fl_method_error_response_new(), FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT, FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED, fl_platform_channel_make_system_request_app_exit_response(), kInProgressError, method_call, quit_application(), request_app_exit(), self, type, and user_data.

◆ system_initialization_complete()

static void system_initialization_complete ( gpointer  user_data)
static

Definition at line 169 of file fl_platform_handler.cc.

169 {
170 FlPlatformHandler* self = FL_PLATFORM_HANDLER(user_data);
171 self->app_initialization_complete = TRUE;
172}
return TRUE

References self, TRUE, and user_data.

◆ system_navigator_pop()

static void system_navigator_pop ( gpointer  user_data)
static

Definition at line 220 of file fl_platform_handler.cc.

220 {
222}

References quit_application().

◆ system_sound_play()

static void system_sound_play ( const gchar *  type,
gpointer  user_data 
)
static

Definition at line 204 of file fl_platform_handler.cc.

204 {
205 if (strcmp(type, kSoundTypeAlert) == 0) {
206 GdkDisplay* display = gdk_display_get_default();
207 if (display != nullptr) {
208 gdk_display_beep(display);
209 }
210 } else if (strcmp(type, kSoundTypeClick) == 0) {
211 // We don't make sounds for keyboard on desktops.
212 } else if (strcmp(type, kSoundTypeTick) == 0) {
213 // We don't make ticking sounds on desktops.
214 } else {
215 g_warning("Ignoring unknown sound type %s in SystemSound.play.\n", type);
216 }
217}
static constexpr char kSoundTypeTick[]
static constexpr char kSoundTypeAlert[]
static constexpr char kSoundTypeClick[]
void gdk_display_beep(GdkDisplay *display)
Definition mock_gtk.cc:70

References gdk_display_beep(), gdk_display_get_default(), kSoundTypeAlert, kSoundTypeClick, kSoundTypeTick, and type.

Variable Documentation

◆ kInProgressError

constexpr char kInProgressError[] = "In Progress"
staticconstexpr

Definition at line 13 of file fl_platform_handler.cc.

Referenced by system_exit_application().

◆ kSoundTypeAlert

constexpr char kSoundTypeAlert[] = "SystemSoundType.alert"
staticconstexpr

Definition at line 19 of file fl_platform_handler.cc.

Referenced by system_sound_play().

◆ kSoundTypeClick

constexpr char kSoundTypeClick[] = "SystemSoundType.click"
staticconstexpr

Definition at line 20 of file fl_platform_handler.cc.

Referenced by system_sound_play().

◆ kSoundTypeTick

constexpr char kSoundTypeTick[] = "SystemSoundType.tick"
staticconstexpr

Definition at line 21 of file fl_platform_handler.cc.

Referenced by system_sound_play().

◆ kTextPlainFormat

constexpr char kTextPlainFormat[] = "text/plain"
staticconstexpr

Definition at line 17 of file fl_platform_handler.cc.

Referenced by clipboard_get_data().

◆ kUnknownClipboardFormatError

constexpr char kUnknownClipboardFormatError[]
staticconstexpr
Initial value:
=
"Unknown Clipboard Format"

Definition at line 14 of file fl_platform_handler.cc.

Referenced by clipboard_get_data().

◆ platform_channel_vtable

FlPlatformChannelVTable platform_channel_vtable
static
Initial value:
= {
.clipboard_set_data = clipboard_set_data,
.clipboard_get_data = clipboard_get_data,
.clipboard_has_strings = clipboard_has_strings,
.system_exit_application = system_exit_application,
.system_initialization_complete = system_initialization_complete,
.system_sound_play = system_sound_play,
.system_navigator_pop = system_navigator_pop,
}
static void system_initialization_complete(gpointer user_data)
static FlMethodResponse * system_exit_application(FlMethodCall *method_call, FlPlatformChannelExitType type, gpointer user_data)
static FlMethodResponse * clipboard_set_data(FlMethodCall *method_call, const gchar *text, gpointer user_data)
static FlMethodResponse * clipboard_has_strings(FlMethodCall *method_call, gpointer user_data)
static void system_navigator_pop(gpointer user_data)
static FlMethodResponse * clipboard_get_data(FlMethodCall *method_call, const gchar *format, gpointer user_data)
static void system_sound_play(const gchar *type, gpointer user_data)

Definition at line 244 of file fl_platform_handler.cc.

244 {
245 .clipboard_set_data = clipboard_set_data,
246 .clipboard_get_data = clipboard_get_data,
247 .clipboard_has_strings = clipboard_has_strings,
248 .system_exit_application = system_exit_application,
249 .system_initialization_complete = system_initialization_complete,
250 .system_sound_play = system_sound_play,
251 .system_navigator_pop = system_navigator_pop,
252};

Referenced by fl_platform_handler_new().