| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 66107b2 commit a276fd8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,20 @@ cdef PyBrowser GetPyBrowserById(int browserId): | |||
| 33 | 33 | return g_pyBrowsers[browserId] | |
| 34 | 34 | return None | |
| 35 | 35 | ||
| 36 | + cdef py_bool IsBrowserClosed(CefRefPtr[CefBrowser] cefBrowser): | ||
| 37 | + """Possibly fix Issue #455 by using this helper function to detect | ||
| 38 | + if browser is closing/closed.""" | ||
| 39 | + # CefBrowser may sometimes be NULL e.g. Issue #429, Issue #454. | ||
| 40 | + if not cefBrowser.get(): | ||
| 41 | + return True | ||
| 42 | + if not cefBrowser.get().GetHost().get(): | ||
| 43 | + return True | ||
| 44 | + cdef int browserId = cefBrowser.get().GetIdentifier() | ||
| 45 | + if browserId in g_unreferenced_browsers \ | ||
| 46 | + or browserId in g_closed_browsers: | ||
| 47 | + return True | ||
| 48 | + return False | ||
| 49 | + | ||
| 36 | 50 | cdef PyBrowser GetPyBrowser(CefRefPtr[CefBrowser] cefBrowser, | |
| 37 | 51 | callerIdStr="GetPyBrowser"): | |
| 38 | 52 | """The second argument 'callerIdStr' is so that a debug | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -68,6 +68,11 @@ cdef public cpp_bool RequestHandler_OnBeforeBrowse( | |||
| 68 | 68 | cdef object clientCallback | |
| 69 | 69 | cdef py_bool returnValue | |
| 70 | 70 | try: | |
| 71 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 72 | + # browser was closed. | ||
| 73 | + if IsBrowserClosed(cefBrowser): | ||
| 74 | + return False | ||
| 75 | + | ||
| 71 | 76 | pyBrowser = GetPyBrowser(cefBrowser, "OnBeforeBrowse") | |
| 72 | 77 | pyFrame = GetPyFrame(cefFrame) | |
| 73 | 78 | pyRequest = CreatePyRequest(cefRequest) | |
@@ -98,6 +103,11 @@ cdef public cpp_bool RequestHandler_OnBeforeResourceLoad( | |||
| 98 | 103 | cdef object clientCallback | |
| 99 | 104 | cdef py_bool returnValue | |
| 100 | 105 | try: | |
| 106 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 107 | + # browser was closed. | ||
| 108 | + if IsBrowserClosed(cefBrowser): | ||
| 109 | + return False | ||
| 110 | + | ||
| 101 | 111 | pyBrowser = GetPyBrowser(cefBrowser, "OnBeforeResourceLoad") | |
| 102 | 112 | pyFrame = GetPyFrame(cefFrame) | |
| 103 | 113 | pyRequest = CreatePyRequest(cefRequest) | |
@@ -126,6 +136,11 @@ cdef public CefRefPtr[CefResourceHandler] RequestHandler_GetResourceHandler( | |||
| 126 | 136 | cdef object clientCallback | |
| 127 | 137 | cdef object returnValue | |
| 128 | 138 | try: | |
| 139 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 140 | + # browser was closed. | ||
| 141 | + if IsBrowserClosed(cefBrowser): | ||
| 142 | + return <CefRefPtr[CefResourceHandler]>NULL | ||
| 143 | + | ||
| 129 | 144 | pyBrowser = GetPyBrowser(cefBrowser, "GetResourceHandler") | |
| 130 | 145 | pyFrame = GetPyFrame(cefFrame) | |
| 131 | 146 | pyRequest = CreatePyRequest(cefRequest) | |
@@ -162,6 +177,11 @@ cdef public void RequestHandler_OnResourceRedirect( | |||
| 162 | 177 | cdef PyResponse pyResponse | |
| 163 | 178 | cdef object clientCallback | |
| 164 | 179 | try: | |
| 180 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 181 | + # browser was closed. | ||
| 182 | + if IsBrowserClosed(cefBrowser): | ||
| 183 | + return | ||
| 184 | + | ||
| 165 | 185 | pyBrowser = GetPyBrowser(cefBrowser, "OnResourceRedirect") | |
| 166 | 186 | pyFrame = GetPyFrame(cefFrame) | |
| 167 | 187 | pyOldUrl = CefToPyString(cefOldUrl) | |
@@ -207,6 +227,11 @@ cdef public cpp_bool RequestHandler_GetAuthCredentials( | |||
| 207 | 227 | cdef list pyPasswordOut | |
| 208 | 228 | cdef object clientCallback | |
| 209 | 229 | try: | |
| 230 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 231 | + # browser was closed. | ||
| 232 | + if IsBrowserClosed(cefBrowser): | ||
| 233 | + return False | ||
| 234 | + | ||
| 210 | 235 | pyBrowser = GetPyBrowser(cefBrowser, "GetAuthCredentials") | |
| 211 | 236 | pyFrame = GetPyFrame(cefFrame) | |
| 212 | 237 | pyIsProxy = bool(cefIsProxy) | |
@@ -261,6 +286,11 @@ cdef public cpp_bool RequestHandler_OnQuotaRequest( | |||
| 261 | 286 | cdef py_bool returnValue | |
| 262 | 287 | cdef object clientCallback | |
| 263 | 288 | try: | |
| 289 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 290 | + # browser was closed. | ||
| 291 | + if IsBrowserClosed(cefBrowser): | ||
| 292 | + return False | ||
| 293 | + | ||
| 264 | 294 | pyBrowser = GetPyBrowser(cefBrowser, "OnQuotaRequest") | |
| 265 | 295 | pyOriginUrl = CefToPyString(cefOriginUrl) | |
| 266 | 296 | clientCallback = pyBrowser.GetClientCallback("OnQuotaRequest") | |
@@ -291,10 +321,16 @@ cdef public CefRefPtr[CefCookieManager] RequestHandler_GetCookieManager( | |||
| 291 | 321 | cdef object clientCallback | |
| 292 | 322 | cdef PyCookieManager returnValue | |
| 293 | 323 | try: | |
| 324 | + # Issue #429: in some cases due to a race condition the browser | ||
| 325 | + # may be NULL. | ||
| 294 | 326 | if not cefBrowser.get(): | |
| 295 | - # Bug: In some cases due to a race condition the browser | ||
| 296 | - # may be NULL. Issue #429. | ||
| 297 | 327 | return <CefRefPtr[CefCookieManager]>NULL | |
| 328 | + | ||
| 329 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 330 | + # browser was closed. | ||
| 331 | + if IsBrowserClosed(cefBrowser): | ||
| 332 | + return <CefRefPtr[CefCookieManager]>NULL | ||
| 333 | + | ||
| 298 | 334 | pyBrowser = GetPyBrowser(cefBrowser, "GetCookieManager") | |
| 299 | 335 | pyMainUrl = CefToPyString(cefMainUrl) | |
| 300 | 336 | clientCallback = pyBrowser.GetClientCallback("GetCookieManager") | |
@@ -325,6 +361,11 @@ cdef public void RequestHandler_OnProtocolExecution( | |||
| 325 | 361 | cdef list pyAllowOSExecutionOut | |
| 326 | 362 | cdef object clientCallback | |
| 327 | 363 | try: | |
| 364 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 365 | + # browser was closed. | ||
| 366 | + if IsBrowserClosed(cefBrowser): | ||
| 367 | + return | ||
| 368 | + | ||
| 328 | 369 | pyBrowser = GetPyBrowser(cefBrowser, "OnProtocolExecution") | |
| 329 | 370 | pyUrl = CefToPyString(cefUrl) | |
| 330 | 371 | pyAllowOSExecutionOut = [bool(cefAllowOSExecution)] | |
@@ -369,6 +410,12 @@ cdef public cpp_bool RequestHandler_OnBeforePluginLoad( | |||
| 369 | 410 | Debug("WARNING: RequestHandler_OnBeforePluginLoad() failed," | |
| 370 | 411 | " Browser object is not available") | |
| 371 | 412 | return False | |
| 413 | + | ||
| 414 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 415 | + # browser was closed. | ||
| 416 | + if IsBrowserClosed(browser): | ||
| 417 | + return False | ||
| 418 | + | ||
| 372 | 419 | py_browser = GetPyBrowser(browser, "OnBeforePluginLoad") | |
| 373 | 420 | py_plugin_info = CreatePyWebPluginInfo(plugin_info) | |
| 374 | 421 | clientCallback = GetGlobalClientCallback("OnBeforePluginLoad") | |
@@ -424,6 +471,11 @@ cdef public void RequestHandler_OnRendererProcessTerminated( | |||
| 424 | 471 | cdef PyBrowser pyBrowser | |
| 425 | 472 | cdef object clientCallback | |
| 426 | 473 | try: | |
| 474 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 475 | + # browser was closed. | ||
| 476 | + if IsBrowserClosed(cefBrowser): | ||
| 477 | + return | ||
| 478 | + | ||
| 427 | 479 | pyBrowser = GetPyBrowser(cefBrowser, "OnRendererProcessTerminated") | |
| 428 | 480 | clientCallback = pyBrowser.GetClientCallback( | |
| 429 | 481 | "OnRendererProcessTerminated") | |
@@ -439,13 +491,18 @@ cdef public void RequestHandler_OnPluginCrashed( | |||
| 439 | 491 | const CefString& cefPluginPath | |
| 440 | 492 | ) except * with gil: | |
| 441 | 493 | # TODO: plugin may crash during browser creation. Let this callback | |
| 442 | - # to be set either through cefpython.SetGlobalClientCallback() | ||
| 494 | + # to be set either through cefpython.SetGlobalClientCallback() | ||
| 443 | 495 | # or PyBrowser.SetClientCallback(). Modify the | |
| 444 | 496 | # PyBrowser.GetClientCallback() implementation to return a global | |
| 445 | 497 | # callback first if set. | |
| 446 | 498 | cdef PyBrowser pyBrowser | |
| 447 | 499 | cdef object clientCallback | |
| 448 | 500 | try: | |
| 501 | + # Issue #455: CefRequestHandler callbacks still executed after | ||
| 502 | + # browser was closed. | ||
| 503 | + if IsBrowserClosed(cefBrowser): | ||
| 504 | + return | ||
| 505 | + | ||
| 449 | 506 | pyBrowser = GetPyBrowser(cefBrowser, "OnPluginCrashed") | |
| 450 | 507 | clientCallback = pyBrowser.GetClientCallback("OnPluginCrashed") | |
| 451 | 508 | if clientCallback: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments