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