• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 Marshall A. Greenblatt. All rights reserved.
2 //
3 // Redistribution and use in source and binary forms, with or without
4 // modification, are permitted provided that the following conditions are
5 // met:
6 //
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
12 // distribution.
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.
17 //
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.
29 //
30 // ---------------------------------------------------------------------------
31 //
32 // The contents of this file are only available to applications that link
33 // against the libcef_dll_wrapper target.
34 //
35 
36 #ifndef CEF_INCLUDE_WRAPPER_CEF_BYTE_READ_HANDLER_H_
37 #define CEF_INCLUDE_WRAPPER_CEF_BYTE_READ_HANDLER_H_
38 #pragma once
39 
40 #include "include/base/cef_lock.h"
41 #include "include/cef_base.h"
42 #include "include/cef_stream.h"
43 
44 ///
45 // Thread safe implementation of the CefReadHandler class for reading an
46 // in-memory array of bytes.
47 ///
48 class CefByteReadHandler : public CefReadHandler {
49  public:
50   ///
51   // Create a new object for reading an array of bytes. An optional |source|
52   // reference can be kept to keep the underlying data source from being
53   // released while the reader exists.
54   ///
55   CefByteReadHandler(const unsigned char* bytes,
56                      size_t size,
57                      CefRefPtr<CefBaseRefCounted> source);
58 
59   CefByteReadHandler(const CefByteReadHandler&) = delete;
60   CefByteReadHandler& operator=(const CefByteReadHandler&) = delete;
61 
62   // CefReadHandler methods.
63   virtual size_t Read(void* ptr, size_t size, size_t n) override;
64   virtual int Seek(int64 offset, int whence) override;
65   virtual int64 Tell() override;
66   virtual int Eof() override;
MayBlock()67   virtual bool MayBlock() override { return false; }
68 
69  private:
70   const unsigned char* bytes_;
71   int64 size_;
72   int64 offset_;
73   CefRefPtr<CefBaseRefCounted> source_;
74 
75   base::Lock lock_;
76 
77   IMPLEMENT_REFCOUNTING(CefByteReadHandler);
78 };
79 
80 #endif  // CEF_INCLUDE_WRAPPER_CEF_BYTE_READ_HANDLER_H_
81