NS_IMETHODIMP nsNativeAppSupportUnix::Start(bool *aRetVal) { NS_ASSERTION(gAppData, "gAppData must not be null."); // The dbus library is used by both nsWifiScannerDBus and BluetoothDBusService, // from diffrent threads. This could lead to race conditions if the dbus is not // initialized before making any other library calls. #ifdef MOZ_ENABLE_DBUS dbus_threads_init_default(); #endif #if (MOZ_WIDGET_GTK == 2) if (gtk_major_version < MIN_GTK_MAJOR_VERSION || (gtk_major_version == MIN_GTK_MAJOR_VERSION && gtk_minor_version < MIN_GTK_MINOR_VERSION)) { GtkWidget* versionErrDialog = gtk_message_dialog_new(NULL, GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, UNSUPPORTED_GTK_MSG, gtk_major_version, gtk_minor_version, MIN_GTK_MAJOR_VERSION, MIN_GTK_MINOR_VERSION); gtk_dialog_run(GTK_DIALOG(versionErrDialog)); gtk_widget_destroy(versionErrDialog); exit(0); } #endif #if (MOZ_PLATFORM_MAEMO == 5) /* zero state out. */ memset(&m_hw_state, 0, sizeof(osso_hw_state_t)); /* Initialize maemo application The initalization name will be of the form "Vendor.Name". If a Vendor isn't given, then we will just use "Name". Note that this value must match your X-Osso-Service name defined in your desktop file. If it doesn't, the OSSO system will happily kill your process. */ nsAutoCString applicationName; if (gAppData->vendor) { applicationName.Append(gAppData->vendor); applicationName.Append("."); } applicationName.Append(gAppData->name); ToLowerCase(applicationName); m_osso_context = osso_initialize(applicationName.get(), gAppData->version ? gAppData->version : "1.0", true, nullptr); /* Check that initilialization was ok */ if (m_osso_context == nullptr) { return NS_ERROR_FAILURE; } osso_hw_set_event_cb(m_osso_context, nullptr, OssoHardwareCallback, &m_hw_state); osso_hw_set_display_event_cb(m_osso_context, OssoDisplayCallback, m_osso_context); osso_rpc_set_default_cb_f(m_osso_context, OssoDbusCallback, nullptr); // Setup an MCE callback to monitor orientation DBusConnection *connnection = (DBusConnection*)osso_get_sys_dbus_connection(m_osso_context); dbus_bus_add_match(connnection, MCE_MATCH_RULE, nullptr); dbus_connection_add_filter(connnection, OssoModeControlCallback, nullptr, nullptr); #endif *aRetVal = true; #if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2) PRLibrary *gnomeuiLib = PR_LoadLibrary("libgnomeui-2.so.0"); if (!gnomeuiLib) return NS_OK; PRLibrary *gnomeLib = PR_LoadLibrary("libgnome-2.so.0"); if (!gnomeLib) { PR_UnloadLibrary(gnomeuiLib); return NS_OK; } _gnome_program_init_fn gnome_program_init = (_gnome_program_init_fn)PR_FindFunctionSymbol(gnomeLib, "gnome_program_init"); _gnome_program_get_fn gnome_program_get = (_gnome_program_get_fn)PR_FindFunctionSymbol(gnomeLib, "gnome_program_get"); _libgnomeui_module_info_get_fn libgnomeui_module_info_get = (_libgnomeui_module_info_get_fn)PR_FindFunctionSymbol(gnomeuiLib, "libgnomeui_module_info_get"); if (!gnome_program_init || !gnome_program_get || !libgnomeui_module_info_get) { PR_UnloadLibrary(gnomeuiLib); PR_UnloadLibrary(gnomeLib); return NS_OK; } #endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */ #ifdef ACCESSIBILITY // We will load gail, atk-bridge by ourself later // We can't run atk-bridge init here, because gail get the control // Set GNOME_ACCESSIBILITY to 0 can avoid this static const char *accEnv = "GNOME_ACCESSIBILITY"; const char *accOldValue = getenv(accEnv); setenv(accEnv, "0", 1); #endif #if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2) if (!gnome_program_get()) { gnome_program_init("Gecko", "1.0", libgnomeui_module_info_get(), gArgc, gArgv, NULL); } #endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */ #ifdef ACCESSIBILITY if (accOldValue) { setenv(accEnv, accOldValue, 1); } else { unsetenv(accEnv); } #endif // Careful! These libraries cannot be unloaded after this point because // gnome_program_init causes atexit handlers to be registered. Strange // crashes will occur if these libraries are unloaded. // TODO GTK3 - see Bug 694570 - Stop using libgnome and libgnomeui on Linux #if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2) gnome_client_set_restart_command = (_gnome_client_set_restart_command_fn) PR_FindFunctionSymbol(gnomeuiLib, "gnome_client_set_restart_command"); _gnome_master_client_fn gnome_master_client = (_gnome_master_client_fn) PR_FindFunctionSymbol(gnomeuiLib, "gnome_master_client"); GnomeClient *client = gnome_master_client(); g_signal_connect(client, "save-yourself", G_CALLBACK(save_yourself_cb), NULL); g_signal_connect(client, "die", G_CALLBACK(die_cb), NULL); // Set the correct/requested restart command in any case. // Is there a request to suppress default binary launcher? nsAutoCString path; char* argv1 = getenv("MOZ_APP_LAUNCHER"); if(!argv1) { // Tell the desktop the command for restarting us so that we can be part of XSMP session restore NS_ASSERTION(gDirServiceProvider, "gDirServiceProvider is NULL! This shouldn't happen!"); nsCOMPtr<nsIFile> executablePath; nsresult rv; bool dummy; rv = gDirServiceProvider->GetFile(XRE_EXECUTABLE_FILE, &dummy, getter_AddRefs(executablePath)); if (NS_SUCCEEDED(rv)) { // Strip off the -bin suffix to get the shell script we should run; this is what Breakpad does nsAutoCString leafName; rv = executablePath->GetNativeLeafName(leafName); if (NS_SUCCEEDED(rv) && StringEndsWith(leafName, NS_LITERAL_CSTRING("-bin"))) { leafName.SetLength(leafName.Length() - strlen("-bin")); executablePath->SetNativeLeafName(leafName); } executablePath->GetNativePath(path); argv1 = (char*)(path.get()); } } if (argv1) { gnome_client_set_restart_command(client, 1, &argv1); } #endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */ return NS_OK; }
NS_IMETHODIMP nsNativeAppSupportUnix::Start(bool *aRetVal) { NS_ASSERTION(gAppData, "gAppData must not be null."); // The dbus library is used by both nsWifiScannerDBus and BluetoothDBusService, // from diffrent threads. This could lead to race conditions if the dbus is not // initialized before making any other library calls. #ifdef MOZ_ENABLE_DBUS dbus_threads_init_default(); #endif #if (MOZ_WIDGET_GTK == 2) if (gtk_major_version < MIN_GTK_MAJOR_VERSION || (gtk_major_version == MIN_GTK_MAJOR_VERSION && gtk_minor_version < MIN_GTK_MINOR_VERSION)) { GtkWidget* versionErrDialog = gtk_message_dialog_new(NULL, GtkDialogFlags(GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT), GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, UNSUPPORTED_GTK_MSG, gtk_major_version, gtk_minor_version, MIN_GTK_MAJOR_VERSION, MIN_GTK_MINOR_VERSION); gtk_dialog_run(GTK_DIALOG(versionErrDialog)); gtk_widget_destroy(versionErrDialog); exit(0); } #endif *aRetVal = true; #if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2) PRLibrary *gnomeuiLib = PR_LoadLibrary("libgnomeui-2.so.0"); if (!gnomeuiLib) return NS_OK; PRLibrary *gnomeLib = PR_LoadLibrary("libgnome-2.so.0"); if (!gnomeLib) { PR_UnloadLibrary(gnomeuiLib); return NS_OK; } _gnome_program_init_fn gnome_program_init = (_gnome_program_init_fn)PR_FindFunctionSymbol(gnomeLib, "gnome_program_init"); _gnome_program_get_fn gnome_program_get = (_gnome_program_get_fn)PR_FindFunctionSymbol(gnomeLib, "gnome_program_get"); _libgnomeui_module_info_get_fn libgnomeui_module_info_get = (_libgnomeui_module_info_get_fn)PR_FindFunctionSymbol(gnomeuiLib, "libgnomeui_module_info_get"); if (!gnome_program_init || !gnome_program_get || !libgnomeui_module_info_get) { PR_UnloadLibrary(gnomeuiLib); PR_UnloadLibrary(gnomeLib); return NS_OK; } #endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */ #ifdef ACCESSIBILITY // We will load gail, atk-bridge by ourself later // We can't run atk-bridge init here, because gail get the control // Set GNOME_ACCESSIBILITY to 0 can avoid this static const char *accEnv = "GNOME_ACCESSIBILITY"; const char *accOldValue = getenv(accEnv); setenv(accEnv, "0", 1); #endif #if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2) if (!gnome_program_get()) { gnome_program_init("Gecko", "1.0", libgnomeui_module_info_get(), gArgc, gArgv, NULL); } #endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */ #ifdef ACCESSIBILITY if (accOldValue) { setenv(accEnv, accOldValue, 1); } else { unsetenv(accEnv); } #endif // Careful! These libraries cannot be unloaded after this point because // gnome_program_init causes atexit handlers to be registered. Strange // crashes will occur if these libraries are unloaded. // TODO GTK3 - see Bug 694570 - Stop using libgnome and libgnomeui on Linux #if defined(MOZ_X11) && (MOZ_WIDGET_GTK == 2) gnome_client_set_restart_command = (_gnome_client_set_restart_command_fn) PR_FindFunctionSymbol(gnomeuiLib, "gnome_client_set_restart_command"); _gnome_master_client_fn gnome_master_client = (_gnome_master_client_fn) PR_FindFunctionSymbol(gnomeuiLib, "gnome_master_client"); GnomeClient *client = gnome_master_client(); g_signal_connect(client, "save-yourself", G_CALLBACK(save_yourself_cb), NULL); g_signal_connect(client, "die", G_CALLBACK(die_cb), NULL); // Set the correct/requested restart command in any case. // Is there a request to suppress default binary launcher? nsAutoCString path; char* argv1 = getenv("MOZ_APP_LAUNCHER"); if(!argv1) { // Tell the desktop the command for restarting us so that we can be part of XSMP session restore NS_ASSERTION(gDirServiceProvider, "gDirServiceProvider is NULL! This shouldn't happen!"); nsCOMPtr<nsIFile> executablePath; nsresult rv; bool dummy; rv = gDirServiceProvider->GetFile(XRE_EXECUTABLE_FILE, &dummy, getter_AddRefs(executablePath)); if (NS_SUCCEEDED(rv)) { // Strip off the -bin suffix to get the shell script we should run; this is what Breakpad does nsAutoCString leafName; rv = executablePath->GetNativeLeafName(leafName); if (NS_SUCCEEDED(rv) && StringEndsWith(leafName, NS_LITERAL_CSTRING("-bin"))) { leafName.SetLength(leafName.Length() - strlen("-bin")); executablePath->SetNativeLeafName(leafName); } executablePath->GetNativePath(path); argv1 = (char*)(path.get()); } } if (argv1) { gnome_client_set_restart_command(client, 1, &argv1); } #endif /* MOZ_X11 && (MOZ_WIDGET_GTK == 2) */ return NS_OK; }
nsresult nsIconChannel::InitWithGnome(nsIMozIconURI *aIconURI) { nsresult rv; if (!gnome_program_get()) { // Get the brandShortName from the string bundle to pass to GNOME // as the application name. This may be used for things such as // the title of grouped windows in the panel. nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID); NS_ASSERTION(bundleService, "String bundle service must be present!"); nsCOMPtr<nsIStringBundle> bundle; bundleService->CreateBundle("chrome://branding/locale/brand.properties", getter_AddRefs(bundle)); nsXPIDLString appName; if (bundle) { bundle->GetStringFromName(NS_LITERAL_STRING("brandShortName").get(), getter_Copies(appName)); } else { NS_WARNING("brand.properties not present, using default application name"); appName.AssignLiteral("Gecko"); } char* empty[] = { "" }; gnome_init(NS_ConvertUTF16toUTF8(appName).get(), "1.0", 1, empty); } nsCAutoString iconSizeString; aIconURI->GetIconSize(iconSizeString); PRUint32 iconSize; if (iconSizeString.IsEmpty()) { rv = aIconURI->GetImageSize(&iconSize); NS_ASSERTION(NS_SUCCEEDED(rv), "GetImageSize failed"); } else { int size; GtkIconSize icon_size = moz_gtk_icon_size(iconSizeString.get()); gtk_icon_size_lookup(icon_size, &size, NULL); iconSize = size; } nsCAutoString type; aIconURI->GetContentType(type); GnomeVFSFileInfo fileInfo = {0}; fileInfo.refcount = 1; // In case some GnomeVFS function addrefs and releases it nsCAutoString spec; nsCOMPtr<nsIURI> fileURI; rv = aIconURI->GetIconFile(getter_AddRefs(fileURI)); if (fileURI) { fileURI->GetAsciiSpec(spec); // Only ask gnome-vfs for a GnomeVFSFileInfo for file: uris, to avoid a // network request PRBool isFile; if (NS_SUCCEEDED(fileURI->SchemeIs("file", &isFile)) && isFile) { gnome_vfs_get_file_info(spec.get(), &fileInfo, GNOME_VFS_FILE_INFO_DEFAULT); } else { // We have to get a leaf name from our uri... nsCOMPtr<nsIURL> url(do_QueryInterface(fileURI)); if (url) { nsCAutoString name; // The filename we get is UTF-8-compatible, which matches gnome expectations. // See also: http://lists.gnome.org/archives/gnome-vfs-list/2004-March/msg00049.html // "Whenever we can detect the charset used for the URI type we try to // convert it to/from utf8 automatically inside gnome-vfs." // I'll interpret that as "otherwise, this field is random junk". url->GetFileName(name); fileInfo.name = g_strdup(name.get()); } // If this is no nsIURL, nothing we can do really. if (!type.IsEmpty()) { fileInfo.valid_fields = GNOME_VFS_FILE_INFO_FIELDS_MIME_TYPE; fileInfo.mime_type = g_strdup(type.get()); } } } if (type.IsEmpty()) { nsCOMPtr<nsIMIMEService> ms(do_GetService("@mozilla.org/mime;1")); if (ms) { nsCAutoString fileExt; aIconURI->GetFileExtension(fileExt); ms->GetTypeFromExtension(fileExt, type); } } // Get the icon theme if (!gIconTheme) { gIconTheme = gnome_icon_theme_new(); if (!gIconTheme) { gnome_vfs_file_info_clear(&fileInfo); return NS_ERROR_NOT_AVAILABLE; } } char* name = gnome_icon_lookup(gIconTheme, NULL, spec.get(), NULL, &fileInfo, type.get(), GNOME_ICON_LOOKUP_FLAGS_NONE, NULL); gnome_vfs_file_info_clear(&fileInfo); if (!name) { return NS_ERROR_NOT_AVAILABLE; } char* file = gnome_icon_theme_lookup_icon(gIconTheme, name, iconSize, NULL, NULL); g_free(name); if (!file) return NS_ERROR_NOT_AVAILABLE; // Create a GdkPixbuf buffer and scale it GError *err = nsnull; GdkPixbuf* buf = gdk_pixbuf_new_from_file(file, &err); g_free(file); if (!buf) { if (err) g_error_free(err); return NS_ERROR_UNEXPECTED; } GdkPixbuf* scaled = buf; if (gdk_pixbuf_get_width(buf) != iconSize && gdk_pixbuf_get_height(buf) != iconSize) { // scale... scaled = gdk_pixbuf_scale_simple(buf, iconSize, iconSize, GDK_INTERP_BILINEAR); gdk_pixbuf_unref(buf); if (!scaled) return NS_ERROR_OUT_OF_MEMORY; } // XXX Respect icon state rv = moz_gdk_pixbuf_to_channel(scaled, aIconURI, getter_AddRefs(mRealChannel)); gdk_pixbuf_unref(scaled); return rv; }