I have been trying to write a sample code for embedding mozilla in
wxWidgets.
I dont seem to be able to embed Mozilla even though i follow all the steps
given in http://developer.mozilla.org/en/docs/XPCOM_Glue and
http://developer.mozilla.org/en/docs/GRE
I am running Ubuntu 8.04.
Code:
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#define XPCOM_GLUE
#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"
#define wxCSTR wxString::FromAscii
XRE_InitEmbeddingType XRE_InitEmbedding;
XRE_TermEmbeddingType XRE_TermEmbedding;
class MyApp : public wxApp
{
public:
virtual bool OnInit();
};
class MyFrame : public wxFrame
{
public:
MyFrame(const wxString& title);
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
private:
DECLARE_EVENT_TABLE()
};
enum
{
Minimal_Quit = wxID_EXIT,
Minimal_About = wxID_ABOUT
};
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout)
END_EVENT_TABLE()
IMPLEMENT_APP(MyApp)
bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
MyFrame *frame = new MyFrame(wxCSTR("Minimal wxWidgets App"));
SetTopWindow(frame);
frame->Show(true);
nsCOMPtr<nsIBaseWindow> baseWindow;
nsCOMPtr<nsIWebBrowser> webBrowser;
nsCOMPtr<nsILocalFile> libxul;
nsCOMPtr<nsILocalFile> appDir;
nsCOMPtr<nsIWebNavigation> webNavigation;
nsDynamicFunctionLoad nsFuncs[] = { {"XRE_InitEmbedding",
(NSFuncPtr*)&XRE_InitEmbedding},
{"XRE_TermEmbedding",
(NSFuncPtr*)&XRE_TermEmbedding},
{0, 0} };
nsresult rv;
rv = XPCOMGlueStartup("/home/raravi/xulrunner-sdk/bin/libxpcom.so");
if (NS_FAILED(rv))
{
printf("XPCOMGlueStartup\n");
}
rv = XPCOMGlueLoadXULFunctions(nsFuncs);
if (NS_FAILED(rv))
{
printf("XPCOMGlueLoadXULFunctions\n");
}
rv = NS_NewNativeLocalFile(
nsEmbedCString("/home/raravi/xulrunner-sdk/bin"), PR_FALSE,
getter_AddRefs(libxul));
if (NS_FAILED(rv))
{
printf("NS_NewNativeLocalFile\n");
}
rv = NS_NewNativeLocalFile(
nsEmbedCString("/home/raravi/NetBeansProjects/wxXULTest/dist/Debug/GNU-Linux-x86"),
PR_FALSE, getter_AddRefs(appDir));
if(NS_FAILED(rv))
{
printf("NS_NewNativeLocalFile\n");
}
rv = XRE_InitEmbedding(libxul, appDir, 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(frame, 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_LITERAL_STRING("http://mail.yahoo.com/
").get(),
nsIWebNavigation::LOAD_FLAGS_NONE, 0, 0, 0);
if (NS_FAILED(rv))
{
printf("LoadURI\n");
}
return true;
}
MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
wxMenu *fileMenu = new wxMenu;
wxMenu *helpMenu = new wxMenu;
wxMenuBar *menuBar = new wxMenuBar();
helpMenu->Append(Minimal_About, wxCSTR("&About...\tF1"), wxCSTR("Show
about dialog"));
fileMenu->Append(Minimal_Quit, wxCSTR("E&xit\tAlt-X"), wxCSTR("Quit this
program"));
menuBar->Append(fileMenu, wxCSTR("&File"));
menuBar->Append(helpMenu, wxCSTR("&Help"));
SetMenuBar(menuBar);
CreateStatusBar(2);
SetStatusText(wxCSTR("Welcome to wxWidgets!"));
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
XRE_TermEmbedding();
XPCOMGlueShutdown();
Close(true);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
wxMessageBox(wxCSTR("This is the minimal wxWidgets sample\n"),
wxCSTR("About wxWidgets minimal sample"),
wxOK | wxICON_INFORMATION,
this);
}
This code compiles and runs successfully. But when run, i dont see the
embedded mozilla window...:-(
Its as if i am running a normal wxWidgets app. What am i doing wrong?
These are the cmds i use.
g++ `wx-config --cppflags` -fshort-wchar -c -g
-I/home/raravi/xulrunner-sdk/sdk/include
-I/home/raravi/xulrunner-sdk/include -o
build/Debug/GNU-Linux-x86/_ext/home/raravi/NetBeansProjects/wxXULTest/wxXULTest.o
/home/raravi/NetBeansProjects/wxXULTest/wxXULTest.cpp
g++ `wx-config --cppflags` -fshort-wchar `wx-config --libs` -o
dist/Debug/GNU-Linux-x86/wxxultest
build/Debug/GNU-Linux-x86/_ext/home/raravi/NetBeansProjects/wxXULTest/wxXULTest.o
/home/raravi/xulrunner-sdk/lib/libxpcomglue.a
Any help would be greatly appreciately.
--
The most successful people are those who are good at plan B
rArAvi
I don't really know much about wxWidgets, but I'm guessing the problem
is from this call:
rv = baseWindow->InitWindow(frame, 0, 0, 0, 300, 400);
InitWindow should get a native pointer/handler to the parent window.
For ubuntu I believe this should be a Gtk window handle. Maybe there
is a way to get that from the wxWidgets frame?
Hope this helps,
-Pelle
On Jul 4, 4:55 am, "amith raravi" <amith.rar...@gmail.com> wrote:
> Hi everyone.
>
> I have been trying to write a sample code for embedding mozilla in
> wxWidgets.
> I dont seem to be able to embed Mozilla even though i follow all the steps
> given inhttp://developer.mozilla.org/en/docs/XPCOM_Glueandhttp://developer.mozilla.org/en/docs/GRE
Should help. I spend lot of time figuring this out and I am not quit
done yet.
Another thing you might need to do is responding to OnSize events:
void MyFrame::OnSize ( wxSizeEvent &pEvent )
{
wxRect newRect = this->GetClientRect();
baseWindow->SetPositionAndSize (
newRect.GetLeft(), newRect.GetTop(),
newRect.GetWidth(), newRect.GetHeight(), PR_FALSE );
}
This works for me. Well almost. I still need to manually resize the
window once it's created to get the Mozilla contents drawn.
Also when I exit I get some error messages from Gtk.
If you can figure out how to correct these errors please report the
fixes back here or to me directly :-)
-Martin
(wxMinimal:10803): GLib-GObject-WARNING **: invalid uninstantiatable
type `(null)' in cast to `GtkWidget'
(wxMinimal:10803): Gtk-CRITICAL **: gtk_widget_hide: assertion
`GTK_IS_WIDGET (widget)' failed
(wxMinimal:10803): GLib-GObject-WARNING **: invalid uninstantiatable
type `(null)' in cast to `GtkWidget'
(wxMinimal:10803): GLib-GObject-WARNING **: instance of invalid non-
instantiatable type `(null)'
(wxMinimal:10803): GLib-GObject-CRITICAL **:
g_signal_handlers_disconnect_matched: assertion `G_TYPE_CHECK_INSTANCE
(instance)' failed
(wxMinimal:10803): GLib-GObject-WARNING **: instance of invalid non-
instantiatable type `(null)'
(wxMinimal:10803): GLib-GObject-CRITICAL **:
g_signal_handlers_disconnect_matched: assertion `G_TYPE_CHECK_INSTANCE
(instance)' failed
(wxMinimal:10803): GLib-GObject-WARNING **: invalid uninstantiatable
type `(null)' in cast to `GtkWidget'
(wxMinimal:10803): Gtk-CRITICAL **: gtk_widget_destroy: assertion
`GTK_IS_WIDGET (widget)' failed
Any help to get rid of these would be greatly appreciated :-)
-Martin Lütken
On Jul 4, 4:35 pm, mlutken <nit...@lutken.dk> wrote:
> My errors whe exiting are these:
>
> ....
> (wxMinimal:10803): Gtk-CRITICAL **: gtk_widget_destroy: assertion
> `GTK_IS_WIDGET (widget)' failed
>
> Any help to get rid of these would be greatly appreciated :-)
>
> -Martin Lütken
I was getting those errors myself when i linked to these libs -lxul -
lsoftokn3 -lsqlite3 -lmozjs -lxpcomglue
I am not sure exactly why it happened.
Now i link only to -lxpcomglue.
-Amith Raravi
=====================================================
1.rv = XPCOMGlueStartup("/home/raravi/xulrunner-sdk/bin/libxpcom.so");
to
rv = XPCOMGlueStartup("H:/Programming/xulrunner-1.9/dist-win/bin/
xpcom.dll");
2.rv = NS_NewNativeLocalFile(nsEmbedCString("/home/raravi/xulrunner-
sdk/bin"), PR_FALSE,getter_AddRefs(libxul));
to
rv = NS_NewNativeLocalFile( nsEmbedCString("H:/Programming/
xulrunner-1.9/dist-win/bin"), PR_FALSE,getter_AddRefs(libxul));
3.rv = NS_NewNativeLocalFile(nsEmbedCString("/home/raravi/
NetBeansProjects/wxXULTest/dist/Debug/GNU-Linux-x86"),PR_FALSE,
getter_AddRefs(appDir));
to
rv = NS_NewNativeLocalFile( nsEmbedCString("D:/Documents and
Settings/rArAvi/My Documents/Visual Studio 2005/Projects/wxXULTest/
wxXULTest"), PR_FALSE, getter_AddRefs(appDir));
4. rv = baseWindow->InitWindow(this->m_wxwindow, 0, 0, 0, 300, 400);
to
rv = baseWindow->InitWindow(this->GetHWND(), 0, 0, 0, 300, 400);
======================================================
I use the XP_WIN compiler flag.
And also /Zc:wchar_t- (Treat wchar_t as built-in type : No)
I use xpcomglue.lib only.
And also /NODEFAULTLIB:MSVCRT
But wxWidgets libraries need MSVCRT and i get lots of (more then 2000
actually) Unresolved External Symbol errors.
If i dont use /NODEFAULTLIB:MSVCRT, i get the followin error,
========================================================
MSVCRT.lib(crtexe.obj) : error LNK2001: unresolved external
symbol_main
=========================================================
How to solve this situation??
My application needs both wxWidgets and Mozilla. wxWidgets needs
MSVCRT but Mozilla does not.
Ps. I even compiled wxWidgets libs with /NODEFAULTLIB:MSVCRT, but it
doesnot change anything.
I use Visual Studio 2005 Express Edition on Windows 32bit XP with SP2.
wxWidgets is also compiled with /Zc:wchar_t- option.
Please help...
-Amith Raravi
Hope this helps,
-Pelle
You could try and check that out and build it. And I could even create
a release branch for you to get from via subversion. On Linux you
would probably need to install some things which I currently haven't
included/auto detected dependency for. Also I so far only compiled it
with VS2005, but it might work with the Express edition also.
-Martin
I will try the /Mt option and get back to you shortly.
Ps. I have had no problems in linux, (except the native window handle
issue). I was busy for the past few days, but i will try out what you
have suggested and get back to you.
-Amith Raravi
> nsEmbedCString("/home/raravi/NetBeansProjects/wxXULTest/dist/Debug/GNU-Linux-x86"),
> PR_FALSE, getter_AddRefs(appDir));
Out of curiosity, what do you have in the appDir foler? is it a XUL
application?
I am unable to find XRE_InitEmbedding documentation...
Thanks a lot!
Vlad
> > nsEmbedCString("/home/raravi/NetBeansProjects/wxXULTest/dist/Debug/GNU-Linux-x86"),
> > PR_FALSE, getter_AddRefs(appDir));
>
> Out of curiosity, what do you have in the appDir foler? is it a XUL
> application?
> I am unable to find XRE_InitEmbedding documentation...
Hey,
appDir contains my application binary.
-
Amith Raravi
I am linking my embedding app against the FIREFOX_3_0_1_RELEASE and
MOZ_CO_PROJECT=xulrunner code base
and following libs.
nspr4.lib
plc4.lib
plds4.lib
xul.lib
xpcomglue.lib
profdirserviceprovidersa_s.lib
jpeg3250.lib
And with XPCOM_GLUE=1 defined, I am getting these link errors:
error LNK2019: unresolved external symbol "public: int __thiscall
nsRect::IntersectRect(struct nsRect const &,struct nsRect const &)"
(?IntersectRect@nsRect@@QAEHABU1@0@Z) referenced in function "public:
virtual void __thiscall BrowserFrame::threadUpdate(void)"
(?threadUpdate@BrowserFrame@@UAEXXZ)
error LNK2001: unresolved external symbol "public: int __thiscall
nsRect::IntersectRect(struct nsRect const &,struct nsRect const &)"
(?IntersectRect@nsRect@@QAEHABU1@0@Z)
error LNK2019: unresolved external symbol "public: int __thiscall
nsRect::Intersects(struct nsRect const &)const "
(?Intersects@nsRect@@QBEHABU1@@Z) referenced in function "public: void
__thiscall DirtyRectList::MergeRemainingRects(class DirtyRect *)"
(?MergeRemainingRects@DirtyRectList@@QAEXPAVDirtyRect@@@Z)
error LNK2019: unresolved external symbol "public: int __thiscall
nsRect::UnionRect(struct nsRect const &,struct nsRect const &)"
(?UnionRect@nsRect@@QAEHABU1@0@Z) referenced in function "public: void
__thiscall DirtyRectList::InsertRect(struct nsRect,int)"
(?InsertRect@DirtyRectList@@QAEXUnsRect@@H@Z)
If I link to gkgfx.lib and string_s.lib these errors went away... but
then I get
error LNK2005: "public: __thiscall gfxIntSize::gfxIntSize(int,int)"
(??0gfxIntSize@@QAE@HH@Z) already defined in xul.lib(xul.dll)
I need to use both nsRect and gfxIntSize struct.. can they co-exist or
is there a link strategy to solve these errors?
your help is very much appreciated.
Steve
There are a bunch of problems here ;-)
* it doesn't make sense to link against xul.lib and xpcomglue.lib at the
same time. You either need to
1) use standalone linkage. Link only against xpcomglue.lib. Don't link
against NSPR/xul.lib at all. Define XPCOM_GLUE
2) use dependent linkage. link against xul.lib, xpcom.lib, and
xpcomglue_s.lib. Don't define XPCOM_GLUE
* You're trying to link against nsRect. I'm not sure why, but you can't use
nsRect. It is an internal API and is not avaialable to you. You should
figure out why you're trying to link with these symbols and remove the
dependency.
--BDS