/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=2 et sw=2 tw=80: */ /* 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/. */
usingnamespace mozilla; usingnamespace mozilla::widget; using mozilla::widget::HeadlessScreenHelper; using mozilla::widget::ScreenHelperGTK; using mozilla::widget::ScreenManager;
// Wrapper function to disable hang monitoring while waiting in poll(). static gint PollWrapper(GPollFD* aUfds, guint aNfsd, gint aTimeout) { if (aTimeout == 0) { // When the timeout is 0, there is no wait, so no point in notifying // the BackgroundHangMonitor and the profiler. return (*sPollFunc)(aUfds, aNfsd, aTimeout);
}
mozilla::BackgroundHangMonitor().NotifyWait();
gint result;
{
gint timeout = aTimeout;
gint64 begin = 0; if (aTimeout != -1) {
begin = g_get_monotonic_time();
}
AUTO_PROFILER_LABEL("PollWrapper", IDLE);
AUTO_PROFILER_THREAD_SLEEP; do {
result = (*sPollFunc)(aUfds, aNfsd, timeout);
// The result will be -1 with the EINTR error if the poll was interrupted // by a signal, typically the signal sent by the profiler to sample the // process. We are only done waiting if we are not in that case. if (result != -1 || errno != EINTR) { break;
}
if (aTimeout != -1) { // Adjust the timeout to account for the time already spent waiting.
gint elapsedSinceBegin = (g_get_monotonic_time() - begin) / 1000; if (elapsedSinceBegin < aTimeout) {
timeout = aTimeout - elapsedSinceBegin;
} else { // poll returns 0 to indicate the call timed out before any fd // became ready.
result = 0; break;
}
}
} while (true);
}
mozilla::BackgroundHangMonitor().NotifyActivity(); return result;
}
// Emit resume-events on GdkFrameClock if flush-events has not been // balanced by resume-events at dispose. // For https://bugzilla.gnome.org/show_bug.cgi?id=742636 static decltype(GObjectClass::constructed) sRealGdkFrameClockConstructed; static decltype(GObjectClass::dispose) sRealGdkFrameClockDispose; static GQuark sPendingResumeQuark;
// Based on // https://github.com/lcp/NetworkManager/blob/240f47c892b4e935a3e92fc09eb15163d1fa28d8/src/nm-sleep-monitor-systemd.c // Use login1 to signal sleep and wake notifications. void nsAppShell::StartDBusListening() {
MOZ_DIAGNOSTIC_ASSERT(!mLogin1Proxy, "Already configured?");
MOZ_DIAGNOSTIC_ASSERT(!mTimedate1Proxy, "Already configured?");
MOZ_DIAGNOSTIC_ASSERT(!mLogin1ProxyCancellable, "Already configured?");
MOZ_DIAGNOSTIC_ASSERT(!mTimedate1ProxyCancellable, "Already configured?");
#ifdef MOZ_ENABLE_DBUS if (XRE_IsParentProcess()) {
StartDBusListening();
} #endif
if (!sPollFunc) {
sPollFunc = g_main_context_get_poll_func(nullptr);
g_main_context_set_poll_func(nullptr, &PollWrapper);
}
if (XRE_IsParentProcess()) {
ScreenManager& screenManager = ScreenManager::GetSingleton(); if (gfxPlatform::IsHeadless()) {
screenManager.SetHelper(mozilla::MakeUnique<HeadlessScreenHelper>());
} else {
screenManager.SetHelper(mozilla::MakeUnique<ScreenHelperGTK>());
}
if (gtk_check_version(3, 16, 3) == nullptr) { // Before 3.16.3, GDK cannot override classname by --class command line // option when program uses gdk_set_program_class(). // // See https://bugzilla.gnome.org/show_bug.cgi?id=747634 // // Only bother doing this for the parent process, since it's the one // creating top-level windows. if (gAppData) {
gdk_set_program_class(gAppData->remotingName);
}
}
}
if (!sPendingResumeQuark &&
gtk_check_version(3, 14, 7) != nullptr) { // GTK 3.0 to GTK 3.14.7. // GTK 3.8 - 3.14 registered this type when creating the frame clock // for the root window of the display when the display was opened.
GType gdkFrameClockIdleType = g_type_from_name("GdkFrameClockIdle"); if (gdkFrameClockIdleType) { // not in versions prior to 3.8
sPendingResumeQuark = g_quark_from_string("moz-resume-is-pending"); auto gdk_frame_clock_idle_class =
G_OBJECT_CLASS(g_type_class_peek_static(gdkFrameClockIdleType)); auto constructed = &gdk_frame_clock_idle_class->constructed;
sRealGdkFrameClockConstructed = *constructed;
*constructed = WrapGdkFrameClockConstructed; auto dispose = &gdk_frame_clock_idle_class->dispose;
sRealGdkFrameClockDispose = *dispose;
*dispose = WrapGdkFrameClockDispose;
}
}
// Workaround for bug 1209659 which is fixed by Gtk3.20 if (gtk_check_version(3, 20, 0) != nullptr) {
unsetenv("GTK_CSD");
}
// Whitelist of only common, stable formats - see bugs 1197059 and 1203078
GSList* pixbufFormats = gdk_pixbuf_get_formats(); for (GSList* iter = pixbufFormats; iter; iter = iter->next) {
GdkPixbufFormat* format = static_cast<GdkPixbufFormat*>(iter->data);
gchar* name = gdk_pixbuf_format_get_name(format); if (strcmp(name, "jpeg") && strcmp(name, "png") && strcmp(name, "gif") &&
strcmp(name, "bmp") && strcmp(name, "ico") && strcmp(name, "xpm") &&
strcmp(name, "svg") && strcmp(name, "webp") && strcmp(name, "avif")) {
gdk_pixbuf_format_set_disabled(format, TRUE);
}
g_free(name);
}
g_slist_free(pixbufFormats);
int err = pipe(mPipeFDs); if (err) return NS_ERROR_OUT_OF_MEMORY;
GIOChannel* ioc;
GSource* source;
// make the pipe nonblocking
int flags = fcntl(mPipeFDs[0], F_GETFL, 0); if (flags == -1) goto failed;
err = fcntl(mPipeFDs[0], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed;
flags = fcntl(mPipeFDs[1], F_GETFL, 0); if (flags == -1) goto failed;
err = fcntl(mPipeFDs[1], F_SETFL, flags | O_NONBLOCK); if (err == -1) goto failed;
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.