Skip to content

Commit c385b49

Browse files
committed
Added LifespanHandler.OnBeforePopup, see issue 93. Thanks
to Greg Farrell for the patch. Improved readability of console logs in the wxpython example on Windows. Added some comments in Cython setup files.
1 parent 26e93be commit c385b49

12 files changed

Lines changed: 153 additions & 41 deletions

File tree

cefpython/browser.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ cdef class PyBrowser:
213213
self.allowedClientCallbacks += ["OnLoadStart", "OnLoadEnd",
214214
"OnLoadError", "OnRendererProcessTerminated",
215215
"OnPluginCrashed"]
216+
# LifespanHandler
217+
self.allowedClientCallbacks += ["OnBeforePopup"]
216218
# RenderHandler
217219
self.allowedClientCallbacks += ["GetRootScreenRect",
218220
"GetViewRect", "GetScreenPoint", "GetScreenInfo",

cefpython/cef1/linux/setup/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def CompileTimeConstants():
3535
"cefpython_py%s" % PYTHON_VERSION,
3636
["cefpython.pyx"],
3737

38+
# Ignore the warning in the console:
39+
# > C:\Python27\lib\distutils\extension.py:133: UserWarning:
40+
# > Unknown Extension options: 'cython_directives' warnings.warn(msg)
3841
cython_directives={
3942
# Any conversion to unicode must be explicit using .decode().
4043
"c_string_type": "bytes",

cefpython/cef1/windows/setup/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ def CompileTimeConstants():
5050
"cefpython_py%s" % PYTHON_VERSION,
5151
["cefpython.pyx"],
5252

53+
# Ignore the warning in the console:
54+
# > C:\Python27\lib\distutils\extension.py:133: UserWarning:
55+
# > Unknown Extension options: 'cython_directives' warnings.warn(msg)
5356
cython_directives={
5457
# Any conversion to unicode must be explicit using .decode().
5558
"c_string_type": "bytes",

cefpython/cef3/client_handler/client_handler.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,11 @@ bool ClientHandler::OnBeforePopup(CefRefPtr<CefBrowser> browser,
118118
CefRefPtr<CefClient>& client,
119119
CefBrowserSettings& settings,
120120
bool* no_javascript_access) {
121-
return false;
121+
REQUIRE_IO_THREAD();
122+
// Note: passing popupFeatures is not yet supported.
123+
return LifespanHandler_OnBeforePopup(browser, frame, target_url,
124+
target_frame_name, NULL, windowInfo, client, settings,
125+
no_javascript_access);
122126
}
123127

124128
///

cefpython/cef3/linux/binaries_32bit/wxpython.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,11 @@ def Visit(self, cookie, count, total, deleteCookie):
264264
return True
265265

266266
class ClientHandler:
267+
267268
# -------------------------------------------------------------------------
268269
# DisplayHandler
269270
# -------------------------------------------------------------------------
271+
270272
def OnLoadingStateChange(self, browser, isLoading, canGoBack,
271273
canGoForward):
272274
print("DisplayHandler::OnLoadingStateChange()")
@@ -309,6 +311,7 @@ def OnConsoleMessage(self, browser, message, source, line):
309311
# -------------------------------------------------------------------------
310312
# KeyboardHandler
311313
# -------------------------------------------------------------------------
314+
312315
def OnPreKeyEvent(self, browser, event, eventHandle,
313316
isKeyboardShortcutOut):
314317
print("KeyboardHandler::OnPreKeyEvent()")
@@ -325,6 +328,7 @@ def OnKeyEvent(self, browser, event, eventHandle):
325328
# -------------------------------------------------------------------------
326329
# RequestHandler
327330
# -------------------------------------------------------------------------
331+
328332
def OnBeforeResourceLoad(self, browser, frame, request):
329333
print("RequestHandler::OnBeforeResourceLoad()")
330334
print("url = %s" % request.GetUrl()[:70])
@@ -404,6 +408,7 @@ def _OnCertificateError(self, certError, requestUrl, callback):
404408
# -------------------------------------------------------------------------
405409
# LoadHandler
406410
# -------------------------------------------------------------------------
411+
407412
def OnLoadStart(self, browser, frame):
408413
print("LoadHandler::OnLoadStart()")
409414
print("frame url = %s" % frame.GetUrl()[:70])
@@ -439,6 +444,19 @@ def OnPluginCrashed(self, browser, pluginPath):
439444
print("LoadHandler::OnPluginCrashed()")
440445
print("plugin path = %s" % pluginPath)
441446

447+
# -------------------------------------------------------------------------
448+
# LifespanHandler
449+
# -------------------------------------------------------------------------
450+
451+
# Empty place-holders: popupFeatures, windowInfo, client, browserSettings.
452+
def OnBeforePopup(self, browser, frame, targetUrl, targetFrameName,
453+
popupFeatures, windowInfo, client, browserSettings, noJavascriptAccess):
454+
print("LifespanHandler::OnBeforePopup()")
455+
print("targetUrl = %s" % targetUrl)
456+
allowPopups = True
457+
return not allowPopups
458+
459+
442460
class MyApp(wx.App):
443461
timer = None
444462
timerID = 1

cefpython/cef3/linux/binaries_64bit/wxpython.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def PyCallback(self, *args):
209209
# -------------------------------------------------------------------------
210210
# Cookies
211211
# -------------------------------------------------------------------------
212+
212213
cookieVisitor = None
213214

214215
def VisitAllCookies(self):
@@ -264,9 +265,11 @@ def Visit(self, cookie, count, total, deleteCookie):
264265
return True
265266

266267
class ClientHandler:
268+
267269
# -------------------------------------------------------------------------
268270
# DisplayHandler
269271
# -------------------------------------------------------------------------
272+
270273
def OnLoadingStateChange(self, browser, isLoading, canGoBack,
271274
canGoForward):
272275
print("DisplayHandler::OnLoadingStateChange()")
@@ -309,6 +312,7 @@ def OnConsoleMessage(self, browser, message, source, line):
309312
# -------------------------------------------------------------------------
310313
# KeyboardHandler
311314
# -------------------------------------------------------------------------
315+
312316
def OnPreKeyEvent(self, browser, event, eventHandle,
313317
isKeyboardShortcutOut):
314318
print("KeyboardHandler::OnPreKeyEvent()")
@@ -325,6 +329,7 @@ def OnKeyEvent(self, browser, event, eventHandle):
325329
# -------------------------------------------------------------------------
326330
# RequestHandler
327331
# -------------------------------------------------------------------------
332+
328333
def OnBeforeResourceLoad(self, browser, frame, request):
329334
print("RequestHandler::OnBeforeResourceLoad()")
330335
print("url = %s" % request.GetUrl()[:70])
@@ -404,6 +409,7 @@ def _OnCertificateError(self, certError, requestUrl, callback):
404409
# -------------------------------------------------------------------------
405410
# LoadHandler
406411
# -------------------------------------------------------------------------
412+
407413
def OnLoadStart(self, browser, frame):
408414
print("LoadHandler::OnLoadStart()")
409415
print("frame url = %s" % frame.GetUrl()[:70])
@@ -439,6 +445,19 @@ def OnPluginCrashed(self, browser, pluginPath):
439445
print("LoadHandler::OnPluginCrashed()")
440446
print("plugin path = %s" % pluginPath)
441447

448+
# -------------------------------------------------------------------------
449+
# LifespanHandler
450+
# -------------------------------------------------------------------------
451+
452+
# Empty place-holders: popupFeatures, windowInfo, client, browserSettings.
453+
def OnBeforePopup(self, browser, frame, targetUrl, targetFrameName,
454+
popupFeatures, windowInfo, client, browserSettings, noJavascriptAccess):
455+
print("LifespanHandler::OnBeforePopup()")
456+
print("targetUrl = %s" % targetUrl)
457+
allowPopups = True
458+
return not allowPopups
459+
460+
442461
class MyApp(wx.App):
443462
timer = None
444463
timerID = 1

cefpython/cef3/linux/setup/cefpython.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ __PYX_EXTERN_C DL_IMPORT(void) V8FunctionHandler_Execute(CefRefPtr<CefBrowser>,
1818
__PYX_EXTERN_C DL_IMPORT(void) RemovePythonCallbacksForFrame(int);
1919
__PYX_EXTERN_C DL_IMPORT(bool) ExecutePythonCallback(CefRefPtr<CefBrowser>, int, CefRefPtr<CefListValue>);
2020
__PYX_EXTERN_C DL_IMPORT(void) LifespanHandler_OnBeforeClose(CefRefPtr<CefBrowser>);
21+
__PYX_EXTERN_C DL_IMPORT(bool) LifespanHandler_OnBeforePopup(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefString const &, CefString const &, const int, CefWindowInfo &, CefRefPtr<CefClient> &, CefBrowserSettings &, bool *);
2122
__PYX_EXTERN_C DL_IMPORT(void) DisplayHandler_OnLoadingStateChange(CefRefPtr<CefBrowser>, bool, bool, bool);
2223
__PYX_EXTERN_C DL_IMPORT(void) DisplayHandler_OnAddressChange(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, CefString const &);
2324
__PYX_EXTERN_C DL_IMPORT(void) DisplayHandler_OnTitleChange(CefRefPtr<CefBrowser>, CefString const &);

cefpython/cef3/linux/setup/setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def CompileTimeConstants():
3535
"cefpython_py%s" % PYTHON_VERSION,
3636
["cefpython.pyx"],
3737

38+
# Ignore the warning in the console:
39+
# > C:\Python27\lib\distutils\extension.py:133: UserWarning:
40+
# > Unknown Extension options: 'cython_directives' warnings.warn(msg)
3841
cython_directives={
3942
# Any conversion to unicode must be explicit using .decode().
4043
"c_string_type": "bytes",

0 commit comments

Comments
 (0)