HTMLViewer in Homebrew

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

HTMLViewer in Homebrew

Post by Ooblik »

I cannot for the life of me figure out how to load the internet browser in my program. I have gone over the htmlviewer sample in the SDK samples and i tried a few different ways to add it to my code but then i try to load the browser it just crashes. My code compiles fine so i have no idea what i did wrong.

If anyone has figured this out already help would be much appreciated :)

My Code:

browser.c

Code: Select all

#include <pspsdk.h>
#include <pspuser.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspgu.h>
#include <psputility.h>
#include <psputility_netmodules.h>
#include <psputility_htmlviewer.h>
#include <pspnet.h>
#include <pspnet_inet.h>
#include <pspnet_apctl.h>
#include <pspnet_resolver.h>
#include <psphttp.h>
#include <pspssl.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <sys/unistd.h>

#include "graphics.h"

void throwError&#40;int milisecs, char *fmt, ...&#41;
&#123;
	va_list list;
	char msg&#91;256&#93;;	

	va_start&#40;list, fmt&#41;;
	vsprintf&#40;msg, fmt, list&#41;;
	va_end&#40;list&#41;;

	pspDebugScreenClear&#40;&#41;;
	pspDebugScreenPrintf&#40;msg&#41;;

	sceKernelDelayThread&#40;milisecs * 1000&#41;;
	sceKernelExitGame&#40;&#41;;
&#125;

void loadNetModules&#40;&#41;
&#123;
	sceUtilityLoadNetModule&#40;PSP_NET_MODULE_COMMON&#41;;
	sceUtilityLoadNetModule&#40;PSP_NET_MODULE_INET&#41;;
	sceUtilityLoadNetModule&#40;PSP_NET_MODULE_PARSEURI&#41;;
	sceUtilityLoadNetModule&#40;PSP_NET_MODULE_PARSEHTTP&#41;;
	sceUtilityLoadNetModule&#40;PSP_NET_MODULE_HTTP&#41;;
	sceUtilityLoadNetModule&#40;PSP_NET_MODULE_SSL&#41;;
&#125;

void unloadNetModules&#40;&#41;
&#123;
	sceUtilityUnloadNetModule&#40;PSP_NET_MODULE_SSL&#41;;
	sceUtilityUnloadNetModule&#40;PSP_NET_MODULE_HTTP&#41;;
	sceUtilityUnloadNetModule&#40;PSP_NET_MODULE_PARSEHTTP&#41;;
	sceUtilityUnloadNetModule&#40;PSP_NET_MODULE_PARSEURI&#41;;
	sceUtilityUnloadNetModule&#40;PSP_NET_MODULE_INET&#41;;
	sceUtilityUnloadNetModule&#40;PSP_NET_MODULE_COMMON&#41;;
&#125;

void netTerm&#40;&#41;
&#123;
	sceHttpSaveSystemCookie&#40;&#41;;
	sceHttpsEnd&#40;&#41;;
	sceHttpEnd&#40;&#41;;
	sceSslEnd&#40;&#41;;
	sceNetApctlTerm&#40;&#41;;
	sceNetInetTerm&#40;&#41;;
	sceNetTerm&#40;&#41;;
	
	unloadNetModules&#40;&#41;;	
&#125;

void netInit&#40;&#41;
&#123;
	int res;

	loadNetModules&#40;&#41;;

	res = sceNetInit&#40;0x20000, 0x2A, 0, 0x2A, 0&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		throwError&#40;6000, "Error 0x%08X in sceNetInit\n", res&#41;;		
	&#125;

	res = sceNetInetInit&#40;&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceNetInetInit\n", res&#41;;				
	&#125;

	res = sceNetResolverInit&#40;&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceNetResolverInit\n", res&#41;;		
	&#125;

	res = sceNetApctlInit&#40;0x1800, 0x30&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceNetApctlInit\n", res&#41;;		
	&#125;

	res = sceSslInit&#40;0x28000&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceSslInit\n", res&#41;;
	&#125;

	res = sceHttpInit&#40;0x25800&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceHttpInit\n", res&#41;;
	&#125;

	res = sceHttpsInit&#40;0, 0, 0, 0&#41;;
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceHttpsInit\n", res&#41;;
	&#125;

	res = sceHttpsLoadDefaultCert&#40;0, 0&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceHttpsLoadDefaultCert\n", res&#41;;
	&#125;

	res = sceHttpLoadSystemCookie&#40;&#41;;
	
	if &#40;res < 0&#41; 
	&#123;
		netTerm&#40;&#41;;
		throwError&#40;6000, "Error 0x%08X in sceHttpsLoadDefaultCert\n", res&#41;;
	&#125;	
&#125;

#define BROWSER_MEMORY &#40;10*1024*1024&#41; 

SceUID vpl;
pspUtilityHtmlViewerParam params;

void htmlViewerInit&#40;char *url&#41;
&#123;
	int res;
	
	vpl = sceKernelCreateVpl&#40;"BrowserVpl", PSP_MEMORY_PARTITION_USER, 0, BROWSER_MEMORY + 256, NULL&#41;;
	
	if &#40;vpl < 0&#41; 
		throwError&#40;6000, "Error 0x%08X creating vpl.\n", vpl&#41;;

	memset&#40;&params, 0, sizeof&#40;pspUtilityHtmlViewerParam&#41;&#41;;
	
	params.base.size = sizeof&#40;pspUtilityHtmlViewerParam&#41;;
	
	sceUtilityGetSystemParamInt&#40;PSP_SYSTEMPARAM_ID_INT_LANGUAGE, &params.base.language&#41;;
	sceUtilityGetSystemParamInt&#40;PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &params.base.buttonSwap&#41;;
	
	params.base.graphicsThread = 17;
	params.base.accessThread = 19;
	params.base.fontThread = 18;
	params.base.soundThread = 16;	
	params.memsize = BROWSER_MEMORY;
	params.initialurl = url;
	params.numtabs = 1;
	params.cookiemode = PSP_UTILITY_HTMLVIEWER_COOKIEMODE_DEFAULT;
	params.homeurl = url;
	params.textsize = PSP_UTILITY_HTMLVIEWER_TEXTSIZE_NORMAL;
	params.displaymode = PSP_UTILITY_HTMLVIEWER_DISPLAYMODE_SMART_FIT;
	params.options = PSP_UTILITY_HTMLVIEWER_DISABLE_STARTUP_LIMITS|PSP_UTILITY_HTMLVIEWER_ENABLE_FLASH;
	params.interfacemode = PSP_UTILITY_HTMLVIEWER_INTERFACEMODE_FULL;
	params.connectmode = PSP_UTILITY_HTMLVIEWER_CONNECTMODE_MANUAL_ALL;
	
	// Note the lack of 'ms0&#58;' on the paths	
	params.dldirname = "/PSP/PHOTO";
	
	res = sceKernelAllocateVpl&#40;vpl, params.memsize, &params.memaddr, NULL&#41;;
	
	if &#40;res < 0&#41; 
		throwError&#40;6000, "Error 0x%08X allocating browser memory.\n", res&#41;;

	res = sceUtilityHtmlViewerInitStart&#40;&params&#41;;
	
	if &#40;res < 0&#41;
		throwError&#40;6000, "Error 0x%08X initing browser.\n", res&#41;;
&#125;

int updateHtmlViewer&#40;&#41;
&#123;
	guStart&#40;&#41;;

	switch &#40;sceUtilityHtmlViewerGetStatus&#40;&#41;&#41;
	&#123;	
		case PSP_UTILITY_DIALOG_VISIBLE&#58;			
			sceUtilityHtmlViewerUpdate&#40;1&#41;;
		break;
	
		case PSP_UTILITY_DIALOG_QUIT&#58;		
			sceUtilityHtmlViewerShutdownStart&#40;&#41;;		
		break;
	
		case PSP_UTILITY_DIALOG_NONE&#58;
			return 0;
		break;
		
		default&#58;
			break;
	&#125;

	return 1;
&#125;

void launchBrowser&#40;void&#41;
&#123;
	char url&#91;&#93; = "http&#58;//www.ps2dev.org/";

	netInit&#40;&#41;;
	htmlViewerInit&#40;url&#41;;	

	while&#40;updateHtmlViewer&#40;&#41;&#41;
	&#123;
		sceDisplayWaitVblankStart&#40;&#41;;
		flipScreen&#40;&#41;;
	&#125;

	netTerm&#40;&#41;;
	sceKernelFreeVpl&#40;vpl, params.memaddr&#41;;
	sceKernelDeleteVpl&#40;vpl&#41;;
&#125;
browser.h

Code: Select all

#ifndef __BROWSER__
#define __BROWSER_H__

extern void launchBrowser&#40;void&#41;;

#endif 
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Hi Ooblik, welcome to the forums.

What heap size are you giving your program?
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

PSP_HEAP_SIZE_MAX();

I also tested it on a Slim with PSP_LARGE_MEMORY = 1 in the Makefile to see if that would make any difference. Still just crashes...
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Probably BECAUSE of max... try not allocating all the memory to the heap.
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

Still crashes when I set it lower.. hmm.. I think it might be something graphics related..
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

You have the browser set to allocate 10 MB of memory... did you leave at least that much free? Lowering the memory heap from MAX to MAX-1MB won't allow the browser to allocate 10 MB. :)
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

You need the 10MB for the VPL and you need around ~6MB of space free for the cache too.

PSP_HEAP_SIZE_MAX() is no good.

You can get away with allocating about 3MB for the VPL, but you still need 6MB of space free for the cache.
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

I've already said i tried setting the heap lower. So are you saying its not possible or what? If it is what should the heap be set too?
Insert_witty_name
Posts: 376
Joined: Wed May 10, 2006 11:31 pm

Post by Insert_witty_name »

Give the VPL 4MB.

Set your heap size to 8MB.

Experiment, it's hard to say otherwise.
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

If i use

Code: Select all

PSP_HEAP_SIZE_KB&#40;-12*1024&#41;;
then the browser doesn't crash but it says:

Code: Select all

Error 0x800200D9 initing browser.
* 800200D9 = failed to allocate the memory block

I load a bunch of images and the main fonts with IntraFont before this.
DylanNIRVANA
Posts: 7
Joined: Thu Jan 03, 2008 7:52 am

Post by DylanNIRVANA »

Sorry for bump.

Ooblik the error you refer to:

0x800200D9 = failed to allocate the memory block

check over code?
Art
Posts: 642
Joined: Wed Nov 09, 2005 8:01 am

Post by Art »

Audio Mechanica uses almost all the RAM, so I used the eboot launch sample
to launch a seperate browser eboot from the program menu,
and then when the broser is done, it relaunches the original eboot into the
menu, so it looks like the web browser is built in.
If not actually, then potentially.
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

Thats what I ended up doing. The browser is really slow this way though.
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Ooblik wrote:Thats what I ended up doing. The browser is really slow this way though.
The browser is really slow ANY way you run it. :D
User avatar
Torch
Posts: 825
Joined: Wed May 28, 2008 2:50 am

Post by Torch »

You could load PSPKVM (and maybe modify it to disable its main menu, and to exit back to your eboot) and set it set to autorun Opera Mini. At least the browser would be fast.
Ooblik
Posts: 38
Joined: Thu Apr 10, 2008 1:47 pm

Post by Ooblik »

I mean that it becomes laggy, not the download speed..etc.
MysticWhiteDragon
Posts: 30
Joined: Thu Feb 16, 2006 8:46 am

Post by MysticWhiteDragon »

I'm not sure if you are willing to do this but you could always port a browser or make your own. Here are two good sources if you are willing to take this approach.

http://www.codeproject.com/KB/recipes/krhtmlviewer.aspx

http://www.dillo.org/
Post Reply