/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
bool DBusService::LaunchApp(constchar* aCommand, constchar** aURIList, int aURIListLen) {
nsAutoCString param(mAppFile); if (aCommand) {
param.Append(" ");
param.Append(aCommand);
} for (int i = 0; aURIList && i < aURIListLen; i++) {
param.Append(" ");
GUniquePtr<char> escUri(g_shell_quote(aURIList[i]));
param.Append(escUri.get());
}
char* argv[] = {strdup("/bin/sh"), strdup("-c"), strdup(param.get()),
nullptr}; int ret =
PR_CreateProcessDetached("/bin/sh", argv, nullptr, nullptr) != PR_FAILURE; for (auto str : argv) {
free(str);
} return ret;
}
// The Activate method is called when the application is started without // files to open. // Open :: (a{sv}) → () void DBusService::HandleFreedesktopActivate(GVariant* aParameters,
GDBusMethodInvocation* aReply) { if (!LaunchApp(nullptr, nullptr, 0)) {
g_dbus_method_invocation_return_error(aReply, G_DBUS_ERROR,
G_DBUS_ERROR_FAILED, "Failed to run target application."); return;
}
g_dbus_method_invocation_return_value(aReply, nullptr);
}
// The Open method is called when the application is started with files. // The array of strings is an array of URIs, in UTF-8. // Open :: (as,a{sv}) → () void DBusService::HandleFreedesktopOpen(GVariant* aParameters,
GDBusMethodInvocation* aReply) {
RefPtr<GVariant> variant =
dont_AddRef(g_variant_get_child_value(aParameters, 0));
gsize uriNum = 0;
GUniquePtr<constchar*> uriArray(g_variant_get_strv(variant, &uriNum)); if (!LaunchApp(nullptr, uriArray.get(), uriNum)) {
g_dbus_method_invocation_return_error(aReply, G_DBUS_ERROR,
G_DBUS_ERROR_FAILED, "Failed to run target application."); return;
}
g_dbus_method_invocation_return_value(aReply, nullptr);
}
// The ActivateAction method is called when Desktop Actions are activated. // The action-name parameter is the name of the action. // ActivateAction :: (s,av,a{sv}) → () void DBusService::HandleFreedesktopActivateAction(
GVariant* aParameters, GDBusMethodInvocation* aReply) { constchar* actionName;
// aParameters is "(s,av,a{sv})" type
RefPtr<GVariant> r = dont_AddRef(g_variant_get_child_value(aParameters, 0)); if (!(actionName = g_variant_get_string(r, nullptr))) {
g_dbus_method_invocation_return_error(
aReply, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Wrong params!"); return;
}
// TODO: Read av params and pass them to LaunchApp?
// actionName matches desktop action defined in .desktop file. // We implement it for .desktop file shipped by flatpak // (taskcluster/docker/firefox-flatpak/org.mozilla.firefox.desktop) bool ret = false; if (!strcmp(actionName, "new-window")) {
ret = LaunchApp(nullptr, nullptr, 0);
} elseif (!strcmp(actionName, "new-private-window")) {
ret = LaunchApp("--private-window", nullptr, 0);
} elseif (!strcmp(actionName, "profile-manager-window")) {
ret = LaunchApp("--ProfileManager", nullptr, 0);
} if (!ret) {
g_dbus_method_invocation_return_error(aReply, G_DBUS_ERROR,
G_DBUS_ERROR_FAILED, "Failed to run target application."); return;
}
g_dbus_method_invocation_return_value(aReply, nullptr);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.