|
| 1 | +// Copyright (c) 2012-2013 The CEF Python authors. All rights reserved. |
| 2 | +// License: New BSD License. |
| 3 | +// Website: http://code.google.com/p/cefpython/ |
| 4 | + |
| 5 | +#include "resource_handler.h" |
| 6 | + |
| 7 | +/// |
| 8 | +// Begin processing the request. To handle the request return true and call |
| 9 | +// CefCallback::Continue() once the response header information is available |
| 10 | +// (CefCallback::Continue() can also be called from inside this method if |
| 11 | +// header information is available immediately). To cancel the request return |
| 12 | +// false. |
| 13 | +/// |
| 14 | +/*--cef()--*/ |
| 15 | +bool ResourceHandler::ProcessRequest(CefRefPtr<CefRequest> request, |
| 16 | + CefRefPtr<CefCallback> callback) { |
| 17 | + REQUIRE_IO_THREAD(); |
| 18 | + return ResourceHandler_ProcessRequest(resourceHandlerId_, request, |
| 19 | + callback); |
| 20 | +} |
| 21 | + |
| 22 | +/// |
| 23 | +// Retrieve response header information. If the response length is not known |
| 24 | +// set |response_length| to -1 and ReadResponse() will be called until it |
| 25 | +// returns false. If the response length is known set |response_length| |
| 26 | +// to a positive value and ReadResponse() will be called until it returns |
| 27 | +// false or the specified number of bytes have been read. Use the |response| |
| 28 | +// object to set the mime type, http status code and other optional header |
| 29 | +// values. To redirect the request to a new URL set |redirectUrl| to the new |
| 30 | +// URL. |
| 31 | +/// |
| 32 | +/*--cef()--*/ |
| 33 | +void ResourceHandler::GetResponseHeaders(CefRefPtr<CefResponse> response, |
| 34 | + int64& response_length, |
| 35 | + CefString& redirectUrl) { |
| 36 | + REQUIRE_IO_THREAD(); |
| 37 | + ResourceHandler_GetResponseHeaders(resourceHandlerId_, response, |
| 38 | + response_length, redirectUrl); |
| 39 | +} |
| 40 | + |
| 41 | +/// |
| 42 | +// Read response data. If data is available immediately copy up to |
| 43 | +// |bytes_to_read| bytes into |data_out|, set |bytes_read| to the number of |
| 44 | +// bytes copied, and return true. To read the data at a later time set |
| 45 | +// |bytes_read| to 0, return true and call CefCallback::Continue() when the |
| 46 | +// data is available. To indicate response completion return false. |
| 47 | +/// |
| 48 | +/*--cef()--*/ |
| 49 | +bool ResourceHandler::ReadResponse(void* data_out, |
| 50 | + int bytes_to_read, |
| 51 | + int& bytes_read, |
| 52 | + CefRefPtr<CefCallback> callback) { |
| 53 | + REQUIRE_IO_THREAD(); |
| 54 | + return ResourceHandler_ReadResponse(resourceHandlerId_, data_out, |
| 55 | + bytes_to_read, bytes_read, callback); |
| 56 | +} |
| 57 | + |
| 58 | +/// |
| 59 | +// Return true if the specified cookie can be sent with the request or false |
| 60 | +// otherwise. If false is returned for any cookie then no cookies will be sent |
| 61 | +// with the request. |
| 62 | +/// |
| 63 | +/*--cef()--*/ |
| 64 | +bool ResourceHandler::CanGetCookie(const CefCookie& cookie) { |
| 65 | + REQUIRE_IO_THREAD(); |
| 66 | + return ResourceHandler_CanGetCookie(resourceHandlerId_, cookie); |
| 67 | +} |
| 68 | + |
| 69 | +/// |
| 70 | +// Return true if the specified cookie returned with the response can be set |
| 71 | +// or false otherwise. |
| 72 | +/// |
| 73 | +/*--cef()--*/ |
| 74 | +bool ResourceHandler::CanSetCookie(const CefCookie& cookie) { |
| 75 | + REQUIRE_IO_THREAD(); |
| 76 | + return ResourceHandler_CanSetCookie(resourceHandlerId_, cookie); |
| 77 | +} |
| 78 | + |
| 79 | +/// |
| 80 | +// Request processing has been canceled. |
| 81 | +/// |
| 82 | +/*--cef()--*/ |
| 83 | +void ResourceHandler::Cancel() { |
| 84 | + REQUIRE_IO_THREAD(); |
| 85 | + return ResourceHandler_Cancel(resourceHandlerId_); |
| 86 | +} |
0 commit comments