I am using wxWebView for showing our page content and when I don't have any content for the page, i.e. page is blank, I see the following error:
I have my own file system handler class derived from wxWebViewHandler
like below and in GetFile
function, I set the content of page. Everything works fine except when page does not have any content. Maybe I should return something else.
struct WxHtmlFSHandler: public wxWebViewHandler
{
WxHtml* dst_;
WxHtmlFSHandler( const wxString& scheme, WxHtml* dst ): wxWebViewHandler( scheme ), dst_( dst )
{ }
wxFSFile* GetFile( const wxString& uri ) override;
~WxHtmlFSHandler()
{
dst_ = nullptr;
}
};
...
if( dst_ && !uri.empty() )
{
if( uri.Contains( dst_->defaultURL_ ) )
{
// load the page's content
//if( !dst_->currentPage_.empty() )
return new wxFSFile( new wxMemoryInputStream( dst_->currentPage_.data(), dst_->currentPage_.size() ),
uri, wxT( "text/html" ), dst_->currentAnchor_
#if wxUSE_DATETIME
, wxDateTime::Now()
#endif
);
...
}
I am also using IE engine for now.
#if wxUSE_WEBVIEW_IE
wxWebViewIE::MSWSetEmulationLevel( wxWEBVIEWIE_EMU_IE11 );
#endif
I am using wxWidgets 3.1.5 on Win 10.
CodePudding user response:
So the problem is when the page content is empty. So I just tried to add a space char to my memory input stream like below and see the effect. It seems working!
Basically I replaced
return new wxFSFile( new wxMemoryInputStream( "", 0 ),
uri, wxT( "text/html" ), dst_->currentAnchor_
#if wxUSE_DATETIME
, wxDateTime::Now()
#endif
);
with
return new wxFSFile( new wxMemoryInputStream( " ", 1 ),
uri, wxT( "text/html" ), dst_->currentAnchor_
#if wxUSE_DATETIME
, wxDateTime::Now()
#endif
);
and now page is blank and does not show anything as expected. I don't know whether this hack is good or even correct, so if anyone has a better answer, please let me know.