1 // Copyright (c) 2011 Marshall A. Greenblatt. All rights reserved.
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above
10 // copyright notice, this list of conditions and the following disclaimer
11 // in the documentation and/or other materials provided with the
13 // * Neither the name of Google Inc. nor the name Chromium Embedded
14 // Framework nor the names of its contributors may be used to endorse
15 // or promote products derived from this software without specific prior
16 // written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 // ---------------------------------------------------------------------------
32 // The contents of this file are only available to applications that link
33 // against the libcef_dll_wrapper target.
36 #ifndef CEF_INCLUDE_WRAPPER_CEF_ZIP_ARCHIVE_H_
37 #define CEF_INCLUDE_WRAPPER_CEF_ZIP_ARCHIVE_H_
42 #include "include/base/cef_lock.h"
43 #include "include/base/cef_macros.h"
44 #include "include/base/cef_ref_counted.h"
45 #include "include/cef_base.h"
47 class CefStreamReader;
50 // Thread-safe class for accessing zip archive file contents. This class should
51 // not be used with large archive files because all data will be resident in
52 // memory at the same time. This implementation supports a restricted set of zip
54 // (1) All file names are stored and compared in lower case.
55 // (2) File ordering from the original zip archive is not maintained. This
56 // means that files from the same folder may not be located together in the
59 class CefZipArchive : public base::RefCountedThreadSafe<CefZipArchive> {
62 // Class representing a file in the archive. Accessing the file data from
63 // multiple threads is safe provided a reference to the File object is kept.
65 class File : public CefBase {
68 // Returns the read-only data contained in the file.
70 virtual const unsigned char* GetData() const =0;
73 // Returns the size of the data in the file.
75 virtual size_t GetDataSize() const =0;
78 // Returns a CefStreamReader object for streaming the contents of the file.
80 virtual CefRefPtr<CefStreamReader> GetStreamReader() const =0;
83 typedef std::map<CefString, CefRefPtr<File> > FileMap;
86 // Create a new object.
91 // Load the contents of the specified zip archive stream into this object.
92 // If the zip archive requires a password then provide it via |password|.
93 // If |overwriteExisting| is true then any files in this object that also
94 // exist in the specified archive will be replaced with the new files.
95 // Returns the number of files successfully loaded.
97 size_t Load(CefRefPtr<CefStreamReader> stream,
98 const CefString& password,
99 bool overwriteExisting);
102 // Clears the contents of this object.
107 // Returns the number of files in the archive.
109 size_t GetFileCount() const;
112 // Returns true if the specified file exists and has contents.
114 bool HasFile(const CefString& fileName) const;
117 // Returns the specified file.
119 CefRefPtr<File> GetFile(const CefString& fileName) const;
122 // Removes the specified file.
124 bool RemoveFile(const CefString& fileName);
127 // Returns the map of all files.
129 size_t GetFiles(FileMap& map) const;
132 // Protect against accidental deletion of this object.
133 friend class base::RefCountedThreadSafe<CefZipArchive>;
138 mutable base::Lock lock_;
140 DISALLOW_COPY_AND_ASSIGN(CefZipArchive);
143 #endif // CEF_INCLUDE_WRAPPER_CEF_ZIP_ARCHIVE_H_