roadlabs / cefpython

Automatically exported from code.google.com/p/cefpython
0 stars 0 forks source link

Basic support for OnBeforePopup #93

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Patch that adds support for OnBeforePopup callback to cef3.

Includes a simple modification to wxpython.py demonstrating how to use it.

Only passes the Browser and URL arguments. Other arguments exist that other 
people may find useful to add to this.

Original issue reported on code.google.com by gregfarr...@gmail.com on 7 Nov 2013 at 4:32

Attachments:

GoogleCodeExporter commented 9 years ago
If supporting this callback partially it would be a good idea to have complete 
list of arguments passed, those not implemented could just be passed as None 
values. I think that these arguments can already be passed without any hassle: 
browser, frame, target_url, target_frame_name, no_javascript_access. All the 
other could just pass None: popupFeatures, windowInfo, client, settings.

Original comment by czarek.t...@gmail.com on 13 Nov 2013 at 12:06

GoogleCodeExporter commented 9 years ago
I've tried adding the extra arguments but I'm struggling with the cdef line for 
CefPopupFeatures.

Here's the snippet from lifespan_handler_cef3.pyx
I get a cython error of "lifespan_handler_cef3.pyx:27:14: 'CefPopupFeatures' is 
not a type identifier"
I've tried various options like cef_types.cef_popup_features_t but I don't 
really understand the cython code nor see why it doesn't recognise that type 
here.

I only want a way of correctly accepting  the argument as I'll be passing None 
onward to the python callback anyway as suggested.

Do you have any suggestion?

cdef public cpp_bool LifespanHandler_OnBeforePopup(
        CefRefPtr[CefBrowser] cefBrowser,
        CefRefPtr[CefFrame] cefFrame,
        const CefString& targetUrl,
        const CefString& target_frame_name,
        const CefPopupFeatures& popupFeatures,
        CefWindowInfo& windowInfo,
        CefRefPtr[CefClient]& client,
        CefBrowserSettings& settings,
        cpp_bool* no_javascript_access
        ) except * with gil:
    cdef PyBrowser pyBrowser
    cdef PyFrame pyFrame,
    cdef py_string pyTargetUrl
    cdef py_string pyTargetFrameName
    cdef py_bool pyNoJavascriptAccess
    cdef object callback
    cdef py_bool returnValue
    try:
        callback = pyBrowser.GetClientCallback("OnBeforePopup")
        if callback:
            pyBrowser = GetPyBrowser(cefBrowser)
            pyFrame = GetPyFrame(cefFrame)
            pyTargetUrl = CefToPyString(targetUrl)
            pyTargetFrameName = CefToPyString(target_frame_name)
            pyNoJavascriptAccess = bool(no_javascript_access)
            return bool(callback(pyBrowser, pyFrame, pyTargetUrl,
                pyTargetFrameName, None, None, None, None,
                pyNoJavascriptAccess))
    except:
        (exc_type, exc_value, exc_trace) = sys.exc_info()
        sys.excepthook(exc_type, exc_value, exc_trace)
    return False;

Original comment by gregfarr...@gmail.com on 13 Nov 2013 at 4:36

GoogleCodeExporter commented 9 years ago
You could just pass NULL and declare the popupFeatures argument as an int in 
the pyx file.

Original comment by czarek.t...@gmail.com on 13 Nov 2013 at 5:39

GoogleCodeExporter commented 9 years ago
Here's a further version that passes those arguments that can be passed without 
creating new classes, and passes None for the remainder.

Original comment by gregfarr...@gmail.com on 14 Nov 2013 at 12:05

Attachments:

GoogleCodeExporter commented 9 years ago
Some additional modifications were made. The no_javascript_access is an out 
variable, py_bool was specified, but should be list. In 
LifespanHandler_OnBeforePopup when returning bool variable it needs to be 
casted with bool() otherwise warnings appear when compiling. Added 
OnBeforePopup example also to windows/wxpython.py. Added print statements in 
OnBeforePopup wx example, as all other callbacks have them. Variables camel 
case fixes, indentation and other minor fixes.

Updated LifeSpanHandler wiki page.

Commited as revision f8abf0d73a64:
https://code.google.com/p/cefpython/source/detail?r=f8abf0d73a646993e67065f1138e
24bf9ae3691a

Thank you for the patch.

Original comment by czarek.t...@gmail.com on 16 Dec 2013 at 12:58