Skip to content

Commit 716671a

Browse files
committed
Added new methods to the Frame object: GetSource() and GetText().
Added the StringVisitor class. Thanks to Greg Farrell for the patch, see Issue 96.
1 parent e66bfcc commit 716671a

File tree

20 files changed

+240
-32
lines changed

20 files changed

+240
-32
lines changed

cefpython/cef3/client_handler/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ CC = g++
1212
CCFLAGS = -g -fPIC -Wall -Werror
1313

1414
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
15-
web_request_client.cpp
15+
web_request_client.cpp string_visitor.cpp
1616
OBJ = $(SRC:.cpp=.o)
1717
OUT = libclient_handler.a
1818

cefpython/cef3/client_handler/client_handler_py27.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@
100100
<File
101101
RelativePath=".\web_request_client.h"
102102
>
103+
</File>
104+
<File
105+
RelativePath=".\string_visitor.h"
106+
>
103107
</File>
104108
</Filter>
105109
<Filter
@@ -128,6 +132,10 @@
128132
<File
129133
RelativePath=".\web_request_client.cpp"
130134
>
135+
</File>
136+
<File
137+
RelativePath=".\string_visitor.cpp"
138+
>
131139
</File>
132140
</Filter>
133141
</Files>

cefpython/cef3/client_handler/client_handler_py32.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
<File
100100
RelativePath=".\web_request_client.h"
101101
>
102+
</File>
103+
<File
104+
RelativePath=".\string_visitor.h"
105+
>
102106
</File>
103107
</Filter>
104108
<Filter
@@ -127,6 +131,10 @@
127131
<File
128132
RelativePath=".\web_request_client.cpp"
129133
>
134+
</File>
135+
<File
136+
RelativePath=".\string_visitor.cpp"
137+
>
130138
</File>
131139
</Filter>
132140
</Files>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (c) 2012-2013 The CEF Python authors. All rights reserved.
2+
// License: New BSD License.
3+
// Website: http://code.google.com/p/cefpython/
4+
5+
#include "string_visitor.h"
6+
#include <stdio.h>
7+
8+
void StringVisitor::Visit(
9+
const CefString& string
10+
) {
11+
StringVisitor_Visit(stringVisitorId_, string);
12+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2012-2013 The CEF Python authors. All rights reserved.
2+
// License: New BSD License.
3+
// Website: http://code.google.com/p/cefpython/
4+
5+
#pragma once
6+
7+
#if defined(_WIN32)
8+
#include "../windows/stdint.h"
9+
#endif
10+
11+
#include "cefpython_public_api.h"
12+
13+
class StringVisitor : public CefStringVisitor
14+
{
15+
public:
16+
int stringVisitorId_;
17+
public:
18+
StringVisitor(int stringVisitorId)
19+
: stringVisitorId_(stringVisitorId) {
20+
}
21+
22+
virtual void Visit(
23+
const CefString& string
24+
) OVERRIDE;
25+
26+
protected:
27+
// Include the default reference counting implementation.
28+
IMPLEMENT_REFCOUNTING(StringVisitor);
29+
};

cefpython/cef3/linux/binaries_32bit/wxpython.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ <h3>Javascript bindings</h3>
7979
external.ExecuteFunction('JavascriptAlert',
8080
'python called from js and then js called from python')</a>
8181

82+
<br><br>
83+
<a href="javascript:external.GetSource()">
84+
GetSource() to console</a><br>
85+
<a href="javascript:external.GetText()">
86+
GetText() to console</a>
8287

8388

8489
<h3>Javascript callbacks</h3>

cefpython/cef3/linux/binaries_32bit/wxpython.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def PyPrint(message):
161161

162162
class JavascriptExternal:
163163
mainBrowser = None
164+
stringVisitor = None
164165

165166
def __init__(self, mainBrowser):
166167
self.mainBrowser = mainBrowser
@@ -206,6 +207,18 @@ def PyCallback(self, *args):
206207
self.mainBrowser.GetMainFrame().ExecuteJavascript(
207208
"window.alert(\"%s\")" % message)
208209

210+
def GetSource(self):
211+
# Must keep a strong reference to the StringVisitor object
212+
# during the visit.
213+
self.stringVisitor = StringVisitor()
214+
self.mainBrowser.GetMainFrame().GetSource(self.stringVisitor)
215+
216+
def GetText(self):
217+
# Must keep a strong reference to the StringVisitor object
218+
# during the visit.
219+
self.stringVisitor = StringVisitor()
220+
self.mainBrowser.GetMainFrame().GetText(self.stringVisitor)
221+
209222
# -------------------------------------------------------------------------
210223
# Cookies
211224
# -------------------------------------------------------------------------
@@ -254,6 +267,13 @@ def DeleteCookies(self):
254267
"Created_Via_Python")
255268
print("\nCookie deleted! Visit html-kit cookietester to see the result")
256269

270+
class StringVisitor:
271+
def Visit(self, string):
272+
print("\nStringVisitor.Visit(): string:")
273+
print("--------------------------------")
274+
print(string)
275+
print("--------------------------------")
276+
257277
class CookieVisitor:
258278
def Visit(self, cookie, count, total, deleteCookie):
259279
if count == 0:

cefpython/cef3/linux/binaries_64bit/wxpython.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ <h3>Javascript bindings</h3>
7979
external.ExecuteFunction('JavascriptAlert',
8080
'python called from js and then js called from python')</a>
8181

82+
<br><br>
83+
<a href="javascript:external.GetSource()">
84+
GetSource() to console</a><br>
85+
<a href="javascript:external.GetText()">
86+
GetText() to console</a>
8287

8388

8489
<h3>Javascript callbacks</h3>

cefpython/cef3/linux/binaries_64bit/wxpython.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def PyPrint(message):
161161

162162
class JavascriptExternal:
163163
mainBrowser = None
164+
stringVisitor = None
164165

165166
def __init__(self, mainBrowser):
166167
self.mainBrowser = mainBrowser
@@ -206,10 +207,21 @@ def PyCallback(self, *args):
206207
self.mainBrowser.GetMainFrame().ExecuteJavascript(
207208
"window.alert(\"%s\")" % message)
208209

210+
def GetSource(self):
211+
# Must keep a strong reference to the StringVisitor object
212+
# during the visit.
213+
self.stringVisitor = StringVisitor()
214+
self.mainBrowser.GetMainFrame().GetSource(self.stringVisitor)
215+
216+
def GetText(self):
217+
# Must keep a strong reference to the StringVisitor object
218+
# during the visit.
219+
self.stringVisitor = StringVisitor()
220+
self.mainBrowser.GetMainFrame().GetText(self.stringVisitor)
221+
209222
# -------------------------------------------------------------------------
210223
# Cookies
211224
# -------------------------------------------------------------------------
212-
213225
cookieVisitor = None
214226

215227
def VisitAllCookies(self):
@@ -255,6 +267,13 @@ def DeleteCookies(self):
255267
"Created_Via_Python")
256268
print("\nCookie deleted! Visit html-kit cookietester to see the result")
257269

270+
class StringVisitor:
271+
def Visit(self, string):
272+
print("\nStringVisitor.Visit(): string:")
273+
print("--------------------------------")
274+
print(string)
275+
print("--------------------------------")
276+
258277
class CookieVisitor:
259278
def Visit(self, cookie, count, total, deleteCookie):
260279
if count == 0:

cefpython/cef3/linux/setup/cefpython.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ __PYX_EXTERN_C DL_IMPORT(void) RequestHandler_OnProtocolExecution(CefRefPtr<CefB
3838
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_OnBeforePluginLoad(CefRefPtr<CefBrowser>, CefString const &, CefString const &, CefRefPtr<CefWebPluginInfo>);
3939
__PYX_EXTERN_C DL_IMPORT(bool) RequestHandler_OnCertificateError(int, CefString const &, CefRefPtr<CefAllowCertificateErrorCallback>);
4040
__PYX_EXTERN_C DL_IMPORT(bool) CookieVisitor_Visit(int, CefCookie const &, int, int, bool &);
41+
__PYX_EXTERN_C DL_IMPORT(void) StringVisitor_Visit(int, CefString const &);
4142
__PYX_EXTERN_C DL_IMPORT(void) LoadHandler_OnLoadStart(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>);
4243
__PYX_EXTERN_C DL_IMPORT(void) LoadHandler_OnLoadEnd(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, int);
4344
__PYX_EXTERN_C DL_IMPORT(void) LoadHandler_OnLoadError(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>, enum cef_errorcode_t, CefString const &, CefString const &);

0 commit comments

Comments
 (0)