HTMLView integration

BlitzMax Forums/MaxGUI Module/HTMLView integration

Blueapples(Posted 2007) [#1]
I know there is a way to call javascript code from a BlitzMax application wrapping a HTMLView... haven't tried it but it boils down to NSRun() on Mac OS and I think bbHtmlViewRun() on Windows (I'm not quite sure how the Windows side is compiled... it mentions BlitzPlus, which seems odd... is it based on BP codebase?)

Anyway, I would like to be able to make a call the opposite direction: call a BlitzMax function from within a javascript function inside the page I am rendering. Any way to do this?


Blueapples(Posted 2007) [#2]
Looking into it a bit more, on the windows side, POST data is available in the BeforeNavigate2 function in win32htmlview.cpp line 902. Only the URL is being sent along to the BBEVENT_GADGETACTION event... would it be possible to also send the POST data?

The header might end up looking like this:

void DWebBrowserEventsImpl::BeforeNavigate2(IDispatch*, VARIANT*URL, VARIANT*,
VARIANT*TARGET, VARIANT*POST, VARIANT*, VARIANT_BOOL*Cancel)


I'm not sure how rep->owner->emit behaves, but if there were a way to send additional bit of data along with the event, that would be great...


Blueapples(Posted 2007) [#3]
Okay, and decidePolicyForNavigationAction in cocoa.macos.m handles the same thing for Mac OS X... and NSURLRequest has a property HTTPBody. So it can be done... just a matter of knowing how to do it. May I humbly ask that someone with more experience in these matters look at this? I have to go to bed... it's 12:30 AM here.


Blueapples(Posted 2007) [#4]
Well, what little time I have to work on this so far has yeilded this new version of decidePolicyForNaviationAction:



This will intercept any navigation event, including form submittal.

I'm worried about two things:

1. I should really use some kind of structure to send in the URL and HTTPBody as separate strings.
2. In all those calls to bbStringConcat, am I generating a memory leak? It looks like they boil down to bbGCAlloc(), so I assume the memory will eventually be cleaned up and it'll be okay. That said, should I do my own clean up here?

Is there any kind of API reference for this level of the BMax / BB runtime? I would really be interested in seeing that kind of documentation...


Dreamora(Posted 2007) [#5]
No there is no reference nor documentation for this level of source


SebHoll(Posted 2007) [#6]
Is there a reason why you aren't using HTMLViewRun() or am I missing something?


Blueapples(Posted 2007) [#7]
Uh, well, this spontaneously sends data out of the HTMLView. HTMLViewRun() can only send data "in" by executing scripts in the page. I assume the script's return value is sent back, but it's still not the same thing.

This will allow me to catch PUT operations, for instance, and redirect them to a database file.


skidracer(Posted 2007) [#8]
the nonavigate flag should enable you to intercept the post events, the following is an example intercepting the query the user submits to google.com

Strict 

Local window:TGadget
Local htmlview:TGadget

window=CreateWindow("My Window",30,20,600,440,,15|WINDOW_ACCEPTFILES)

htmlview=CreateHTMLView(0,0,ClientWidth(window),ClientHeight(window),window,HTMLVIEW_NONAVIGATE)
SetGadgetLayout htmlview,1,1,1,1 

HtmlViewGo htmlview,"www.google.com"

While WaitEvent()
	Print CurrentEvent.ToString()
	Select EventID()
		Case EVENT_GADGETACTION
			Notify ""+EventID()+String(EventExtra())
		Case EVENT_WINDOWCLOSE
			End
	End Select
Wend



Blueapples(Posted 2007) [#9]
skid, did you look at my code at all?

I guess I have left out a few details, I hadn't mentioned NONAVIGATE.

Anyway, the code above extends the NONAVIGATE flag so that it catches all types of navigation, including form submits, and parses the HTTPBody, returning it as part of the EventText() (in the form URL + ~n + HTTPBody). It's a hack but without any idea how to do a better job it'll have to work.

<edit>This is useful so that I can catch complex form submits, PUT operations, etc. that are sent to a server through the HTTPBody and redirect them to a local DB file instead of going out to the network.</edit>

How can I create a BMax object at the C source level and return it as the EventExtra() data? I'd rather have URL and HTTPBody as separate fields of an object.