Add method for testing whether the canvas size is valid

This is a way to detect whether a canvas exceeds the maximum
dimensions if these are limited on the target device. See
https://developer.apple.com/library/ios/documentation/AppleApplications/Reference/SafariWebContent/CreatingContentforSafarioniPhone/CreatingContentforSafarioniPhone.html
for limitations on iOS devices.
Allow to make canvas smaller when it is too big

For performance reason, we only make the canvas bigger, but not
smaller. With this change, we also make it smaller, but only
when we know that its current size exceeds the maximum
dimensions.
Initialize canvasTooBig_ member
Make testCanvasSize a static function
Merge pull request #1928 from ahocevar/recover-from-canvas-too-big

Recover from situations where the maximum canvas size is exceeded