int main(int argc, char **argv) { #ifdef NS_TRACE_MALLOC argc = NS_TraceMallocStartupArgs(argc, argv); #endif gtk_set_locale(); gtk_init(&argc, &argv); #ifdef MOZ_JPROF setupProfilingStuff(); #endif char *home_path; char *full_path; home_path = PR_GetEnv("HOME"); if (!home_path) { fprintf(stderr, "Failed to get HOME\n"); exit(1); } full_path = g_strdup_printf("%s/%s", home_path, ".TestGtkEmbed"); gtk_moz_embed_set_profile_path(full_path, "TestGtkEmbed"); TestGtkBrowser *browser = new_gtk_browser(GTK_MOZ_EMBED_FLAG_DEFAULTCHROME); // set our minimum size gtk_widget_set_usize(browser->mozEmbed, 400, 400); set_browser_visibility(browser, TRUE); if (argc > 1) gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser->mozEmbed), argv[1]); // get the singleton object and hook up to its new window callback // so we can create orphaned windows. GtkMozEmbedSingle *single; single = gtk_moz_embed_single_get(); if (!single) { fprintf(stderr, "Failed to get singleton embed object!\n"); exit(1); } gtk_signal_connect(GTK_OBJECT(single), "new_window_orphan", GTK_SIGNAL_FUNC(new_window_orphan_cb), NULL); gtk_main(); }
// our callback from the window creator service void gtk_moz_embed_single_create_window(GtkMozEmbed **aNewEmbed, guint aChromeFlags) { GtkMozEmbedSingle *single = gtk_moz_embed_single_get(); *aNewEmbed = nsnull; if (!single) return; g_signal_emit(G_OBJECT(single), moz_embed_single_signals[NEW_WINDOW_ORPHAN], 0, aNewEmbed, aChromeFlags); }
int mozembed_main(int argc, char **argv) { if (argc > 1) { if (strstr(argv[1], "-port=")) { int port = atoi(&(argv[1][6])); gMessenger.SetPort(port); gMessenger.CreateServerSocket(); } else if (strcmp(argv[1], "-test") == 0) { gTestMode = 1; } } if (!gTestMode && gMessenger.IsFailed()) { ReportError("Failed to create server socket!"); exit(1); } gtk_set_locale(); gtk_init(&argc, &argv); // force the startup code to be executed because we need to start // the profile in a different way gtk_moz_embed_push_startup(); if (NS_FAILED(InitializeProfile())) { ReportError("Failed to initialize profile!"); exit(1); } gMsgLock = PR_NewLock(); if (!gTestMode) { PRThread *socketListenThread = PR_CreateThread(PR_USER_THREAD, PortListening, (void*)SocketMsgHandler, PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_UNJOINABLE_THREAD, 0); if (!socketListenThread) { ReportError("Failed to create socket listening thread!"); exit(1); } // add event source to process socket messages #ifdef MOZ_WIDGET_GTK g_source_add (GDK_PRIORITY_EVENTS, TRUE, &event_funcs, NULL, NULL, NULL); #endif #ifdef MOZ_WIDGET_GTK2 GSource *newsource = g_source_new(&event_funcs, sizeof(GSource)); g_source_attach(newsource, NULL); #endif } else { GtkBrowser *browser = new_gtk_browser(GTK_MOZ_EMBED_FLAG_DEFAULTCHROME); // set our minimum size gtk_widget_set_usize(browser->mozEmbed, 400, 400); set_browser_visibility(browser, TRUE); } // get the singleton object and hook up to its new window callback // so we can create orphaned windows. GtkMozEmbedSingle *single; single = gtk_moz_embed_single_get(); if (!single) { ReportError("Failed to get singleton embed object!"); exit(1); } gtk_signal_connect(GTK_OBJECT(single), "new_window_orphan", GTK_SIGNAL_FUNC(new_window_orphan_cb), NULL); gtk_main(); gtk_moz_embed_pop_startup(); PR_DestroyLock(gMsgLock); return 0; }