|
28 | 28 | import platform |
29 | 29 | import inspect |
30 | 30 |
|
| 31 | +g_browserSettings = None |
| 32 | + |
31 | 33 | # Which method to use for message loop processing. |
32 | 34 | # EVT_IDLE - wx application has priority (default) |
33 | 35 | # EVT_TIMER - cef browser has priority |
@@ -119,10 +121,10 @@ def __init__(self, url=None): |
119 | 121 | windowInfo, |
120 | 122 | # If there are problems with Flash you can disable it here, |
121 | 123 | # by disabling all plugins. |
122 | | - browserSettings={"plugins_disabled": False}, |
| 124 | + browserSettings=g_browserSettings, |
123 | 125 | navigateUrl=url) |
124 | 126 |
|
125 | | - clientHandler = ClientHandler() |
| 127 | + clientHandler = ClientHandler(self.browser) |
126 | 128 | self.browser.SetClientHandler(clientHandler) |
127 | 129 | cefpython.SetGlobalClientCallback("OnCertificateError", |
128 | 130 | clientHandler._OnCertificateError) |
@@ -316,6 +318,11 @@ def Visit(self, cookie, count, total, deleteCookie): |
316 | 318 | return True |
317 | 319 |
|
318 | 320 | class ClientHandler: |
| 321 | + mainBrowser = None |
| 322 | + |
| 323 | + def __init__(self, browser): |
| 324 | + self.mainBrowser = browser |
| 325 | + |
319 | 326 | # ------------------------------------------------------------------------- |
320 | 327 | # DisplayHandler |
321 | 328 | # ------------------------------------------------------------------------- |
@@ -376,18 +383,18 @@ def OnKeyEvent(self, browser, event, eventHandle): |
376 | 383 |
|
377 | 384 | def OnBeforeBrowse(self, browser, frame, request, isRedirect): |
378 | 385 | print("[wxpython.py] RequestHandler::OnBeforeBrowse()") |
379 | | - print(" url = %s" % request.GetUrl()[:70]) |
| 386 | + print(" url = %s" % request.GetUrl()[:100]) |
380 | 387 | return False |
381 | 388 |
|
382 | 389 | def OnBeforeResourceLoad(self, browser, frame, request): |
383 | 390 | print("[wxpython.py] RequestHandler::OnBeforeResourceLoad()") |
384 | | - print(" url = %s" % request.GetUrl()[:70]) |
| 391 | + print(" url = %s" % request.GetUrl()[:100]) |
385 | 392 | return False |
386 | 393 |
|
387 | 394 | def OnResourceRedirect(self, browser, frame, oldUrl, newUrlOut): |
388 | 395 | 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]) |
391 | 398 |
|
392 | 399 | def GetAuthCredentials(self, browser, frame, isProxy, host, port, realm, |
393 | 400 | scheme, callback): |
@@ -495,17 +502,23 @@ def OnLoadingStateChange(self, browser, isLoading, canGoBack, |
495 | 502 |
|
496 | 503 | def OnLoadStart(self, browser, frame): |
497 | 504 | print("[wxpython.py] LoadHandler::OnLoadStart()") |
498 | | - print(" frame url = %s" % frame.GetUrl()[:70]) |
| 505 | + print(" frame url = %s" % frame.GetUrl()[:100]) |
499 | 506 |
|
500 | 507 | def OnLoadEnd(self, browser, frame, httpStatusCode): |
501 | 508 | print("[wxpython.py] LoadHandler::OnLoadEnd()") |
502 | | - print(" frame url = %s" % frame.GetUrl()[:70]) |
| 509 | + print(" frame url = %s" % frame.GetUrl()[:100]) |
503 | 510 | # For file:// urls the status code = 0 |
504 | 511 | 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")) |
505 | 518 |
|
506 | 519 | def OnLoadError(self, browser, frame, errorCode, errorTextList, failedUrl): |
507 | 520 | print("[wxpython.py] LoadHandler::OnLoadError()") |
508 | | - print(" frame url = %s" % frame.GetUrl()[:70]) |
| 521 | + print(" frame url = %s" % frame.GetUrl()[:100]) |
509 | 522 | print(" error code = %s" % errorCode) |
510 | 523 | print(" error text = %s" % errorTextList[0]) |
511 | 524 | print(" failed url = %s" % failedUrl) |
@@ -645,9 +658,19 @@ def GetSources(): |
645 | 658 | # for each browser created using CreateBrowserSync. |
646 | 659 | "unique_request_context_per_browser": True |
647 | 660 | } |
| 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 | + } |
648 | 669 |
|
649 | 670 | # Command line switches set programmatically |
650 | 671 | switches = { |
| 672 | + "allow-file-access-from-files": "", |
| 673 | + "allow-file-access": "", |
651 | 674 | # "proxy-server": "socks5://127.0.0.1:8888", |
652 | 675 | # "no-proxy-server": "", |
653 | 676 | # "enable-media-stream": "", |
|
0 commit comments