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
Родитель 6edf075155
Коммит 2402d7d9ed
4 изменённых файлов: 126 добавлений и 184 удалений

Просмотреть файл

@ -59,12 +59,6 @@
#include "nsILegacyPluginWrapperOS2.h" #include "nsILegacyPluginWrapperOS2.h"
#endif #endif
#ifdef MOZ_WIDGET_GTK2
#include <gdk/gdk.h>
#include <gdk/gdkx.h>
#include "gtk2xtbin.h"
#endif
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// CID's && IID's // CID's && IID's
static NS_DEFINE_IID(kCPluginManagerCID, NS_PLUGINMANAGER_CID); // needed for NS_TRY_SAFE_CALL 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)); 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 // clean the stream list if any
for(nsInstanceStream *is = mStreams; is != nsnull;) { for(nsInstanceStream *is = mStreams; is != nsnull;) {
nsInstanceStream * next = is->mNext; 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)); PLUGIN_LOG(PLUGIN_LOG_NORMAL, ("ns4xPluginInstance::Initialize this=%p\n",this));
#if defined (MOZ_WIDGET_GTK2)
mXtBin = nsnull;
#endif
return InitializePlugin(peer); 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) if(!mStarted)
return NS_OK; return NS_OK;
@ -1117,109 +1096,12 @@ NS_IMETHODIMP ns4xPluginInstance::SetWindow(nsPluginWindow* window)
NPError error; 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 defined (MOZ_WIDGET_GTK2)
if (window->type == nsPluginWindowType_Window) { if (window->type == nsPluginWindowType_Window &&
PRBool isXembed = PR_FALSE; (window->width <= 0 || window->height <= 0)) {
// bug 108337, flash plugin on linux doesn't like window->width <= 0 // bug 108347, flash plugin on linux doesn't like window->width <= 0
if ((PRInt32) window->width <= 0 || (PRInt32) window->height <= 0)
return NS_OK; 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);
}
}
#endif // MOZ_WIDGET #endif // MOZ_WIDGET
if (fCallbacks->setwindow) { if (fCallbacks->setwindow) {

Просмотреть файл

@ -63,10 +63,6 @@
#endif #endif
#include "prlink.h" // for PRLibrary #include "prlink.h" // for PRLibrary
#if defined (MOZ_WIDGET_GTK2)
#include <gtk/gtk.h>
#endif
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
class ns4xPluginStreamListener; class ns4xPluginStreamListener;
@ -174,14 +170,6 @@ protected:
*/ */
NPPluginFuncs* fCallbacks; 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 * The 4.x-style structure used to communicate between the plugin
* instance and the browser. * instance and the browser.

Просмотреть файл

@ -48,6 +48,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkx.h> #include <gdk/gdkx.h>
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include "gtk2xtbin.h"
#ifdef OJI #ifdef OJI
#include "plstr.h" #include "plstr.h"
#include "nsIPlugin.h" #include "nsIPlugin.h"
@ -63,9 +64,14 @@ public:
virtual nsresult CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance); virtual nsresult CallSetWindow(nsCOMPtr<nsIPluginInstance> &aPluginInstance);
private: private:
GtkWidget* mGtkSocket; NPSetWindowCallbackStruct mWsInfo;
NPSetWindowCallbackStruct m_ws_info; /**
* 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 CreateXEmbedWindow();
nsresult CreateXtWindow();
void SetAllocation(); void SetAllocation();
PRBool CanGetValueFromPlugin(nsCOMPtr<nsIPluginInstance> &aPluginInstance); PRBool CanGetValueFromPlugin(nsCOMPtr<nsIPluginInstance> &aPluginInstance);
}; };
@ -81,21 +87,20 @@ nsPluginNativeWindowGtk2::nsPluginNativeWindowGtk2() : nsPluginNativeWindow()
width = 0; width = 0;
height = 0; height = 0;
memset(&clipRect, 0, sizeof(clipRect)); memset(&clipRect, 0, sizeof(clipRect));
ws_info = &m_ws_info; ws_info = &mWsInfo;
type = nsPluginWindowType_Window; type = nsPluginWindowType_Window;
mGtkSocket = 0; mSocketWidget = 0;
m_ws_info.type = 0; mWsInfo.type = 0;
m_ws_info.display = nsnull; mWsInfo.display = nsnull;
m_ws_info.visual = nsnull; mWsInfo.visual = nsnull;
m_ws_info.colormap = 0; mWsInfo.colormap = 0;
m_ws_info.depth = 0; mWsInfo.depth = 0;
} }
nsPluginNativeWindowGtk2::~nsPluginNativeWindowGtk2() nsPluginNativeWindowGtk2::~nsPluginNativeWindowGtk2()
{ {
if(mGtkSocket) { if(mSocketWidget) {
gtk_widget_destroy(mGtkSocket); gtk_widget_destroy(mSocketWidget);
mGtkSocket = 0;
} }
} }
@ -119,28 +124,42 @@ nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aP
if(aPluginInstance) { if(aPluginInstance) {
if (type == nsPluginWindowType_Window) { if (type == nsPluginWindowType_Window) {
nsresult rv; nsresult rv;
PRBool val = PR_FALSE; if(!mSocketWidget) {
if(!mGtkSocket) { PRBool needXEmbed = PR_FALSE;
if (CanGetValueFromPlugin(aPluginInstance)) if (CanGetValueFromPlugin(aPluginInstance)) {
rv = aPluginInstance->GetValue rv = aPluginInstance->GetValue
((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &val); ((nsPluginInstanceVariable)NPPVpluginNeedsXEmbed, &needXEmbed);
}
#ifdef DEBUG #ifdef DEBUG
printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", val); printf("nsPluginNativeWindowGtk2: NPPVpluginNeedsXEmbed=%d\n", needXEmbed);
#endif #endif
if(val) { }
if(needXEmbed) {
CreateXEmbedWindow(); CreateXEmbedWindow();
} }
else {
CreateXtWindow();
}
}
if(mGtkSocket) { if(!mSocketWidget)
// Make sure to resize and re-place the window if required 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(); SetAllocation();
window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mGtkSocket)); window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mSocketWidget));
} }
#ifdef DEBUG #ifdef DEBUG
printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window); printf("nsPluginNativeWindowGtk2: call SetWindow with xid=%p\n", (void *)window);
#endif #endif
} } // nsPluginWindowType_Window
aPluginInstance->SetWindow(this); aPluginInstance->SetWindow(this);
} }
else if (mPluginInstance) else if (mPluginInstance)
@ -151,41 +170,50 @@ nsresult nsPluginNativeWindowGtk2::CallSetWindow(nsCOMPtr<nsIPluginInstance> &aP
} }
nsresult nsPluginNativeWindowGtk2::CreateXEmbedWindow() { nsresult nsPluginNativeWindowGtk2::CreateXEmbedWindow() {
if(!mGtkSocket) { NS_ASSERTION(!mSocketWidget,"Already created a socket widget!");
GdkWindow *win = gdk_window_lookup((XID)window);
mGtkSocket = gtk_socket_new(); GdkWindow *parent_win = gdk_window_lookup((XID)window);
mSocketWidget = gtk_socket_new();
//attach the socket to the container widget //attach the socket to the container widget
gtk_widget_set_parent_window(mGtkSocket, win); gtk_widget_set_parent_window(mSocketWidget, parent_win);
// Make sure to handle the plug_removed signal. If we don't the // Make sure to handle the plug_removed signal. If we don't the
// socket will automatically be destroyed when the plug is // socket will automatically be destroyed when the plug is
// removed, which means we're destroying it more than once. // removed, which means we're destroying it more than once.
// SYNTAX ERROR. // SYNTAX ERROR.
g_signal_connect(mGtkSocket, "plug_removed", g_signal_connect(mSocketWidget, "plug_removed",
G_CALLBACK(plug_removed_cb), NULL); G_CALLBACK(plug_removed_cb), NULL);
gpointer user_data = NULL; gpointer user_data = NULL;
gdk_window_get_user_data(win, &user_data); gdk_window_get_user_data(parent_win, &user_data);
GtkContainer *container = GTK_CONTAINER(user_data); GtkContainer *container = GTK_CONTAINER(user_data);
gtk_container_add(container, mGtkSocket); gtk_container_add(container, mSocketWidget);
gtk_widget_realize(mGtkSocket); gtk_widget_realize(mSocketWidget);
// Resize before we show // Resize before we show
SetAllocation(); SetAllocation();
gtk_widget_show(mGtkSocket); gtk_widget_show(mSocketWidget);
gdk_flush(); gdk_flush();
window = (nsPluginPort *)gtk_socket_get_id(GTK_SOCKET(mGtkSocket)); 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; return NS_OK;
} }
void nsPluginNativeWindowGtk2::SetAllocation() { void nsPluginNativeWindowGtk2::SetAllocation() {
if (!mGtkSocket) if (!mSocketWidget)
return; return;
GtkAllocation new_allocation; GtkAllocation new_allocation;
@ -193,7 +221,45 @@ void nsPluginNativeWindowGtk2::SetAllocation() {
new_allocation.y = 0; new_allocation.y = 0;
new_allocation.width = width; new_allocation.width = width;
new_allocation.height = height; 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) PRBool nsPluginNativeWindowGtk2::CanGetValueFromPlugin(nsCOMPtr<nsIPluginInstance> &aPluginInstance)

Просмотреть файл

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