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 must follow a specific format in order to 33 // support the CEF translator tool. See the translator.README.txt file in the 34 // tools directory for more information. 35 // 36 37 #ifndef CEF_INCLUDE_CEF_RESOURCE_HANDLER_H_ 38 #define CEF_INCLUDE_CEF_RESOURCE_HANDLER_H_ 39 #pragma once 40 41 #include "include/cef_base.h" 42 #include "include/cef_browser.h" 43 #include "include/cef_callback.h" 44 #include "include/cef_cookie.h" 45 #include "include/cef_request.h" 46 #include "include/cef_response.h" 47 48 /// 49 // Callback for asynchronous continuation of CefResourceHandler::Skip(). 50 /// 51 /*--cef(source=library)--*/ 52 class CefResourceSkipCallback : public virtual CefBaseRefCounted { 53 public: 54 /// 55 // Callback for asynchronous continuation of Skip(). If |bytes_skipped| > 0 56 // then either Skip() will be called again until the requested number of 57 // bytes have been skipped or the request will proceed. If |bytes_skipped| 58 // <= 0 the request will fail with ERR_REQUEST_RANGE_NOT_SATISFIABLE. 59 /// 60 /*--cef(capi_name=cont)--*/ 61 virtual void Continue(int64 bytes_skipped) = 0; 62 }; 63 64 /// 65 // Callback for asynchronous continuation of CefResourceHandler::Read(). 66 /// 67 /*--cef(source=library)--*/ 68 class CefResourceReadCallback : public virtual CefBaseRefCounted { 69 public: 70 /// 71 // Callback for asynchronous continuation of Read(). If |bytes_read| == 0 72 // the response will be considered complete. If |bytes_read| > 0 then Read() 73 // will be called again until the request is complete (based on either the 74 // result or the expected content length). If |bytes_read| < 0 then the 75 // request will fail and the |bytes_read| value will be treated as the error 76 // code. 77 /// 78 /*--cef(capi_name=cont)--*/ 79 virtual void Continue(int bytes_read) = 0; 80 }; 81 82 /// 83 // Class used to implement a custom request handler interface. The methods of 84 // this class will be called on the IO thread unless otherwise indicated. 85 /// 86 /*--cef(source=client)--*/ 87 class CefResourceHandler : public virtual CefBaseRefCounted { 88 public: 89 /// 90 // Open the response stream. To handle the request immediately set 91 // |handle_request| to true and return true. To decide at a later time set 92 // |handle_request| to false, return true, and execute |callback| to continue 93 // or cancel the request. To cancel the request immediately set 94 // |handle_request| to true and return false. This method will be called in 95 // sequence but not from a dedicated thread. For backwards compatibility set 96 // |handle_request| to false and return false and the ProcessRequest method 97 // will be called. 98 /// 99 /*--cef()--*/ Open(CefRefPtr<CefRequest> request,bool & handle_request,CefRefPtr<CefCallback> callback)100 virtual bool Open(CefRefPtr<CefRequest> request, 101 bool& handle_request, 102 CefRefPtr<CefCallback> callback) { 103 handle_request = false; 104 return false; 105 } 106 107 /// 108 // Begin processing the request. To handle the request return true and call 109 // CefCallback::Continue() once the response header information is available 110 // (CefCallback::Continue() can also be called from inside this method if 111 // header information is available immediately). To cancel the request return 112 // false. 113 // 114 // WARNING: This method is deprecated. Use Open instead. 115 /// 116 /*--cef()--*/ ProcessRequest(CefRefPtr<CefRequest> request,CefRefPtr<CefCallback> callback)117 virtual bool ProcessRequest(CefRefPtr<CefRequest> request, 118 CefRefPtr<CefCallback> callback) { 119 return false; 120 } 121 122 /// 123 // Retrieve response header information. If the response length is not known 124 // set |response_length| to -1 and ReadResponse() will be called until it 125 // returns false. If the response length is known set |response_length| 126 // to a positive value and ReadResponse() will be called until it returns 127 // false or the specified number of bytes have been read. Use the |response| 128 // object to set the mime type, http status code and other optional header 129 // values. To redirect the request to a new URL set |redirectUrl| to the new 130 // URL. |redirectUrl| can be either a relative or fully qualified URL. 131 // It is also possible to set |response| to a redirect http status code 132 // and pass the new URL via a Location header. Likewise with |redirectUrl| it 133 // is valid to set a relative or fully qualified URL as the Location header 134 // value. If an error occured while setting up the request you can call 135 // SetError() on |response| to indicate the error condition. 136 /// 137 /*--cef()--*/ 138 virtual void GetResponseHeaders(CefRefPtr<CefResponse> response, 139 int64& response_length, 140 CefString& redirectUrl) = 0; 141 142 /// 143 // Skip response data when requested by a Range header. Skip over and discard 144 // |bytes_to_skip| bytes of response data. If data is available immediately 145 // set |bytes_skipped| to the number of bytes skipped and return true. To 146 // read the data at a later time set |bytes_skipped| to 0, return true and 147 // execute |callback| when the data is available. To indicate failure set 148 // |bytes_skipped| to < 0 (e.g. -2 for ERR_FAILED) and return false. This 149 // method will be called in sequence but not from a dedicated thread. 150 /// 151 /*--cef()--*/ Skip(int64 bytes_to_skip,int64 & bytes_skipped,CefRefPtr<CefResourceSkipCallback> callback)152 virtual bool Skip(int64 bytes_to_skip, 153 int64& bytes_skipped, 154 CefRefPtr<CefResourceSkipCallback> callback) { 155 bytes_skipped = -2; 156 return false; 157 } 158 159 /// 160 // Read response data. If data is available immediately copy up to 161 // |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of 162 // bytes copied, and return true. To read the data at a later time keep a 163 // pointer to |data_out|, set |bytes_read| to 0, return true and execute 164 // |callback| when the data is available (|data_out| will remain valid until 165 // the callback is executed). To indicate response completion set |bytes_read| 166 // to 0 and return false. To indicate failure set |bytes_read| to < 0 (e.g. -2 167 // for ERR_FAILED) and return false. This method will be called in sequence 168 // but not from a dedicated thread. For backwards compatibility set 169 // |bytes_read| to -1 and return false and the ReadResponse method will be 170 // called. 171 /// 172 /*--cef()--*/ Read(void * data_out,int bytes_to_read,int & bytes_read,CefRefPtr<CefResourceReadCallback> callback)173 virtual bool Read(void* data_out, 174 int bytes_to_read, 175 int& bytes_read, 176 CefRefPtr<CefResourceReadCallback> callback) { 177 bytes_read = -1; 178 return false; 179 } 180 181 /// 182 // Read response data. If data is available immediately copy up to 183 // |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of 184 // bytes copied, and return true. To read the data at a later time set 185 // |bytes_read| to 0, return true and call CefCallback::Continue() when the 186 // data is available. To indicate response completion return false. 187 // 188 // WARNING: This method is deprecated. Use Skip and Read instead. 189 /// 190 /*--cef()--*/ ReadResponse(void * data_out,int bytes_to_read,int & bytes_read,CefRefPtr<CefCallback> callback)191 virtual bool ReadResponse(void* data_out, 192 int bytes_to_read, 193 int& bytes_read, 194 CefRefPtr<CefCallback> callback) { 195 bytes_read = -2; 196 return false; 197 } 198 199 /// 200 // Request processing has been canceled. 201 /// 202 /*--cef()--*/ 203 virtual void Cancel() = 0; 204 }; 205 206 #endif // CEF_INCLUDE_CEF_RESOURCE_HANDLER_H_ 207