FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cefpython/src/request_handler.pyx at cefpython52 · pythonthings/cefpython · GitHub
pythonthings
cefpython
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cefpython
/
src
/
request_handler.pyx
Copy path
More file actions
More file actions
Latest commit
History
History
History
399 lines (374 loc) · 15.1 KB
Breadcrumbs
cefpython
/
src
/
request_handler.pyx
Copy path
File metadata and controls
399 lines (374 loc) · 15.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
#
Copyright (c) 2012-2014 The CEF Python authors. All rights reserved.
#
License: New BSD License.
#
Website: http://code.google.com/p/cefpython/
include
"
cefpython.pyx
"
#
cef_termination_status_t
cimport cef_types
TS_ABNORMAL_TERMINATION
=
cef_types.TS_ABNORMAL_TERMINATION
TS_PROCESS_WAS_KILLED
=
cef_types.TS_PROCESS_WAS_KILLED
TS_PROCESS_CRASHED
=
cef_types.TS_PROCESS_CRASHED
#
-----------------------------------------------------------------------------
#
PyAuthCallback
#
-----------------------------------------------------------------------------
cdef PyAuthCallback CreatePyAuthCallback(
CefRefPtr[CefAuthCallback] cefCallback):
cdef PyAuthCallback pyCallback
=
PyAuthCallback()
pyCallback.cefCallback
=
cefCallback
return
pyCallback
cdef
class
PyAuthCallback:
cdef CefRefPtr[CefAuthCallback] cefCallback
cpdef py_void Continue(
self
, py_string username, py_string password):
self
.cefCallback.get().Continue(
PyToCefStringValue(username),
PyToCefStringValue(password))
cpdef py_void Cancel(
self
):
self
.cefCallback.get().Cancel()
#
-----------------------------------------------------------------------------
#
PyRequestCallback
#
-----------------------------------------------------------------------------
cdef PyRequestCallback CreatePyRequestCallback(
CefRefPtr[CefRequestCallback] cefCallback):
cdef PyRequestCallback pyCallback
=
PyRequestCallback()
pyCallback.cefCallback
=
cefCallback
return
pyCallback
cdef
class
PyRequestCallback:
cdef CefRefPtr[CefRequestCallback] cefCallback
cpdef py_void Continue(
self
, py_bool allow):
self
.cefCallback.get().Continue(
bool
(allow))
cpdef py_void Cancel(
self
):
self
.cefCallback.get().Cancel()
#
-----------------------------------------------------------------------------
#
RequestHandler
#
-----------------------------------------------------------------------------
cdef public cpp_bool RequestHandler_OnBeforeResourceLoad(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
CefRefPtr[CefRequest] cefRequest
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef PyRequest pyRequest
cdef
object
clientCallback
cdef py_bool returnValue
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyFrame
=
GetPyFrame(cefFrame)
pyRequest
=
CreatePyRequest(cefRequest)
clientCallback
=
pyBrowser.GetClientCallback(
"
OnBeforeResourceLoad
"
)
if
clientCallback:
returnValue
=
clientCallback(pyBrowser, pyFrame, pyRequest)
return
bool
(returnValue)
else
:
return
False
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RequestHandler_OnBeforeBrowse(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
CefRefPtr[CefRequest] cefRequest,
cpp_bool cefIsRedirect
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef PyRequest pyRequest
cdef py_bool pyIsRedirect
cdef
object
clientCallback
cdef py_bool returnValue
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyFrame
=
GetPyFrame(cefFrame)
pyRequest
=
CreatePyRequest(cefRequest)
pyIsRedirect
=
bool
(cefIsRedirect)
clientCallback
=
pyBrowser.GetClientCallback(
"
OnBeforeBrowse
"
)
if
clientCallback:
returnValue
=
clientCallback(pyBrowser, pyFrame, pyRequest,
pyIsRedirect)
return
bool
(returnValue)
else
:
return
False
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public CefRefPtr[CefResourceHandler] RequestHandler_GetResourceHandler(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
CefRefPtr[CefRequest] cefRequest
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef PyRequest pyRequest
cdef
object
clientCallback
cdef
object
returnValue
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyFrame
=
GetPyFrame(cefFrame)
pyRequest
=
CreatePyRequest(cefRequest)
clientCallback
=
pyBrowser.GetClientCallback(
"
GetResourceHandler
"
)
if
clientCallback:
returnValue
=
clientCallback(pyBrowser, pyFrame, pyRequest)
if
returnValue:
return
CreateResourceHandler(returnValue)
else
:
return
<
CefRefPtr[CefResourceHandler]
>
NULL
else
:
return
<
CefRefPtr[CefResourceHandler]
>
NULL
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public
void
RequestHandler_OnResourceRedirect(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
const CefString
&
cefOldUrl,
CefString
&
cefNewUrl,
CefRefPtr[CefRequest] cefRequest
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef
str
pyOldUrl
cdef
list
pyNewUrlOut
cdef PyRequest pyRequest
cdef
object
clientCallback
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyFrame
=
GetPyFrame(cefFrame)
pyOldUrl
=
CefToPyString(cefOldUrl)
pyNewUrlOut
=
[CefToPyString(cefNewUrl)]
pyRequest
=
CreatePyRequest(cefRequest)
clientCallback
=
pyBrowser.GetClientCallback(
"
OnResourceRedirect
"
)
if
clientCallback:
clientCallback(pyBrowser, pyFrame, pyOldUrl, pyNewUrlOut,
pyRequest)
if
pyNewUrlOut[
0
]:
PyToCefString(pyNewUrlOut[
0
], cefNewUrl)
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RequestHandler_GetAuthCredentials(
CefRefPtr[CefBrowser] cefBrowser,
CefRefPtr[CefFrame] cefFrame,
cpp_bool cefIsProxy,
const CefString
&
cefHost,
int
cefPort,
const CefString
&
cefRealm,
const CefString
&
cefScheme,
CefRefPtr[CefAuthCallback] cefAuthCallback
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef py_bool pyIsProxy
cdef
str
pyHost
cdef
int
pyPort
cdef
str
pyRealm
cdef
str
pyScheme
cdef PyAuthCallback pyAuthCallback
cdef py_bool returnValue
cdef
list
pyUsernameOut
cdef
list
pyPasswordOut
cdef
object
clientCallback
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyFrame
=
GetPyFrame(cefFrame)
pyIsProxy
=
bool
(cefIsProxy)
pyHost
=
CefToPyString(cefHost)
pyPort
=
int
(cefPort)
pyRealm
=
CefToPyString(cefRealm)
pyScheme
=
CefToPyString(cefScheme)
pyAuthCallback
=
CreatePyAuthCallback(cefAuthCallback)
pyUsernameOut
=
[
"
"
]
pyPasswordOut
=
[
"
"
]
clientCallback
=
pyBrowser.GetClientCallback(
"
GetAuthCredentials
"
)
if
clientCallback:
returnValue
=
clientCallback(
pyBrowser, pyFrame,
pyIsProxy, pyHost, pyPort, pyRealm, pyScheme,
pyAuthCallback)
return
bool
(returnValue)
else
:
#
TODO: port it from CEF 1, copy the cef1/http_authentication/.
#
--
#
Default implementation for Windows.
#
IF UNAME_SYSNAME == "Windows":
#
returnValue = HttpAuthenticationDialog(
#
pyBrowser,
#
pyIsProxy, pyHost, pyPort, pyRealm, pyScheme,
#
pyUsernameOut, pyPasswordOut)
#
if returnValue:
#
pyAuthCallback.Continue(pyUsernameOut[0], pyPasswordOut[0])
#
return True
#
return False
#
ELSE:
#
return False
return
False
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RequestHandler_OnQuotaRequest(
CefRefPtr[CefBrowser] cefBrowser,
const CefString
&
cefOriginUrl,
int64 newSize,
CefRefPtr[CefRequestCallback] cefRequestCallback
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef py_string pyOriginUrl
cdef py_bool returnValue
cdef
object
clientCallback
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyOriginUrl
=
CefToPyString(cefOriginUrl)
clientCallback
=
pyBrowser.GetClientCallback(
"
OnQuotaRequest
"
)
if
clientCallback:
returnValue
=
clientCallback(pyBrowser, pyOriginUrl,
long
(newSize),
CreatePyRequestCallback(cefRequestCallback))
return
bool
(returnValue)
else
:
return
False
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public CefRefPtr[CefCookieManager] RequestHandler_GetCookieManager(
CefRefPtr[CefBrowser] cefBrowser,
const CefString
&
cefMainUrl
)
except
*
with
gil:
#
In CEF the GetCookieManager callback belongs to
#
CefRequestContextHandler.
#
In an exceptional case the browser parameter may be None
#
due to limitation in CEF API. No workaround as of now.
cdef PyBrowser pyBrowser
cdef
str
pyMainUrl
cdef
object
clientCallback
cdef PyCookieManager returnValue
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyMainUrl
=
CefToPyString(cefMainUrl)
if
pyBrowser:
#
Browser may be empty.
clientCallback
=
pyBrowser.GetClientCallback(
"
GetCookieManager
"
)
if
clientCallback:
returnValue
=
clientCallback(pyBrowser, pyMainUrl)
if
returnValue:
if
isinstance
(returnValue, PyCookieManager):
return
returnValue.cefCookieManager
else
:
raise
Exception
(
"
Expected a CookieManager object
"
)
return
<
CefRefPtr[CefCookieManager]
>
NULL
else
:
return
<
CefRefPtr[CefCookieManager]
>
NULL
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public
void
RequestHandler_OnProtocolExecution(
CefRefPtr[CefBrowser] cefBrowser,
const CefString
&
cefUrl,
cpp_bool
&
cefAllowOSExecution
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef
str
pyUrl
cdef
list
pyAllowOSExecutionOut
cdef
object
clientCallback
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
pyUrl
=
CefToPyString(cefUrl)
pyAllowOSExecutionOut
=
[
bool
(cefAllowOSExecution)]
clientCallback
=
pyBrowser.GetClientCallback(
"
OnProtocolExecution
"
)
if
clientCallback:
clientCallback(pyBrowser, pyUrl, pyAllowOSExecutionOut)
#
Since Cython 0.17.4 assigning a value to an argument
#
passed by reference will throw an error, the fix is to
#
to use "(&arg)[0] =" instead of "arg =", see this topic:
#
https://groups.google.com/forum/#!msg/cython-users/j58Sp3QMrD4/y9vJy9YBi_kJ
#
For CefRefPtr you should use swap() method instead.
(
&
cefAllowOSExecution)[
0
]
=
1
#
(&cefAllowOSExecution)[0] = <cpp_bool>bool(pyAllowOSExecutionOut[0])
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RequestHandler_OnBeforePluginLoad(
CefRefPtr[CefBrowser] browser,
const CefString
&
mime_type,
const CefString
&
plugin_url,
const CefString
&
top_origin_url,
CefRefPtr[CefWebPluginInfo] plugin_info,
cef_types.cef_plugin_policy_t
*
plugin_policy
)
except
*
with
gil:
cdef PyBrowser pyBrowser
cdef PyWebPluginInfo pyInfo
cdef py_bool returnValue
cdef
object
clientCallback
try
:
py_browser
=
GetPyBrowser(browser)
py_plugin_info
=
CreatePyWebPluginInfo(plugin_info)
clientCallback
=
GetGlobalClientCallback(
"
OnBeforePluginLoad
"
)
if
clientCallback:
returnValue
=
clientCallback(
py_browser,
CefToPyString(mime_type),
CefToPyString(plugin_url),
CefToPyString(top_origin_url),
py_plugin_info)
if
returnValue:
plugin_policy[
0
]
=
cef_types.PLUGIN_POLICY_DISABLE
return
bool
(returnValue)
else
:
return
False
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public cpp_bool RequestHandler_OnCertificateError(
int
certError,
const CefString
&
cefRequestUrl,
CefRefPtr[CefRequestCallback] cefCertCallback
)
except
*
with
gil:
cdef py_bool returnValue
cdef
object
clientCallback
try
:
clientCallback
=
GetGlobalClientCallback(
"
OnCertificateError
"
)
if
clientCallback:
returnValue
=
clientCallback(certError,
CefToPyString(cefRequestUrl),
CreatePyRequestCallback(cefCertCallback))
return
bool
(returnValue)
else
:
return
False
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public
void
RequestHandler_OnRendererProcessTerminated(
CefRefPtr[CefBrowser] cefBrowser,
cef_types.cef_termination_status_t cefStatus
)
except
*
with
gil:
#
TODO: proccess may crash during browser creation. Let this callback
#
to be set either through cefpython.SetGlobalClientCallback()
#
or PyBrowser.SetClientCallback(). Modify the
#
PyBrowser.GetClientCallback() implementation to return a global
#
callback first if set.
cdef PyBrowser pyBrowser
cdef
object
clientCallback
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
clientCallback
=
pyBrowser.GetClientCallback(
"
OnRendererProcessTerminated
"
)
if
clientCallback:
clientCallback(pyBrowser, cefStatus)
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
cdef public
void
RequestHandler_OnPluginCrashed(
CefRefPtr[CefBrowser] cefBrowser,
const CefString
&
cefPluginPath
)
except
*
with
gil:
#
TODO: plugin may crash during browser creation. Let this callback
#
to be set either through cefpython.SetGlobalClientCallback()
#
or PyBrowser.SetClientCallback(). Modify the
#
PyBrowser.GetClientCallback() implementation to return a global
#
callback first if set.
cdef PyBrowser pyBrowser
cdef
object
clientCallback
try
:
pyBrowser
=
GetPyBrowser(cefBrowser)
clientCallback
=
pyBrowser.GetClientCallback(
"
OnPluginCrashed
"
)
if
clientCallback:
clientCallback(pyBrowser, CefToPyString(cefPluginPath))
except
:
(exc_type, exc_value, exc_trace)
=
sys.exc_info()
sys.excepthook(exc_type, exc_value, exc_trace)
Back
|
FazBrowse Home
|
New Git URL