X Tutup
Skip to content

Commit 5cdc1cf

Browse files
committed
Fixed issues related to embedding multiple browsers in tabs (Issue 97).
Added the Browser.`LoadUrl` and `GetUrl` methods.
1 parent 913310f commit 5cdc1cf

File tree

10 files changed

+179
-103
lines changed

10 files changed

+179
-103
lines changed

cefpython/browser.pyx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ cdef class PyBrowser:
402402
else:
403403
return self.GetWindowHandle()
404404

405+
cpdef py_string GetUrl(self):
406+
return self.GetMainFrame().GetUrl()
407+
405408
cpdef object GetUserData(self, object key):
406409
if key in self.userData:
407410
return self.userData[key]
@@ -457,9 +460,12 @@ cdef class PyBrowser:
457460
ELIF CEF_VERSION == 3:
458461
return self.GetCefBrowserHost().get().IsWindowRenderingDisabled()
459462

460-
cpdef py_void Navigate(self, py_string url):
463+
cpdef py_string LoadUrl(self, py_string url):
461464
self.GetMainFrame().LoadUrl(url)
462465

466+
cpdef py_void Navigate(self, py_string url):
467+
self.LoadUrl(url)
468+
463469
IF CEF_VERSION == 3:
464470
cpdef py_void Print(self):
465471
self.GetCefBrowserHost().get().Print()

cefpython/cef3/linux/binaries_32bit/wxpython.html

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ <h2>Table of contents</h2>
3737
<li><a href="#user-agent">User agent</a></li>
3838
<li><a href="#popups">Popups</a></li>
3939
<li><a href="#html5-video">HTML 5 video</a></li>
40+
<li><a href="#browser-object">Browser object</a></li>
41+
<li><a href="#frame-object">Frame object</a></li>
4042
<li><a href="#javascript-bindings">Javascript bindings</a></li>
4143
<li><a href="#javascript-callbacks">Javascript callbacks</a></li>
4244
<li><a href="#python-callbacks">Python callbacks</a></li>
@@ -46,7 +48,6 @@ <h2>Table of contents</h2>
4648
<li><a href="#cookie-tests">Cookie tests</a></li>
4749
<li><a href="#load-handler">Load handler</a></li>
4850
<li><a href="#javascript-dialog-handler">Javascript Dialog handler</a></li>
49-
<li><a href="#other-tests">Other tests</a></li>
5051
</ol>
5152

5253
<!-- ********************************************************************** -->
@@ -115,6 +116,37 @@ <h2>HTML5 video and accelerated content</h2>
115116
<a href="http://www.webkit.org/blog-files/3d-transforms/poster-circle.html">
116117
Accelerated layers</a><br>
117118

119+
<!-- ********************************************************************** -->
120+
<!-- Browser object -->
121+
<!-- ********************************************************************** -->
122+
123+
<a name="browser-object"></a>
124+
<h2>Browser object</h2>
125+
126+
Tests for the Browser object methods.
127+
128+
<h3>GoBack</h3>
129+
<script>ShowSource("GoBack");</script>
130+
<a href="javascript:external.GoBack()">external.GoBack()</a>
131+
132+
<h3>GoForward</h3>
133+
<script>ShowSource("GoForward");</script>
134+
<a href="javascript:external.GoForward()">external.GoForward()</a>
135+
136+
<h3>LoadUrl, GetUrl</h3>
137+
<script>ShowSource("_Browser_LoadUrl");</script>
138+
<a href="javascript:window.open('data:text/html,Test#Browser.LoadUrl')">
139+
window.open('data:text/html,Test#Browser.LoadUrl')</a>
140+
141+
<!-- ********************************************************************** -->
142+
<!-- Frame object -->
143+
<!-- ********************************************************************** -->
144+
145+
<a name="frame-object"></a>
146+
<h2>Frame object</h2>
147+
148+
Tests for the Frame object methods. TODO.
149+
118150
<!-- ********************************************************************** -->
119151
<!-- Javascript bindings -->
120152
<!-- ********************************************************************** -->
@@ -558,21 +590,6 @@ <h3>OnResetJavascriptDialogState</h3>
558590
<h3>OnJavascriptDialogClosed</h3>
559591
<script>ShowSource("OnJavascriptDialogClosed");</script>
560592

561-
<!-- ********************************************************************** -->
562-
<!-- Other tests -->
563-
<!-- ********************************************************************** -->
564-
565-
<a name="other-tests"></a>
566-
<h2>Other tests</h2>
567-
568-
<h3>GoBack</h3>
569-
<script>ShowSource("GoBack");</script>
570-
<a href="javascript:external.GoBack()">external.GoBack()</a>
571-
572-
<h3>GoForward</h3>
573-
<script>ShowSource("GoForward");</script>
574-
<a href="javascript:external.GoForward()">external.GoForward()</a>
575-
576593
<!-- ********************************************************************** -->
577594
<!-- Other -->
578595
<!-- ********************************************************************** -->

cefpython/cef3/linux/binaries_32bit/wxpython.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import platform
2929
import inspect
3030

31+
g_browserSettings = None
32+
3133
# Which method to use for message loop processing.
3234
# EVT_IDLE - wx application has priority (default)
3335
# EVT_TIMER - cef browser has priority
@@ -119,10 +121,10 @@ def __init__(self, url=None):
119121
windowInfo,
120122
# If there are problems with Flash you can disable it here,
121123
# by disabling all plugins.
122-
browserSettings={"plugins_disabled": False},
124+
browserSettings=g_browserSettings,
123125
navigateUrl=url)
124126

125-
clientHandler = ClientHandler()
127+
clientHandler = ClientHandler(self.browser)
126128
self.browser.SetClientHandler(clientHandler)
127129
cefpython.SetGlobalClientCallback("OnCertificateError",
128130
clientHandler._OnCertificateError)
@@ -316,6 +318,11 @@ def Visit(self, cookie, count, total, deleteCookie):
316318
return True
317319

318320
class ClientHandler:
321+
mainBrowser = None
322+
323+
def __init__(self, browser):
324+
self.mainBrowser = browser
325+
319326
# -------------------------------------------------------------------------
320327
# DisplayHandler
321328
# -------------------------------------------------------------------------
@@ -376,18 +383,18 @@ def OnKeyEvent(self, browser, event, eventHandle):
376383

377384
def OnBeforeBrowse(self, browser, frame, request, isRedirect):
378385
print("[wxpython.py] RequestHandler::OnBeforeBrowse()")
379-
print(" url = %s" % request.GetUrl()[:70])
386+
print(" url = %s" % request.GetUrl()[:100])
380387
return False
381388

382389
def OnBeforeResourceLoad(self, browser, frame, request):
383390
print("[wxpython.py] RequestHandler::OnBeforeResourceLoad()")
384-
print(" url = %s" % request.GetUrl()[:70])
391+
print(" url = %s" % request.GetUrl()[:100])
385392
return False
386393

387394
def OnResourceRedirect(self, browser, frame, oldUrl, newUrlOut):
388395
print("[wxpython.py] RequestHandler::OnResourceRedirect()")
389-
print(" old url = %s" % oldUrl[:70])
390-
print(" new url = %s" % newUrlOut[0][:70])
396+
print(" old url = %s" % oldUrl[:100])
397+
print(" new url = %s" % newUrlOut[0][:100])
391398

392399
def GetAuthCredentials(self, browser, frame, isProxy, host, port, realm,
393400
scheme, callback):
@@ -495,17 +502,23 @@ def OnLoadingStateChange(self, browser, isLoading, canGoBack,
495502

496503
def OnLoadStart(self, browser, frame):
497504
print("[wxpython.py] LoadHandler::OnLoadStart()")
498-
print(" frame url = %s" % frame.GetUrl()[:70])
505+
print(" frame url = %s" % frame.GetUrl()[:100])
499506

500507
def OnLoadEnd(self, browser, frame, httpStatusCode):
501508
print("[wxpython.py] LoadHandler::OnLoadEnd()")
502-
print(" frame url = %s" % frame.GetUrl()[:70])
509+
print(" frame url = %s" % frame.GetUrl()[:100])
503510
# For file:// urls the status code = 0
504511
print(" http status code = %s" % httpStatusCode)
512+
# Tests for the Browser object methods
513+
self._Browser_LoadUrl(browser)
514+
515+
def _Browser_LoadUrl(self, browser):
516+
if browser.GetUrl() == "data:text/html,Test#Browser.LoadUrl":
517+
browser.LoadUrl("file://"+GetApplicationPath("wxpython.html"))
505518

506519
def OnLoadError(self, browser, frame, errorCode, errorTextList, failedUrl):
507520
print("[wxpython.py] LoadHandler::OnLoadError()")
508-
print(" frame url = %s" % frame.GetUrl()[:70])
521+
print(" frame url = %s" % frame.GetUrl()[:100])
509522
print(" error code = %s" % errorCode)
510523
print(" error text = %s" % errorTextList[0])
511524
print(" failed url = %s" % failedUrl)
@@ -645,9 +658,19 @@ def GetSources():
645658
# for each browser created using CreateBrowserSync.
646659
"unique_request_context_per_browser": True
647660
}
661+
662+
# Browser settings. You may have different settings for each
663+
# browser, see the call to CreateBrowserSync.
664+
g_browserSettings = {
665+
# "plugins_disabled": True,
666+
"file_access_from_file_urls_allowed": True,
667+
"universal_access_from_file_urls_allowed": True,
668+
}
648669

649670
# Command line switches set programmatically
650671
switches = {
672+
"allow-file-access-from-files": "",
673+
"allow-file-access": "",
651674
# "proxy-server": "socks5://127.0.0.1:8888",
652675
# "no-proxy-server": "",
653676
# "enable-media-stream": "",

cefpython/cef3/linux/binaries_64bit/wxpython.html

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ <h2>Table of contents</h2>
3737
<li><a href="#user-agent">User agent</a></li>
3838
<li><a href="#popups">Popups</a></li>
3939
<li><a href="#html5-video">HTML 5 video</a></li>
40+
<li><a href="#browser-object">Browser object</a></li>
41+
<li><a href="#frame-object">Frame object</a></li>
4042
<li><a href="#javascript-bindings">Javascript bindings</a></li>
4143
<li><a href="#javascript-callbacks">Javascript callbacks</a></li>
4244
<li><a href="#python-callbacks">Python callbacks</a></li>
@@ -46,7 +48,6 @@ <h2>Table of contents</h2>
4648
<li><a href="#cookie-tests">Cookie tests</a></li>
4749
<li><a href="#load-handler">Load handler</a></li>
4850
<li><a href="#javascript-dialog-handler">Javascript Dialog handler</a></li>
49-
<li><a href="#other-tests">Other tests</a></li>
5051
</ol>
5152

5253
<!-- ********************************************************************** -->
@@ -115,6 +116,37 @@ <h2>HTML5 video and accelerated content</h2>
115116
<a href="http://www.webkit.org/blog-files/3d-transforms/poster-circle.html">
116117
Accelerated layers</a><br>
117118

119+
<!-- ********************************************************************** -->
120+
<!-- Browser object -->
121+
<!-- ********************************************************************** -->
122+
123+
<a name="browser-object"></a>
124+
<h2>Browser object</h2>
125+
126+
Tests for the Browser object methods.
127+
128+
<h3>GoBack</h3>
129+
<script>ShowSource("GoBack");</script>
130+
<a href="javascript:external.GoBack()">external.GoBack()</a>
131+
132+
<h3>GoForward</h3>
133+
<script>ShowSource("GoForward");</script>
134+
<a href="javascript:external.GoForward()">external.GoForward()</a>
135+
136+
<h3>LoadUrl, GetUrl</h3>
137+
<script>ShowSource("_Browser_LoadUrl");</script>
138+
<a href="javascript:window.open('data:text/html,Test#Browser.LoadUrl')">
139+
window.open('data:text/html,Test#Browser.LoadUrl')</a>
140+
141+
<!-- ********************************************************************** -->
142+
<!-- Frame object -->
143+
<!-- ********************************************************************** -->
144+
145+
<a name="frame-object"></a>
146+
<h2>Frame object</h2>
147+
148+
Tests for the Frame object methods. TODO.
149+
118150
<!-- ********************************************************************** -->
119151
<!-- Javascript bindings -->
120152
<!-- ********************************************************************** -->
@@ -558,21 +590,6 @@ <h3>OnResetJavascriptDialogState</h3>
558590
<h3>OnJavascriptDialogClosed</h3>
559591
<script>ShowSource("OnJavascriptDialogClosed");</script>
560592

561-
<!-- ********************************************************************** -->
562-
<!-- Other tests -->
563-
<!-- ********************************************************************** -->
564-
565-
<a name="other-tests"></a>
566-
<h2>Other tests</h2>
567-
568-
<h3>GoBack</h3>
569-
<script>ShowSource("GoBack");</script>
570-
<a href="javascript:external.GoBack()">external.GoBack()</a>
571-
572-
<h3>GoForward</h3>
573-
<script>ShowSource("GoForward");</script>
574-
<a href="javascript:external.GoForward()">external.GoForward()</a>
575-
576593
<!-- ********************************************************************** -->
577594
<!-- Other -->
578595
<!-- ********************************************************************** -->

cefpython/cef3/linux/binaries_64bit/wxpython.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import platform
2929
import inspect
3030

31+
g_browserSettings = None
32+
3133
# Which method to use for message loop processing.
3234
# EVT_IDLE - wx application has priority (default)
3335
# EVT_TIMER - cef browser has priority
@@ -119,10 +121,10 @@ def __init__(self, url=None):
119121
windowInfo,
120122
# If there are problems with Flash you can disable it here,
121123
# by disabling all plugins.
122-
browserSettings={"plugins_disabled": False},
124+
browserSettings=g_browserSettings,
123125
navigateUrl=url)
124126

125-
clientHandler = ClientHandler()
127+
clientHandler = ClientHandler(self.browser)
126128
self.browser.SetClientHandler(clientHandler)
127129
cefpython.SetGlobalClientCallback("OnCertificateError",
128130
clientHandler._OnCertificateError)
@@ -316,6 +318,11 @@ def Visit(self, cookie, count, total, deleteCookie):
316318
return True
317319

318320
class ClientHandler:
321+
mainBrowser = None
322+
323+
def __init__(self, browser):
324+
self.mainBrowser = browser
325+
319326
# -------------------------------------------------------------------------
320327
# DisplayHandler
321328
# -------------------------------------------------------------------------
@@ -376,18 +383,18 @@ def OnKeyEvent(self, browser, event, eventHandle):
376383

377384
def OnBeforeBrowse(self, browser, frame, request, isRedirect):
378385
print("[wxpython.py] RequestHandler::OnBeforeBrowse()")
379-
print(" url = %s" % request.GetUrl()[:70])
386+
print(" url = %s" % request.GetUrl()[:100])
380387
return False
381388

382389
def OnBeforeResourceLoad(self, browser, frame, request):
383390
print("[wxpython.py] RequestHandler::OnBeforeResourceLoad()")
384-
print(" url = %s" % request.GetUrl()[:70])
391+
print(" url = %s" % request.GetUrl()[:100])
385392
return False
386393

387394
def OnResourceRedirect(self, browser, frame, oldUrl, newUrlOut):
388395
print("[wxpython.py] RequestHandler::OnResourceRedirect()")
389-
print(" old url = %s" % oldUrl[:70])
390-
print(" new url = %s" % newUrlOut[0][:70])
396+
print(" old url = %s" % oldUrl[:100])
397+
print(" new url = %s" % newUrlOut[0][:100])
391398

392399
def GetAuthCredentials(self, browser, frame, isProxy, host, port, realm,
393400
scheme, callback):
@@ -495,17 +502,23 @@ def OnLoadingStateChange(self, browser, isLoading, canGoBack,
495502

496503
def OnLoadStart(self, browser, frame):
497504
print("[wxpython.py] LoadHandler::OnLoadStart()")
498-
print(" frame url = %s" % frame.GetUrl()[:70])
505+
print(" frame url = %s" % frame.GetUrl()[:100])
499506

500507
def OnLoadEnd(self, browser, frame, httpStatusCode):
501508
print("[wxpython.py] LoadHandler::OnLoadEnd()")
502-
print(" frame url = %s" % frame.GetUrl()[:70])
509+
print(" frame url = %s" % frame.GetUrl()[:100])
503510
# For file:// urls the status code = 0
504511
print(" http status code = %s" % httpStatusCode)
512+
# Tests for the Browser object methods
513+
self._Browser_LoadUrl(browser)
514+
515+
def _Browser_LoadUrl(self, browser):
516+
if browser.GetUrl() == "data:text/html,Test#Browser.LoadUrl":
517+
browser.LoadUrl("file://"+GetApplicationPath("wxpython.html"))
505518

506519
def OnLoadError(self, browser, frame, errorCode, errorTextList, failedUrl):
507520
print("[wxpython.py] LoadHandler::OnLoadError()")
508-
print(" frame url = %s" % frame.GetUrl()[:70])
521+
print(" frame url = %s" % frame.GetUrl()[:100])
509522
print(" error code = %s" % errorCode)
510523
print(" error text = %s" % errorTextList[0])
511524
print(" failed url = %s" % failedUrl)
@@ -645,9 +658,19 @@ def GetSources():
645658
# for each browser created using CreateBrowserSync.
646659
"unique_request_context_per_browser": True
647660
}
661+
662+
# Browser settings. You may have different settings for each
663+
# browser, see the call to CreateBrowserSync.
664+
g_browserSettings = {
665+
# "plugins_disabled": True,
666+
"file_access_from_file_urls_allowed": True,
667+
"universal_access_from_file_urls_allowed": True,
668+
}
648669

649670
# Command line switches set programmatically
650671
switches = {
672+
"allow-file-access-from-files": "",
673+
"allow-file-access": "",
651674
# "proxy-server": "socks5://127.0.0.1:8888",
652675
# "no-proxy-server": "",
653676
# "enable-media-stream": "",

cefpython/cef3/linux/example.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

cefpython/cef3/linux/rebuild.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python compile.py

0 commit comments

Comments
 (0)
X Tutup