Skip to content

Commit

Permalink
RequestHandler.OnBeforeBrowse hsa a new param 'user_gesture' (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
cztomczak committed May 25, 2018
1 parent 44a74ad commit 5f7a3f1
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 21 deletions.
21 changes: 12 additions & 9 deletions api/RequestHandler.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions docs/Migration-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)



Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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`.
Expand All @@ -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`.

6 changes: 3 additions & 3 deletions src/cef_v59..v66_changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/client_handler/request_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
bool RequestHandler::OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> 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);
}


Expand Down
1 change: 1 addition & 0 deletions src/client_handler/request_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RequestHandler : public CefRequestHandler
bool OnBeforeBrowse(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
bool user_gesture,
bool is_redirect) override;

ReturnValue OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/request_handler.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5f7a3f1

Please sign in to comment.