Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

enabling javascript

2 views
Skip to first unread message

cyril giraudon

unread,
Sep 3, 2008, 3:51:47 AM9/3/08
to cyril.g...@free.fr
Hello,

I've succeeded in embedding gecko 1.9 in a wxWidget window.
It is a very simple beginning.

However, when the "http;//developer.mozilla.org" is loaded, I can see
the noscript element :
<div id="noscript"><p>Some features of this site require JavaScript.</
p></div>.
That is to say, javascript is disabled. When I click on hyperlink, the
application crashes.


What is to be done to enable javascript ?


Is it necessary to handle a profile like the ".vendor / app /
profile.file " created by xulrunner ?


Thanks a lot,

Cyril.


===============================================
#define XPCOM_GLUE

#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

#include <iostream>
#include "xpcom-config.h"
#include "nsXPCOMGlue.h"
#include "nsDebug.h"
#include "nsCOMPtr.h"
#include "widget/nsIBaseWindow.h"
#include "nsILocalFile.h"
#include "nsIWebBrowser.h"
#include "nsIWebBrowserSetup.h"
#include "nsStringAPI.h"
#include "docshell/nsIWebNavigation.h"
#include "nsEmbedCID.h"
#include "nsEmbedString.h"
#include "xulapp/nsXULAppAPI.h"
#include "nsComponentManagerUtils.h"
#include "docshell/nsIDocShell.h"
#include "docshell/nsIDocShellTreeItem.h"

#define wxCSTR wxString::FromAscii

using namespace std;

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);
nsCOMPtr<nsIWebBrowser> webBrowser;
nsCOMPtr<nsIWebBrowserSetup> webBrowserSetup;
nsCOMPtr<nsIBaseWindow> baseWindow;
nsCOMPtr<nsIWebNavigation> webNavigation;

void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnSize(wxSizeEvent& 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)
EVT_SIZE(MyFrame::OnSize)
END_EVENT_TABLE()

IMPLEMENT_APP(MyApp)

bool MyApp::OnInit()
{
if ( !wxApp::OnInit() )
return false;
nsCOMPtr<nsILocalFile> libxul;
nsCOMPtr<nsILocalFile> appDir;
nsCOMPtr<nsILocalFile> profile;
nsDynamicFunctionLoad nsFuncs[] = {
{"XRE_InitEmbedding",
(NSFuncPtr*)&XRE_InitEmbedding},
{"XRE_TermEmbedding",
(NSFuncPtr*)&XRE_TermEmbedding},
{0, 0}
};
nsresult rv;
rv = XPCOMGlueStartup("/home/XXX/YYY/libxpcom.so");
if (NS_FAILED(rv))
{
printf("XPCOMGlueStartup\n");
}
rv = XPCOMGlueLoadXULFunctions(nsFuncs);
if (NS_FAILED(rv))
{
printf("XPCOMGlueLoadXULFunctions\n");
}
rv = NS_NewNativeLocalFile(nsEmbedCString("/home/XXX/YYY"),
PR_FALSE,

getter_AddRefs(libxul));
if (NS_FAILED(rv))
{
printf("NS_NewNativeLocalFile 1 \n");
}

rv = NS_NewNativeLocalFile(nsEmbedCString("/home/XXX/ZZZ"),
PR_FALSE,
getter_AddRefs(appDir));
if(NS_FAILED(rv))
{
printf("NS_NewNativeLocalFile 2\n");
}

rv = XRE_InitEmbedding(libxul, appDir, nsnull, 0, 0);
if (NS_FAILED(rv))
{
printf("XRE_InitEmbedding\n");
}

MyFrame *frame = new MyFrame(wxCSTR("Minimal wxWidgets App"));
SetTopWindow(frame);
frame->Show(true);

printf("OnInit OK\n");
return true;
}

MyFrame::MyFrame(const wxString& title)
: wxFrame(NULL, wxID_ANY, title)
{
nsresult rv;
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!"));

webBrowser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
if (NS_FAILED(rv))
{
printf("do_CreateInstance webBrowser\n");
}

nsCOMPtr<nsIDocShellTreeItem> dsti =
do_QueryInterface( webBrowser );
dsti->SetItemType( nsIDocShellTreeItem::typeContentWrapper );

baseWindow = do_QueryInterface(webBrowser);
printf("Just before InitWindow\n");
rv = baseWindow->InitWindow(m_wxwindow, 0, 0, 0, 300, 400);
if (NS_FAILED(rv))
{
printf("InitWindow\n");
}
printf("Just after 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://
developer.mozilla.org").get(),
nsIWebNavigation::LOAD_FLAGS_NONE,
0, 0, 0);

if (NS_FAILED(rv))
{
printf("LoadURI\n");
}
printf("MyFrame::MyFrame\n");

}

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);
}

void MyFrame::OnSize ( wxSizeEvent &pEvent )
{
printf("OnSize ... \n");
wxRect newRect = this->GetClientRect();
baseWindow->SetPositionAndSize( newRect.GetLeft(),
newRect.GetTop(),
newRect.GetWidth(),
newRect.GetHeight(),
PR_FALSE );
}

Make :
g++ `wx-config --cppflags` -fshort-wchar -c -g $(INCLUDE) wxgecko.cpp
-DXPCOM_GLUE
g++ -o wxgecko `wx-config --cppflags` `wx-config --libs` wxgecko.o -L$
(SDK)/lib/ -lxpcomglue

mlutken

unread,
Sep 4, 2008, 4:42:27 AM9/4/08
to
I did not have any trouble getting javascript to work.
You can perhaps look into this, which I got to work.

http://www.doxys.org/download/minimal.zip

-Martin Lütken

cyril giraudon

unread,
Sep 4, 2008, 6:20:56 AM9/4/08
to


Thanks a lot Martin,

I try to compile minimal with the following commands :
> ls
> unzip minimal.zip
> ls
minimal minimal.zip
> mkdir build
> cd build
> cmake -version
cmake version 2.4-patch 3
> cmake ../minimal -DCBS_BUILD=1

I obtain the error :
"""
-- Check for working C compiler: gcc
-- Check for working C compiler: gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: c++
-- Check for working CXX compiler: c++ -- works
CMake Error: Error in cmake code at
/home/cyril/affaires/kbee/minimal/minimal/CMakeLists.txt:9:
INCLUDE Could not find include file: /cbs_common_rules.cbs
Current CMake stack: /home/cyril/affaires/kbee/minimal/minimal/
CMakeLists.txt;/usr/share/CMake/Modules/CMakeCInformation.cmake;/usr/
share/CMake/Modules/CMakeCXXInformation.cmake;/cbs_common_rules.cbs
CMake Error: Error in cmake code at
/home/cyril/affaires/kbee/minimal/minimal/CMakeLists.txt:10:
Unknown CMake command "BUILD_EXECUTABLE".
-- Configuring done
"""

Can Minimal be compiled or is it an example to be read ?
What is the cmake version you use, BULD_EXECUTABLE is recognized with
2.4-patch 3 ?

I use a mandriva 2007 linux box.

Thanks,

Cyril.

cyril giraudon

unread,
Sep 4, 2008, 5:53:22 PM9/4/08
to
I've finally succeeded in compiling minimal by writing a new simple
makefile.
Minimal works fine, three little issues :
- gecko dimensions are initially very little and gecko is localized
in the left upper corner (it is ok after the first OnSize event);
- When I exit the application, there's a segmentation fault.
- When the about window is shown, gecko disappears in the left right
corner.

I will look at that.

Thanks again.

Cyril.

0 new messages