Skip to content

Commit 2b2dbca

Browse files
committed
Working on Browser and Frame api, still in progress.
1 parent 0ee18e9 commit 2b2dbca

25 files changed

Lines changed: 617 additions & 46 deletions

accelerated compositing.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

browser.pyx

Lines changed: 141 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,160 @@ class Browser:
1818
# Call this function to see whether Browser object is still valid, if windowID == 0 then invalid.
1919
return self.windowID
2020

21-
def CloseBrowser(self):
21+
def GetOpenerWindowID(self):
2222

23-
assert self.windowID, "Browser was destroyed earlier"
24-
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(self.windowID)
25-
assert <void*>cefBrowser != NULL, "CefBrowser not found, destroyed?"
23+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
24+
cdef HWND hwnd = (<CefBrowser*>(cefBrowser.get())).GetOpenerWindowHandle()
25+
openerID = <int>hwnd
26+
27+
if openerID:
28+
assert win32gui.IsWindow(openerID), "CefBrowser.GetOpenerWindowHandle() returned invalid handle"
29+
return openerID
30+
31+
return None
32+
33+
def CloseBrowser(self):
2634

27-
if __debug: print "CefBrowser.ParentWindowWillClose()"
35+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
2836
(<CefBrowser*>(cefBrowser.get())).ParentWindowWillClose()
29-
30-
if __debug: print "CefBrowser.CloseBrowser()"
3137
(<CefBrowser*>(cefBrowser.get())).CloseBrowser()
32-
3338
__cefBrowsers.erase(<int>self.windowID)
3439
del __pyBrowsers[self.windowID]
3540
self.windowID = 0
3641

3742
def ShowDevTools(self):
3843

39-
assert self.windowID, "Browser was destroyed earlier"
40-
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(self.windowID)
41-
assert <void*>cefBrowser != NULL, "CefBrowser not found, destroyed?"
42-
44+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
4345
(<CefBrowser*>(cefBrowser.get())).ShowDevTools()
4446

4547
def CloseDevTools(self):
4648

47-
assert self.windowID, "Browser was destroyed earlier"
48-
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(self.windowID)
49-
assert <void*>cefBrowser != NULL, "CefBrowser not found, destroyed?"
50-
49+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
5150
(<CefBrowser*>(cefBrowser.get())).CloseDevTools()
5251

52+
def CanGoBack(self):
53+
54+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
55+
cdef cbool canGoBack = (<CefBrowser*>(cefBrowser.get())).CanGoBack()
56+
return canGoBack
57+
58+
def GoBack(self):
59+
60+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
61+
(<CefBrowser*>(cefBrowser.get())).GoBack()
62+
63+
def CanGoForward(self):
64+
65+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
66+
cdef cbool canGoForward = (<CefBrowser*>(cefBrowser.get())).CanGoForward()
67+
return canGoForward
68+
69+
def GoForward(self):
70+
71+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
72+
(<CefBrowser*>(cefBrowser.get())).GoForward()
73+
74+
def Reload(self):
75+
76+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
77+
(<CefBrowser*>(cefBrowser.get())).Reload()
78+
79+
def ReloadIgnoreCache(self):
80+
81+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
82+
(<CefBrowser*>(cefBrowser.get())).ReloadIgnoreCache()
83+
84+
def StopLoad(self):
85+
86+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
87+
(<CefBrowser*>(cefBrowser.get())).StopLoad()
88+
89+
def IsPopup(self):
90+
91+
pass
92+
93+
def HasDocument(self):
94+
95+
pass
96+
97+
def GetMainFrame(self):
98+
99+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
100+
101+
cdef CefRefPtr[CefFrame] cefFrame = (<CefBrowser*>(cefBrowser.get())).GetMainFrame()
102+
103+
global __pyFrames
104+
cdef long long frameID
105+
if <void*>cefFrame != NULL and <CefFrame*>(cefFrame.get()):
106+
frameID = (<CefFrame*>(cefFrame.get())).GetIdentifier()
107+
__cefFrames[frameID] = cefFrame
108+
pyFrameID = long(frameID)
109+
print "pyFrameID: %s" % pyFrameID
110+
if pyFrameID in __pyFrames:
111+
return __pyFrames[pyFrameID]
112+
__pyFrames[pyFrameID] = Frame(pyFrameID)
113+
return __pyFrames[pyFrameID]
114+
115+
def GetFocusedFrame(self):
116+
117+
assert CurrentlyOn(TID_UI), "Browser.GetFocusedFrame() should only be called on the UI thread"
118+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
119+
120+
cdef CefRefPtr[CefFrame] cefFrame = (<CefBrowser*>(cefBrowser.get())).GetFocusedFrame()
121+
122+
global __pyFrames
123+
cdef cef_types.int64 frameID
124+
if <void*>cefFrame != NULL and <CefFrame*>(cefFrame.get()):
125+
frameID = (<CefFrame*>(cefFrame.get())).GetIdentifier()
126+
__cefFrames[frameID] = cefFrame
127+
pyFrameID = long(frameID)
128+
print "pyFrameID: %s" % pyFrameID
129+
if pyFrameID in __pyFrames:
130+
return __pyFrames[pyFrameID]
131+
__pyFrames[pyFrameID] = Frame(pyFrameID)
132+
return __pyFrames[pyFrameID]
133+
134+
def GetFrame(self, name):
135+
136+
assert CurrentlyOn(TID_UI), "Browser.GetFocusedFrame() should only be called on the UI thread"
137+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
138+
139+
cdef CefString cefName
140+
cefName.FromASCII(<char*>name)
141+
cdef CefRefPtr[CefFrame] cefFrame = (<CefBrowser*>(cefBrowser.get())).GetFrame(cefName)
142+
143+
global __pyFrames
144+
cdef cef_types.int64 frameID
145+
if <void*>cefFrame != NULL and <CefFrame*>(cefFrame.get()):
146+
frameID = (<CefFrame*>(cefFrame.get())).GetIdentifier()
147+
__cefFrames[frameID] = cefFrame
148+
pyFrameID = long(frameID)
149+
if pyFrameID in __pyFrames:
150+
return __pyFrames[pyFrameID]
151+
__pyFrames[pyFrameID] = Frame(pyFrameID)
152+
return __pyFrames[pyFrameID]
153+
154+
def GetFrameNames(self):
155+
156+
# Seems not to work! cefNames.size() is always 0
157+
# Tried on iframe and frameset.
158+
159+
assert CurrentlyOn(TID_UI), "Browser.GetFrameNames() should only be called on the UI thread"
160+
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByWindowID(CheckWindowID(self.windowID))
161+
162+
cdef vector[CefString] cefNames
163+
(<CefBrowser*>(cefBrowser.get())).GetFrameNames(cefNames)
164+
if __debug: print "GetFrameNames() vector size: %s" % cefNames.size()
165+
166+
names = []
167+
cdef vector[CefString].iterator iterator = cefNames.begin()
168+
cdef CefString cefString
169+
while iterator != cefNames.end():
170+
cefString = deref(iterator)
171+
names.push(CefStringToPyString(cefString))
172+
preinc(iterator)
173+
174+
return names
175+
176+
cdef GetPyFrame():
177+
pass

callback/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
all:
2+
python Setup.py build_ext --inplace
3+
4+
test: all
5+
python run_cheese.py
6+
7+
clean:
8+
@echo Cleaning Demos/callback
9+
@rm -f cheese.c *.o *.so *~ core
10+
@rm -rf build

callback/Makefile.nodistutils

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
PYHOME = $(HOME)/pkg/python/version
2+
PYINCLUDE = \
3+
-I$(PYHOME)/include/python2.2 \
4+
-I$(PYHOME)/$(ARCH)/include/python2.2
5+
6+
%.c: %.pyx
7+
../../bin/cython $<
8+
9+
%.o: %.c
10+
gcc -c -fPIC $(PYINCLUDE) $<
11+
12+
%.so: %.o
13+
gcc -shared $< -lm -o $@
14+
15+
all: cheese.so
16+
17+
clean:
18+
@echo Cleaning Demos/callback
19+
@rm -f *.c *.o *.so *~ core core.*

callback/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This example demonstrates how you can wrap a C APIthat has a callback interface, so that you canpass Python functions to it as callbacks.The files cheesefinder.h and cheesefinder.crepresent the C library to be wrapped.The file cheese.pyx is the Pyrex modulewhich wraps it.The file run_cheese.py demonstrates how tocall the wrapper.

callback/Setup.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from distutils.core import setup
2+
from distutils.extension import Extension
3+
from Cython.Distutils import build_ext
4+
5+
setup(
6+
name = 'callback',
7+
ext_modules=[
8+
Extension("cheese", ["cheese.pyx", "cheesefinder.c"]),
9+
],
10+
cmdclass = {'build_ext': build_ext}
11+
)

callback/cheese.pyx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Cython wrapper for the cheesefinder API
3+
#
4+
5+
cdef extern from "cheesefinder.h":
6+
ctypedef void (*cheesefunc)(char *name, void *user_data)
7+
void find_cheeses(cheesefunc user_func, void *user_data)
8+
9+
def find(f):
10+
find_cheeses(callback, <void*>f)
11+
12+
cdef void callback(char *name, void *f):
13+
(<object>f)(name)

callback/cheesefinder.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* An example of a C API that provides a callback mechanism.
3+
*/
4+
5+
#include "cheesefinder.h"
6+
7+
static char *cheeses[] = {
8+
"cheddar",
9+
"camembert",
10+
"that runny one",
11+
0
12+
};
13+
14+
void find_cheeses(cheesefunc user_func, void *user_data) {
15+
char **p = cheeses;
16+
while (*p) {
17+
user_func(*p, user_data);
18+
++p;
19+
}
20+
}
21+

callback/cheesefinder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
typedef void (*cheesefunc)(char *name, void *user_data);void find_cheeses(cheesefunc user_func, void *user_data);

callback/run_cheese.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import cheese
2+
3+
def report_cheese(name):
4+
print("Found cheese: " + name)
5+
6+
cheese.find(report_cheese)
7+

0 commit comments

Comments
 (0)