/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:expandtab:shiftwidth=2:tabstop=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/. */
int DBusGetIndexFromIDKey(constchar* aIDKey) { // ID is NN:S:URL where NN is index to our current history // result container. char tmp[] = {aIDKey[0], aIDKey[1], '\0'}; return atoi(tmp);
}
char DBusGetStateFromIDKey(constchar* aIDKey) { // ID is NN:S:URL where NN is index to our current history // result container, and S is the state, which can be 'o'pen or 'h'istory if (std::strlen(aIDKey) > 3) { return aIDKey[3];
} // Should never happen, but just to avoid any possible segfault, we // default to state 'history'. return'h';
}
staticvoid ConcatArray(nsACString& aOutputStr, constchar** aStringArray) { for (constchar** term = aStringArray; *term; term++) {
aOutputStr.Append(*term); if (*(term + 1)) {
aOutputStr.Append(" ");
}
}
}
// GetInitialResultSet :: (as) → (as) // GetSubsearchResultSet :: (as,as) → (as) void DBusHandleResultSet(RefPtr<nsGNOMEShellHistorySearchResult> aSearchResult,
GVariant* aParameters, bool aInitialSearch,
GDBusMethodInvocation* aReply) { // Inital search has params (as), any following one has (as,as) and we want // the second string array.
fprintf(stderr, "%s\n", g_variant_get_type_string(aParameters));
RefPtr<GVariant> variant = dont_AddRef(
g_variant_get_child_value(aParameters, aInitialSearch ? 0 : 1)); constchar** stringArray = g_variant_get_strv(variant, nullptr); if (!stringArray) {
g_dbus_method_invocation_return_error(
aReply, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS, "Wrong params!"); return;
}
aSearchResult->SetReply(aReply);
nsAutoCString searchTerm;
ConcatArray(searchTerm, stringArray);
aSearchResult->SetSearchTerm(searchTerm.get());
GetGNOMEShellHistoryService()->QueryHistory(aSearchResult); // DBus reply will be send asynchronously by // nsGNOMEShellHistorySearchResult::SendDBusSearchResultReply() // when GetGNOMEShellHistoryService() has the results.
g_free(stringArray);
}
/* "icon-data": a tuple of type (iiibiiay) describing a pixbuf with width, height, rowstride, has-alpha, bits-per-sample, channels, image data
*/ staticvoid DBusAppendIcon(GVariantBuilder* aBuilder, GnomeHistoryIcon* aIcon) {
GVariantBuilder b;
g_variant_builder_init(&b, G_VARIANT_TYPE("(iiibiiay)"));
g_variant_builder_add_value(&b, g_variant_new_int32(aIcon->GetWidth()));
g_variant_builder_add_value(&b, g_variant_new_int32(aIcon->GetHeight()));
g_variant_builder_add_value(&b, g_variant_new_int32(aIcon->GetWidth() * 4));
g_variant_builder_add_value(&b, g_variant_new_boolean(true));
g_variant_builder_add_value(&b, g_variant_new_int32(8));
g_variant_builder_add_value(&b, g_variant_new_int32(4));
g_variant_builder_add_value(
&b, g_variant_new_fixed_array(G_VARIANT_TYPE("y"), aIcon->GetData(),
aIcon->GetWidth() * aIcon->GetHeight() * 4, sizeof(char)));
g_variant_builder_add(aBuilder, "{sv}", "icon-data",
g_variant_builder_end(&b));
}
/* Appends history search results to the DBUS reply.
We can return those fields at GetResultMetas:
"id": the result ID "name": the display name for the result "icon": a serialized GIcon (see g_icon_serialize()), or alternatively, "gicon": a textual representation of a GIcon (see g_icon_to_string()), or alternativly, "icon-data": a tuple of type (iiibiiay) describing a pixbuf with width, height, rowstride, has-alpha, bits-per-sample, and image data "description": an optional short description (1-2 lines)
*/ static already_AddRefed<GVariant> DBusAppendResultID(
nsGNOMEShellHistorySearchResult* aSearchResult, constchar* aID) {
nsCOMPtr<nsINavHistoryContainerResultNode> container =
aSearchResult->GetSearchResultContainer();
int index = DBusGetIndexFromIDKey(aID); char state = DBusGetStateFromIDKey(aID);
nsCOMPtr<nsINavHistoryResultNode> child;
container->GetChild(index, getter_AddRefs(child));
nsAutoCString title; if (!child || NS_FAILED(child->GetTitle(title))) { return nullptr;
}
if (title.IsEmpty()) { if (NS_FAILED(child->GetUri(title)) || title.IsEmpty()) { return nullptr;
}
}
// Check if the URI state is "open tab". If so, mark it with an asterisk to // indicate this to the user. if (state == 'o') {
title = "(*) "_ns + title;
}
// Extract ssssss part from aID
nsAutoCString searchTerm(aID + KEYWORD_SEARCH_STRING_LEN + 1);
nsAutoCString gnomeSearchTitle; if (GetGnomeSearchTitle(searchTerm.get(), gnomeSearchTitle)) {
g_variant_builder_add(&b, "{sv}", "name",
g_variant_new_string(gnomeSearchTitle.get())); // TODO: When running on flatpak/snap we may need to use // icon like org.mozilla.Firefox or so.
g_variant_builder_add(&b, "{sv}", "gicon", g_variant_new_string("firefox"));
}
// If the state of the URI is 'o'pen, we send it along to JS and let // it switch the tab accordingly if (state == 'o') { // If we can't successfully switch to an open tab, use the existing // 'open in a new tab'-mechanism as a fallback.
nsresult rv;
nsCOMPtr<nsIOpenTabsProvider> provider = do_ImportESModule( "resource:///modules/OpenTabsProvider.sys.mjs", &rv); if (NS_SUCCEEDED(rv)) {
rv = provider->SwitchToOpenTab(uri); if (NS_SUCCEEDED(rv)) { return;
}
}
}
if (childCount > MAX_SEARCH_RESULTS_NUM) {
childCount = MAX_SEARCH_RESULTS_NUM;
}
// Allocate space for all found results, "unused", "--search" and // potential search request. constchar** urlList =
(constchar**)moz_xmalloc(sizeof(char*) * (childCount + 3)); int urlListElements = 0;
urlList[urlListElements++] = strdup("unused");
for (uint32_t i = 0; i < childCount; i++) {
nsCOMPtr<nsINavHistoryResultNode> child;
aSearchResult->GetSearchResultContainer()->GetChild(i,
getter_AddRefs(child));
// When there isn't any uri to open pass search at least. if (!childCount) {
urlList[urlListElements++] = strdup("--search");
urlList[urlListElements++] = strdup(aSearchResult->GetSearchTerm().get());
}
int len; char* commandLine =
ConstructCommandLine(urlListElements, urlList, nullptr, &len); if (commandLine) {
aSearchResult->HandleCommandLine(mozilla::Span(commandLine, len),
aTimeStamp);
free(commandLine);
}
for (int i = 0; i < urlListElements; i++) {
free((void*)urlList[i]);
}
free(urlList);
}
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.