#define XPCOM_GLUE
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <gtk/gtk.h>
#include "xpcom-config.h"
#include "nsXPCOMGlue.h"
#include "nsDebug.h"
#include "nsCOMPtr.h"
#include "widget/nsIBaseWindow.h"
#include "nsILocalFile.h"
#include "nsIWebBrowser.h"
#include "docshell/nsIWebNavigation.h"
#include "nsEmbedCID.h"
#include "nsEmbedString.h"
#include "xulapp/nsXULAppAPI.h"
#include "nsComponentManagerUtils.h"
XRE_InitEmbeddingType XRE_InitEmbedding;
XRE_TermEmbeddingType XRE_TermEmbedding;
static gboolean delete_event( GtkWidget *widget, GdkEvent *event,
gpointer data ) {
gtk_main_quit();
return FALSE;
}
int main(int argc, char** argv) {
GtkWidget *window;
nsCOMPtr<nsIBaseWindow> baseWindow;
nsCOMPtr<nsIWebBrowser> webBrowser;
nsCOMPtr<nsILocalFile> libxul;
nsCOMPtr<nsIWebNavigation> webNavigation;
nsDynamicFunctionLoad nsFuncs[] = {
{"XRE_InitEmbedding", (NSFuncPtr*)&XRE_InitEmbedding},
{"XRE_TermEmbedding", (NSFuncPtr*)
&XRE_TermEmbedding},
{0, 0}
};
nsresult rv;
gtk_init (&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
rv = XPCOMGlueStartup("/opt/xulrunner/libxpcom.so");
if (NS_FAILED(rv)) {
printf("XPCOMGlueStartup\n");
}
rv = XPCOMGlueLoadXULFunctions(nsFuncs);
if (NS_FAILED(rv)) {
printf("XPCOMGlueLoadXULFunctions\n");
}
rv = NS_NewNativeLocalFile(nsEmbedCString("/opt/xulrunner"),
PR_FALSE, getter_AddRefs(libxul));
if (NS_FAILED(rv)) {
printf("NS_NewNativeLocalFile\n");
}
rv = XRE_InitEmbedding(libxul, 0, 0, 0, 0);
if (NS_FAILED(rv)) {
printf("XRE_InitEmbedding\n");
}
webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
printf("do_CreateInstance webBrowser\n");
}
baseWindow = do_QueryInterface(webBrowser);
rv = baseWindow->InitWindow(window, 0, 0, 0, 300, 400);
if (NS_FAILED(rv)) {
printf("InitWindow\n");
}
rv = baseWindow->Create();
if (NS_FAILED(rv)) {
printf("Create\n");
}
rv =baseWindow->SetVisibility(PR_TRUE);
if (NS_FAILED(rv)) {
printf("SetVisibility\n");
}
webNavigation = do_QueryInterface(webBrowser);
rv = webNavigation->LoadURI(NS_ConvertASCIItoUTF16("http://
www.google.com").get(),
nsIWebNavigation::LOAD_FLAGS_NONE, 0, 0, 0);
if (NS_FAILED(rv)) {
printf("LoadURI\n");
}
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(delete_event), 0);
gtk_main();
printf("exit...\n");
XRE_TermEmbedding();
XPCOMGlueShutdown();
return 0;
}
hello
i try your code in fedora8, but it compiled wrong
Hi!
I could not compile the above piece of code.
maybe I didn't use the correct options. Can you please let me know how
you compiled the code?
Regards,
Vinod
g++ -Wall -Wno-non-virtual-dtor -I/home/user/xulrunner-sdk/include -I/
home/user/xulrunner-sdk/sdk/include `pkg-config --cflags gtk+-2.0` -c
-o embed_xul.o embed_xul.cpp
cc embed_xul.o -L/home/user/xulrunner-sdk/lib -lxpcomglue -lstdc++
`pkg-config --libs gtk+-2.0` -o embed_xul
I have been trying to compile and run the example but I am running
into some difficulties.
The following lines:
XRE_InitEmbeddingType XRE_InitEmbedding;
XRE_TermEmbeddingType XRE_TermEmbedding;
Give me the following errors when compiling:
embed_xul.cpp:27: error: expected initializer before
‘XRE_InitEmbeddingType’
embed_xul.cpp:28: error: ‘XRE_TermEmbeddingType’ does not name a type
If I remove these definitions I am able to compile the application but
I run into some linking issues as follows:
embed_xul.cpp:(.text+0x3e): undefined reference to `XRE_InitEmbedding'
embed_xul.cpp:(.text+0x4d): undefined reference to `XRE_TermEmbedding'
embed_xul.cpp:(.text+0x1ac): undefined reference to
`XRE_InitEmbedding'
embed_xul.cpp:(.text+0x40a): undefined reference to
`XRE_TermEmbedding'
I have tried liking with libembed_base_s.a found under the /embedding/
base directory of the objects folder after building firefox. This
fixes the linking issues but now causes a segmentation fault when
XPCOMGlueLoadXULFunctions is called.
Any help would be greatly appreciated.
Thanks in advance
Sorry I needed to add -lxul not libembed_base_s.a to remove the
linking problem.
Hello, I managed to perfectly compile your example with
CFLAGS=`pkg-config --cflags gtk+-2.0 gthread-2.0 libxul-embedding-
unstable` -g -Wall
LD_ADD=`pkg-config --libs gtk+-2.0 gthread-2.0 libxul-embedding-
unstable`
minim: minim.cc
g++ -Wno-non-virtual-dtor $(CFLAGS) minim.cc -o minim $(LD_ADD)
on Ubuntu 8.04, with xulrunner-1.9-dev installed, and after changing
the " to < in the include directives
However the app crashes on any browser link clicked.
I do not have the debugging symbols for xulrunner, for a meaningful
backtrace, but are you having the same problem?
If so, what would be the cause? (I saw you're building mozilla from
the source.)
Thanks,
Vlad