/* -*- 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/. */
NS_IMETHODIMP
AsyncFaviconDataReady::OnComplete(nsIURI* aFaviconURI, uint32_t aDataLen, const uint8_t* aData, const nsACString& aMimeType,
uint16_t aWidth) { // This is a callback from some previous search so we don't want it if (mTimeStamp != mSearchResult->GetTimeStamp() || !aData || !aDataLen) { return NS_ERROR_FAILURE;
}
// Decode the image from the format it was returned to us in (probably PNG)
nsCOMPtr<imgIContainer> container;
nsCOMPtr<imgITools> imgtool = do_CreateInstance("@mozilla.org/image/tools;1");
nsresult rv = imgtool->DecodeImageFromBuffer( reinterpret_cast<constchar*>(aData), aDataLen, aMimeType,
getter_AddRefs(container));
NS_ENSURE_SUCCESS(rv, rv);
if (!surface || surface->GetFormat() != SurfaceFormat::B8G8R8A8) { return NS_ERROR_FAILURE;
}
// Allocate a new buffer that we own.
RefPtr<DataSourceSurface> dataSurface = surface->GetDataSurface();
UniquePtr<uint8_t[]> data = SurfaceToPackedRGBA(dataSurface); if (!data) { return NS_ERROR_OUT_OF_MEMORY;
}
RefPtr<nsGNOMEShellHistorySearchResult> newSearch = new nsGNOMEShellHistorySearchResult(this, mConnection,
mSearchResultTimeStamp);
mSearchResultTimeStamp++;
newSearch->SetTimeStamp(mSearchResultTimeStamp);
// Send the search request over DBus. We'll get reply over DBus it will be // set to mSearchResult by nsGNOMEShellSearchProvider::SetSearchResult().
DBusHandleResultSet(newSearch.forget(), aParameters, aInitialSearch,
aInvocation);
}
nsresult nsGNOMEShellSearchProvider::Startup() { if (mDBusID) { // We're already connected so we don't need to reconnect return NS_ERROR_ALREADY_INITIALIZED;
}
// Simulate async searching by delayed reply. This search API will // likely become async in the future and we want to be sure to not rely on // its current synchronous behavior.
MOZ_ASSERT(MessageLoop::current());
MessageLoop::current()->PostTask(
NewRunnableFunction("Gnome shell search results", &DispatchSearchResults,
aSearchResult, resultContainer));
return NS_OK;
}
staticvoid DBusGetIDKeyForURI(int aIndex, bool aIsOpen, nsAutoCString& aUri,
nsAutoCString& aIDKey) { // Compose ID as 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
aIDKey =
nsPrintfCString("%.2d:%c:%s", aIndex, aIsOpen ? 'o' : 'h', aUri.get());
}
uint32_t childCount = 0;
nsresult rv = mHistResultContainer->GetChildCount(&childCount); if (NS_SUCCEEDED(rv) && childCount > 0) { // Obtain the favicon service and get the favicon for the specified page
nsCOMPtr<nsIFaviconService> favIconSvc(
do_GetService("@mozilla.org/browser/favicon-service;1"));
nsCOMPtr<nsIIOService> ios(do_GetService(NS_IOSERVICE_CONTRACTID));
if (childCount > MAX_SEARCH_RESULTS_NUM) {
childCount = MAX_SEARCH_RESULTS_NUM;
}
for (uint32_t i = 0; i < childCount; i++) {
nsCOMPtr<nsINavHistoryResultNode> child;
rv = mHistResultContainer->GetChild(i, getter_AddRefs(child)); if (NS_WARN_IF(NS_FAILED(rv))) { continue;
} if (!IsHistoryResultNodeURI(child)) { continue;
}
nsAutoCString uri;
child->GetUri(uri);
nsCOMPtr<nsIURI> iconIri;
ios->NewURI(uri, nullptr, nullptr, getter_AddRefs(iconIri));
nsCOMPtr<nsIFaviconDataCallback> callback = new AsyncFaviconDataReady(this, i, mTimeStamp);
favIconSvc->GetFaviconDataForPage(iconIri, callback, 0);
void nsGNOMEShellHistorySearchResult::ReceiveSearchResultContainer(
nsCOMPtr<nsINavHistoryContainerResultNode> aHistResultContainer) { // Propagate search results to nsGNOMEShellSearchProvider. // SetSearchResult() checks this is up-to-date search (our time stamp matches // latest requested search timestamp). if (!mSearchProvider->SetSearchResult(this)) { return;
}
mHistResultContainer = aHistResultContainer;
// Getting the currently open tabs to mark them accordingly
nsresult rv;
nsCOMPtr<nsIOpenTabsProvider> provider =
do_ImportESModule("resource:///modules/OpenTabsProvider.sys.mjs", &rv); if (NS_FAILED(rv)) { // Don't fail, just log an error message
NS_WARNING("Failed to determine currently open tabs. Using history only.");
}
nsTArray<nsCString> openTabs; if (provider) {
rv = provider->GetOpenTabs(openTabs); if (NS_FAILED(rv)) { // Don't fail, just log an error message
NS_WARNING( "Failed to determine currently open tabs. Using history only.");
}
} // In case of error, we just clear out mOpenTabs with an empty new array
mOpenTabs = std::move(openTabs);
HandleSearchResultReply();
}
void nsGNOMEShellHistorySearchResult::SetHistoryIcon(int aTimeStamp,
UniquePtr<uint8_t[]> aData, int aWidth, int aHeight, int aIconIndex) {
MOZ_ASSERT(mTimeStamp == aTimeStamp);
MOZ_RELEASE_ASSERT(aIconIndex < MAX_SEARCH_RESULTS_NUM);
mHistoryIcons[aIconIndex].Set(mTimeStamp, std::move(aData), aWidth, aHeight);
}
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.