Skip to content

Commit 696c8f4

Browse files
CzarekCzarek
authored andcommitted
Added comments in regards to memory corruption fix in
WebRequest and ContentFilter. Fixed trailing whitespaces. Enhancements to the compile.py script.
1 parent dede9c7 commit 696c8f4

12 files changed

Lines changed: 134 additions & 78 deletions

File tree

cefpython/cef1/linux/binaries_32bit/wxpython.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ <h3>WebRequest test</h3>
9393

9494
See the console for messages.<br>
9595

96-
<a href="javascript:external.WebRequest('http://www.sitepoint.com/robots.txt')">
97-
external.WebRequest('http://www.sitepoint.com/robots.txt')</a>
96+
<a href="javascript:external.WebRequest('https://code.google.com/robots.txt')">
97+
external.WebRequest('https://code.google.com/robots.txt')</a>
9898

9999
<h3>Frame.CallFunction() test</h3>
100100

cefpython/cef1/linux/binaries_32bit/wxpython.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
# EVT_IDLE - wx application has priority (default)
2323
# EVT_TIMER - cef browser has priority
2424
# It seems that Flash content behaves better when using a timer.
25-
# IMPORTANT! On Linux EVT_IDLE does not work, the events seems to
26-
# be propagated only when you move your mouse, which is not the
25+
# IMPORTANT! On Linux EVT_IDLE does not work, the events seems to
26+
# be propagated only when you move your mouse, which is not the
2727
# expected behavior, it is recommended to use EVT_TIMER on Linux,
2828
# so set this value to False.
2929
USE_EVT_IDLE = False
@@ -59,7 +59,7 @@ def ExceptHook(type, value, traceObject):
5959
with open(error_file, "a") as file:
6060
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
6161
except:
62-
# If this is an example run from
62+
# If this is an example run from
6363
# /usr/local/lib/python2.7/dist-packages/cefpython1/examples/
6464
# then we might have not permission to write to that directory.
6565
print("cefpython: WARNING: failed writing to error file: %s" % (
@@ -93,7 +93,7 @@ def __init__(self):
9393
navigateUrl="file://"+GetApplicationPath("wxpython.html"))
9494

9595
self.browser.SetClientHandler(ClientHandler())
96-
96+
9797
jsBindings = cefpython.JavascriptBindings(
9898
bindToFrames=False, bindToPopups=False)
9999
jsBindings.SetObject("external", JavascriptBindings(self.browser))
@@ -127,16 +127,17 @@ def OnIdle(self, event):
127127
class JavascriptBindings:
128128
mainBrowser = None
129129
webRequest = None
130+
webRequestId = 0
130131
cookieVisitor = None
131-
132+
132133
def __init__(self, mainBrowser):
133134
self.mainBrowser = mainBrowser
134135

135136
def WebRequest(self, url):
136137
request = cefpython.Request.CreateRequest()
137138
request.SetUrl(url)
138139
webRequestClient = WebRequestClient()
139-
# Must keep the reference otherwise WebRequestClient
140+
# Must keep the reference otherwise WebRequestClient
140141
# callbacks won't be called.
141142
self.webRequest = cefpython.WebRequest.CreateWebRequest(request,
142143
webRequestClient)
@@ -195,14 +196,14 @@ def Visit(self, cookie, count, total, deleteCookie):
195196
print("\nCookieVisitor.Visit(): cookie:")
196197
print(cookie.Get())
197198
# True to continue visiting cookies
198-
return True
199+
return True
199200

200201
class WebRequestClient:
201202
def OnStateChange(self, webRequest, state):
202203
stateName = "unknown"
203204
for key, value in cefpython.WebRequest.State.iteritems():
204205
if value == state:
205-
stateName = key
206+
stateName = key
206207
print("\nWebRequestClient::OnStateChange(): state = %s" % stateName)
207208

208209
def OnRedirect(self, webRequest, request, response):
@@ -234,18 +235,18 @@ def OnData(self, data, substitute_data):
234235
def OnDrain(self, remainder):
235236
remainder.SetData("body h3 { color: orange; }")
236237

237-
class ClientHandler:
238-
238+
class ClientHandler:
239+
239240
# --------------------------------------------------------------------------
240241
# RequestHandler
241242
# --------------------------------------------------------------------------
242243

243-
contentFilter = None
244+
contentFilter = None
244245

245246
def OnBeforeBrowse(self, browser, frame, request, navType, isRedirect):
246247
# - frame.GetUrl() returns current url
247248
# - request.GetUrl() returns new url
248-
# - Return true to cancel the navigation or false to allow
249+
# - Return true to cancel the navigation or false to allow
249250
# the navigation to proceed.
250251
# - Modifying headers or post data can be done only in
251252
# OnBeforeResourceLoad()
@@ -256,7 +257,7 @@ def OnBeforeBrowse(self, browser, frame, request, navType, isRedirect):
256257
print("\nOnBeforeBrowse(): POST data: %s" % (
257258
request.GetPostData()))
258259

259-
def OnBeforeResourceLoad(self, browser, request, redirectUrl,
260+
def OnBeforeResourceLoad(self, browser, request, redirectUrl,
260261
streamReader, response, loadFlags):
261262
print("\nOnBeforeResourceLoad(): request.GetUrl() = %s" % (
262263
request.GetUrl()[:80]))
@@ -319,10 +320,10 @@ def OnDragStart(self, browser, dragData, mask):
319320
print(" GetFragmentHtml(): %s" % dragData.GetFragmentHtml())
320321
print(" GetFragmentBaseUrl(): %s" % dragData.GetFragmentBaseUrl())
321322
print(" GetFile(): %s" % dragData.GetFile())
322-
print(" GetFiles(): %s" % dragData.GetFiles())
323+
print(" GetFiles(): %s" % dragData.GetFiles())
323324
# Returning True on Linux causes segmentation fault,
324325
# reported the bug here:
325-
# http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=10693
326+
# http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=10693
326327
# Not being able to cancel a drag event is a problem
327328
# only when a link or a folder is dragged, as this will
328329
# cause loading the link or the folder in the browser window.
@@ -349,7 +350,7 @@ def OnDragEnter(self, browser, dragData, mask):
349350
print(" GetFiles(): %s" % dragData.GetFiles())
350351
# Returning True on Linux causes segmentation fault,
351352
# reported the bug here:
352-
# http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=10693
353+
# http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=10693
353354
# Not being able to cancel a drag event is a problem
354355
# only when a link or a folder is dragged, as this will
355356
# cause loading the link or the folder in the browser window.
@@ -364,7 +365,7 @@ def OnDragEnter(self, browser, dragData, mask):
364365
downloadHandler = None
365366

366367
def GetDownloadHandler(self, browser, mimeType, filename, contentLength):
367-
# Close the browser window if it is a popup with
368+
# Close the browser window if it is a popup with
368369
# no other document contents.
369370
if browser.IsPopup() and not browser.HasDocument():
370371
browser.CloseBrowser()
@@ -373,7 +374,7 @@ def GetDownloadHandler(self, browser, mimeType, filename, contentLength):
373374
if self.downloadHandler and self.downloadHandler.downloading:
374375
print("\nDownload is already in progress")
375376
return False
376-
self.downloadHandler = DownloadHandler(mimeType, filename,
377+
self.downloadHandler = DownloadHandler(mimeType, filename,
377378
contentLength)
378379
return self.downloadHandler
379380

@@ -402,7 +403,7 @@ def __init__(self, mimeType, filename, contentLength):
402403
# when download finishes get rid of this extension.
403404
filename += ".downloading"
404405
if os.path.exists(self.downloadsDir+"/"+filename):
405-
# If the last download did not succeed, the
406+
# If the last download did not succeed, the
406407
# "xxx.downloading" might still be there.
407408
os.remove(self.downloadsDir+"/"+filename)
408409
self.mimeType = mimeType
@@ -412,9 +413,9 @@ def __init__(self, mimeType, filename, contentLength):
412413

413414
def GetSafeFilename(self, filename):
414415
# TODO:
415-
# - remove any unsafe characters (".." or "/" or "\" and
416+
# - remove any unsafe characters (".." or "/" or "\" and
416417
# others), the safest way is to have a regexp with a list
417-
# safe characters. The dots ".." is a special case that
418+
# safe characters. The dots ".." is a special case that
418419
# needs to be treated separately.
419420
if os.path.exists(self.downloadsDir+"/"+filename):
420421
filename = self.GetUniqueFilename()[:4]+"_"+filename
@@ -425,11 +426,11 @@ def GetSafeFilename(self, filename):
425426
def GetUniqueFilename(self):
426427
# The filename may be empty, in that case generate
427428
# an unique name.
428-
# TODO:
429+
# TODO:
429430
# - guess the extension using the mimeType (but mimeType
430431
# may also be empty), "text/css" => ".css".
431432
return str(uuid.uuid4()).replace("-", "")[:16]
432-
433+
433434
def OnData(self, data):
434435
# TODO: display progress in percentage or/and KiB/MiB.
435436
if self.alreadyDownloaded == 0:
@@ -441,14 +442,14 @@ def OnData(self, data):
441442
# time.sleep(1) # Let's make the progress a bit slower (if cached)
442443
# Return True to continue receiving data, False to cancel.
443444
return True
444-
445+
445446
def OnComplete(self):
446447
sys.stdout.write("\n")
447448
sys.stdout.flush()
448449
self.fp.close()
449450
currentFile = self.downloadsDir+"/"+self.filename
450451
newFilename = re.sub(".downloading$", "", self.filename)
451-
os.rename(self.downloadsDir+"/"+self.filename,
452+
os.rename(self.downloadsDir+"/"+self.filename,
452453
self.downloadsDir+"/"+newFilename)
453454
self.downloading = False
454455
print("\nDownload complete!")
@@ -474,7 +475,7 @@ def OnInit(self):
474475
return True
475476

476477
def CreateTimer(self):
477-
# See "Making a render loop":
478+
# See "Making a render loop":
478479
# http://wiki.wxwidgets.org/Making_a_render_loop
479480
# Another approach is to use EVT_IDLE in MainFrame,
480481
# see which one fits you better.
@@ -488,7 +489,7 @@ def OnTimer(self, event):
488489
cefpython.MessageLoopWork()
489490

490491
def OnExit(self):
491-
# When app.MainLoop() returns, MessageLoopWork() should
492+
# When app.MainLoop() returns, MessageLoopWork() should
492493
# not be called anymore.
493494
if not USE_EVT_IDLE:
494495
self.timer.Stop()

cefpython/cef1/linux/binaries_64bit/wxpython.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ <h3>WebRequest test</h3>
9393

9494
See the console for messages.<br>
9595

96-
<a href="javascript:external.WebRequest('http://www.sitepoint.com/robots.txt')">
97-
external.WebRequest('http://www.sitepoint.com/robots.txt')</a>
96+
<a href="javascript:external.WebRequest('https://code.google.com/robots.txt')">
97+
external.WebRequest('https://code.google.com/robots.txt')</a>
9898

9999
<h3>Frame.CallFunction() test</h3>
100100

0 commit comments

Comments
 (0)