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_STREAM_RESOURCE_HANDLER_H_ 37 #define CEF_INCLUDE_WRAPPER_CEF_STREAM_RESOURCE_HANDLER_H_ 38 #pragma once 39 40 #include "include/cef_resource_handler.h" 41 #include "include/cef_response.h" 42 #include "include/cef_stream.h" 43 44 /// 45 // Implementation of the CefResourceHandler class for reading from a CefStream. 46 /// 47 class CefStreamResourceHandler : public CefResourceHandler { 48 public: 49 /// 50 // Create a new object with default response values. 51 /// 52 CefStreamResourceHandler(const CefString& mime_type, 53 CefRefPtr<CefStreamReader> stream); 54 /// 55 // Create a new object with explicit response values. 56 /// 57 CefStreamResourceHandler(int status_code, 58 const CefString& status_text, 59 const CefString& mime_type, 60 CefResponse::HeaderMap header_map, 61 CefRefPtr<CefStreamReader> stream); 62 63 CefStreamResourceHandler(const CefStreamResourceHandler&) = delete; 64 CefStreamResourceHandler& operator=(const CefStreamResourceHandler&) = delete; 65 66 // CefResourceHandler methods. 67 bool Open(CefRefPtr<CefRequest> request, 68 bool& handle_request, 69 CefRefPtr<CefCallback> callback) override; 70 void GetResponseHeaders(CefRefPtr<CefResponse> response, 71 int64& response_length, 72 CefString& redirectUrl) override; 73 bool Read(void* data_out, 74 int bytes_to_read, 75 int& bytes_read, 76 CefRefPtr<CefResourceReadCallback> callback) override; 77 void Cancel() override; 78 79 private: 80 const int status_code_; 81 const CefString status_text_; 82 const CefString mime_type_; 83 const CefResponse::HeaderMap header_map_; 84 const CefRefPtr<CefStreamReader> stream_; 85 86 IMPLEMENT_REFCOUNTING(CefStreamResourceHandler); 87 }; 88 89 #endif // CEF_INCLUDE_WRAPPER_CEF_STREAM_RESOURCE_HANDLER_H_ 90