55package org .cef .handler ;
66
77import org .cef .callback .CefCallback ;
8+ import org .cef .callback .CefResourceReadCallback ;
9+ import org .cef .callback .CefResourceSkipCallback ;
10+ import org .cef .misc .BoolRef ;
811import org .cef .misc .IntRef ;
12+ import org .cef .misc .LongRef ;
913import org .cef .misc .StringRef ;
1014import org .cef .network .CefCookie ;
1115import org .cef .network .CefRequest ;
1216import org .cef .network .CefResponse ;
1317
1418/**
15- * Implement this interface to handle custom resource requests. The methods of
16- * this class will always be called on the IO thread.
19+ * Implement this interface to handle custom resource requests. This interface is a "new" API and an
20+ * old API in one: the deprecated methods are part of the old API. The new API allows for parallel
21+ * processing of requests, because it does not channel all reads through a dedicated IO thread, and
22+ * it allows for skipping of bytes as part of handling Range requests.
1723 */
1824public interface CefResourceHandler {
1925 /**
@@ -23,9 +29,22 @@ public interface CefResourceHandler {
2329 * @param callback Callback to continue or cancel the request.
2430 * @return True to handle the request and call CefCallback.Continue() once the response header
2531 * information is available.
32+ * @deprecated Use open() instead
2633 */
2734 boolean processRequest (CefRequest request , CefCallback callback );
2835
36+ /**
37+ * Open the response stream. This and related (getResponseHeaders, read, skip) methods will be
38+ * called in sequence but not from a dedicated thread. <p> For backwards compatibility set
39+ * |handleRequest| to false and return false and the processRequest() method will be called.
40+ * @param request The request itself. Cannot be modified in this callback. Instance only valid
41+ * within the scope of this method.
42+ * @param handleRequest Set to true to handle/cancel the request immediately
43+ * @param callback Callback to continue or cancel the request at a later time
44+ * @return True to handle the request
45+ */
46+ boolean open (CefRequest request , BoolRef handleRequest , CefCallback callback );
47+
2948 /**
3049 * Retrieve response header information. If the response length is not known set
3150 * |responseLength| to -1 and readResponse() will be called until it returns false. If the
@@ -49,9 +68,41 @@ public interface CefResourceHandler {
4968 * @param bytesRead Number of bytes written to the buffer.
5069 * @param callback Callback to execute if data will be available asynchronously.
5170 * @return True if more data is or will be available.
71+ * @deprecated Use read() instead
5272 */
5373 boolean readResponse (byte [] dataOut , int bytesToRead , IntRef bytesRead , CefCallback callback );
5474
75+ /**
76+ * Read response data. If data is available immediately copy up to |bytesToRead| bytes into
77+ * |dataOut|, set |bytesRead| to the number of bytes copied, and return true. To read the data
78+ * at a later time store |dataOut|, set |bytesRead| to 0, return true and call the callback when
79+ * the data is available. To indicate response completion set |bytesRead| to 0 and return false.
80+ * To indicate failure set |bytesRead| to <0 (e.g. -2 for ERR_FAILED) and return false. <p> For
81+ * backwards compatibility set |bytesRead| to -1 and return false and the readResponse() method
82+ * will be called.
83+ * @param dataOut Write data to this buffer. Buffer remains valid until either an immediate
84+ * response is delivered (return true) or the callback is called later when data is
85+ * available (return false).
86+ * @param bytesToRead Size of the buffer.
87+ * @param bytesRead Number of bytes written to the buffer.
88+ * @param callback Callback to execute if data will be available asynchronously.
89+ * @return True if more data is or will be available.
90+ */
91+ boolean read (
92+ byte [] dataOut , int bytesToRead , IntRef bytesRead , CefResourceReadCallback callback );
93+
94+ /**
95+ * Skip response data when requested by a Range header. Skip over and discard |bytesToSkip|
96+ * bytes of response data. If data is available immediately set |bytesSkipped| to the number of
97+ * bytes skipped and return true. To read the data at a later time set |bytesSkipped| to 0,
98+ * return true and execute |callback| when the data is available. To indicate failure set
99+ * |bytesSkipped| to < 0 (e.g. -2 for ERR_FAILED) and return false.
100+ * @param bytesToSkip Number of bytes to skip.
101+ * @param bytesSkipped Number of bytes skipped.
102+ * @param callback Callback to execute if data will be skipped asynchronously.
103+ */
104+ boolean skip (long bytesToSkip , LongRef bytesSkipped , CefResourceSkipCallback callback );
105+
55106 /**
56107 * Request processing has been canceled.
57108 */
0 commit comments