diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-12-16 17:02:46 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-12-16 19:50:21 +0100 |
commit | e0f20211a8048a87b078aa4cf0f28c0c847487ad (patch) | |
tree | 64a80f7cee0dad62f55aec3a6b8cc8000eaf8dd9 /sw/source/filter/html | |
parent | b6f4d3b92789e972d9b079a5561723f3e73e07a6 (diff) |
sw reqif-xhtml import: add a new AllowedRTFOLEMimeTypes parameter
The HTML import is an old-style filter, so it has no XFilter
implementation where filter() would get custom parameters out of the
box. One way would be to fix by adding one more entry to the aFormalArgs
table under sfx2/, but doing that with a random parameter of a random
import filter feels dirty.
So instead make SfxMedium store all arguments as-is, this way accessing
other keys is as easy to accessing the already available FilterOptions
(string) key.
Regarding the actual filter change, don't require "text/rtf" as a mime
type for embedded objects in the reqif XHTML import, so that in case the
file has e.g. application/rtf, then that works as well.
In case an (UNO) client wants to still limit the accepted set of MIME
types, that's possible via the new parameter.
Change-Id: Ia60da44d692f550d8ad5bbf374171cac67d9e04f
Reviewed-on: https://gerrit.libreoffice.org/85229
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'sw/source/filter/html')
-rw-r--r-- | sw/source/filter/html/htmlplug.cxx | 6 | ||||
-rw-r--r-- | sw/source/filter/html/swhtml.cxx | 19 | ||||
-rw-r--r-- | sw/source/filter/html/swhtml.hxx | 3 |
3 files changed, 27 insertions, 1 deletions
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx index fc224925153a..4d5d58d23ade 100644 --- a/sw/source/filter/html/htmlplug.cxx +++ b/sw/source/filter/html/htmlplug.cxx @@ -554,7 +554,11 @@ bool SwHTMLParser::InsertEmbed() StreamMode::READ); uno::Reference<io::XInputStream> xInStream; SvMemoryStream aMemoryStream; - if (aType == "text/rtf") + + // Allow any MIME type that starts with magic, unless a set of allowed types are + // specified. + auto it = m_aAllowedRTFOLEMimeTypes.find(aType); + if (m_aAllowedRTFOLEMimeTypes.empty() || it != m_aAllowedRTFOLEMimeTypes.end()) { OString aMagic("{\\object"); OString aHeader(read_uInt8s_ToOString(aFileStream, aMagic.getLength())); diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index b2e0f520b961..2ed9ed17625f 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -118,6 +118,8 @@ #include <sfx2/viewfrm.hxx> #include <svx/svdobj.hxx> #include <officecfg/Office/Writer.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <comphelper/sequence.hxx> #include <swerror.h> #include <hints.hxx> @@ -433,6 +435,23 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn, if (rNamespace == "reqif-xhtml") m_bReqIF = true; } + + // Extract load parameters which are specific to this filter. + if (!pMed) + { + return; + } + + comphelper::SequenceAsHashMap aLoadMap(pMed->GetArgs()); + auto it = aLoadMap.find("AllowedRTFOLEMimeTypes"); + if (it == aLoadMap.end()) + { + return; + } + + uno::Sequence<OUString> aTypes; + it->second >>= aTypes; + m_aAllowedRTFOLEMimeTypes = comphelper::sequenceToContainer<std::set<OUString>>(aTypes); } SwHTMLParser::~SwHTMLParser() diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index dc31880f3ec0..d4f9876e3ab6 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -35,6 +35,7 @@ #include <vector> #include <deque> #include <stack> +#include <set> class SfxMedium; class SfxViewFrame; @@ -470,6 +471,8 @@ class SwHTMLParser : public SfxHTMLParser, public SvtListener */ std::stack<SwOLENode*> m_aEmbeds; + std::set<OUString> m_aAllowedRTFOLEMimeTypes; + void DeleteFormImpl(); void DocumentDetected(); |