Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Very long pages shouldn't crash the window server

Fixes #24
  • Loading branch information...
commit 9cc902953a81c25cd7b8e3be130a211ab47b6d55 1 parent 4c50b33
Paul Hammond authored
Showing with 23 additions and 14 deletions.
  1. +23 −14 webkit2png
37 webkit2png
View
@@ -25,7 +25,7 @@ __version__ = "0.6 beta"
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
-
+
import sys
import optparse
@@ -36,9 +36,7 @@ try:
import objc
except ImportError:
print "Cannot find pyobjc library files. Are you sure it is installed?"
- sys.exit()
-
-
+ sys.exit()
class AppDelegate (Foundation.NSObject):
# what happens when the app starts up
@@ -151,20 +149,27 @@ class WebkitLoad (Foundation.NSObject, WebKit.protocols.WebFrameLoadDelegate):
webview.setDrawsBackground_(objc.NO)
webview.setFrame_(rect)
-
- def resizeWebview(self,view):
- view.window().display()
- view.window().setContentSize_(view.bounds().size)
- view.setFrame_(view.bounds())
def captureView(self,view):
+ bounds = view.bounds()
+ if bounds.size.height > self.options.UNSAFE_max_height:
+ print >> sys.stderr, "Error: page height greater than %s, clipping to avoid crashing windowserver." % self.options.UNSAFE_max_height
+ bounds.size.height = self.options.UNSAFE_max_height
+ if bounds.size.width > self.options.UNSAFE_max_width:
+ print >> sys.stderr, "Error: page width greater than %s, clipping to avoid crashing windowserver." % self.options.UNSAFE_max_width
+ bounds.size.width = self.options.UNSAFE_max_width
+
+ view.window().display()
+ view.window().setContentSize_(Foundation.NSSize(bounds.size.width, self.options.initHeight))
+ view.setFrame_(bounds)
+
if hasattr(view, "bitmapImageRepForCachingDisplayInRect_"):
- bitmapdata = view.bitmapImageRepForCachingDisplayInRect_(view.bounds())
- view.cacheDisplayInRect_toBitmapImageRep_(view.bounds(), bitmapdata)
+ bitmapdata = view.bitmapImageRepForCachingDisplayInRect_(bounds)
+ view.cacheDisplayInRect_toBitmapImageRep_(bounds, bitmapdata)
else:
view.lockFocus()
bitmapdata = AppKit.NSBitmapImageRep.alloc()
- bitmapdata.initWithFocusedViewRect_(view.bounds())
+ bitmapdata.initWithFocusedViewRect_(bounds)
view.unlockFocus()
return bitmapdata
@@ -180,8 +185,6 @@ class WebkitLoad (Foundation.NSObject, WebKit.protocols.WebFrameLoadDelegate):
def doGrab(self,timer):
webview = timer.userInfo()
view = webview.mainFrame().frameView().documentView()
-
- self.resizeWebview(view)
URL = webview.mainFrame().dataSource().initialRequest().URL().absoluteString()
filename = self.makeFilename(URL, self.options)
@@ -212,6 +215,12 @@ Examples:
cmdparser.add_option("--debug", action="store_true",
help=optparse.SUPPRESS_HELP)
+ # warning: setting these too high can crash your window server
+ cmdparser.add_option("--UNSAFE-max-height", type="int",default=30000,
+ help=optparse.SUPPRESS_HELP)
+ cmdparser.add_option("--UNSAFE-max-width", type="int",default=30000,
+ help=optparse.SUPPRESS_HELP)
+
group = optparse.OptionGroup(cmdparser, "Browser Window Options")
group.add_option("-W", "--width",type="float",default=800.0,
help="initial (and minimum) width of browser (default: 800)")
Please sign in to comment.
Something went wrong with that request. Please try again.