Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.clientHandler._OnCertificateError)
cefpython.SetGlobalClientCallback("OnBeforePluginLoad",
self.clientHandler._OnBeforePluginLoad)
cefpython.SetGlobalClientCallback("OnAfterCreated",
self.clientHandler._OnAfterCreated)
windowInfo = cefpython.WindowInfo()
windowInfo.SetAsChild(self.GetHandleForBrowser())
self.browser = cefpython.CreateBrowserSync(windowInfo,
browserSettings=g_browserSettings,
navigateUrl=url)
self.clientHandler.mainBrowser = self.browser
self.browser.SetClientHandler(self.clientHandler)
jsBindings = cefpython.JavascriptBindings(
bindToFrames=False, bindToPopups=True)
jsBindings.SetFunction("PyPrint", PyPrint)
jsBindings.SetProperty("pyProperty", "This was set in Python")
jsBindings.SetProperty("pyConfig", ["This was set in Python",
{"name": "Nested dictionary", "isNested": True},
[1,"2", None]])
self.javascriptExternal = JavascriptExternal(self.browser)
jsBindings.SetObject("external", self.javascriptExternal)
# jsBindings.SetProperty("sources", GetSources())
self.browser.SetJavascriptBindings(jsBindings)
if self.mainPanel:
self.mainPanel.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
self.mainPanel.Bind(wx.EVT_SIZE, self.OnSize)
else:
self.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
if isWin and w and h:
window_handle = b.GetOuterWindowHandle()
SWP_NOMOVE = 0x0002 # X,Y ignored with SWP_NOMOVE flag
ctypes.windll.user32.SetWindowPos(
window_handle, 0, 0, 0, w, h, SWP_NOMOVE
)
# ===---
def wuyInit(width, height):
if size == FULLSCREEN:
if isWin:
b.ToggleFullscreen() # win only
else:
b.SetBounds(0, 0, width, height) # not win
bindings = cef.JavascriptBindings()
bindings.SetFunction("wuyInit", wuyInit)
b.SetJavascriptBindings(bindings)
b.ExecuteJavascript("wuyInit(window.screen.width,window.screen.height)")
# ===---
class WuyClientHandler(object):
def OnLoadEnd(self, browser, **_):
pass # could serve in the future (?)
class WuyDisplayHandler(object):
def OnTitleChange(self, browser, title):
try:
cef.WindowUtils.SetTitle(browser, title)
except AttributeError:
print(
(width, height) = self.mainPanel.GetClientSizeTuple()
windowInfo.SetAsChild(self.mainPanel.GetHandle(),
[0, 0, width, height])
# Linux requires adding "file://" for local files,
# otherwise /home/some will be replaced as http://home/some
self.browser = cefpython.CreateBrowserSync(
windowInfo,
# If there are problems with Flash you can disable it here,
# by disabling all plugins.
browserSettings=g_browserSettings,
navigateUrl=url)
self.clientHandler.mainBrowser = self.browser
self.browser.SetClientHandler(self.clientHandler)
jsBindings = cefpython.JavascriptBindings(
bindToFrames=False, bindToPopups=True)
jsBindings.SetFunction("PyPrint", PyPrint)
jsBindings.SetProperty("pyProperty", "This was set in Python")
jsBindings.SetProperty("pyConfig", ["This was set in Python",
{"name": "Nested dictionary", "isNested": True},
[1,"2", None]])
self.javascriptExternal = JavascriptExternal(self.browser)
jsBindings.SetObject("external", self.javascriptExternal)
jsBindings.SetProperty("sources", GetSources())
self.browser.SetJavascriptBindings(jsBindings)
self.Bind(wx.EVT_CLOSE, self.OnClose)
if USE_EVT_IDLE:
# Bind EVT_IDLE only for the main application frame.
self.Bind(wx.EVT_IDLE, self.OnIdle)
self.clientHandler._OnCertificateError)
cefpython.SetGlobalClientCallback("OnBeforePluginLoad",
self.clientHandler._OnBeforePluginLoad)
cefpython.SetGlobalClientCallback("OnAfterCreated",
self.clientHandler._OnAfterCreated)
windowInfo = cefpython.WindowInfo()
windowInfo.SetAsChild(self.GetHandleForBrowser())
self.browser = cefpython.CreateBrowserSync(windowInfo,
browserSettings=g_browserSettings,
navigateUrl=url)
self.clientHandler.mainBrowser = self.browser
self.browser.SetClientHandler(self.clientHandler)
jsBindings = cefpython.JavascriptBindings(
bindToFrames=False, bindToPopups=True)
jsBindings.SetFunction("PyPrint", PyPrint)
jsBindings.SetProperty("pyProperty", "This was set in Python")
jsBindings.SetProperty("pyConfig", ["This was set in Python",
{"name": "Nested dictionary", "isNested": True},
[1,"2", None]])
global gdata
if gdata is None:
gdata = GetData()
self.javascriptExternal = JavascriptExternal(self.browser, gdata)
jsBindings.SetObject("external", self.javascriptExternal)
jsBindings.SetProperty("sources", GetSources())
jsBindings.SetProperty("GData", gdata)
if not params is None:
def set_js_bindings(self):
if not self._js_bindings:
self._js_bindings = cef.JavascriptBindings(
bindToFrames=True, bindToPopups=True)
self._js_bindings.SetFunction("__kivy__request_keyboard",
self.request_keyboard)
self._js_bindings.SetFunction("__kivy__release_keyboard",
self.release_keyboard)
self.browser.SetJavascriptBindings(self._js_bindings)
def main():
cef.Initialize()
browser = cef.CreateBrowserSync(url=cef.GetDataUrl(g_htmlcode),
window_title="Javascript Bindings")
browser.SetClientHandler(LoadHandler())
bindings = cef.JavascriptBindings()
bindings.SetFunction("py_function", py_function)
bindings.SetFunction("py_callback", py_callback)
browser.SetJavascriptBindings(bindings)
cef.MessageLoop()
del browser
cef.Shutdown()
def on_after_create(browser, **_):
cef.WindowUtils.SetTitle(browser, 'Kam1n0')
bindings = cef.JavascriptBindings(
bindToFrames=True, bindToPopups=False)
bindings.SetObject("browser_controller", BrowserController(browser))
bindings.SetFunction("send_msg", send_msg)
browser.SetJavascriptBindings(bindings)
def set_javascript_bindings(browser):
external = External(browser)
bindings = cef.JavascriptBindings(bindToFrames=False, bindToPopups=False)
bindings.SetObject("external", external)
browser.SetJavascriptBindings(bindings)
def set_javascript_bindings(browser, request_url, request_method,
request_param, external_data):
request_param = '{}' if request_param is None else request_param
external_data = '{}' if external_data is None else external_data
bindings = cef.JavascriptBindings(
bindToFrames=True, bindToPopups=False)
bindings.SetProperty("url", str(request_url))
bindings.SetProperty("method", str(request_method))
bindings.SetProperty("param", request_param)
bindings.SetProperty("external", external_data)
bindings.SetFunction("send_msg", send_msg)
bindings.SetObject("browser_controller", BrowserController(browser))
browser.SetJavascriptBindings(bindings)