mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Update wrapper implementations to use base types (issue #1336).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1775 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
@ -37,6 +37,7 @@
|
|||||||
#define CEF_INCLUDE_WRAPPER_CEF_MESSAGE_ROUTER_H_
|
#define CEF_INCLUDE_WRAPPER_CEF_MESSAGE_ROUTER_H_
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "include/base/cef_ref_counted.h"
|
||||||
#include "include/cef_base.h"
|
#include "include/cef_base.h"
|
||||||
#include "include/cef_browser.h"
|
#include "include/cef_browser.h"
|
||||||
#include "include/cef_process_message.h"
|
#include "include/cef_process_message.h"
|
||||||
@ -211,7 +212,8 @@ struct CefMessageRouterConfig {
|
|||||||
// Implements the browser side of query routing. The methods of this class may
|
// Implements the browser side of query routing. The methods of this class may
|
||||||
// be called on any browser process thread unless otherwise indicated.
|
// be called on any browser process thread unless otherwise indicated.
|
||||||
///
|
///
|
||||||
class CefMessageRouterBrowserSide : public CefBase {
|
class CefMessageRouterBrowserSide :
|
||||||
|
public base::RefCountedThreadSafe<CefMessageRouterBrowserSide> {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
// Callback associated with a single pending asynchronous query. Execute the
|
// Callback associated with a single pending asynchronous query. Execute the
|
||||||
@ -360,16 +362,20 @@ class CefMessageRouterBrowserSide : public CefBase {
|
|||||||
CefRefPtr<CefBrowser> browser,
|
CefRefPtr<CefBrowser> browser,
|
||||||
CefProcessId source_process,
|
CefProcessId source_process,
|
||||||
CefRefPtr<CefProcessMessage> message) =0;
|
CefRefPtr<CefProcessMessage> message) =0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Protect against accidental deletion of this object.
|
||||||
|
friend class base::RefCountedThreadSafe<CefMessageRouterBrowserSide>;
|
||||||
|
virtual ~CefMessageRouterBrowserSide() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
///
|
///
|
||||||
// Implements the renderer side of query routing. The methods of this class must
|
// Implements the renderer side of query routing. The methods of this class must
|
||||||
// be called on the render process main thread.
|
// be called on the render process main thread.
|
||||||
///
|
///
|
||||||
class CefMessageRouterRendererSide : public CefBase {
|
class CefMessageRouterRendererSide :
|
||||||
|
public base::RefCountedThreadSafe<CefMessageRouterRendererSide> {
|
||||||
public:
|
public:
|
||||||
virtual ~CefMessageRouterRendererSide() {}
|
|
||||||
|
|
||||||
///
|
///
|
||||||
// Create a new router with the specified configuration.
|
// Create a new router with the specified configuration.
|
||||||
///
|
///
|
||||||
@ -412,6 +418,11 @@ class CefMessageRouterRendererSide : public CefBase {
|
|||||||
CefRefPtr<CefBrowser> browser,
|
CefRefPtr<CefBrowser> browser,
|
||||||
CefProcessId source_process,
|
CefProcessId source_process,
|
||||||
CefRefPtr<CefProcessMessage> message) =0;
|
CefRefPtr<CefProcessMessage> message) =0;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// Protect against accidental deletion of this object.
|
||||||
|
friend class base::RefCountedThreadSafe<CefMessageRouterRendererSide>;
|
||||||
|
virtual ~CefMessageRouterRendererSide() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CEF_INCLUDE_WRAPPER_CEF_MESSAGE_ROUTER_H_
|
#endif // CEF_INCLUDE_WRAPPER_CEF_MESSAGE_ROUTER_H_
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "include/base/cef_macros.h"
|
#include "include/base/cef_macros.h"
|
||||||
|
#include "include/base/cef_scoped_ptr.h"
|
||||||
#include "include/cef_base.h"
|
#include "include/cef_base.h"
|
||||||
#include "include/cef_resource_handler.h"
|
#include "include/cef_resource_handler.h"
|
||||||
#include "include/cef_response.h"
|
#include "include/cef_response.h"
|
||||||
@ -89,7 +90,7 @@ class CefStreamResourceHandler : public CefResourceHandler {
|
|||||||
bool read_on_file_thread_;
|
bool read_on_file_thread_;
|
||||||
|
|
||||||
class Buffer;
|
class Buffer;
|
||||||
Buffer* buffer_;
|
scoped_ptr<Buffer> buffer_;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// Used in debug builds to verify that |buffer_| isn't being accessed on
|
// Used in debug builds to verify that |buffer_| isn't being accessed on
|
||||||
// multiple threads at the same time.
|
// multiple threads at the same time.
|
||||||
|
@ -37,13 +37,15 @@
|
|||||||
#define CEF_INCLUDE_WRAPPER_CEF_XML_OBJECT_H_
|
#define CEF_INCLUDE_WRAPPER_CEF_XML_OBJECT_H_
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "include/base/cef_lock.h"
|
|
||||||
#include "include/base/cef_macros.h"
|
|
||||||
#include "include/cef_base.h"
|
|
||||||
#include "include/cef_xml_reader.h"
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "include/base/cef_lock.h"
|
||||||
|
#include "include/base/cef_macros.h"
|
||||||
|
#include "include/base/cef_ref_counted.h"
|
||||||
|
#include "include/cef_base.h"
|
||||||
|
#include "include/cef_xml_reader.h"
|
||||||
|
|
||||||
class CefStreamReader;
|
class CefStreamReader;
|
||||||
|
|
||||||
///
|
///
|
||||||
@ -69,7 +71,7 @@ class CefStreamReader;
|
|||||||
// (c) Element nodes are represented by their outer XML string.
|
// (c) Element nodes are represented by their outer XML string.
|
||||||
// </pre>
|
// </pre>
|
||||||
///
|
///
|
||||||
class CefXmlObject : public CefBase {
|
class CefXmlObject : public base::RefCountedThreadSafe<CefXmlObject> {
|
||||||
public:
|
public:
|
||||||
typedef std::vector<CefRefPtr<CefXmlObject> > ObjectVector;
|
typedef std::vector<CefRefPtr<CefXmlObject> > ObjectVector;
|
||||||
typedef std::map<CefString, CefString > AttributeMap;
|
typedef std::map<CefString, CefString > AttributeMap;
|
||||||
@ -79,7 +81,6 @@ class CefXmlObject : public CefBase {
|
|||||||
// at least one character long.
|
// at least one character long.
|
||||||
///
|
///
|
||||||
explicit CefXmlObject(const CefString& name);
|
explicit CefXmlObject(const CefString& name);
|
||||||
virtual ~CefXmlObject();
|
|
||||||
|
|
||||||
///
|
///
|
||||||
// Load the contents of the specified XML stream into this object. The
|
// Load the contents of the specified XML stream into this object. The
|
||||||
@ -175,6 +176,10 @@ class CefXmlObject : public CefBase {
|
|||||||
size_t FindChildren(const CefString& name, ObjectVector& children);
|
size_t FindChildren(const CefString& name, ObjectVector& children);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Protect against accidental deletion of this object.
|
||||||
|
friend class base::RefCountedThreadSafe<CefXmlObject>;
|
||||||
|
~CefXmlObject();
|
||||||
|
|
||||||
void SetParent(CefXmlObject* parent);
|
void SetParent(CefXmlObject* parent);
|
||||||
|
|
||||||
CefString name_;
|
CefString name_;
|
||||||
@ -185,7 +190,6 @@ class CefXmlObject : public CefBase {
|
|||||||
|
|
||||||
base::Lock lock_;
|
base::Lock lock_;
|
||||||
|
|
||||||
IMPLEMENT_REFCOUNTING(CefXmlObject);
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CefXmlObject);
|
DISALLOW_COPY_AND_ASSIGN(CefXmlObject);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -37,10 +37,12 @@
|
|||||||
#define CEF_INCLUDE_WRAPPER_CEF_ZIP_ARCHIVE_H_
|
#define CEF_INCLUDE_WRAPPER_CEF_ZIP_ARCHIVE_H_
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "include/base/cef_lock.h"
|
#include "include/base/cef_lock.h"
|
||||||
#include "include/base/cef_macros.h"
|
#include "include/base/cef_macros.h"
|
||||||
|
#include "include/base/cef_ref_counted.h"
|
||||||
#include "include/cef_base.h"
|
#include "include/cef_base.h"
|
||||||
#include <map>
|
|
||||||
|
|
||||||
class CefStreamReader;
|
class CefStreamReader;
|
||||||
|
|
||||||
@ -49,13 +51,12 @@ class CefStreamReader;
|
|||||||
// not be used with large archive files because all data will be resident in
|
// not be used with large archive files because all data will be resident in
|
||||||
// memory at the same time. This implementation supports a restricted set of zip
|
// memory at the same time. This implementation supports a restricted set of zip
|
||||||
// archive features:
|
// archive features:
|
||||||
// (1) Password-protected files are not supported.
|
// (1) All file names are stored and compared in lower case.
|
||||||
// (2) All file names are stored and compared in lower case.
|
// (2) File ordering from the original zip archive is not maintained. This
|
||||||
// (3) File ordering from the original zip archive is not maintained. This
|
|
||||||
// means that files from the same folder may not be located together in the
|
// means that files from the same folder may not be located together in the
|
||||||
// file content map.
|
// file content map.
|
||||||
///
|
///
|
||||||
class CefZipArchive : public CefBase {
|
class CefZipArchive : public base::RefCountedThreadSafe<CefZipArchive> {
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
// Class representing a file in the archive. Accessing the file data from
|
// Class representing a file in the archive. Accessing the file data from
|
||||||
@ -66,25 +67,25 @@ class CefZipArchive : public CefBase {
|
|||||||
///
|
///
|
||||||
// Returns the read-only data contained in the file.
|
// Returns the read-only data contained in the file.
|
||||||
///
|
///
|
||||||
virtual const unsigned char* GetData() =0;
|
virtual const unsigned char* GetData() const =0;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Returns the size of the data in the file.
|
// Returns the size of the data in the file.
|
||||||
///
|
///
|
||||||
virtual size_t GetDataSize() =0;
|
virtual size_t GetDataSize() const =0;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Returns a CefStreamReader object for streaming the contents of the file.
|
// Returns a CefStreamReader object for streaming the contents of the file.
|
||||||
///
|
///
|
||||||
virtual CefRefPtr<CefStreamReader> GetStreamReader() =0;
|
virtual CefRefPtr<CefStreamReader> GetStreamReader() const =0;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<CefString, CefRefPtr<File> > FileMap;
|
typedef std::map<CefString, CefRefPtr<File> > FileMap;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Create a new object.
|
// Create a new object.
|
||||||
///
|
///
|
||||||
CefZipArchive();
|
CefZipArchive();
|
||||||
virtual ~CefZipArchive();
|
|
||||||
|
|
||||||
///
|
///
|
||||||
// Load the contents of the specified zip archive stream into this object.
|
// Load the contents of the specified zip archive stream into this object.
|
||||||
@ -105,17 +106,17 @@ class CefZipArchive : public CefBase {
|
|||||||
///
|
///
|
||||||
// Returns the number of files in the archive.
|
// Returns the number of files in the archive.
|
||||||
///
|
///
|
||||||
size_t GetFileCount();
|
size_t GetFileCount() const;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Returns true if the specified file exists and has contents.
|
// Returns true if the specified file exists and has contents.
|
||||||
///
|
///
|
||||||
bool HasFile(const CefString& fileName);
|
bool HasFile(const CefString& fileName) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Returns the specified file.
|
// Returns the specified file.
|
||||||
///
|
///
|
||||||
CefRefPtr<File> GetFile(const CefString& fileName);
|
CefRefPtr<File> GetFile(const CefString& fileName) const;
|
||||||
|
|
||||||
///
|
///
|
||||||
// Removes the specified file.
|
// Removes the specified file.
|
||||||
@ -125,14 +126,17 @@ class CefZipArchive : public CefBase {
|
|||||||
///
|
///
|
||||||
// Returns the map of all files.
|
// Returns the map of all files.
|
||||||
///
|
///
|
||||||
size_t GetFiles(FileMap& map);
|
size_t GetFiles(FileMap& map) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Protect against accidental deletion of this object.
|
||||||
|
friend class base::RefCountedThreadSafe<CefZipArchive>;
|
||||||
|
~CefZipArchive();
|
||||||
|
|
||||||
FileMap contents_;
|
FileMap contents_;
|
||||||
|
|
||||||
base::Lock lock_;
|
mutable base::Lock lock_;
|
||||||
|
|
||||||
IMPLEMENT_REFCOUNTING(CefZipArchive);
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CefZipArchive);
|
DISALLOW_COPY_AND_ASSIGN(CefZipArchive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -598,7 +598,6 @@ class CefMessageRouterBrowserSideImpl : public CefMessageRouterBrowserSide {
|
|||||||
typedef CefBrowserInfoMap<int64, QueryInfo*> BrowserQueryInfoMap;
|
typedef CefBrowserInfoMap<int64, QueryInfo*> BrowserQueryInfoMap;
|
||||||
BrowserQueryInfoMap browser_query_info_map_;
|
BrowserQueryInfoMap browser_query_info_map_;
|
||||||
|
|
||||||
IMPLEMENT_REFCOUNTING(CefMessageRouterBrowserSideImpl);
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CefMessageRouterBrowserSideImpl);
|
DISALLOW_COPY_AND_ASSIGN(CefMessageRouterBrowserSideImpl);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1124,7 +1123,6 @@ class CefMessageRouterRendererSideImpl : public CefMessageRouterRendererSide {
|
|||||||
typedef std::map<int, CefRefPtr<CefV8Context> > ContextMap;
|
typedef std::map<int, CefRefPtr<CefV8Context> > ContextMap;
|
||||||
ContextMap context_map_;
|
ContextMap context_map_;
|
||||||
|
|
||||||
IMPLEMENT_REFCOUNTING(CefMessageRouterRendererSideImpl);
|
|
||||||
DISALLOW_COPY_AND_ASSIGN(CefMessageRouterRendererSideImpl);
|
DISALLOW_COPY_AND_ASSIGN(CefMessageRouterRendererSideImpl);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6,36 +6,29 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include "include/base/cef_bind.h"
|
||||||
#include "include/base/cef_logging.h"
|
#include "include/base/cef_logging.h"
|
||||||
#include "include/base/cef_macros.h"
|
#include "include/base/cef_macros.h"
|
||||||
#include "include/cef_callback.h"
|
#include "include/cef_callback.h"
|
||||||
#include "include/cef_request.h"
|
#include "include/cef_request.h"
|
||||||
#include "include/cef_runnable.h"
|
|
||||||
#include "include/cef_stream.h"
|
#include "include/cef_stream.h"
|
||||||
|
#include "include/wrapper/cef_closure_task.h"
|
||||||
#include "include/wrapper/cef_helpers.h"
|
#include "include/wrapper/cef_helpers.h"
|
||||||
|
|
||||||
// Class that represents a readable/writable character buffer.
|
// Class that represents a readable/writable character buffer.
|
||||||
class CefStreamResourceHandler::Buffer {
|
class CefStreamResourceHandler::Buffer {
|
||||||
public:
|
public:
|
||||||
Buffer()
|
Buffer()
|
||||||
: buffer_(NULL),
|
: size_(0),
|
||||||
size_(0),
|
|
||||||
bytes_requested_(0),
|
bytes_requested_(0),
|
||||||
bytes_written_(0),
|
bytes_written_(0),
|
||||||
bytes_read_(0) {
|
bytes_read_(0) {
|
||||||
}
|
}
|
||||||
|
|
||||||
~Buffer() {
|
|
||||||
if (buffer_)
|
|
||||||
delete [] buffer_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Reset(int new_size) {
|
void Reset(int new_size) {
|
||||||
if (size_ < new_size) {
|
if (size_ < new_size) {
|
||||||
if (buffer_)
|
|
||||||
delete [] buffer_;
|
|
||||||
size_ = new_size;
|
size_ = new_size;
|
||||||
buffer_ = new char[size_];
|
buffer_.reset(new char[size_]);
|
||||||
DCHECK(buffer_);
|
DCHECK(buffer_);
|
||||||
}
|
}
|
||||||
bytes_requested_ = new_size;
|
bytes_requested_ = new_size;
|
||||||
@ -55,7 +48,7 @@ class CefStreamResourceHandler::Buffer {
|
|||||||
const int write_size =
|
const int write_size =
|
||||||
std::min(bytes_to_read, bytes_written_ - bytes_read_);
|
std::min(bytes_to_read, bytes_written_ - bytes_read_);
|
||||||
if (write_size > 0) {
|
if (write_size > 0) {
|
||||||
memcpy(data_out, buffer_ + bytes_read_, write_size);
|
memcpy(data_out, buffer_ .get() + bytes_read_, write_size);
|
||||||
bytes_read_ += write_size;
|
bytes_read_ += write_size;
|
||||||
}
|
}
|
||||||
return write_size;
|
return write_size;
|
||||||
@ -67,7 +60,7 @@ class CefStreamResourceHandler::Buffer {
|
|||||||
int bytes_read;
|
int bytes_read;
|
||||||
do {
|
do {
|
||||||
bytes_read = static_cast<int>(
|
bytes_read = static_cast<int>(
|
||||||
reader->Read(buffer_ + bytes_written_, 1,
|
reader->Read(buffer_.get() + bytes_written_, 1,
|
||||||
bytes_requested_ - bytes_written_));
|
bytes_requested_ - bytes_written_));
|
||||||
bytes_written_ += bytes_read;
|
bytes_written_ += bytes_read;
|
||||||
} while (bytes_read != 0 && bytes_written_ < bytes_requested_);
|
} while (bytes_read != 0 && bytes_written_ < bytes_requested_);
|
||||||
@ -76,7 +69,7 @@ class CefStreamResourceHandler::Buffer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
char* buffer_;
|
scoped_ptr<char[]> buffer_;
|
||||||
int size_;
|
int size_;
|
||||||
int bytes_requested_;
|
int bytes_requested_;
|
||||||
int bytes_written_;
|
int bytes_written_;
|
||||||
@ -91,8 +84,7 @@ CefStreamResourceHandler::CefStreamResourceHandler(
|
|||||||
: status_code_(200),
|
: status_code_(200),
|
||||||
status_text_("OK"),
|
status_text_("OK"),
|
||||||
mime_type_(mime_type),
|
mime_type_(mime_type),
|
||||||
stream_(stream),
|
stream_(stream)
|
||||||
buffer_(NULL)
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
, buffer_owned_by_file_thread_(false)
|
, buffer_owned_by_file_thread_(false)
|
||||||
#endif
|
#endif
|
||||||
@ -112,16 +104,13 @@ CefStreamResourceHandler::CefStreamResourceHandler(
|
|||||||
status_text_(status_text),
|
status_text_(status_text),
|
||||||
mime_type_(mime_type),
|
mime_type_(mime_type),
|
||||||
header_map_(header_map),
|
header_map_(header_map),
|
||||||
stream_(stream),
|
stream_(stream) {
|
||||||
buffer_(NULL) {
|
|
||||||
DCHECK(!mime_type_.empty());
|
DCHECK(!mime_type_.empty());
|
||||||
DCHECK(stream_.get());
|
DCHECK(stream_.get());
|
||||||
read_on_file_thread_ = stream_->MayBlock();
|
read_on_file_thread_ = stream_->MayBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
CefStreamResourceHandler::~CefStreamResourceHandler() {
|
CefStreamResourceHandler::~CefStreamResourceHandler() {
|
||||||
if (buffer_)
|
|
||||||
delete buffer_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefStreamResourceHandler::ProcessRequest(CefRefPtr<CefRequest> request,
|
bool CefStreamResourceHandler::ProcessRequest(CefRefPtr<CefRequest> request,
|
||||||
@ -171,8 +160,8 @@ bool CefStreamResourceHandler::ReadResponse(void* data_out,
|
|||||||
buffer_owned_by_file_thread_ = true;
|
buffer_owned_by_file_thread_ = true;
|
||||||
#endif
|
#endif
|
||||||
CefPostTask(TID_FILE,
|
CefPostTask(TID_FILE,
|
||||||
NewCefRunnableMethod(this, &CefStreamResourceHandler::ReadOnFileThread,
|
base::Bind(&CefStreamResourceHandler::ReadOnFileThread, this,
|
||||||
bytes_to_read, callback));
|
bytes_to_read, callback));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -203,7 +192,7 @@ void CefStreamResourceHandler::ReadOnFileThread(
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!buffer_)
|
if (!buffer_)
|
||||||
buffer_ = new Buffer();
|
buffer_.reset(new Buffer());
|
||||||
buffer_->Reset(bytes_to_read);
|
buffer_->Reset(bytes_to_read);
|
||||||
buffer_->ReadFrom(stream_);
|
buffer_->ReadFrom(stream_);
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@
|
|||||||
#include "include/wrapper/cef_zip_archive.h"
|
#include "include/wrapper/cef_zip_archive.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "include/base/cef_logging.h"
|
#include "include/base/cef_logging.h"
|
||||||
#include "include/base/cef_macros.h"
|
#include "include/base/cef_macros.h"
|
||||||
|
#include "include/base/cef_scoped_ptr.h"
|
||||||
#include "include/cef_stream.h"
|
#include "include/cef_stream.h"
|
||||||
#include "include/cef_zip_reader.h"
|
#include "include/cef_zip_reader.h"
|
||||||
#include "include/wrapper/cef_byte_read_handler.h"
|
#include "include/wrapper/cef_byte_read_handler.h"
|
||||||
@ -19,30 +19,48 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
// Convert |str| to lowercase in a Unicode-friendly manner.
|
||||||
|
CefString ToLower(const CefString& str) {
|
||||||
|
std::wstring wstr = str;
|
||||||
|
std::transform(wstr.begin(), wstr.end(), wstr.begin(), towlower);
|
||||||
|
return wstr;
|
||||||
|
}
|
||||||
|
|
||||||
class CefZipFile : public CefZipArchive::File {
|
class CefZipFile : public CefZipArchive::File {
|
||||||
public:
|
public:
|
||||||
explicit CefZipFile(size_t size) : data_(size) {}
|
CefZipFile() : data_size_(0) {}
|
||||||
~CefZipFile() {}
|
|
||||||
|
|
||||||
// Returns the read-only data contained in the file.
|
bool Initialize(size_t data_size) {
|
||||||
virtual const unsigned char* GetData() { return &data_[0]; }
|
data_.reset(new unsigned char[data_size]);
|
||||||
|
if (data_) {
|
||||||
|
data_size_ = data_size;
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
DLOG(ERROR) << "Failed to allocate " << data_size << " bytes of memory";
|
||||||
|
data_size_ = 0;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the size of the data in the file.
|
virtual const unsigned char* GetData() const OVERRIDE { return data_.get(); }
|
||||||
virtual size_t GetDataSize() { return data_.size(); }
|
|
||||||
|
|
||||||
// Returns a CefStreamReader object for streaming the contents of the file.
|
virtual size_t GetDataSize() const OVERRIDE { return data_size_; }
|
||||||
virtual CefRefPtr<CefStreamReader> GetStreamReader() {
|
|
||||||
|
virtual CefRefPtr<CefStreamReader> GetStreamReader() const OVERRIDE {
|
||||||
CefRefPtr<CefReadHandler> handler(
|
CefRefPtr<CefReadHandler> handler(
|
||||||
new CefByteReadHandler(GetData(), GetDataSize(), this));
|
new CefByteReadHandler(data_.get(), data_size_,
|
||||||
|
const_cast<CefZipFile*>(this)));
|
||||||
return CefStreamReader::CreateForHandler(handler);
|
return CefStreamReader::CreateForHandler(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<unsigned char>* GetDataVector() { return &data_; }
|
unsigned char* data() { return data_.get(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<unsigned char> data_;
|
size_t data_size_;
|
||||||
|
scoped_ptr<unsigned char[]> data_;
|
||||||
|
|
||||||
IMPLEMENT_REFCOUNTING(CefZipFile);
|
IMPLEMENT_REFCOUNTING(CefZipFile);
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(CefZipFile);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
@ -67,14 +85,12 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
|
|||||||
if (!reader->MoveToFirstFile())
|
if (!reader->MoveToFirstFile())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
std::wstring name;
|
|
||||||
CefRefPtr<CefZipFile> contents;
|
CefRefPtr<CefZipFile> contents;
|
||||||
FileMap::iterator it;
|
FileMap::iterator it;
|
||||||
std::vector<unsigned char>* data;
|
size_t count = 0;
|
||||||
size_t count = 0, size, offset;
|
|
||||||
|
|
||||||
do {
|
do {
|
||||||
size = static_cast<size_t>(reader->GetFileSize());
|
const size_t size = static_cast<size_t>(reader->GetFileSize());
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
// Skip directories and empty files.
|
// Skip directories and empty files.
|
||||||
continue;
|
continue;
|
||||||
@ -83,8 +99,7 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
|
|||||||
if (!reader->OpenFile(password))
|
if (!reader->OpenFile(password))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
name = reader->GetFileName();
|
const CefString& name = ToLower(reader->GetFileName());
|
||||||
std::transform(name.begin(), name.end(), name.begin(), towlower);
|
|
||||||
|
|
||||||
it = contents_.find(name);
|
it = contents_.find(name);
|
||||||
if (it != contents_.end()) {
|
if (it != contents_.end()) {
|
||||||
@ -94,13 +109,15 @@ size_t CefZipArchive::Load(CefRefPtr<CefStreamReader> stream,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
contents = new CefZipFile(size);
|
CefRefPtr<CefZipFile> contents = new CefZipFile();
|
||||||
data = contents->GetDataVector();
|
if (!contents->Initialize(size))
|
||||||
offset = 0;
|
continue;
|
||||||
|
unsigned char* data = contents->data();
|
||||||
|
size_t offset = 0;
|
||||||
|
|
||||||
// Read the file contents.
|
// Read the file contents.
|
||||||
do {
|
do {
|
||||||
offset += reader->ReadFile(&(*data)[offset], size - offset);
|
offset += reader->ReadFile(data + offset, size - offset);
|
||||||
} while (offset < size && !reader->Eof());
|
} while (offset < size && !reader->Eof());
|
||||||
|
|
||||||
DCHECK(offset == size);
|
DCHECK(offset == size);
|
||||||
@ -120,38 +137,29 @@ void CefZipArchive::Clear() {
|
|||||||
contents_.clear();
|
contents_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CefZipArchive::GetFileCount() {
|
size_t CefZipArchive::GetFileCount() const {
|
||||||
base::AutoLock lock_scope(lock_);
|
base::AutoLock lock_scope(lock_);
|
||||||
return contents_.size();
|
return contents_.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefZipArchive::HasFile(const CefString& fileName) {
|
bool CefZipArchive::HasFile(const CefString& fileName) const {
|
||||||
std::wstring str = fileName;
|
|
||||||
std::transform(str.begin(), str.end(), str.begin(), towlower);
|
|
||||||
|
|
||||||
base::AutoLock lock_scope(lock_);
|
base::AutoLock lock_scope(lock_);
|
||||||
FileMap::const_iterator it = contents_.find(CefString(str));
|
FileMap::const_iterator it = contents_.find(ToLower(fileName));
|
||||||
return (it != contents_.end());
|
return (it != contents_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
CefRefPtr<CefZipArchive::File> CefZipArchive::GetFile(
|
CefRefPtr<CefZipArchive::File> CefZipArchive::GetFile(
|
||||||
const CefString& fileName) {
|
const CefString& fileName) const {
|
||||||
std::wstring str = fileName;
|
|
||||||
std::transform(str.begin(), str.end(), str.begin(), towlower);
|
|
||||||
|
|
||||||
base::AutoLock lock_scope(lock_);
|
base::AutoLock lock_scope(lock_);
|
||||||
FileMap::const_iterator it = contents_.find(CefString(str));
|
FileMap::const_iterator it = contents_.find(ToLower(fileName));
|
||||||
if (it != contents_.end())
|
if (it != contents_.end())
|
||||||
return it->second;
|
return it->second;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CefZipArchive::RemoveFile(const CefString& fileName) {
|
bool CefZipArchive::RemoveFile(const CefString& fileName) {
|
||||||
std::wstring str = fileName;
|
|
||||||
std::transform(str.begin(), str.end(), str.begin(), towlower);
|
|
||||||
|
|
||||||
base::AutoLock lock_scope(lock_);
|
base::AutoLock lock_scope(lock_);
|
||||||
FileMap::iterator it = contents_.find(CefString(str));
|
FileMap::iterator it = contents_.find(ToLower(fileName));
|
||||||
if (it != contents_.end()) {
|
if (it != contents_.end()) {
|
||||||
contents_.erase(it);
|
contents_.erase(it);
|
||||||
return true;
|
return true;
|
||||||
@ -159,7 +167,7 @@ bool CefZipArchive::RemoveFile(const CefString& fileName) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t CefZipArchive::GetFiles(FileMap& map) {
|
size_t CefZipArchive::GetFiles(FileMap& map) const {
|
||||||
base::AutoLock lock_scope(lock_);
|
base::AutoLock lock_scope(lock_);
|
||||||
map = contents_;
|
map = contents_;
|
||||||
return contents_.size();
|
return contents_.size();
|
||||||
|
Reference in New Issue
Block a user