diff --git a/modules/plugin/base/src/ns4xPluginInstance.cpp b/modules/plugin/base/src/ns4xPluginInstance.cpp index e19b6ac1ded..3877c28332f 100644 --- a/modules/plugin/base/src/ns4xPluginInstance.cpp +++ b/modules/plugin/base/src/ns4xPluginInstance.cpp @@ -853,8 +853,9 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window) ws = (NPSetWindowCallbackStruct *)window->ws_info; GdkWindow *win = gdk_window_lookup((XID)window->window); - if (win) - { + if (!win) + return NS_ERROR_FAILURE; + { #ifdef NS_DEBUG printf("About to create new xtbin of %i X %i from %p...\n", window->width, window->height, win); @@ -881,6 +882,10 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window) if (!mXtBin) { mXtBin = gtk_xtbin_new(win, 0); + // Check to see if creating mXtBin failed for some reason. + // if it did, we can't go any further. + if (!mXtBin) + return NS_ERROR_FAILURE; } gtk_widget_set_usize(mXtBin, window->width, window->height); @@ -904,6 +909,9 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window) XFlush(ws->display); } // !window->ws_info + if (!mXtBin) + return NS_ERROR_FAILURE; + // And now point the NPWindow structures window // to the actual X window window->window = (nsPluginPort *)GTK_XTBIN(mXtBin)->xtwindow; diff --git a/widget/src/gtkxtbin/gtkxtbin.c b/widget/src/gtkxtbin/gtkxtbin.c index e8d1c4eaefc..db979721e6d 100644 --- a/widget/src/gtkxtbin/gtkxtbin.c +++ b/widget/src/gtkxtbin/gtkxtbin.c @@ -173,58 +173,12 @@ gtk_xtbin_class_init (GtkXtBinClass *klass) static void gtk_xtbin_init (GtkXtBin *xtbin) { - static Display *xtdisplay = NULL; - + xtbin->xtdisplay = NULL; xtbin->xtwidget = NULL; xtbin->parent_window = NULL; xtbin->xtwindow = 0; xtbin->x = 0; xtbin->y = 0; - - /* Initialize the Xt toolkit */ - if (xt_is_initialized == 0) { - char *mArgv[1]; - int mArgc = 0; - XtAppContext app_context; - int cnumber; - -#ifdef DEBUG_XTBIN - printf("starting up Xt stuff\n"); -#endif - /* - * Initialize Xt stuff - */ - - XtToolkitInitialize(); - app_context = XtCreateApplicationContext(); - if (fallback) - XtAppSetFallbackResources(app_context, fallback); - - xtdisplay = XtOpenDisplay(app_context, NULL, NULL, - "Wrapper", NULL, 0, &mArgc, mArgv); - - /* - * hook Xt event loop into the glib event loop. - */ - - /* the assumption is that gtk_init has already been called */ - g_source_add (GDK_PRIORITY_EVENTS, TRUE, - &xt_event_funcs, NULL, xtdisplay, NULL); - -#ifdef VMS - cnumber = XConnectionNumber(xtdisplay); -#else - cnumber = ConnectionNumber(xtdisplay); -#endif - xt_event_poll_fd.fd = cnumber; - xt_event_poll_fd.events = G_IO_IN; - xt_event_poll_fd.revents = 0; /* hmm... is this correct? */ - - g_main_add_poll (&xt_event_poll_fd, G_PRIORITY_DEFAULT); - } - xt_is_initialized++; /* bump up our count here */ - - xtbin->xtdisplay = xtdisplay; } static void @@ -239,13 +193,11 @@ gtk_xtbin_realize (GtkWidget *widget) Window win; Widget embeded; - g_return_if_fail (GTK_IS_XTBIN (widget)); gdk_flush(); xtbin = GTK_XTBIN (widget); - if (widget->allocation.x == -1 && widget->allocation.y == -1 && widget->allocation.width == 1 && @@ -370,11 +322,72 @@ gtk_xtbin_realize (GtkWidget *widget) GtkWidget* gtk_xtbin_new (GdkWindow *parent_window, String * f) { - GtkXtBin *xtbin; + static Display *xtdisplay = NULL; + GtkXtBin *xtbin; assert(parent_window != NULL); xtbin = gtk_type_new (GTK_TYPE_XTBIN); + + if (!xtbin) + return (GtkWidget*)NULL; + + /* Initialize the Xt toolkit */ + if (xt_is_initialized == 0) { + char *mArgv[1]; + int mArgc = 0; + XtAppContext app_context; + int cnumber; + +#ifdef DEBUG_XTBIN + printf("starting up Xt stuff\n"); +#endif + /* + * Initialize Xt stuff + */ + + XtToolkitInitialize(); + app_context = XtCreateApplicationContext(); + if (fallback) + XtAppSetFallbackResources(app_context, fallback); + + xtdisplay = XtOpenDisplay(app_context, NULL, NULL, + "Wrapper", NULL, 0, &mArgc, mArgv); + + if (!xtdisplay) { + /* If XtOpenDisplay failed, we can't go any further. + * Bail out. + */ +#ifdef DEBUG_XTBIN + printf("gtk_xtbin_init: XtOpenDisplay() returned NULL.\n"); +#endif + + gtk_type_free (GTK_TYPE_XTBIN, xtbin); + return (GtkWidget *)NULL; + } + + /* + * hook Xt event loop into the glib event loop. + */ + + /* the assumption is that gtk_init has already been called */ + g_source_add (GDK_PRIORITY_EVENTS, TRUE, + &xt_event_funcs, NULL, xtdisplay, (GDestroyNotify)NULL); + +#ifdef VMS + cnumber = XConnectionNumber(xtdisplay); +#else + cnumber = ConnectionNumber(xtdisplay); +#endif + xt_event_poll_fd.fd = cnumber; + xt_event_poll_fd.events = G_IO_IN; + xt_event_poll_fd.revents = 0; /* hmm... is this correct? */ + + g_main_add_poll (&xt_event_poll_fd, G_PRIORITY_DEFAULT); + xt_is_initialized++; /* bump up our count here */ + } + + xtbin->xtdisplay = xtdisplay; xtbin->parent_window = parent_window; if (f) fallback = f;