Kirix Support Forums

set/get source

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

set/get source

Postby johnadoe on Mon Sep 28, 2009 3:40 pm

Hi

I have just started to play with webconnect and so far i haven't found any way to get/set html document content, except using temporary files like in testapp's OnGoAbout().

It would be nice to have functions like:
SetContent(const wxString& str);
wxString GetContent();

Do you have any plans to implement anything like that in webconnect api ?

Regards
John
johnadoe
Registered User
 
Posts: 1
Joined: Mon Sep 28, 2009 3:24 pm

Re: set/get source

Postby Ben on Mon Sep 28, 2009 4:31 pm

Hi there,

Because of a browsers forward/backward buttons, as well as history, we've had the most success by writing out a temporary .html file locally and then navigating to it.

One other thing we use in our software package is mozilla's built-in zip/jar support. For instance, we put our entire about graphic and html inside a single zip file.

Best,
Ben
Ben Williams
Kirix Support Team
User avatar
Ben
Kirix Support Team
 
Posts: 525
Joined: Mon Dec 19, 2005 6:29 am

Re: set/get source

Postby EzPresso on Sun Oct 25, 2009 5:37 pm

We have implemented this functionality using some of the code from wxMozilla:
Code: Select all
bool wxWebControl::SetPage(const wxString &data)
{
    // create stream to put string in
    nsresult rv;
    nsCOMPtr<nsIStringInputStream> inputStream( do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv) );
    if (NS_FAILED(rv)) return false;

    // convert our string to stream
    inputStream->SetData( data.mb_str(wxConvUTF8), data.length() );

    // get document shell
    nsCOMPtr<nsIDocShell> docShell( do_GetInterface(m_ptrs->m_web_browser) );
    NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);

    // finally, load the stream we made!
    rv = docShell->LoadStream( inputStream, NULL /*URI*/,
                               NS_LITERAL_CSTRING("text/html"),
#if wxUSE_UNICODE
                               NS_LITERAL_CSTRING("UTF-8"),
#else
                               nsCAutoString( wxLocale::GetSystemEncodingName() ),
#endif
                               NULL /*loadInfo*/ );
    if (NS_FAILED(rv)) return false;
    return true;
}

wxString wxWebControl::GetPage( const wxString &mimeType )
{
    // get dom document from web nav
    nsCOMPtr<nsIDOMDocument> domDocument;
    nsresult rv = m_ptrs->m_web_navigation->GetDocument( getter_AddRefs(domDocument) );
    if (NS_FAILED(rv)) return wxEmptyString;
    if (!domDocument) return wxEmptyString;

    // create document encoder to turn document into string
    wxString instanceName = wxT("@mozilla.org/layout/documentEncoder;1?type=") + mimeType;
    ns_smartptr<nsIDocumentEncoder> docEncoder = nsCreateInstance( instanceName.ToAscii() );

    nsString nstype; wx2ns( mimeType, nstype );
    docEncoder->Init( domDocument, nstype, 0 );

    nsString docStr;
    docEncoder->EncodeToString( docStr );
    return ns2wx(docStr);
}

Hope this helps!
Ilya
EzPresso
Registered User
 
Posts: 5
Joined: Fri Oct 16, 2009 5:32 am

Return to wxWebConnect Questions, Thoughts & Feedback