Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using QTWebKit to display a website stored in memory

Currently I have my HTML, JS, CSS, graphics, etc stored locally on hard disk and access them using QWebFrame::SetUrl( QUrl::fromLocalFile( "appFolder\html\index.html" )). At some point I am going to need to encrypt the locally stored files so I'm looking for a way to either decrypt them as they're requested or to decrypt them all into memory and access them that way.

I know I can use QWebFrame::setContent( htmlData ) to load the HTML from memory so I can load the encrypted HTML file, decrypt it in memory and then display it that way, but how would I go about the other data (JS, CSS, graphics, etc) which is currently stored in subfolders?

Alternatively, is there a way I can intercept requests for access to all the HTML, JS, CSS, etc files and decrypt them as they're loaded?

By using my own NetworkAccessManager I can intercept calls to createRequest so I can see when each file is being loaded, but I can't see how to use this to decrypt the data on the fly. I can also connect a slot function to the finished(QNetworkReply*) signal, but at that point the data has already been read - the QIODevice's current position is pointing to the end of the file.

I'd be very grateful for any advice or pointers in the right direction.

like image 721
Rok Avatar asked Nov 04 '22 19:11

Rok


1 Answers

I think in your case the best solution is to inherit QNetworkReply class and use this new class in reimplemented QNetworkAccessManager::createRequest() function.

In general, you should reimplement next virtual functions of QNetworkReply: bytesAvailable(), readData(char *data, qint64 maxSize), close(), abort().

For example, readData should be the folowing:

qint64 NetworkReplyEx::readData(char *data, qint64 maxSize)
{
    return m_buffer.read(data, maxSize);
}

where m_buffer is already decrypted data.

Also you need to add all necessary logic in this class to get encrypted data, decrypt this data... In the end you should manually emit finished() signal inside new class, so QWebView or other related class will get decrypted html.

like image 174
Johnny Avatar answered Nov 12 '22 20:11

Johnny