Skip to content

Commit 875b8b7

Browse files
committed
Added the WebRequest object and the WebRequestClient callbacks.
1 parent 4ba421f commit 875b8b7

22 files changed

Lines changed: 416 additions & 14 deletions

cefpython/cef3/cefpython_public_api.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
// All the imports that are required when including "cefpython.h".
1818
#include "include/cef_client.h"
19-
// #include "include/cef_web_urlrequest.h"
20-
// #include "include/cef_cookie.h"
19+
#include "include/cef_urlrequest.h"
2120
#include "util.h"
2221

2322
// Python 3.2 fix - DL_IMPORT is not defined in Python.h

cefpython/cef3/client_handler/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
CC = g++
1212
CCFLAGS = -g -fPIC -Wall -Werror
1313

14-
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp
14+
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
15+
web_request_client.cpp
1516
OBJ = $(SRC:.cpp=.o)
1617
OUT = libclient_handler.a
1718

cefpython/cef3/client_handler/client_handler_py27.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@
9696
<File
9797
RelativePath=".\resource_handler.h"
9898
>
99+
</File>
100+
<File
101+
RelativePath=".\web_request_client.h"
102+
>
99103
</File>
100104
</Filter>
101105
<Filter
@@ -120,6 +124,10 @@
120124
<File
121125
RelativePath=".\resource_handler.cpp"
122126
>
127+
</File>
128+
<File
129+
RelativePath=".\web_request_client.cpp"
130+
>
123131
</File>
124132
</Filter>
125133
</Files>

cefpython/cef3/client_handler/client_handler_py32.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@
9595
<File
9696
RelativePath=".\resource_handler.h"
9797
>
98+
</File>
99+
<File
100+
RelativePath=".\web_request_client.h"
101+
>
98102
</File>
99103
</Filter>
100104
<Filter
@@ -119,6 +123,10 @@
119123
<File
120124
RelativePath=".\resource_handler.cpp"
121125
>
126+
</File>
127+
<File
128+
RelativePath=".\web_request_client.cpp"
129+
>
122130
</File>
123131
</Filter>
124132
</Files>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 "web_request_client.h"
6+
7+
///
8+
// Interface that should be implemented by the CefURLRequest client. The
9+
// methods of this class will be called on the same thread that created the
10+
// request.
11+
///
12+
13+
///
14+
// Notifies the client that the request has completed. Use the
15+
// CefURLRequest::GetRequestStatus method to determine if the request was
16+
// successful or not.
17+
///
18+
/*--cef()--*/
19+
void WebRequestClient::OnRequestComplete(CefRefPtr<CefURLRequest> request) {
20+
WebRequestClient_OnRequestComplete(webRequestId_, request);
21+
}
22+
23+
///
24+
// Notifies the client of upload progress. |current| denotes the number of
25+
// bytes sent so far and |total| is the total size of uploading data (or -1 if
26+
// chunked upload is enabled). This method will only be called if the
27+
// UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request.
28+
///
29+
/*--cef()--*/
30+
void WebRequestClient::OnUploadProgress(CefRefPtr<CefURLRequest> request,
31+
uint64 current,
32+
uint64 total) {
33+
WebRequestClient_OnUploadProgress(webRequestId_, request, current, total);
34+
}
35+
36+
///
37+
// Notifies the client of download progress. |current| denotes the number of
38+
// bytes received up to the call and |total| is the expected total size of the
39+
// response (or -1 if not determined).
40+
///
41+
/*--cef()--*/
42+
void WebRequestClient::OnDownloadProgress(CefRefPtr<CefURLRequest> request,
43+
uint64 current,
44+
uint64 total) {
45+
WebRequestClient_OnDownloadProgress(webRequestId_, request, current,
46+
total);
47+
}
48+
49+
///
50+
// Called when some part of the response is read. |data| contains the current
51+
// bytes received since the last call. This method will not be called if the
52+
// UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request.
53+
///
54+
/*--cef()--*/
55+
void WebRequestClient::OnDownloadData(CefRefPtr<CefURLRequest> request,
56+
const void* data,
57+
size_t data_length) {
58+
WebRequestClient_OnDownloadData(webRequestId_, request, data, data_length);
59+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
#pragma once
6+
7+
#if defined(_WIN32)
8+
#include "../windows/stdint.h"
9+
#endif
10+
11+
#include "cefpython_public_api.h"
12+
13+
class WebRequestClient : public CefURLRequestClient
14+
{
15+
public:
16+
int webRequestId_;
17+
public:
18+
WebRequestClient(int webRequestId) :
19+
webRequestId_(webRequestId) {
20+
}
21+
virtual ~WebRequestClient(){}
22+
23+
///
24+
// Interface that should be implemented by the CefURLRequest client. The
25+
// methods of this class will be called on the same thread that created the
26+
// request.
27+
///
28+
29+
///
30+
// Notifies the client that the request has completed. Use the
31+
// CefURLRequest::GetRequestStatus method to determine if the request was
32+
// successful or not.
33+
///
34+
/*--cef()--*/
35+
virtual void OnRequestComplete(CefRefPtr<CefURLRequest> request) OVERRIDE;
36+
37+
///
38+
// Notifies the client of upload progress. |current| denotes the number of
39+
// bytes sent so far and |total| is the total size of uploading data (or -1 if
40+
// chunked upload is enabled). This method will only be called if the
41+
// UR_FLAG_REPORT_UPLOAD_PROGRESS flag is set on the request.
42+
///
43+
/*--cef()--*/
44+
virtual void OnUploadProgress(CefRefPtr<CefURLRequest> request,
45+
uint64 current,
46+
uint64 total) OVERRIDE;
47+
48+
///
49+
// Notifies the client of download progress. |current| denotes the number of
50+
// bytes received up to the call and |total| is the expected total size of the
51+
// response (or -1 if not determined).
52+
///
53+
/*--cef()--*/
54+
virtual void OnDownloadProgress(CefRefPtr<CefURLRequest> request,
55+
uint64 current,
56+
uint64 total) OVERRIDE;
57+
58+
///
59+
// Called when some part of the response is read. |data| contains the current
60+
// bytes received since the last call. This method will not be called if the
61+
// UR_FLAG_NO_DOWNLOAD_DATA flag is set on the request.
62+
///
63+
/*--cef()--*/
64+
virtual void OnDownloadData(CefRefPtr<CefURLRequest> request,
65+
const void* data,
66+
size_t data_length) OVERRIDE;
67+
68+
protected:
69+
// Include the default reference counting implementation.
70+
IMPLEMENT_REFCOUNTING(WebRequestClient);
71+
};

cefpython/cef3/linux/setup/cefpython.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ __PYX_EXTERN_C DL_IMPORT(bool) ResourceHandler_ReadResponse(int, void *, int, in
5858
__PYX_EXTERN_C DL_IMPORT(bool) ResourceHandler_CanGetCookie(int, CefCookie const &);
5959
__PYX_EXTERN_C DL_IMPORT(bool) ResourceHandler_CanSetCookie(int, CefCookie const &);
6060
__PYX_EXTERN_C DL_IMPORT(void) ResourceHandler_Cancel(int);
61+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnUploadProgress(int, CefRefPtr<CefURLRequest>, uint64, uint64);
62+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnDownloadProgress(int, CefRefPtr<CefURLRequest>, uint64, uint64);
63+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnDownloadData(int, CefRefPtr<CefURLRequest>, void const *, size_t);
64+
__PYX_EXTERN_C DL_IMPORT(void) WebRequestClient_OnRequestComplete(int, CefRefPtr<CefURLRequest>);
6165

6266
#endif /* !__PYX_HAVE_API__cefpython_py27 */
6367

cefpython/cefpython.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ IF CEF_VERSION == 1:
127127
include "load_handler_cef1.pyx"
128128
include "keyboard_handler_cef1.pyx"
129129
include "request_cef1.pyx"
130-
include "web_request.pyx"
130+
include "web_request_cef1.pyx"
131131
include "stream.pyx"
132132
include "content_filter.pyx"
133133
include "request_handler_cef1.pyx"
@@ -169,6 +169,7 @@ IF CEF_VERSION == 3:
169169
include "callback_cef3.pyx"
170170
include "resource_handler_cef3.pyx"
171171
include "response_cef3.pyx"
172+
include "web_request_cef3.pyx"
172173

173174
# Try not to run any of the CEF code until Initialize() is called.
174175
# Do not allocate any memory on the heap until Initialize() is called,

cefpython/content_filter.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ cdef public void ContentFilterHandler_ProcessData(
8989
callback = contentFilter.GetCallback("OnData")
9090
if callback:
9191
pyStreamReader = PyStreamReader()
92-
callback(VoidPtrToStr(data, data_size), pyStreamReader)
92+
callback(VoidPtrToString(data, data_size), pyStreamReader)
9393
if pyStreamReader.HasCefStreamReader():
9494
substitute_data.swap(pyStreamReader.GetCefStreamReader())
9595
except:

cefpython/cython_includes/cef_types_cef3.pxd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ cdef extern from "include/internal/cef_types.h":
2626
TID_IO,
2727
TID_RENDERER
2828

29-
ctypedef long long int64
3029
ctypedef unsigned int uint32
3130
ctypedef int int32
31+
ctypedef long long int64
32+
ctypedef unsigned long long uint64
3233

3334
IF UNAME_SYSNAME == "Windows":
3435
ctypedef wchar_t char16
@@ -208,3 +209,11 @@ cdef extern from "include/internal/cef_types.h":
208209
cef_rect_t rect
209210
cef_rect_t available_rect
210211
ctypedef cef_screen_info_t CefScreenInfo
212+
213+
# CefURLRequest.GetStatus()
214+
enum cef_urlrequest_status_t:
215+
UR_UNKNOWN = 0
216+
UR_SUCCESS
217+
UR_IO_PENDING
218+
UR_CANCELED
219+
UR_FAILED

0 commit comments

Comments
 (0)