X Tutup
Skip to content

Commit 074d3e5

Browse files
CzarekCzarek
authored andcommitted
Updated CEF Python to CEF branch 1650 revision 1639. Chrome version is
31.0.1650.69 (Issue 124). Tested currently only on Linux. Updated python examples. Added ApplicationSettings.unique_request_context_per_browser. Fixed problems with unique cookie manager per browser session (Issue 126).
1 parent d84ca69 commit 074d3e5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1260
-2139
lines changed

cefpython/browser.pyx

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ IF CEF_VERSION == 3:
9292
# TODO: call this function also in CEF 1.
9393
global g_pyBrowsers
9494
if browserId in g_pyBrowsers:
95+
if len(g_pyBrowsers) == 1:
96+
# This is the last browser remaining.
97+
if g_sharedRequestContext.get():
98+
# A similar release is done in Shutdown and CloseBrowser.
99+
Debug("RemovePyBrowser: releasing shared request context")
100+
g_sharedRequestContext.get().Release()
95101
Debug("del g_pyBrowsers[%s]" % browserId)
96102
del g_pyBrowsers[browserId]
97103
else:
@@ -157,6 +163,9 @@ cdef class PyBrowser:
157163
ELIF CEF_VERSION == 3:
158164
self.SetClientCallback_CEF3(name, callback)
159165

166+
# -------------------------------------------------------------------------
167+
# CEF 1
168+
# -------------------------------------------------------------------------
160169
cpdef py_void SetClientCallback_CEF1(self,
161170
py_string name, object callback):
162171
if not self.allowedClientCallbacks:
@@ -174,6 +183,7 @@ cdef class PyBrowser:
174183
"OnResourceResponse", "OnProtocolExecution",
175184
"GetDownloadHandler", "GetAuthCredentials",
176185
"GetCookieManager"]
186+
177187
# CefDisplayHandler.
178188
self.allowedClientCallbacks += ["OnAddressChange",
179189
"OnConsoleMessage", "OnContentsSizeChange",
@@ -193,11 +203,14 @@ cdef class PyBrowser:
193203
"callback: %s" % name)
194204
self.clientCallbacks[name] = callback
195205

206+
# -------------------------------------------------------------------------
207+
# CEF 3
208+
# -------------------------------------------------------------------------
196209
cpdef py_void SetClientCallback_CEF3(self,
197210
py_string name, object callback):
198211
if not self.allowedClientCallbacks:
199212
# DisplayHandler
200-
self.allowedClientCallbacks += ["OnLoadingStateChange",
213+
self.allowedClientCallbacks += [
201214
"OnAddressChange", "OnTitleChange", "OnTooltip",
202215
"OnStatusMessage", "OnConsoleMessage"]
203216
# KeyboardHandler
@@ -207,13 +220,15 @@ cdef class PyBrowser:
207220
# set using cefpython.SetGlobalClientCallback()
208221
self.allowedClientCallbacks += ["OnBeforeResourceLoad",
209222
"OnResourceRedirect", "GetAuthCredentials",
210-
"OnQuotaRequest", "GetCookieManager",
211-
"OnProtocolExecution", "GetResourceHandler",
212-
"OnBeforeBrowse"]
213-
# LoadHandler
214-
self.allowedClientCallbacks += ["OnLoadStart", "OnLoadEnd",
215-
"OnLoadError", "OnRendererProcessTerminated",
223+
"OnQuotaRequest", "OnProtocolExecution",
224+
"GetResourceHandler",
225+
"OnBeforeBrowse", "OnRendererProcessTerminated",
216226
"OnPluginCrashed"]
227+
# RequestContextHandler
228+
self.allowedClientCallbacks += ["GetCookieManager"]
229+
# LoadHandler
230+
self.allowedClientCallbacks += ["OnLoadingStateChange",
231+
"OnLoadStart", "OnLoadEnd", "OnLoadError"]
217232
# LifespanHandler
218233
self.allowedClientCallbacks += ["OnBeforePopup"]
219234
# RenderHandler
@@ -294,6 +309,13 @@ cdef class PyBrowser:
294309
# implementing LifespanHandler::DoClose().
295310
# | Debug("CefBrowser::ParentWindowWillClose()")
296311
# | self.GetCefBrowserHost().get().ParentWindowWillClose()
312+
if len(g_pyBrowsers) == 1:
313+
# This is the last browser remaining.
314+
if g_sharedRequestContext.get():
315+
# A similar release is done in Shutdown
316+
# and RemovePyBrowser.
317+
Debug("CloseBrowser: releasing shared request context")
318+
g_sharedRequestContext.get().Release()
297319
Debug("CefBrowser::CloseBrowser(%s)" % forceClose)
298320
self.GetCefBrowserHost().get().CloseBrowser(bool(forceClose))
299321

cefpython/cef3/BUILD_COMPATIBILITY.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Chromium/CEF branch:
2-
1547
2+
1650
33
Chromium release url:
4-
http://src.chromium.org/svn/releases/29.0.1547.80
4+
http://src.chromium.org/svn/releases/31.0.1650.69
55
CEF revision:
6-
1491
6+
1639
77
CEF repository url:
8-
http://chromiumembedded.googlecode.com/svn/branches/1547/cef3@1491
8+
http://chromiumembedded.googlecode.com/svn/branches/1650/cef3@1639
99

1010
----
1111

cefpython/cef3/DebugLog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ inline void DebugLog(const char* szString)
1515
if (!g_debug)
1616
return;
1717
// TODO: get the log_file option from CefSettings.
18-
printf("cefpython: %s\n", szString);
18+
printf("[CEF Python] %s\n", szString);
1919
if (g_logFile.length()) {
2020
FILE* pFile = fopen(g_logFile.c_str(), "a");
21-
fprintf(pFile, "cefpython_app: %s\n", szString);
21+
fprintf(pFile, "[CEF Python] App: %s\n", szString);
2222
fclose(pFile);
2323
}
2424
}

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 string_visitor.cpp
15+
web_request_client.cpp string_visitor.cpp request_context_handler.cpp
1616
OBJ = $(SRC:.cpp=.o)
1717
OUT = libclient_handler.a
1818

cefpython/cef3/client_handler/client_handler.cpp

Lines changed: 37 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -228,19 +228,6 @@ void ClientHandler::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
228228
// The methods of this class will be called on the UI thread.
229229
///
230230

231-
///
232-
// Called when the loading state has changed.
233-
///
234-
/*--cef()--*/
235-
void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
236-
bool isLoading,
237-
bool canGoBack,
238-
bool canGoForward) {
239-
REQUIRE_UI_THREAD();
240-
DisplayHandler_OnLoadingStateChange(browser, isLoading, canGoBack,
241-
canGoForward);
242-
}
243-
244231
///
245232
// Called when a frame's address has changed.
246233
///
@@ -357,7 +344,7 @@ bool ClientHandler::OnKeyEvent(CefRefPtr<CefBrowser> browser,
357344
// Called on the UI thread before browser navigation. Return true to cancel
358345
// the navigation or false to allow the navigation to proceed. The |request|
359346
// object cannot be modified in this callback.
360-
// CefDisplayHandler::OnLoadingStateChange will be called twice in all cases.
347+
// CefLoadHandler::OnLoadingStateChange will be called twice in all cases.
361348
// If the navigation is allowed CefLoadHandler::OnLoadStart and
362349
// CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled
363350
// CefLoadHandler::OnLoadError will be called with an |errorCode| value of
@@ -456,21 +443,6 @@ bool ClientHandler::OnQuotaRequest(CefRefPtr<CefBrowser> browser,
456443
// Default: return false;
457444
}
458445

459-
///
460-
// Called on the IO thread to retrieve the cookie manager. |main_url| is the
461-
// URL of the top-level frame. Cookies managers can be unique per browser or
462-
// shared across multiple browsers. The global cookie manager will be used if
463-
// this method returns NULL.
464-
///
465-
/*--cef()--*/
466-
CefRefPtr<CefCookieManager> ClientHandler::GetCookieManager(
467-
CefRefPtr<CefBrowser> browser,
468-
const CefString& main_url) {
469-
REQUIRE_IO_THREAD();
470-
return RequestHandler_GetCookieManager(browser, main_url);
471-
// Default: return NULL.
472-
}
473-
474446
///
475447
// Called on the UI thread to handle requests for URLs with an unknown
476448
// protocol component. Set |allow_os_execution| to true to attempt execution
@@ -520,6 +492,29 @@ bool ClientHandler::OnCertificateError(
520492
// Default: return false;
521493
}
522494

495+
///
496+
// Called when the render process terminates unexpectedly. |status| indicates
497+
// how the process terminated.
498+
///
499+
/*--cef()--*/
500+
void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
501+
cef_termination_status_t status) {
502+
REQUIRE_UI_THREAD();
503+
DebugLog("Browser: OnRenderProcessTerminated()");
504+
RequestHandler_OnRendererProcessTerminated(browser, status);
505+
}
506+
507+
///
508+
// Called when a plugin has crashed. |plugin_path| is the path of the plugin
509+
// that crashed.
510+
///
511+
/*--cef()--*/
512+
void ClientHandler::OnPluginCrashed(CefRefPtr<CefBrowser> browser,
513+
const CefString& plugin_path) {
514+
REQUIRE_UI_THREAD();
515+
RequestHandler_OnPluginCrashed(browser, plugin_path);
516+
}
517+
523518
// --------------------------------------------------------------------------
524519
// CefLoadHandler
525520
// --------------------------------------------------------------------------
@@ -529,6 +524,19 @@ bool ClientHandler::OnCertificateError(
529524
// The methods of this class will be called on the UI thread.
530525
///
531526

527+
///
528+
// Called when the loading state has changed.
529+
///
530+
/*--cef()--*/
531+
void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
532+
bool isLoading,
533+
bool canGoBack,
534+
bool canGoForward) {
535+
REQUIRE_UI_THREAD();
536+
LoadHandler_OnLoadingStateChange(browser, isLoading, canGoBack,
537+
canGoForward);
538+
}
539+
532540
///
533541
// Called when the browser begins loading a frame. The |frame| value will
534542
// never be empty -- call the IsMain() method to check if this frame is the
@@ -576,29 +584,6 @@ void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
576584
LoadHandler_OnLoadError(browser, frame, errorCode, errorText, failedUrl);
577585
}
578586

579-
///
580-
// Called when the render process terminates unexpectedly. |status| indicates
581-
// how the process terminated.
582-
///
583-
/*--cef()--*/
584-
void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
585-
cef_termination_status_t status) {
586-
REQUIRE_UI_THREAD();
587-
DebugLog("Browser: OnRenderProcessTerminated()");
588-
LoadHandler_OnRendererProcessTerminated(browser, status);
589-
}
590-
591-
///
592-
// Called when a plugin has crashed. |plugin_path| is the path of the plugin
593-
// that crashed.
594-
///
595-
/*--cef()--*/
596-
void ClientHandler::OnPluginCrashed(CefRefPtr<CefBrowser> browser,
597-
const CefString& plugin_path) {
598-
REQUIRE_UI_THREAD();
599-
LoadHandler_OnPluginCrashed(browser, plugin_path);
600-
}
601-
602587
// ----------------------------------------------------------------------------
603588
// CefRenderHandler
604589
// ----------------------------------------------------------------------------

cefpython/cef3/client_handler/client_handler.h

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,6 @@ class ClientHandler :
271271
// The methods of this class will be called on the UI thread.
272272
///
273273

274-
///
275-
// Called when the loading state has changed.
276-
///
277-
/*--cef()--*/
278-
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
279-
bool isLoading,
280-
bool canGoBack,
281-
bool canGoForward) OVERRIDE;
282-
283274
///
284275
// Called when a frame's address has changed.
285276
///
@@ -370,7 +361,7 @@ class ClientHandler :
370361
// Called on the UI thread before browser navigation. Return true to cancel
371362
// the navigation or false to allow the navigation to proceed. The |request|
372363
// object cannot be modified in this callback.
373-
// CefDisplayHandler::OnLoadingStateChange will be called twice in all cases.
364+
// CefLoadHandler::OnLoadingStateChange will be called twice in all cases.
374365
// If the navigation is allowed CefLoadHandler::OnLoadStart and
375366
// CefLoadHandler::OnLoadEnd will be called. If the navigation is canceled
376367
// CefLoadHandler::OnLoadError will be called with an |errorCode| value of
@@ -447,17 +438,6 @@ class ClientHandler :
447438
int64 new_size,
448439
CefRefPtr<CefQuotaCallback> callback) OVERRIDE;
449440

450-
///
451-
// Called on the IO thread to retrieve the cookie manager. |main_url| is the
452-
// URL of the top-level frame. Cookies managers can be unique per browser or
453-
// shared across multiple browsers. The global cookie manager will be used if
454-
// this method returns NULL.
455-
///
456-
/*--cef()--*/
457-
virtual CefRefPtr<CefCookieManager> GetCookieManager(
458-
CefRefPtr<CefBrowser> browser,
459-
const CefString& main_url) OVERRIDE;
460-
461441
///
462442
// Called on the UI thread to handle requests for URLs with an unknown
463443
// protocol component. Set |allow_os_execution| to true to attempt execution
@@ -495,6 +475,23 @@ class ClientHandler :
495475
const CefString& request_url,
496476
CefRefPtr<CefAllowCertificateErrorCallback> callback) OVERRIDE;
497477

478+
///
479+
// Called when the render process terminates unexpectedly. |status| indicates
480+
// how the process terminated.
481+
///
482+
/*--cef()--*/
483+
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
484+
cef_termination_status_t status)
485+
OVERRIDE;
486+
487+
///
488+
// Called when a plugin has crashed. |plugin_path| is the path of the plugin
489+
// that crashed.
490+
///
491+
/*--cef()--*/
492+
virtual void OnPluginCrashed(CefRefPtr<CefBrowser> browser,
493+
const CefString& plugin_path) OVERRIDE;
494+
498495
// --------------------------------------------------------------------------
499496
// CefLoadHandler
500497
// --------------------------------------------------------------------------
@@ -504,6 +501,15 @@ class ClientHandler :
504501
// The methods of this class will be called on the UI thread.
505502
///
506503

504+
///
505+
// Called when the loading state has changed.
506+
///
507+
/*--cef()--*/
508+
virtual void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
509+
bool isLoading,
510+
bool canGoBack,
511+
bool canGoForward) OVERRIDE;
512+
507513
///
508514
// Called when the browser begins loading a frame. The |frame| value will
509515
// never be empty -- call the IsMain() method to check if this frame is the
@@ -542,23 +548,6 @@ class ClientHandler :
542548
const CefString& errorText,
543549
const CefString& failedUrl) OVERRIDE;
544550

545-
///
546-
// Called when the render process terminates unexpectedly. |status| indicates
547-
// how the process terminated.
548-
///
549-
/*--cef()--*/
550-
virtual void OnRenderProcessTerminated(CefRefPtr<CefBrowser> browser,
551-
cef_termination_status_t status)
552-
OVERRIDE;
553-
554-
///
555-
// Called when a plugin has crashed. |plugin_path| is the path of the plugin
556-
// that crashed.
557-
///
558-
/*--cef()--*/
559-
virtual void OnPluginCrashed(CefRefPtr<CefBrowser> browser,
560-
const CefString& plugin_path) OVERRIDE;
561-
562551
// --------------------------------------------------------------------------
563552
// CefRenderHandler
564553
// --------------------------------------------------------------------------

cefpython/cef3/client_handler/client_handler_py27.vcproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@
104104
<File
105105
RelativePath=".\string_visitor.h"
106106
>
107+
</File>
108+
<File
109+
RelativePath=".\request_context_handler.h"
110+
>
107111
</File>
108112
</Filter>
109113
<Filter
@@ -136,6 +140,10 @@
136140
<File
137141
RelativePath=".\string_visitor.cpp"
138142
>
143+
</File>
144+
<File
145+
RelativePath=".\request_context_handler.cpp"
146+
>
139147
</File>
140148
</Filter>
141149
</Files>

0 commit comments

Comments
 (0)
X Tutup