diff options
author | joshia@google.com <joshia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 01:17:15 +0000 |
---|---|---|
committer | joshia@google.com <joshia@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-12 01:17:15 +0000 |
commit | b6e4beca3a071606c537af2d55eba21d99769cb0 (patch) | |
tree | fa20b394752eb03839814b409a31c01601c9ebb9 /chrome | |
parent | 799edbdbd3aadc8044bccf4e10bf6a3ebfef1d6b (diff) | |
download | chromium_src-b6e4beca3a071606c537af2d55eba21d99769cb0.zip chromium_src-b6e4beca3a071606c537af2d55eba21d99769cb0.tar.gz chromium_src-b6e4beca3a071606c537af2d55eba21d99769cb0.tar.bz2 |
Prevent crash due to DIB allocation failure
Change the way we capture tab thumbnail images so that
the capturing code can deal with failure.
BUG=3795
Review URL: http://codereview.chromium.org/9717
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5244 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/renderer/render_view.cc | 18 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 2 | ||||
-rw-r--r-- | chrome/renderer/webplugin_delegate_proxy.cc | 14 |
3 files changed, 23 insertions, 11 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index bac75d8..30cd633 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -422,8 +422,10 @@ void RenderView::SendThumbnail() { ThumbnailScore score; SkBitmap thumbnail; - CaptureThumbnail(main_frame, kThumbnailWidth, kThumbnailHeight, &thumbnail, - &score); + if (!CaptureThumbnail(main_frame, kThumbnailWidth, kThumbnailHeight, + &thumbnail, &score)) + return; + // send the thumbnail message to the browser process IPC::Message* thumbnail_msg = new IPC::Message(routing_id_, ViewHostMsg_Thumbnail::ID, IPC::Message::PRIORITY_NORMAL); @@ -739,7 +741,7 @@ void RenderView::CaptureText(WebFrame* frame, std::wstring* contents) { } } -void RenderView::CaptureThumbnail(WebFrame* frame, +bool RenderView::CaptureThumbnail(WebFrame* frame, int w, int h, SkBitmap* thumbnail, @@ -748,8 +750,11 @@ void RenderView::CaptureThumbnail(WebFrame* frame, double begin = time_util::GetHighResolutionTimeNow(); #endif - gfx::BitmapPlatformDeviceWin device(frame->CaptureImage(true)); - const SkBitmap& src_bmp = device.accessBitmap(false); + scoped_ptr<gfx::BitmapPlatformDevice> device; + if (!frame->CaptureImage(&device, true)) + return false; + + const SkBitmap& src_bmp = device->accessBitmap(false); SkRect dest_rect; dest_rect.set(0, 0, SkIntToScalar(w), SkIntToScalar(h)); @@ -785,7 +790,7 @@ void RenderView::CaptureThumbnail(WebFrame* frame, score->at_top = (frame->ScrollOffset().height() == 0); SkBitmap subset; - device.accessBitmap(false).extractSubset(&subset, src_rect); + device->accessBitmap(false).extractSubset(&subset, src_rect); // Resample the subset that we want to get it the right size. *thumbnail = gfx::ImageOperations::Resize( @@ -799,6 +804,7 @@ void RenderView::CaptureThumbnail(WebFrame* frame, sprintf_s(buf, "thumbnail in %gms\n", (end - begin) * 1000); OutputDebugStringA(buf); #endif + return true; } double RenderView::CalculateBoringScore(SkBitmap* bitmap) { diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index e73a564..a78df39 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -352,7 +352,7 @@ class RenderView : public RenderWidget, public WebViewDelegate, // Creates a thumbnail of |frame|'s contents resized to (|w|, |h|) // and puts that in |thumbnail|. Thumbnail metadata goes in |score|. - void CaptureThumbnail(WebFrame* frame, int w, int h, + bool CaptureThumbnail(WebFrame* frame, int w, int h, SkBitmap* thumbnail, ThumbnailScore* score); diff --git a/chrome/renderer/webplugin_delegate_proxy.cc b/chrome/renderer/webplugin_delegate_proxy.cc index 67dcce2..efceffb 100644 --- a/chrome/renderer/webplugin_delegate_proxy.cc +++ b/chrome/renderer/webplugin_delegate_proxy.cc @@ -400,12 +400,18 @@ bool WebPluginDelegateProxy::CreateBitmap( scoped_ptr<SharedMemory>* memory, scoped_ptr<gfx::PlatformCanvasWin>* canvas) { size_t size = GetPaintBufSize(plugin_rect_); - memory->reset(new SharedMemory()); - if (!(*memory)->Create(L"", false, true, size)) + scoped_ptr<SharedMemory> new_shared_memory(new SharedMemory()); + if (!new_shared_memory->Create(L"", false, true, size)) return false; - canvas->reset(new gfx::PlatformCanvasWin( - plugin_rect_.width(), plugin_rect_.height(), true, (*memory)->handle())); + scoped_ptr<gfx::PlatformCanvasWin> new_canvas(new gfx::PlatformCanvasWin); + if (!new_canvas->initialize(plugin_rect_.width(), plugin_rect_.height(), + true, new_shared_memory->handle())) { + return false; + } + + memory->swap(new_shared_memory); + canvas->swap(new_canvas); return true; } |