Skip to content

Commit

Permalink
Get rid of the CEF_VERSION compile time constant. Issue #106.
Browse files Browse the repository at this point in the history
Update api/ docs.
  • Loading branch information
cztomczak committed May 14, 2016
1 parent 99d03d0 commit a00c8a4
Show file tree
Hide file tree
Showing 16 changed files with 408 additions and 882 deletions.
1 change: 0 additions & 1 deletion api/API-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@
* [GetModuleDirectory](cefpython.md#getmoduledirectory)
* [Initialize](cefpython.md#initialize)
* [IsThread](cefpython.md#isthread)
* [IsKeyModifier](cefpython.md#iskeymodifier)
* [MessageLoop](cefpython.md#messageloop)
* [MessageLoopWork](cefpython.md#messageloopwork)
* [PostTask](cefpython.md#posttask)
Expand Down
12 changes: 0 additions & 12 deletions api/cefpython.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Table of contents:
* [GetModuleDirectory](#getmoduledirectory)
* [Initialize](#initialize)
* [IsThread](#isthread)
* [IsKeyModifier](#iskeymodifier)
* [MessageLoop](#messageloop)
* [MessageLoopWork](#messageloopwork)
* [PostTask](#posttask)
Expand Down Expand Up @@ -138,17 +137,6 @@ List of threads in the Renderer process:
* TID_RENDERER: The main thread in the renderer. Used for all webkit and V8 interaction.


### IsKeyModifier

| Parameter | Type |
| --- | --- |
| key | int |
| modifiers | int |
| __Return__ | bool |

For use with [KeyboardHandler](KeyboardHandler.md) to check whether ALT, SHIFT or CTRL are pressed.


### MessageLoop

| | |
Expand Down
539 changes: 155 additions & 384 deletions cefpython/browser.pyx

Large diffs are not rendered by default.

58 changes: 20 additions & 38 deletions cefpython/cefpython.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,10 @@ include "browser.pyx"
include "frame.pyx"

include "settings.pyx"
IF UNAME_SYSNAME == "Windows" and CEF_VERSION == 1:
# Off-screen rendering currently supported only on Windows
include "paint_buffer_cef1.pyx"

IF UNAME_SYSNAME == "Windows":
include "window_utils_win.pyx"
include "dpi_aware_win.pyx"
IF CEF_VERSION == 1:
include "http_authentication_win.pyx"
ELIF UNAME_SYSNAME == "Linux":
include "window_utils_linux.pyx"
ELIF UNAME_SYSNAME == "Darwin":
Expand Down Expand Up @@ -302,29 +297,27 @@ def Initialize(applicationSettings=None, commandLineSwitches=None):
# CEF options - default values.
if not "multi_threaded_message_loop" in applicationSettings:
applicationSettings["multi_threaded_message_loop"] = False
IF CEF_VERSION == 3:
if not "single_process" in applicationSettings:
applicationSettings["single_process"] = False
if not "single_process" in applicationSettings:
applicationSettings["single_process"] = False

cdef CefRefPtr[CefApp] cefApp

IF CEF_VERSION == 3:
cefApp = <CefRefPtr[CefApp]?>new CefPythonApp()
IF UNAME_SYSNAME == "Windows":
cdef HINSTANCE hInstance = GetModuleHandle(NULL)
cdef CefMainArgs cefMainArgs = CefMainArgs(hInstance)
ELIF UNAME_SYSNAME == "Linux":
# TODO: use the CefMainArgs(int argc, char** argv) constructor.
cdef CefMainArgs cefMainArgs
ELIF UNAME_SYSNAME == "Darwin":
# TODO: use the CefMainArgs(int argc, char** argv) constructor.
cdef CefMainArgs cefMainArgs
cdef int exitCode = 1
with nogil:
exitCode = CefExecuteProcess(cefMainArgs, cefApp)
Debug("CefExecuteProcess(): exitCode = %s" % exitCode)
if exitCode >= 0:
sys.exit(exitCode)
cefApp = <CefRefPtr[CefApp]?>new CefPythonApp()
IF UNAME_SYSNAME == "Windows":
cdef HINSTANCE hInstance = GetModuleHandle(NULL)
cdef CefMainArgs cefMainArgs = CefMainArgs(hInstance)
ELIF UNAME_SYSNAME == "Linux":
# TODO: use the CefMainArgs(int argc, char** argv) constructor.
cdef CefMainArgs cefMainArgs
ELIF UNAME_SYSNAME == "Darwin":
# TODO: use the CefMainArgs(int argc, char** argv) constructor.
cdef CefMainArgs cefMainArgs
cdef int exitCode = 1
with nogil:
exitCode = CefExecuteProcess(cefMainArgs, cefApp)
Debug("CefExecuteProcess(): exitCode = %s" % exitCode)
if exitCode >= 0:
sys.exit(exitCode)

# Make a copy as applicationSettings is a reference only
# that might get destroyed later.
Expand All @@ -345,12 +338,8 @@ def Initialize(applicationSettings=None, commandLineSwitches=None):

Debug("CefInitialize()")
cdef cpp_bool ret
IF CEF_VERSION == 1:
with nogil:
ret = CefInitialize(cefApplicationSettings, cefApp)
ELIF CEF_VERSION == 3:
with nogil:
ret = CefInitialize(cefMainArgs, cefApplicationSettings, cefApp)
with nogil:
ret = CefInitialize(cefMainArgs, cefApplicationSettings, cefApp)

if not ret:
Debug("CefInitialize() failed")
Expand Down Expand Up @@ -421,13 +410,6 @@ def CreateBrowserSync(windowInfo, browserSettings, navigateUrl, requestContext=N
cdef PyBrowser pyBrowser = GetPyBrowser(cefBrowser)
pyBrowser.SetUserData("__outerWindowHandle", int(windowInfo.parentWindowHandle))

# IF CEF_VERSION == 3:
# Test whether process message sent before renderer thread is created
# will be delivered - OK.
# Debug("Sending 'CreateBrowserSync() done' message to the Renderer")
# pyBrowser.SendProcessMessage(cef_types.PID_RENDERER,
# "CreateBrowserSync() done")

return pyBrowser

def MessageLoop():
Expand Down
26 changes: 9 additions & 17 deletions cefpython/cython_includes/cef_app.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,24 @@ from cef_ptr cimport CefRefPtr
from cef_base cimport CefBase
from libcpp cimport bool as cpp_bool

IF CEF_VERSION == 3:
IF UNAME_SYSNAME == "Windows":
from cef_win cimport CefMainArgs
ELIF UNAME_SYSNAME == "Linux":
from cef_linux cimport CefMainArgs
ELIF UNAME_SYSNAME == "Darwin":
from cef_mac cimport CefMainArgs
IF UNAME_SYSNAME == "Windows":
from cef_win cimport CefMainArgs
ELIF UNAME_SYSNAME == "Linux":
from cef_linux cimport CefMainArgs
ELIF UNAME_SYSNAME == "Darwin":
from cef_mac cimport CefMainArgs

cdef extern from "include/cef_app.h":

cdef cppclass CefApp(CefBase):
pass

IF CEF_VERSION == 3:
cdef int CefExecuteProcess(CefMainArgs& args, CefRefPtr[CefApp] application) nogil
cdef int CefExecuteProcess(CefMainArgs& args, CefRefPtr[CefApp] application) nogil

IF CEF_VERSION == 1:
cdef cpp_bool CefInitialize(CefSettings&, CefRefPtr[CefApp]) nogil
ELIF CEF_VERSION == 3:
cdef cpp_bool CefInitialize(CefMainArgs&, CefSettings&, CefRefPtr[CefApp]) nogil
cdef cpp_bool CefInitialize(CefMainArgs&, CefSettings&, CefRefPtr[CefApp]) nogil

cdef void CefRunMessageLoop() nogil
cdef void CefDoMessageLoopWork() nogil
cdef void CefQuitMessageLoop() nogil
cdef void CefShutdown() nogil

IF CEF_VERSION == 3:
cdef void CefSetOSModalLoop(cpp_bool osModalLoop) nogil

cdef void CefSetOSModalLoop(cpp_bool osModalLoop) nogil
31 changes: 9 additions & 22 deletions cefpython/cython_includes/cef_browser_static.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,12 @@ from cef_browser cimport CefBrowser
from libcpp cimport bool as cpp_bool
from cef_string cimport CefString

IF CEF_VERSION == 1:

# Specifying namespace allows to import a static method.
cdef extern from "include/cef_browser.h" namespace "CefBrowser":

cdef CefRefPtr[CefBrowser] CreateBrowserSync(
CefWindowInfo&,
CefRefPtr[CefClient],
CefString&,
CefBrowserSettings&) nogil

ELIF CEF_VERSION == 3:

# Specifying namespace allows to import a static method.
cdef extern from "include/cef_browser.h" namespace "CefBrowserHost":

cdef CefRefPtr[CefBrowser] CreateBrowserSync(
CefWindowInfo&,
CefRefPtr[CefClient],
CefString&,
CefBrowserSettings&,
CefRefPtr[CefRequestContext]) nogil
# Specifying namespace allows to import a static method.
cdef extern from "include/cef_browser.h" namespace "CefBrowserHost":

cdef CefRefPtr[CefBrowser] CreateBrowserSync(
CefWindowInfo&,
CefRefPtr[CefClient],
CefString&,
CefBrowserSettings&,
CefRefPtr[CefRequestContext]) nogil
7 changes: 3 additions & 4 deletions cefpython/cython_includes/cef_linux.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ cdef extern from "include/internal/cef_linux.h":
void SetTransparentPainting(cpp_bool)
void SetAsOffScreen(CefWindowHandle)

IF CEF_VERSION == 3:
cdef cppclass CefMainArgs(CefStructBase):
CefMainArgs()
CefMainArgs(int argc_arg, char** argv_arg)
cdef cppclass CefMainArgs(CefStructBase):
CefMainArgs()
CefMainArgs(int argc_arg, char** argv_arg)

7 changes: 3 additions & 4 deletions cefpython/cython_includes/cef_mac.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ cdef extern from "include/internal/cef_linux.h":
void SetTransparentPainting(cpp_bool)
void SetAsOffScreen(CefWindowHandle)

IF CEF_VERSION == 3:
cdef cppclass CefMainArgs(CefStructBase):
CefMainArgs()
CefMainArgs(int argc_arg, char** argv_arg)
cdef cppclass CefMainArgs(CefStructBase):
CefMainArgs()
CefMainArgs(int argc_arg, char** argv_arg)
5 changes: 2 additions & 3 deletions cefpython/cython_includes/cef_types_wrappers.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ include "compile_time_constants.pxi"

from libcpp cimport bool as cpp_bool
from cef_string cimport cef_string_t
IF CEF_VERSION == 3:
from cef_types cimport cef_state_t
from cef_types cimport cef_color_t
from cef_types cimport cef_state_t
from cef_types cimport cef_color_t

cdef extern from "include/internal/cef_types_wrappers.h":

Expand Down
7 changes: 3 additions & 4 deletions cefpython/cython_includes/cef_win.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ cdef extern from "include/internal/cef_win.h":
void SetTransparentPainting(int)
void SetAsOffScreen(HWND)

IF CEF_VERSION == 3:
cdef cppclass CefMainArgs(CefStructBase):
CefMainArgs()
CefMainArgs(HINSTANCE hInstance)
cdef cppclass CefMainArgs(CefStructBase):
CefMainArgs()
CefMainArgs(HINSTANCE hInstance)

ctypedef _cef_key_info_t CefKeyInfo
102 changes: 30 additions & 72 deletions cefpython/javascript_bindings.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -80,78 +80,36 @@ cdef class JavascriptBindings:
else:
self.properties[name] = value


IF CEF_VERSION == 1:
cpdef py_void Rebind(self):
# Rebind may also be used for first-time bindings, in
# a case when v8 process/thread was created too fast,
# see Browser.SetJavascriptBindings() that checks whether
# OnContextCreated() event already happened, if so it will
# call Rebind() to do the javascript bindings.
assert IsThread(TID_UI), (
"JavascriptBindings.Rebind() may only be called on UI thread")
cdef CefRefPtr[CefBrowser] cefBrowser
cdef CefRefPtr[CefFrame] cefFrame
cdef CefRefPtr[CefV8Context] v8Context
cdef cpp_bool sameContext
cdef PyBrowser pyBrowser
cdef PyFrame pyFrame
cdef list frames
global g_pyBrowsers
for pyBrowser in g_pyBrowsers:
# These javascript bindings may have been binded
# to many browsers.
if pyBrowser.GetJavascriptBindings() != self:
continue
if self.bindToFrames:
frames = pyBrowser.GetFrames()
else:
frames = [pyBrowser.GetMainFrame()]
for frameId in self.frames:
pyBrowser = self.frames[frameId][0]
pyFrame = self.frames[frameId][1]
cefBrowser = pyBrowser.GetCefBrowser()
cefFrame = pyFrame.GetCefFrame()
v8Context = cefFrame.get().GetV8Context()
sameContext = v8Context.get().IsSame(cef_v8_static.GetCurrentContext())
if not sameContext:
Debug("JavascriptBindings.Rebind(): inside a different context, calling v8Context.Enter()")
assert v8Context.get().Enter(), "v8Context.Enter() failed"
V8ContextHandler_OnContextCreated(cefBrowser, cefFrame, v8Context)
if not sameContext:
assert v8Context.get().Exit(), "v8Context.Exit() failed"
ELIF CEF_VERSION == 3:
cpdef py_void Rebind(self):
# In CEF Python 3 due to its multi-process architecture
# Rebind() is used for both first-time binding and rebinding.
cdef PyBrowser pyBrowser
cdef dict functions
cdef dict properties
cdef dict objects
cdef dict methods
global g_pyBrowsers
for browserId, pyBrowser in g_pyBrowsers.iteritems():
if pyBrowser.GetJavascriptBindings() != self:
continue
# Send to the Renderer process: functions, properties,
# objects and its methods, bindToFrames.
functions = {}
for funcName in self.functions:
functions[funcName] = None
properties = self.properties
objects = {}
for objectName in self.objects:
methods = {}
for methodName in self.objects[objectName]:
methods[methodName] = None
objects[objectName] = methods
pyBrowser.SendProcessMessage(cef_types.PID_RENDERER,
0, "DoJavascriptBindings", [{
"functions": functions,
"properties": properties,
"objects": objects,
"bindToFrames": self.bindToFrames
}])
cpdef py_void Rebind(self):
# Rebind() is called for both first-time binding and rebinding.
cdef PyBrowser pyBrowser
cdef dict functions
cdef dict properties
cdef dict objects
cdef dict methods
global g_pyBrowsers
for browserId, pyBrowser in g_pyBrowsers.iteritems():
if pyBrowser.GetJavascriptBindings() != self:
continue
# Send to the Renderer process: functions, properties,
# objects and its methods, bindToFrames.
functions = {}
for funcName in self.functions:
functions[funcName] = None
properties = self.properties
objects = {}
for objectName in self.objects:
methods = {}
for methodName in self.objects[objectName]:
methods[methodName] = None
objects[objectName] = methods
pyBrowser.SendProcessMessage(cef_types.PID_RENDERER,
0, "DoJavascriptBindings", [{
"functions": functions,
"properties": properties,
"objects": objects,
"bindToFrames": self.bindToFrames
}])

cpdef dict GetProperties(self):
return self.properties
Expand Down
4 changes: 0 additions & 4 deletions cefpython/linux/setup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
# Stop on first error, otherwise hundreds of errors appear in the console.
Options.fast_fail = True

# Written to cython_includes/compile_time_constants.pxi
CEF_VERSION = 3

# Python version string: "27" or "32".
PYTHON_VERSION = str(sys.version_info.major) + str(sys.version_info.minor)

Expand All @@ -28,7 +25,6 @@ def CompileTimeConstants():
fd.write('# This file was generated by setup.py\n')
# A way around Python 3.2 bug: UNAME_SYSNAME is not set.
fd.write('DEF UNAME_SYSNAME = "%s"\n' % platform.uname()[0])
fd.write('DEF CEF_VERSION = %s\n' % CEF_VERSION)
fd.write('DEF PY_MAJOR_VERSION = %s\n' % sys.version_info.major)

CompileTimeConstants()
Expand Down
4 changes: 0 additions & 4 deletions cefpython/mac/setup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
# Stop on first error, otherwise hundreds of errors appear in the console.
Options.fast_fail = True

# Written to cython_includes/compile_time_constants.pxi
CEF_VERSION = 3

# Python version string: "27" or "32".
PYTHON_VERSION = str(sys.version_info.major) + str(sys.version_info.minor)

Expand All @@ -36,7 +33,6 @@ def CompileTimeConstants():
fd.write('# This file was generated by setup.py\n')
# A way around Python 3.2 bug: UNAME_SYSNAME is not set.
fd.write('DEF UNAME_SYSNAME = "%s"\n' % platform.uname()[0])
fd.write('DEF CEF_VERSION = %s\n' % CEF_VERSION)
fd.write('DEF PY_MAJOR_VERSION = %s\n' % sys.version_info.major)

CompileTimeConstants()
Expand Down
Loading

0 comments on commit a00c8a4

Please sign in to comment.