Skip to content

Commit

Permalink
Add wxFileSystemHandler for "data" scheme
Browse files Browse the repository at this point in the history
This notably allows embedding images directly in HTML.

Closes wxWidgets#24138.
  • Loading branch information
SlavaLis-Ef authored and vadz committed Dec 18, 2023
1 parent 68eaff5 commit ca40535
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ ALL_BASE_HEADERS = \
wx/lzmastream.h \
wx/localedefs.h \
wx/uilocale.h \
wx/fs_data.h \
$(BASE_PLATFORM_HDR) \
wx/fs_inet.h \
wx/protocol/file.h \
Expand Down Expand Up @@ -789,6 +790,7 @@ ALL_PORTS_BASE_HEADERS = \
wx/lzmastream.h \
wx/localedefs.h \
wx/uilocale.h \
wx/fs_data.h \
wx/unix/app.h \
wx/unix/apptbase.h \
wx/unix/apptrait.h \
Expand Down Expand Up @@ -925,6 +927,7 @@ ALL_BASE_SOURCES = \
src/common/secretstore.cpp \
src/common/lzmastream.cpp \
src/common/uilocale.cpp \
src/common/fs_data.cpp \
src/common/fdiodispatcher.cpp \
src/common/selectdispatcher.cpp \
src/unix/appunix.cpp \
Expand Down Expand Up @@ -1130,6 +1133,7 @@ MONODLL_OBJECTS = \
monodll_common_secretstore.o \
monodll_lzmastream.o \
monodll_common_uilocale.o \
monodll_fs_data.o \
$(__BASE_PLATFORM_SRC_OBJECTS) \
monodll_event.o \
monodll_fs_mem.o \
Expand Down Expand Up @@ -1289,6 +1293,7 @@ MONOLIB_OBJECTS = \
monolib_common_secretstore.o \
monolib_lzmastream.o \
monolib_common_uilocale.o \
monolib_fs_data.o \
$(__BASE_PLATFORM_SRC_OBJECTS_1) \
monolib_event.o \
monolib_fs_mem.o \
Expand Down Expand Up @@ -1417,6 +1422,7 @@ BASEDLL_OBJECTS = \
basedll_common_secretstore.o \
basedll_lzmastream.o \
basedll_common_uilocale.o \
basedll_fs_data.o \
$(__BASE_PLATFORM_SRC_OBJECTS_2) \
basedll_event.o \
basedll_fs_mem.o \
Expand Down Expand Up @@ -1527,6 +1533,7 @@ BASELIB_OBJECTS = \
baselib_common_secretstore.o \
baselib_lzmastream.o \
baselib_common_uilocale.o \
baselib_fs_data.o \
$(__BASE_PLATFORM_SRC_OBJECTS_3) \
baselib_event.o \
baselib_fs_mem.o \
Expand Down Expand Up @@ -14966,6 +14973,9 @@ monodll_lzmastream.o: $(srcdir)/src/common/lzmastream.cpp $(MONODLL_ODEP)
monodll_common_uilocale.o: $(srcdir)/src/common/uilocale.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/uilocale.cpp

monodll_fs_data.o: $(srcdir)/src/common/fs_data.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/common/fs_data.cpp

monodll_unix_mimetype.o: $(srcdir)/src/unix/mimetype.cpp $(MONODLL_ODEP)
$(CXXC) -c -o $@ $(MONODLL_CXXFLAGS) $(srcdir)/src/unix/mimetype.cpp

Expand Down Expand Up @@ -19712,6 +19722,9 @@ monolib_lzmastream.o: $(srcdir)/src/common/lzmastream.cpp $(MONOLIB_ODEP)
monolib_common_uilocale.o: $(srcdir)/src/common/uilocale.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/uilocale.cpp

monolib_fs_data.o: $(srcdir)/src/common/fs_data.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/common/fs_data.cpp

monolib_unix_mimetype.o: $(srcdir)/src/unix/mimetype.cpp $(MONOLIB_ODEP)
$(CXXC) -c -o $@ $(MONOLIB_CXXFLAGS) $(srcdir)/src/unix/mimetype.cpp

Expand Down Expand Up @@ -24458,6 +24471,9 @@ basedll_lzmastream.o: $(srcdir)/src/common/lzmastream.cpp $(BASEDLL_ODEP)
basedll_common_uilocale.o: $(srcdir)/src/common/uilocale.cpp $(BASEDLL_ODEP)
$(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/uilocale.cpp

basedll_fs_data.o: $(srcdir)/src/common/fs_data.cpp $(BASEDLL_ODEP)
$(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/common/fs_data.cpp

basedll_unix_mimetype.o: $(srcdir)/src/unix/mimetype.cpp $(BASEDLL_ODEP)
$(CXXC) -c -o $@ $(BASEDLL_CXXFLAGS) $(srcdir)/src/unix/mimetype.cpp

Expand Down Expand Up @@ -24938,6 +24954,9 @@ baselib_lzmastream.o: $(srcdir)/src/common/lzmastream.cpp $(BASELIB_ODEP)
baselib_common_uilocale.o: $(srcdir)/src/common/uilocale.cpp $(BASELIB_ODEP)
$(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/uilocale.cpp

baselib_fs_data.o: $(srcdir)/src/common/fs_data.cpp $(BASELIB_ODEP)
$(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/common/fs_data.cpp

baselib_unix_mimetype.o: $(srcdir)/src/unix/mimetype.cpp $(BASELIB_ODEP)
$(CXXC) -c -o $@ $(BASELIB_CXXFLAGS) $(srcdir)/src/unix/mimetype.cpp

Expand Down
2 changes: 2 additions & 0 deletions build/bakefiles/files.bkl
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
src/common/secretstore.cpp
src/common/lzmastream.cpp
src/common/uilocale.cpp
src/common/fs_data.cpp
</set>
<set var="BASE_AND_GUI_CMN_SRC" hints="files">
src/common/event.cpp
Expand Down Expand Up @@ -755,6 +756,7 @@ IMPORTANT: please read docs/tech/tn0016.txt before modifying this file!
wx/lzmastream.h
wx/localedefs.h
wx/uilocale.h
wx/fs_data.h
</set>


Expand Down
2 changes: 2 additions & 0 deletions build/cmake/files.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ set(BASE_CMN_SRC
src/generic/fswatcherg.cpp
src/common/lzmastream.cpp
src/common/uilocale.cpp
src/common/fs_data.cpp
)

set(BASE_AND_GUI_CMN_SRC
Expand Down Expand Up @@ -669,6 +670,7 @@ set(BASE_CMN_HDR
wx/lzmastream.h
wx/localedefs.h
wx/uilocale.h
wx/fs_data.h
)

set(NET_UNIX_SRC
Expand Down
2 changes: 2 additions & 0 deletions build/files
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ BASE_CMN_SRC =
src/common/filtfind.cpp
src/common/fmapbase.cpp
src/common/fs_arc.cpp
src/common/fs_data.cpp
src/common/fs_filter.cpp
src/common/hash.cpp
src/common/hashmap.cpp
Expand Down Expand Up @@ -571,6 +572,7 @@ BASE_CMN_HDR =
wx/fontenc.h
wx/fontmap.h
wx/fs_arc.h
wx/fs_data.h
wx/fs_filter.h
wx/fs_mem.h
wx/fs_zip.h
Expand Down
16 changes: 16 additions & 0 deletions build/msw/makefile.gcc
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ MONODLL_OBJECTS = \
$(OBJS)\monodll_common_secretstore.o \
$(OBJS)\monodll_lzmastream.o \
$(OBJS)\monodll_common_uilocale.o \
$(OBJS)\monodll_fs_data.o \
$(OBJS)\monodll_basemsw.o \
$(OBJS)\monodll_crashrpt.o \
$(OBJS)\monodll_debughlp.o \
Expand Down Expand Up @@ -659,6 +660,7 @@ MONOLIB_OBJECTS = \
$(OBJS)\monolib_common_secretstore.o \
$(OBJS)\monolib_lzmastream.o \
$(OBJS)\monolib_common_uilocale.o \
$(OBJS)\monolib_fs_data.o \
$(OBJS)\monolib_basemsw.o \
$(OBJS)\monolib_crashrpt.o \
$(OBJS)\monolib_debughlp.o \
Expand Down Expand Up @@ -808,6 +810,7 @@ BASEDLL_OBJECTS = \
$(OBJS)\basedll_common_secretstore.o \
$(OBJS)\basedll_lzmastream.o \
$(OBJS)\basedll_common_uilocale.o \
$(OBJS)\basedll_fs_data.o \
$(OBJS)\basedll_basemsw.o \
$(OBJS)\basedll_crashrpt.o \
$(OBJS)\basedll_debughlp.o \
Expand Down Expand Up @@ -938,6 +941,7 @@ BASELIB_OBJECTS = \
$(OBJS)\baselib_common_secretstore.o \
$(OBJS)\baselib_lzmastream.o \
$(OBJS)\baselib_common_uilocale.o \
$(OBJS)\baselib_fs_data.o \
$(OBJS)\baselib_basemsw.o \
$(OBJS)\baselib_crashrpt.o \
$(OBJS)\baselib_debughlp.o \
Expand Down Expand Up @@ -7235,6 +7239,9 @@ $(OBJS)\monodll_lzmastream.o: ../../src/common/lzmastream.cpp
$(OBJS)\monodll_common_uilocale.o: ../../src/common/uilocale.cpp
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\monodll_fs_data.o: ../../src/common/fs_data.cpp
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\monodll_basemsw.o: ../../src/msw/basemsw.cpp
$(CXX) -c -o $@ $(MONODLL_CXXFLAGS) $(CPPDEPS) $<

Expand Down Expand Up @@ -9826,6 +9833,9 @@ $(OBJS)\monolib_lzmastream.o: ../../src/common/lzmastream.cpp
$(OBJS)\monolib_common_uilocale.o: ../../src/common/uilocale.cpp
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\monolib_fs_data.o: ../../src/common/fs_data.cpp
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\monolib_basemsw.o: ../../src/msw/basemsw.cpp
$(CXX) -c -o $@ $(MONOLIB_CXXFLAGS) $(CPPDEPS) $<

Expand Down Expand Up @@ -12417,6 +12427,9 @@ $(OBJS)\basedll_lzmastream.o: ../../src/common/lzmastream.cpp
$(OBJS)\basedll_common_uilocale.o: ../../src/common/uilocale.cpp
$(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\basedll_fs_data.o: ../../src/common/fs_data.cpp
$(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\basedll_basemsw.o: ../../src/msw/basemsw.cpp
$(CXX) -c -o $@ $(BASEDLL_CXXFLAGS) $(CPPDEPS) $<

Expand Down Expand Up @@ -12759,6 +12772,9 @@ $(OBJS)\baselib_lzmastream.o: ../../src/common/lzmastream.cpp
$(OBJS)\baselib_common_uilocale.o: ../../src/common/uilocale.cpp
$(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\baselib_fs_data.o: ../../src/common/fs_data.cpp
$(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<

$(OBJS)\baselib_basemsw.o: ../../src/msw/basemsw.cpp
$(CXX) -c -o $@ $(BASELIB_CXXFLAGS) $(CPPDEPS) $<

Expand Down
16 changes: 16 additions & 0 deletions build/msw/makefile.vc
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ MONODLL_OBJECTS = \
$(OBJS)\monodll_common_secretstore.obj \
$(OBJS)\monodll_lzmastream.obj \
$(OBJS)\monodll_common_uilocale.obj \
$(OBJS)\monodll_fs_data.obj \
$(OBJS)\monodll_basemsw.obj \
$(OBJS)\monodll_crashrpt.obj \
$(OBJS)\monodll_debughlp.obj \
Expand Down Expand Up @@ -704,6 +705,7 @@ MONOLIB_OBJECTS = \
$(OBJS)\monolib_common_secretstore.obj \
$(OBJS)\monolib_lzmastream.obj \
$(OBJS)\monolib_common_uilocale.obj \
$(OBJS)\monolib_fs_data.obj \
$(OBJS)\monolib_basemsw.obj \
$(OBJS)\monolib_crashrpt.obj \
$(OBJS)\monolib_debughlp.obj \
Expand Down Expand Up @@ -862,6 +864,7 @@ BASEDLL_OBJECTS = \
$(OBJS)\basedll_common_secretstore.obj \
$(OBJS)\basedll_lzmastream.obj \
$(OBJS)\basedll_common_uilocale.obj \
$(OBJS)\basedll_fs_data.obj \
$(OBJS)\basedll_basemsw.obj \
$(OBJS)\basedll_crashrpt.obj \
$(OBJS)\basedll_debughlp.obj \
Expand Down Expand Up @@ -1002,6 +1005,7 @@ BASELIB_OBJECTS = \
$(OBJS)\baselib_common_secretstore.obj \
$(OBJS)\baselib_lzmastream.obj \
$(OBJS)\baselib_common_uilocale.obj \
$(OBJS)\baselib_fs_data.obj \
$(OBJS)\baselib_basemsw.obj \
$(OBJS)\baselib_crashrpt.obj \
$(OBJS)\baselib_debughlp.obj \
Expand Down Expand Up @@ -7692,6 +7696,9 @@ $(OBJS)\monodll_lzmastream.obj: ..\..\src\common\lzmastream.cpp
$(OBJS)\monodll_common_uilocale.obj: ..\..\src\common\uilocale.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\uilocale.cpp

$(OBJS)\monodll_fs_data.obj: ..\..\src\common\fs_data.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\common\fs_data.cpp

$(OBJS)\monodll_basemsw.obj: ..\..\src\msw\basemsw.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONODLL_CXXFLAGS) ..\..\src\msw\basemsw.cpp

Expand Down Expand Up @@ -10283,6 +10290,9 @@ $(OBJS)\monolib_lzmastream.obj: ..\..\src\common\lzmastream.cpp
$(OBJS)\monolib_common_uilocale.obj: ..\..\src\common\uilocale.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\uilocale.cpp

$(OBJS)\monolib_fs_data.obj: ..\..\src\common\fs_data.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\common\fs_data.cpp

$(OBJS)\monolib_basemsw.obj: ..\..\src\msw\basemsw.cpp
$(CXX) /c /nologo /TP /Fo$@ $(MONOLIB_CXXFLAGS) ..\..\src\msw\basemsw.cpp

Expand Down Expand Up @@ -12874,6 +12884,9 @@ $(OBJS)\basedll_lzmastream.obj: ..\..\src\common\lzmastream.cpp
$(OBJS)\basedll_common_uilocale.obj: ..\..\src\common\uilocale.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\uilocale.cpp

$(OBJS)\basedll_fs_data.obj: ..\..\src\common\fs_data.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) ..\..\src\common\fs_data.cpp

$(OBJS)\basedll_basemsw.obj: ..\..\src\msw\basemsw.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASEDLL_CXXFLAGS) ..\..\src\msw\basemsw.cpp

Expand Down Expand Up @@ -13216,6 +13229,9 @@ $(OBJS)\baselib_lzmastream.obj: ..\..\src\common\lzmastream.cpp
$(OBJS)\baselib_common_uilocale.obj: ..\..\src\common\uilocale.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) ..\..\src\common\uilocale.cpp

$(OBJS)\baselib_fs_data.obj: ..\..\src\common\fs_data.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) ..\..\src\common\fs_data.cpp

$(OBJS)\baselib_basemsw.obj: ..\..\src\msw\basemsw.cpp
$(CXX) /c /nologo /TP /Fo$@ $(BASELIB_CXXFLAGS) ..\..\src\msw\basemsw.cpp

Expand Down
2 changes: 2 additions & 0 deletions build/msw/wx_base.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(IntDir)common_%(Filename).obj</ObjectFileName>
<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)common_%(Filename).obj</ObjectFileName>
</ClCompile>
<ClCompile Include="..\..\src\common\fs_data.cpp" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\..\src\msw\version.rc">
Expand Down Expand Up @@ -841,6 +842,7 @@
<ClInclude Include="..\..\include\wx\lzmastream.h" />
<ClInclude Include="..\..\include\wx\localedefs.h" />
<ClInclude Include="..\..\include\wx\uilocale.h" />
<ClInclude Include="..\..\include\wx\fs_data.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
6 changes: 6 additions & 0 deletions build/msw/wx_base.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<ClCompile Include="..\..\src\common\fs_arc.cpp">
<Filter>Common Sources</Filter>
</ClCompile>
<ClCompile Include="..\..\src\common\fs_data.cpp">
<Filter>Common Sources</Filter>
</ClCompile>
<ClCompile Include="..\..\src\common\fs_filter.cpp">
<Filter>Common Sources</Filter>
</ClCompile>
Expand Down Expand Up @@ -535,6 +538,9 @@
<ClInclude Include="..\..\include\wx\fs_arc.h">
<Filter>Common Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\wx\fs_data.h">
<Filter>Common Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\wx\fs_filter.h">
<Filter>Common Headers</Filter>
</ClInclude>
Expand Down
4 changes: 4 additions & 0 deletions docs/doxygen/overviews/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ The following virtual file system handlers are part of wxWidgets so far:
A handler for archives such as zip
and tar. Include file is wx/fs_arc.h. URLs examples:
"archive.zip#zip:filename", "archive.tar.gz#gzip:#tar:filename".
@li @b wxDataSchemeFSHandler:
A handler for accessing data inlined in URI according to RFC 2397.
URI example: "data:text/plain;base64,d3hXaWRnZXRzIGV4YW1wbGU=".
Include file is wx/fs_data.h.
@li @b wxFilterFSHandler:
A handler for compression schemes such
as gzip. Header is wx/fs_filter.h. URLs are in the form, e.g.:
Expand Down
31 changes: 31 additions & 0 deletions include/wx/fs_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/fs_data.h
// Purpose: DATA scheme file system.
// Author: Vyacheslav Lisovski
// Copyright: (c) 2023 Vyacheslav Lisovski
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////

#ifndef _WX_FS_DATA_H_
#define _WX_FS_DATA_H_

#include "wx/defs.h"

#if wxUSE_FILESYSTEM

#include "wx/filesys.h"

// ----------------------------------------------------------------------------
// wxDataSchemeFSHandler
// ----------------------------------------------------------------------------

class WXDLLIMPEXP_BASE wxDataSchemeFSHandler : public wxFileSystemHandler
{
public:
virtual bool CanOpen(const wxString& location) override;
virtual wxFSFile* OpenFile(wxFileSystem& fs, const wxString& location) override;
};

#endif // wxUSE_FILESYSTEM

#endif // _WX_FS_DATA_H_
31 changes: 31 additions & 0 deletions interface/wx/fs_data.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/////////////////////////////////////////////////////////////////////////////
// Name: wx/fs_data.h
// Purpose: DATA scheme file system
// Author: Vyacheslav Lisovski
// Copyright: (c) 2023 Vyacheslav Lisovski
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////

/**
@class wxDataSchemeFSHandler
File system handler for "data" URI scheme (RFC 2397).
URI syntax: @c "data:[<mediatype>][;base64],<data>".
The handler makes the data, included (encoded) into URI, available for
components that use the wxFileSystem infrastructure.
To make available for usage it should be registered somewhere within an
initialization procedure:
@code
wxFileSystem::AddHandler(new wxDataSchemeFSHandler);
@endcode
@since 3.3.0
*/

class wxDataSchemeFSHandler : public wxFileSystemHandler
{
public:
wxDataSchemeFSHandler();
};
Loading

0 comments on commit ca40535

Please sign in to comment.