From 5f7a3f1cb723542c7254c82741fbd560e575cd47 Mon Sep 17 00:00:00 2001 From: cztomczak Date: Fri, 25 May 2018 09:03:26 +0200 Subject: [PATCH] RequestHandler.OnBeforeBrowse hsa a new param 'user_gesture' (#403) --- api/RequestHandler.md | 21 ++++++++++++--------- docs/Migration-guide.md | 17 +++++++++++++---- src/cef_v59..v66_changes.txt | 6 +++--- src/client_handler/request_handler.cpp | 4 +++- src/client_handler/request_handler.h | 1 + src/handlers/request_handler.pyx | 8 ++++---- 6 files changed, 36 insertions(+), 21 deletions(-) diff --git a/api/RequestHandler.md b/api/RequestHandler.md index 01b2ea99..6a7c145d 100644 --- a/api/RequestHandler.md +++ b/api/RequestHandler.md @@ -44,18 +44,21 @@ Table of contents: | browser | [Browser](Browser.md) | | frame | [Frame](Frame.md) | | request | [Request](Request.md) | +| user_gesture | bool | | is_redirect | bool | | __Return__ | bool | -Called on the UI thread before browser navigation. Return true to cancel -the navigation or false to allow the navigation to proceed. The |request| -object cannot be modified in this callback. -[DisplayHandler](DisplayHandler.md).`OnLoadingStateChange` will be -called twice in all cases. -If the navigation is allowed [LoadHandler](LoadHandler.md).`OnLoadStart` and -`OnLoadEnd` will be called. If the navigation is canceled -[LoadHandler](LoadHandler.md).`OnLoadError` will be called with -an |error_code| value of ERR_ABORTED. +Description from upstream CEF: +> Called on the UI thread before browser navigation. Return true to cancel +> the navigation or false to allow the navigation to proceed. The |request| +> object cannot be modified in this callback. +> CefLoadHandler::OnLoadingStateChange will be called twice in all cases. +> If the navigation is allowed CefLoadHandler::OnLoadStart and +> CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled +> CefLoadHandler::OnLoadError will be called with an |errorCode| value of +> ERR_ABORTED. The |user_gesture| value will be true if the browser +> navigated via explicit user gesture (e.g. clicking a link) or false if it +> navigated automatically (e.g. via the DomContentLoaded event). ### OnBeforeResourceLoad diff --git a/docs/Migration-guide.md b/docs/Migration-guide.md index e6b804ce..6b0d7660 100644 --- a/docs/Migration-guide.md +++ b/docs/Migration-guide.md @@ -33,12 +33,13 @@ Table of contents: * [v54+ GTK 3 example doesn't work anymore on Linux](#v54-gtk-3-example-doesnt-work-anymore-on-linux) * [v54+ libcef.so library is stripped from symbols on Linux](#v54-libcefso-library-is-stripped-from-symbols-on-linux) * [v55+ HTTPS cache problems on pages with certificate errors](#v55-https-cache-problems-on-pages-with-certificate-errors) -* [v55.3+ Handlers' callbacks and other interfaces](#v553-handlers-callbacks-and-other-interfaces) +* [v55.3+ Handlers' callbacks and other interfaces are now called using keyword args](#v553-handlers-callbacks-and-other-interfaces-are-now-called-using-keyword-args) * [v56+ MacOS 10.9+ required to run](#v56-macos-109-required-to-run) * [v57.1+ High DPI support on Windows](#v571-high-dpi-support-on-windows) * [v66+ Linux patch that fixed HTTPS cache problems on pages with certificate errors was disabled](#v66-linux-patch-that-fixed-https-cache-problems-on-pages-with-certificate-errors-was-disabled) -* [v66+ DisplayHandler.OnConsoleMessage has new param 'level'](#v66-displayhandleronconsolemessage-has-new-param-level) +* [v66+ DisplayHandler.OnConsoleMessage has a new param 'level'](#v66-displayhandleronconsolemessage-has-a-new-param-level) * [v66+ LifespanHandler.OnBeforePopup is now called on UI thread](#v66-lifespanhandleronbeforepopup-is-now-called-on-ui-thread) +* [V66+ RequestHandler.OnBeforeBrowse has a new param 'user_gesture'](#v66-requesthandleronbeforebrowse-has-a-new-param-user_gesture) @@ -212,6 +213,8 @@ API ref: Request.[GetHeaderMap](../api/Request.md#getheadermap) ## v54+ GTK 3 example doesn't work anymore on Linux +Update: GTK 3 example is back working in v57+. + Currently GTK 3 example is broken on Linux. You can either downgrade to an old cefpython v53 (available on GitHub release page) or use GTK 2 example. For more details on the problem see @@ -236,7 +239,7 @@ cefpython starts using CEF prebuilt binaries from Spotify. See Issue [#125](../../../issues/125) for more details. -## v55.3+ Handlers' callbacks and other interfaces +## v55.3+ Handlers' callbacks and other interfaces are now called using keyword args Since v55.3 all handlers' callbacks and other interfaces such as CookieVisitor, StringVisitor and WebRequestClient, are now called @@ -308,7 +311,7 @@ If you need this feature then you can build from sources and apply the patch yourself. See Issue [#125](../../../issues/125) for more details. -## v66+ DisplayHandler.OnConsoleMessage has new param 'level' +## v66+ DisplayHandler.OnConsoleMessage has a new param 'level' The DisplayHandler.[OnConsoleMessage](../api/DisplayHandler.md#onconsolemessage) callback has a new param `level`. @@ -320,3 +323,9 @@ The LifespanHandler.[OnBeforePopup](../api/LifespanHandler.md#onbeforepopup) callback is now called on UI thread. Previously it was called on IO thread. + +## V66+ RequestHandler.OnBeforeBrowse has a new param 'user_gesture' + +The RequestHandler.[OnBeforeBrowse](../api/RequestHandler.md#onbeforebrowse) +callback has a new param `user_gesture`. + diff --git a/src/cef_v59..v66_changes.txt b/src/cef_v59..v66_changes.txt index 51b7daa0..2ae04d86 100644 --- a/src/cef_v59..v66_changes.txt +++ b/src/cef_v59..v66_changes.txt @@ -23,9 +23,9 @@ BREAKAGE (needs updating Migration Guide doc) + cef_render_process_handler.h - + Remove OnBeforeNavigation in subprocess/cefpython_app.h and .cpp files -cef_request_handler.h -- OnBeforeBrowse: new param 'user_gesture' -- update Migration Guide ++ cef_request_handler.h +- + OnBeforeBrowse: new param 'user_gesture' +- + update Migration Guide internal/cef_linux.h internal/cef_types_linux.h diff --git a/src/client_handler/request_handler.cpp b/src/client_handler/request_handler.cpp index c06e098d..ea681559 100644 --- a/src/client_handler/request_handler.cpp +++ b/src/client_handler/request_handler.cpp @@ -9,10 +9,12 @@ bool RequestHandler::OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, + bool user_gesture, bool is_redirect) { REQUIRE_UI_THREAD(); - return RequestHandler_OnBeforeBrowse(browser, frame, request, is_redirect); + return RequestHandler_OnBeforeBrowse(browser, frame, request, + user_gesture, is_redirect); } diff --git a/src/client_handler/request_handler.h b/src/client_handler/request_handler.h index afaf3f83..a56760b2 100644 --- a/src/client_handler/request_handler.h +++ b/src/client_handler/request_handler.h @@ -17,6 +17,7 @@ class RequestHandler : public CefRequestHandler bool OnBeforeBrowse(CefRefPtr browser, CefRefPtr frame, CefRefPtr request, + bool user_gesture, bool is_redirect) override; ReturnValue OnBeforeResourceLoad(CefRefPtr browser, diff --git a/src/handlers/request_handler.pyx b/src/handlers/request_handler.pyx index 0df1d867..ff8799c2 100644 --- a/src/handlers/request_handler.pyx +++ b/src/handlers/request_handler.pyx @@ -59,26 +59,26 @@ cdef public cpp_bool RequestHandler_OnBeforeBrowse( CefRefPtr[CefBrowser] cefBrowser, CefRefPtr[CefFrame] cefFrame, CefRefPtr[CefRequest] cefRequest, - cpp_bool cefIsRedirect + cpp_bool user_gesture, + cpp_bool is_redirect ) 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, "OnBeforeBrowse") pyFrame = GetPyFrame(cefFrame) pyRequest = CreatePyRequest(cefRequest) - pyIsRedirect = bool(cefIsRedirect) clientCallback = pyBrowser.GetClientCallback("OnBeforeBrowse") if clientCallback: returnValue = clientCallback( browser=pyBrowser, frame=pyFrame, request=pyRequest, - is_redirect=pyIsRedirect) + user_gesture=user_gesture, + is_redirect=is_redirect) return bool(returnValue) else: return False