Kirix Support Forums

Set the active page from memory?

Please post all general questions, comments, bug reports, and any other wxWebConnect feedback here.

Set the active page from memory?

Postby MrD on Sat Jan 15, 2011 10:14 pm

Hi,

I was wondering if it was possible to set the active page content directly from a memory buffer. The project that we're using wxWebConnect for is mainly using it to provide a skinnable UI using HTML and CSS, so it doesn't really matter that what we'd be showing wasn't actually a file.

At the minute I'm having to save the memory buffer out to a temporary file on disk and then set the URI to that temporary file, which is a bit naff.

I was also wondering how feasible it is to poke whole blocks of HTML into the DOM of a page. Once our initial page is set-up we'd just like to be able to add content to it by adding it directly to the DOM, however the interface for adding DOM elements seems to only let you add elements of a certain type, and not just give it a blob of HTML to append as a child of another element.

Thanks.
MrD
Registered User
 
Posts: 20
Joined: Mon Jan 10, 2011 6:26 pm

Re: Set the active page from memory?

Postby jonmmorgan on Sun Jan 16, 2011 5:38 am

Have a look at viewtopic.php?f=25&t=817. The topic is discussed there, and a few solutions presented.
jonmmorgan
Registered User
 
Posts: 94
Joined: Fri May 14, 2010 9:48 am

Re: Set the active page from memory?

Postby MrD on Sun Jan 16, 2011 10:48 am

Thanks, I'd missed that when searching. I'll take a look.

With regard to the DOM, I've tried the following but that just shows the literal text of what I entered. I tried viewing the source of the page once I'd messed with the DOM, but the page source didn't show the modified DOM which is annoying as it makes debugging a pain. Is there any way to view the source of the actual page once you've been messing around with the DOM?

This is the code that gets run on the DOM content loaded callback (hacky I know, but I'm just testing it at the minute):
Code: Select all
wxDOMDocument domDocument = m_pWebControl->GetDOMDocument();
wxDOMNode bodyTag = domDocument.GetElementsByTagName(wxT("body")).Item(0);
wxDOMText textNode = domDocument.CreateTextNode(wxT("<div style=\"background-color: #ffffff;\">Hello World!</div>"));
bodyTag.AppendChild(textNode);


My aim is to inject some HTML directly as a child of another DOM node.
MrD
Registered User
 
Posts: 20
Joined: Mon Jan 10, 2011 6:26 pm

Re: Set the active page from memory?

Postby jonmmorgan on Mon Jan 17, 2011 6:13 am

wxWebConnect is exposing a fairly standard DOM API. A text node is just a text node, and so will be interpreted as plain text. I'm not aware of any way to parse arbitrary HTML and put it into the DOM. I tend to find the DOM API in wxWebConnect so hard to use that I quickly drop into executing Javascript instead. You could probably do something like what you want using Javascript and innerHTML, though I think it would get messy ensuring that you had escaped the string correctly.
jonmmorgan
Registered User
 
Posts: 94
Joined: Fri May 14, 2010 9:48 am

Re: Set the active page from memory?

Postby MrD on Mon Jan 17, 2011 5:06 pm

Thanks for the tip.

I've given it a go but have found that the Execute function isn't working correctly with the version of XulRunner I am using (1.9.2.13). I found this thread which stated the GUIDs had changed, so I updated the GUIDs with the versions used in my version of the XulRunner SDK and tried to re-generate nsall.h with this new data, however the generated code was significantly different from the original code (it was using different C macros and all sorts).

I used the command at the top of nsall.idl to generate the file:
Code: Select all
xpidl -m header nsall.idl


Since it seems you've gotten this working correctly on your branch, what was the method you used to re-generate nsall.h when you'd changed it?

On a side note, why is it that it seems everyone who uses wxWebConnect ultimately has to have their own branch of it containing all the changes they need to make it work properly?
MrD
Registered User
 
Posts: 20
Joined: Mon Jan 10, 2011 6:26 pm

Re: Set the active page from memory?

Postby jonmmorgan on Tue Jan 18, 2011 5:37 am

This is one of the other quirks that I forget: because wxWebConnect was originally designed to work with XULRunner 1.8.x, it uses the header style of XR 1.8.x. As it turns out, this XR 1.8 generated header file will actually work with XR 1.9.2 (which is how it can support XR 1.9.2) but you need to use the xpidl from 1.8.x. This annoys me, but the one time I tried to fix it I failed and I've never looked at it since. There is more detail at https://github.com/jonmmorgan/wxwebconn ... es/issue/4, including a download link to a Windows version of 1.8.x xpidl which works.

As to your question about why everyone needs to have a branch, I think it's for two main reasons:
1. Known bugs in the latest released version (e.g. Javascript execution, compilation problems on Mac and Linux). Until there is a new release, people relying on this functionality will need to use a patched version.

2. People adding missing functionality. Many people have been doing it, not as many have reported back their changes (whether the absence of a public repository contributes to this I don't know, but I would guess it does). My Github repository tries to take this further by making my changes publicly accessible and traceable, and also easier for me to work with. However, I too have not been very good at trying to push these changes back to WebConnect (because it also makes it easier for me to just work off Github and ignore the latest WebConnect release). I have had on my to do list for a month or more looking through all the changes to WebConnect I have made (probably at least a dozen?) and trying to submit them back to the main project for review. Some are a little speculative and may not be accepted, but I use them all in my app and I think the majority of them would benefit the project as a whole. At the same time, for all I know, work on wxWebConnect by Kirix that I cannot see could be invalidating my work.

Ultimately, I think it's hard to form a community without a degree of transparency and awareness of what's going on. Without this, it's much easier working on your own private copy with measurable effect than trying to change something you can't see.
jonmmorgan
Registered User
 
Posts: 94
Joined: Fri May 14, 2010 9:48 am

Re: Set the active page from memory?

Postby MrD on Tue Jan 18, 2011 4:08 pm

Thanks. I've managed to update the GUIDs and it's able to get the security manager and principal, but it fails now trying to get the script global object (returns NULL).

Code: Select all
ns_smartptr<nsIScriptGlobalObject> sgo = nsRequestInterface(m_ptrs->m_web_browser);


Any ideas? (Sorry to be a pain, but I'm not familiar at all with XulRunner, and this isn't helped due to the fact that it is being used as a black-box so I can't even see how it's really failing internally).
MrD
Registered User
 
Posts: 20
Joined: Mon Jan 10, 2011 6:26 pm

Re: Set the active page from memory?

Postby jonmmorgan on Wed Jan 19, 2011 8:44 am

I feel your pain: it took me a long time to figure out the various things that are wrong and fix them (and now I don't even necessarily remember what I did). However, I think what I did was to replace each of the classes in that top part of webcontrol.cpp with the new version of that class from the 1.9.2 XULRunner SDK. These classes do not have IDL specifications, but they do have header files (for example, nsIScriptGlobalObject is defined in include/nsIScriptGlobalObject.h). There might be other classes that need replacing in the same way. Unfortunately, I really can't remember exactly. The commit in which I made the change is at https://github.com/jonmmorgan/wxwebconn ... 51bdc8e4bc, which might provide you with helpful information (though that change was before wxWebConnect 1.1, and so might not be identical to the changes you would make with wxWebConnect 1.1). It's worth noting the part of the commit message that says "Note that this commit requires you to include the XULRunner SDK in your includes.", which I think ended up something to do with the Javascript implementation.

As always, you are welcome to use my private repository, which is being used in the real world. However, I do understand reluctance to rely on such a seemingly random collection of changes.
jonmmorgan
Registered User
 
Posts: 94
Joined: Fri May 14, 2010 9:48 am

Re: Set the active page from memory?

Postby MrD on Wed Jan 19, 2011 2:11 pm

Thank you, thank you, thank you :D

I've now managed to get Execute working with XulRunner 1.9.x.

For anyone interested, the change can be found here.
MrD
Registered User
 
Posts: 20
Joined: Mon Jan 10, 2011 6:26 pm

Re: Set the active page from memory?

Postby jonmmorgan on Thu Jan 20, 2011 4:06 am

Glad you got it working. I know it's not fun.
jonmmorgan
Registered User
 
Posts: 94
Joined: Fri May 14, 2010 9:48 am

Return to wxWebConnect Questions, Thoughts & Feedback