Skip to content

Commit 7d47bfe

Browse files
committed
Fix printing on Linux (cztomczak#238) and fix "undefined symbol" error (cztomczak#230).
Fix OnBeforePluginLoad and change args, see docs. Add -std=gnu++11 flag to catch OVERRIDE errors. Minor enhancements to makefiles. Update build instructions - install python dependencies to make sure that the right version of Cython is installed (must be exactly 0.19.2).
1 parent 22ade5c commit 7d47bfe

File tree

23 files changed

+857
-118
lines changed

23 files changed

+857
-118
lines changed

docs/Build-instructions.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,26 @@ binaries from GH releases.
3939

4040
3) Install packages: `sudo apt-get install python-dev cmake g++`
4141

42-
4) Download 64-bit Linux binaries and libraries from
42+
4) Install python dependencies by executing:
43+
`cd cefpython/tools/ && pip install -r requirements.txt`
44+
(Cython 0.19.2 required - the version must match exactly)
45+
46+
5) Download 64-bit Linux binaries and libraries from
4347
[GH releases](https://github.com/cztomczak/cefpython/releases)
4448
tagged 'v51-upstream'.
4549

4650

47-
5) Copy "bin/*" to "cefpython/src/linux/binaries_64bit/"
51+
6) Copy "bin/*" to "cefpython/src/linux/binaries_64bit/"
4852

49-
6) Copy "lib/*" to "cefpython/src/linux/setup/lib_64bit/" (create dir)
53+
7) Copy "lib/*" to "cefpython/src/linux/setup/lib_64bit/" (create dir)
5054

51-
7) Build cefpython:
55+
8) Build cefpython:
5256
```
5357
cd cefpython/src/linux/
5458
python compile.py 51.0
5559
```
5660

57-
8) As of writing only "pygtk_.py" and "kivy_.py" examples are working
61+
9) As of writing only "pygtk_.py" and "kivy_.py" examples are working
5862

5963

6064
## Requirements

docs/api/RequestHandler.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,30 @@ to use [LoadHandler](LoadHandler.md)::OnLoadError() when implementing this on Li
210210
| Parameter | Type |
211211
| --- | --- |
212212
| browser | [Browser](Browser.md) |
213-
| url | string |
214-
| policyUrl | string |
213+
| mime_type | string |
214+
| plugin_url | string |
215+
| top_origin_url | string |
215216
| info | [WebPluginInfo](WebPluginInfo.md) |
216217
| __Return__ | bool |
217218

218-
Called on the browser process IO thread before a plugin is loaded. Return
219-
True to block loading of the plugin.
219+
Description from upstream CEF:
220+
> Called on multiple browser process threads before a plugin instance is
221+
> loaded. |mime_type| is the mime type of the plugin that will be loaded.
222+
> |plugin_url| is the content URL that the plugin will load and may be empty.
223+
> |top_origin_url| is the URL for the top-level frame that contains the
224+
> plugin when loading a specific plugin instance or empty when building the
225+
> initial list of enabled plugins for 'navigator.plugins' JavaScript state.
226+
> |plugin_info| includes additional information about the plugin that will be
227+
> loaded. |plugin_policy| is the recommended policy. Modify |plugin_policy|
228+
> and return true to change the policy. Return false to use the recommended
229+
> policy. The default plugin policy can be set at runtime using the
230+
> `--plugin-policy=[allow|detect|block]` command-line flag. Decisions to mark
231+
> a plugin as disabled by setting |plugin_policy| to PLUGIN_POLICY_DISABLED
232+
> may be cached when |top_origin_url| is empty. To purge the plugin list
233+
> cache and potentially trigger new calls to this method call
234+
> CefRequestContext::PurgePluginListCache.
235+
236+
Return True to block loading of the plugin.
220237

221238
This callback will be executed during browser creation, thus you must call [cefpython](cefpython.md).SetGlobalClientCallback() to use it. The callback name was prefixed with "`_`" to distinguish this special behavior.
222239

src/client_handler/Makefile

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66

77
# Cython compiler options:
88
# -fPIC -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions \
9-
# -Wl,-z,relro
9+
# -Wl,-z,relro
1010

1111
UNAME_S = $(shell uname -s)
12-
1312
CC = g++
14-
CCFLAGS = -g -fPIC -Wall -Werror $(CEF_CCFLAGS)
13+
CCFLAGS = -fPIC -std=gnu++11 -Wall -Werror $(CEF_CCFLAGS)
1514

1615
SRC = client_handler.cpp cookie_visitor.cpp resource_handler.cpp \
17-
web_request_client.cpp string_visitor.cpp request_context_handler.cpp \
18-
task.cpp x11.cpp
16+
web_request_client.cpp string_visitor.cpp request_context_handler.cpp \
17+
task.cpp x11.cpp
1918

2019
OBJ = $(SRC:.cpp=.o)
2120

@@ -25,26 +24,39 @@ endif
2524

2625
OUT = libclient_handler.a
2726

28-
INC = -I./../ -I/usr/include/python2.7 -I/usr/include/gtk-2.0 \
29-
-I/usr/include/glib-2.0 -I/usr/lib/i386-linux-gnu/gtk-2.0/include \
30-
-I/usr/lib/i386-linux-gnu/glib-2.0/include -I/usr/include/cairo \
31-
-I/usr/include/pango-1.0 -I/usr/include/gdk-pixbuf-2.0 \
32-
-I/usr/include/atk-1.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
27+
INC = -I./../ -I/usr/include/python2.7 \
28+
-I/usr/include/gtk-2.0 \
29+
-I/usr/include/gtk-unix-print-2.0 \
30+
-I/usr/include/glib-2.0 \
31+
-I/usr/include/cairo \
32+
-I/usr/include/pango-1.0 \
33+
-I/usr/include/gdk-pixbuf-2.0 \
34+
-I/usr/include/atk-1.0 \
3335
-I/usr/lib/x86_64-linux-gnu/gtk-2.0/include \
34-
-I/usr/lib64/glib-2.0/include -I/usr/lib64/gtk-2.0/include \
35-
-I/usr/lib/glib-2.0/include -I/usr/lib/gtk-2.0/include
36+
-I/usr/lib/x86_64-linux-gnu/gtk-unix-print-2.0 \
37+
-I/usr/lib/x86_64-linux-gnu/glib-2.0/include \
38+
-I/usr/lib/i386-linux-gnu/gtk-2.0/include \
39+
-I/usr/lib/i386-linux-gnu/gtk-unix-print-2.0 \
40+
-I/usr/lib/i386-linux-gnu/glib-2.0/include \
41+
-I/usr/lib64/gtk-2.0/include \
42+
-I/usr/lib64/gtk-unix-print-2.0 \
43+
-I/usr/lib64/glib-2.0/include \
44+
-I/usr/lib/gtk-2.0/include \
45+
-I/usr/lib/gtk-2.0/gtk-unix-print-2.0 \
46+
-I/usr/lib/glib-2.0/include
3647

3748
.cpp.o:
38-
@echo [Makefile] Building $@ from $<...
49+
@echo [CLIENT HANDLER] Building $@ from $<...
3950
$(CC) $(CCFLAGS) $(INC) -c $< -o $@
4051

4152
$(OUT): $(OBJ)
42-
@echo [Makefile] Creating library $(OUT) from $(OBJ)...
53+
@echo [CLIENT HANDLER] Creating library $(OUT) from $(OBJ)...
4354
ar rcs $(OUT) $(OBJ)
4455

4556
util_mac.o: util_mac.mm
46-
@echo [Makefile] Building $@ from $<...
57+
@echo [CLIENT HANDLER] Building $@ from $<...
4758
$(CC) $(CCFLAGS) $(INC) -c $< -o $@
4859

4960
clean:
61+
@echo [CLIENT HANDLER] Cleaning...
5062
rm *.o *.a

src/client_handler/client_handler.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -327,15 +327,6 @@ void ClientHandler::OnProtocolExecution(CefRefPtr<CefBrowser> browser,
327327
RequestHandler_OnProtocolExecution(browser, url, allow_os_execution);
328328
}
329329

330-
bool ClientHandler::OnBeforePluginLoad(CefRefPtr<CefBrowser> browser,
331-
const CefString& url,
332-
const CefString& policy_url,
333-
CefRefPtr<CefWebPluginInfo> info) {
334-
REQUIRE_IO_THREAD();
335-
return RequestHandler_OnBeforePluginLoad(browser, url, policy_url, info);
336-
// Default: return false;
337-
}
338-
339330
bool ClientHandler::OnCertificateError(
340331
CefRefPtr<CefBrowser> browser, // not used
341332
cef_errorcode_t cert_error,

src/client_handler/client_handler.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ class ClientHandler :
194194
virtual void OnProtocolExecution(CefRefPtr<CefBrowser> browser,
195195
const CefString& url,
196196
bool& allow_os_execution) OVERRIDE;
197-
198-
virtual bool OnBeforePluginLoad(CefRefPtr<CefBrowser> browser,
199-
const CefString& url,
200-
const CefString& policy_url,
201-
CefRefPtr<CefWebPluginInfo> info) OVERRIDE;
202-
203197
virtual bool OnCertificateError(
204198
CefRefPtr<CefBrowser> browser, // not used
205199
cef_errorcode_t cert_error,

src/client_handler/request_context_handler.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,15 @@ CefRefPtr<CefCookieManager> RequestContextHandler::GetCookieManager() {
2121
}
2222
// Default: return NULL.
2323
}
24+
25+
bool RequestContextHandler::OnBeforePluginLoad(
26+
const CefString& mime_type,
27+
const CefString& plugin_url,
28+
const CefString& top_origin_url,
29+
CefRefPtr<CefWebPluginInfo> plugin_info,
30+
PluginPolicy* plugin_policy) {
31+
// Called on multiple threads
32+
return RequestHandler_OnBeforePluginLoad(browser_, mime_type, plugin_url,
33+
top_origin_url, plugin_info,
34+
plugin_policy);
35+
}

src/client_handler/request_context_handler.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
class RequestContextHandler :
1414
public CefRequestContextHandler
1515
{
16+
private:
17+
CefRefPtr<CefBrowser> browser_;
18+
typedef cef_plugin_policy_t PluginPolicy;
19+
1620
public:
1721
// Browser may be NULL when instantiated from cefpython.CreateBrowserSync.
1822
// In such case SetBrowser will be called after browser creation.
@@ -26,9 +30,11 @@ class RequestContextHandler :
2630
}
2731

2832
virtual CefRefPtr<CefCookieManager> GetCookieManager() OVERRIDE;
29-
30-
private:
31-
CefRefPtr<CefBrowser> browser_;
33+
virtual bool OnBeforePluginLoad(const CefString& mime_type,
34+
const CefString& plugin_url,
35+
const CefString& top_origin_url,
36+
CefRefPtr<CefWebPluginInfo> plugin_info,
37+
PluginPolicy* plugin_policy) OVERRIDE;
3238

3339
private:
3440
IMPLEMENT_REFCOUNTING(RequestContextHandler);

src/cython_includes/cef_types.pxd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,9 @@ cdef extern from "include/internal/cef_types.h":
328328
PK_LOCAL_APP_DATA,
329329
PK_USER_DATA,
330330
ctypedef cef_path_key_t PathKey
331+
332+
ctypedef enum cef_plugin_policy_t:
333+
PLUGIN_POLICY_ALLOW,
334+
PLUGIN_POLICY_DETECT_IMPORTANT,
335+
PLUGIN_POLICY_BLOCK,
336+
PLUGIN_POLICY_DISABLE,

src/linux/binaries_32bit/wxpython.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -493,15 +493,17 @@ def OnProtocolExecution(self, browser, url, allowExecutionOut):
493493
print("[wxpython.py] Magnet link allowed!")
494494
allowExecutionOut[0] = True
495495

496-
def _OnBeforePluginLoad(self, browser, url, policyUrl, info):
496+
def _OnBeforePluginLoad(self, browser, mimeType, pluginUrl, topOriginUrl,
497+
info):
497498
# This is a global callback set using SetGlobalClientCallback().
498499
# Plugins are loaded on demand, only when website requires it,
499500
# the same plugin may be called multiple times.
500-
# This callback is called on the IO thread, thus print messages
501+
# This callback is called on various threads, thus print messages
501502
# may not be visible.
502503
print("[wxpython.py] RequestHandler::_OnBeforePluginLoad()")
503-
print(" url = %s" % url)
504-
print(" policy url = %s" % policyUrl)
504+
print(" mimeType = %s" % mimeType)
505+
print(" pluginUrl = %s" % pluginUrl)
506+
print(" topOriginUrl = %s" % topOriginUrl)
505507
print(" info.GetName() = %s" % info.GetName())
506508
print(" info.GetPath() = %s" % info.GetPath())
507509
print(" info.GetVersion() = %s" % info.GetVersion())

src/linux/binaries_64bit/wxpython.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,15 +480,17 @@ def OnProtocolExecution(self, browser, url, allowExecutionOut):
480480
print("[wxpython.py] Magnet link allowed!")
481481
allowExecutionOut[0] = True
482482

483-
def _OnBeforePluginLoad(self, browser, url, policyUrl, info):
483+
def _OnBeforePluginLoad(self, browser, mimeType, pluginUrl, topOriginUrl,
484+
info):
484485
# This is a global callback set using SetGlobalClientCallback().
485486
# Plugins are loaded on demand, only when website requires it,
486487
# the same plugin may be called multiple times.
487-
# This callback is called on the IO thread, thus print messages
488+
# This callback is called on various threads, thus print messages
488489
# may not be visible.
489490
print("[wxpython.py] RequestHandler::_OnBeforePluginLoad()")
490-
print(" url = %s" % url)
491-
print(" policy url = %s" % policyUrl)
491+
print(" mimeType = %s" % mimeType)
492+
print(" pluginUrl = %s" % pluginUrl)
493+
print(" topOriginUrl = %s" % topOriginUrl)
492494
print(" info.GetName() = %s" % info.GetName())
493495
print(" info.GetPath() = %s" % info.GetPath())
494496
print(" info.GetVersion() = %s" % info.GetVersion())

0 commit comments

Comments
 (0)