Bug 386844 - "Crash when running Java Applets [@ XSync - JavaPluginInstance5::SetWindow]" (move ws_info and xtbin code from ns4xPluginInstance to nsPluginNativeWindowGtk2) [p=karlt r+sr+a1.9=jst]

This commit is contained in:
reed@reedloden.com 2007-09-29 00:08:14 -07:00
parent ac49f8d5bc
commit 47141f5b4d
4 changed files with 126 additions and 184 deletions

View File

@ -59,12 +59,6 @@
#include "nsILegacyPluginWrapperOS2.h"
#endif
#ifdef MOZ_WIDGET_GTK2
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "gtk2xtbin.h"
#endif
////////////////////////////////////////////////////////////////////////
// CID's && IID's
static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); // needed for NS_TRY_SAFE_CALL
@ -820,11 +814,6 @@ ns4xPluginInstance::~ns4xPluginInstance(void)
{
PLUGIN_LOG(PLUGIN_LOG_BASIC, ("ns4xPluginInstance dtor: this=%p\n",this));
#if defined (MOZ_WIDGET_GTK2)
if (mXtBin)
gtk_widget_destroy(mXtBin);
#endif
// clean the stream list if any
for(nsInstanceStream *is = mStreams; is != nsnull;) {
nsInstanceStream * next = is->mNext;
@ -847,9 +836,6 @@ NS_IMETHODIMP ns4xPluginInstance::Initialize(nsIPluginInstancePeer* peer)
{
PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("ns4xPluginInstance::Initialize this=%p\n",this));
#if defined (MOZ_WIDGET_GTK2)
mXtBin = nsnull;
#endif
return InitializePlugin(peer);
}
@ -890,13 +876,6 @@ NS_IMETHODIMP ns4xPluginInstance::Stop(void)
}
}
#if defined (MOZ_WIDGET_GTK2)
if (mXtBin) {
gtk_widget_destroy(mXtBin);
mXtBin = 0;
}
#endif
if(!mStarted)
return NS_OK;
@ -1117,109 +1096,12 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
NPError error;
// It would be nice if this was all moved to
// nsPluginNativeWindowGtk2::CallSetWindow or nsWindow or somewhere else?
#if defined (MOZ_WIDGET_GTK2)
if (window->type == nsPluginWindowType_Window) {
PRBool isXembed = PR_FALSE;
// bug 108337, flash plugin on linux doesn't like window->width <= 0
if ((PRInt32) window->width <= 0 || (PRInt32) window->height <= 0)
return NS_OK;
// We need to test if this is an xembed window before doing checks
// below, as they might be used on the first pass or on later passes
// when we resize the plugin window.
GdkWindow *win = gdk_window_lookup((XID)window->window);
if (!win)
return NS_ERROR_FAILURE;
gpointer user_data = nsnull;
gdk_window_get_user_data(win, &user_data);
if (user_data && GTK_IS_WIDGET(user_data)) {
GtkWidget* widget = GTK_WIDGET(user_data);
if (GTK_IS_SOCKET(widget))
isXembed = PR_TRUE;
}
// Fill out the ws_info data.
// (ws_info should be non-null but check just in case.)
if (!mXtBin && window->ws_info) {
NPSetWindowCallbackStruct* ws =
static_cast<NPSetWindowCallbackStruct*>(window->ws_info);
if (!isXembed) {
#ifdef NS_DEBUG
printf("About to create new xtbin of %i X %i from %p...\n",
window->width, window->height, (void*)win);
#endif
#if 0
// if we destroyed the plugin when we left the page, we could remove this
// code (i believe) the problem here is that the window gets destroyed when
// its parent, etc does by changing a page the plugin instance is being
// held on to, so when we return to the page, we have a mXtBin, but it is
// in a not-so-good state.
// --
// this is lame. we shouldn't be destroying this everytime, but I can't find
// a good way to tell if we need to destroy/recreate the xtbin or not
// what if the plugin wants to change the window and not just resize it??
// (pav)
if (mXtBin) {
gtk_widget_destroy(mXtBin);
mXtBin = NULL;
}
#endif
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);
#ifdef NS_DEBUG
printf("About to show xtbin(%p)...\n", (void*)mXtBin); fflush(NULL);
#endif
gtk_widget_show(mXtBin);
#ifdef NS_DEBUG
printf("completed gtk_widget_show(%p)\n", (void*)mXtBin); fflush(NULL);
#endif
}
// fill in window info structure
ws->type = 0; // OK, that was a guess!!
#ifdef MOZ_X11
ws->depth = gdk_window_get_visual(win)->depth;
if (!isXembed)
ws->display = GTK_XTBIN(mXtBin)->xtdisplay;
else
ws->display = GDK_WINDOW_XDISPLAY(win);
ws->visual = GDK_VISUAL_XVISUAL(gdk_window_get_visual(win));
ws->colormap = GDK_COLORMAP_XCOLORMAP(gdk_window_get_colormap(win));
XFlush(ws->display);
#endif
} // !mXtBin
if (!mXtBin && !isXembed)
return NS_ERROR_FAILURE;
if (!isXembed) {
// And now point the NPWindow structures window
// to the actual X window
window->window = (nsPluginPort *)GTK_XTBIN(mXtBin)->xtwindow;
gtk_xtbin_resize(mXtBin, window->width, window->height);
}
if (window->type == nsPluginWindowType_Window &&
(window->width <= 0 || window->height <= 0)) {
// bug 108347, flash plugin on linux doesn't like window->width <= 0
return NS_OK;
}
#endif // MOZ_WIDGET
if (fCallbacks->setwindow) {

View File

@ -63,10 +63,6 @@
#endif
#include "prlink.h" // for PRLibrary
#if defined (MOZ_WIDGET_GTK2)
#include <gtk/gtk.h>
#endif
////////////////////////////////////////////////////////////////////////
class ns4xPluginStreamListener;
@ -174,14 +170,6 @@ protected:
*/
NPPluginFuncs* fCallbacks;
#if defined (MOZ_WIDGET_GTK2)
/**
* Special GtkXtBin widget that encapsulates the Xt toolkit
* within a Gtk Application
*/
GtkWidget *mXtBin;
#endif
/**
* The 4.x-style structure used to communicate between the plugin
* instance and the browser.

View File

@ -48,6 +48,7 @@
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
#include <gdk/gdk.h>
#include "gtk2xtbin.h"
#ifdef OJI
#include "plstr.h"
#include "nsIPlugin.h"
@ -63,9 +64,14 @@ public:
virtual nsresult CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance);
private:
GtkWidget* mGtkSocket;
NPSetWindowCallbackStruct m_ws_info;
NPSetWindowCallbackStruct mWsInfo;
/**
* Either a GtkSocket or a special GtkXtBin widget (derived from GtkSocket)
* that encapsulates the Xt toolkit within a Gtk Application.
*/
GtkWidget* mSocketWidget;
nsresult CreateXEmbedWindow();
nsresult CreateXtWindow();
void SetAllocation();
PRBool CanGetValueFromPlugin(nsCOMPtr<nsIPluginInstance> &aPluginInstance);
};
@ -81,21 +87,20 @@ nsPluginNativeWindowGtk2::nsPluginNativeWindowGtk2() : nsPluginNativeWindow()
width = 0;
height = 0;
memset(&clipRect, 0, sizeof(clipRect));
ws_info = &m_ws_info;
ws_info = &mWsInfo;
type = nsPluginWindowType_Window;
mGtkSocket = 0;
m_ws_info.type = 0;
m_ws_info.display = nsnull;
m_ws_info.visual = nsnull;
m_ws_info.colormap = 0;
m_ws_info.depth = 0;
mSocketWidget = 0;
mWsInfo.type = 0;
mWsInfo.display = nsnull;
mWsInfo.visual = nsnull;
mWsInfo.colormap = 0;
mWsInfo.depth = 0;
}
nsPluginNativeWindowGtk2::~nsPluginNativeWindowGtk2()
{
if(mGtkSocket) {
gtk_widget_destroy(mGtkSocket);
mGtkSocket = 0;
if(mSocketWidget) {
gtk_widget_destroy(mSocketWidget);
}
}
@ -119,28 +124,42 @@ nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aP
if(aPluginInstance) {
if (type == nsPluginWindowType_Window) {
nsresult rv;
PRBool val = PR_FALSE;
if(!mGtkSocket) {
if (CanGetValueFromPlugin(aPluginInstance))
if(!mSocketWidget) {
PRBool needXEmbed = PR_FALSE;
if (CanGetValueFromPlugin(aPluginInstance)) {
rv = aPluginInstance->GetValue
((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &val);
}
((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &needXEmbed);
#ifdef DEBUG
printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", val);
printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", needXEmbed);
#endif
if(val) {
CreateXEmbedWindow();
}
if(needXEmbed) {
CreateXEmbedWindow();
}
else {
CreateXtWindow();
}
}
if(mGtkSocket) {
// Make sure to resize and re-place the window if required
if(!mSocketWidget)
return NS_ERROR_FAILURE;
// Make sure to resize and re-place the window if required.
// Need to reset "window" each time as nsObjectFrame::DidReflow sets it
// to the ancestor window.
if(GTK_IS_XTBIN(mSocketWidget)) {
gtk_xtbin_resize(mSocketWidget, width, height);
// Point the NPWindow structures window to the actual X window
window = (nsPluginPort *)GTK_XTBIN(mSocketWidget)->xtwindow;
}
else { // XEmbed
SetAllocation();
window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mGtkSocket));
window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));
}
#ifdef DEBUG
printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window);
#endif
}
} // nsPluginWindowType_Window
aPluginInstance->SetWindow(this);
}
else if (mPluginInstance)
@ -151,41 +170,50 @@ nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aP
}
nsresult nsPluginNativeWindowGtk2::CreateXEmbedWindow() {
if(!mGtkSocket) {
GdkWindow *win = gdk_window_lookup((XID)window);
mGtkSocket = gtk_socket_new();
NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");
//attach the socket to the container widget
gtk_widget_set_parent_window(mGtkSocket, win);
GdkWindow *parent_win = gdk_window_lookup((XID)window);
mSocketWidget = gtk_socket_new();
// Make sure to handle the plug_removed signal. If we don't the
// socket will automatically be destroyed when the plug is
// removed, which means we're destroying it more than once.
// SYNTAX ERROR.
g_signal_connect(mGtkSocket, "plug_removed",
G_CALLBACK(plug_removed_cb), NULL);
//attach the socket to the container widget
gtk_widget_set_parent_window(mSocketWidget, parent_win);
gpointer user_data = NULL;
gdk_window_get_user_data(win, &user_data);
// Make sure to handle the plug_removed signal. If we don't the
// socket will automatically be destroyed when the plug is
// removed, which means we're destroying it more than once.
// SYNTAX ERROR.
g_signal_connect(mSocketWidget, "plug_removed",
G_CALLBACK(plug_removed_cb), NULL);
GtkContainer *container = GTK_CONTAINER(user_data);
gtk_container_add(container, mGtkSocket);
gtk_widget_realize(mGtkSocket);
gpointer user_data = NULL;
gdk_window_get_user_data(parent_win, &user_data);
// Resize before we show
SetAllocation();
GtkContainer *container = GTK_CONTAINER(user_data);
gtk_container_add(container, mSocketWidget);
gtk_widget_realize(mSocketWidget);
gtk_widget_show(mGtkSocket);
// Resize before we show
SetAllocation();
gdk_flush();
window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mGtkSocket));
}
gtk_widget_show(mSocketWidget);
gdk_flush();
window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));
// Fill out the ws_info structure.
// (The windowless case is done in nsObjectFrame.cpp.)
GdkWindow *gdkWindow = gdk_window_lookup((XID)window);
mWsInfo.display = GDK_WINDOW_XDISPLAY(gdkWindow);
mWsInfo.colormap = GDK_COLORMAP_XCOLORMAP(gdk_drawable_get_colormap(gdkWindow));
GdkVisual* gdkVisual = gdk_drawable_get_visual(gdkWindow);
mWsInfo.visual = GDK_VISUAL_XVISUAL(gdkVisual);
mWsInfo.depth = gdkVisual->depth;
return NS_OK;
}
void nsPluginNativeWindowGtk2::SetAllocation() {
if (!mGtkSocket)
if (!mSocketWidget)
return;
GtkAllocation new_allocation;
@ -193,7 +221,45 @@ void nsPluginNativeWindowGtk2::SetAllocation() {
new_allocation.y = 0;
new_allocation.width = width;
new_allocation.height = height;
gtk_widget_size_allocate(mGtkSocket, &new_allocation);
gtk_widget_size_allocate(mSocketWidget, &new_allocation);
}
nsresult nsPluginNativeWindowGtk2::CreateXtWindow() {
NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");
#ifdef NS_DEBUG
printf("About to create new xtbin of %i X %i from %p...\n",
width, height, (void*)window);
#endif
GdkWindow *gdkWindow = gdk_window_lookup((XID)window);
mSocketWidget = gtk_xtbin_new(gdkWindow, 0);
// Check to see if creating the xtbin failed for some reason.
// if it did, we can't go any further.
if (!mSocketWidget)
return NS_ERROR_FAILURE;
gtk_widget_set_size_request(mSocketWidget, width, height);
#ifdef NS_DEBUG
printf("About to show xtbin(%p)...\n", (void*)mSocketWidget); fflush(NULL);
#endif
gtk_widget_show(mSocketWidget);
#ifdef NS_DEBUG
printf("completed gtk_widget_show(%p)\n", (void*)mSocketWidget); fflush(NULL);
#endif
// Fill out the ws_info structure.
GtkXtBin* xtbin = GTK_XTBIN(mSocketWidget);
// The xtbin has its own Display structure.
mWsInfo.display = xtbin->xtdisplay;
mWsInfo.colormap = xtbin->xtclient.xtcolormap;
mWsInfo.visual = xtbin->xtclient.xtvisual;
mWsInfo.depth = xtbin->xtclient.xtdepth;
// Leave mWsInfo.type = 0 - Who knows what this is meant to be?
XFlush(mWsInfo.display);
return NS_OK;
}
PRBool nsPluginNativeWindowGtk2::CanGetValueFromPlugin(nsCOMPtr<nsIPluginInstance> &aPluginInstance)

View File

@ -413,11 +413,17 @@ gtk_xtbin_resize (GtkWidget *widget,
printf("gtk_xtbin_resize %p %d %d\n", (void *)widget, width, height);
#endif
xtbin->height = height;
xtbin->width = width;
// Avoid BadValue errors in XtSetValues
if (height <= 0 || width <=0) {
height = 1;
width = 1;
}
XtSetArg(args[0], XtNheight, height);
XtSetArg(args[1], XtNwidth, width);
XtSetValues(xtbin->xtclient.top_widget, args, 2);
xtbin->height = height;
xtbin->width = width;
/* we need to send a size allocate so the socket knows about the
size changes */