Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
PIM Messagelib
Commits
5b950391
Commit
5b950391
authored
May 29, 2020
by
Laurent Montel
Browse files
Continue to fix loading image from cid scheme
parent
249c0301
Changes
1
Hide whitespace changes
Inline
Side-by-side
messageviewer/src/viewer/webengine/cidreferencesurlinterceptor/cidreferencesurlinterceptor.cpp
View file @
5b950391
...
...
@@ -20,10 +20,14 @@
#include
"cidreferencesurlinterceptor.h"
#include
"htmlwriter/webengineembedpart.h"
#include
<QBuffer>
#include
<QUrl>
#include
<QImage>
#include
<QDebug>
#include
<QWebEngineUrlRequestInfo>
using
namespace
MessageViewer
;
#define LOAD_FROM_FILE 1
CidReferencesUrlInterceptor
::
CidReferencesUrlInterceptor
(
QObject
*
parent
)
:
WebEngineViewer
::
NetworkPluginUrlInterceptorInterface
(
parent
)
{
...
...
@@ -38,10 +42,21 @@ bool CidReferencesUrlInterceptor::interceptRequest(QWebEngineUrlRequestInfo &inf
const
QUrl
urlRequestUrl
(
info
.
requestUrl
());
if
(
urlRequestUrl
.
scheme
()
==
QLatin1String
(
"cid"
))
{
if
(
info
.
resourceType
()
==
QWebEngineUrlRequestInfo
::
ResourceTypeImage
)
{
const
Q
String
newUrl
=
MessageViewer
::
WebEngineEmbedPart
::
self
()
->
contentUrl
(
urlRequestUrl
.
path
());
const
Q
Url
newUrl
=
QUrl
(
MessageViewer
::
WebEngineEmbedPart
::
self
()
->
contentUrl
(
urlRequestUrl
.
path
())
)
;
if
(
!
newUrl
.
isEmpty
())
{
info
.
redirect
(
QUrl
(
newUrl
));
#ifdef LOAD_FROM_FILE
QImage
image
(
newUrl
.
path
());
QByteArray
ba
;
QBuffer
buf
(
&
ba
);
image
.
save
(
&
buf
,
"png"
);
const
QByteArray
hexed
=
ba
.
toBase64
();
buf
.
close
();
const
QUrl
r
=
QUrl
(
QString
::
fromUtf8
(
QByteArray
(
"data:image/png;base64,"
)
+
hexed
));
info
.
redirect
(
r
);
#else
info
.
redirect
(
newUrl
);
#endif
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment