| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/renderer/safe_browsing/phishing_thumbnailer.h" | 5 #include "chrome/renderer/safe_browsing/phishing_thumbnailer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/time.h" | 9 #include "base/time.h" |
| 10 #include "content/public/renderer/render_view.h" | 10 #include "content/public/renderer/render_view.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 namespace safe_browsing { | 25 namespace safe_browsing { |
| 26 | 26 |
| 27 SkBitmap GrabPhishingThumbnail(content::RenderView* render_view, | 27 SkBitmap GrabPhishingThumbnail(content::RenderView* render_view, |
| 28 const gfx::Size& view_size, | 28 const gfx::Size& view_size, |
| 29 const gfx::Size& thumbnail_size) { | 29 const gfx::Size& thumbnail_size) { |
| 30 if (!render_view || !render_view->GetWebView()) { | 30 if (!render_view || !render_view->GetWebView()) { |
| 31 return SkBitmap(); // The WebView is going away. | 31 return SkBitmap(); // The WebView is going away. |
| 32 } | 32 } |
| 33 WebView* view = render_view->GetWebView(); | 33 WebView* view = render_view->GetWebView(); |
| 34 base::TimeTicks beginning_time = base::TimeTicks::Now(); | 34 base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| 35 skia::PlatformCanvas canvas; | 35 SkCanvas* canvas = skia::CreatePlatformCanvas(view_size.width(), |
| 36 if (!canvas.initialize(view_size.width(), view_size.height(), true)) { | 36 view_size.height(), true, 0, |
| 37 skia::RETURN_NULL_ON_FAILURE); |
| 38 if (!canvas) |
| 37 return SkBitmap(); | 39 return SkBitmap(); |
| 38 } | 40 SkAutoUnref au(canvas); |
| 39 | 41 |
| 40 // Make sure we are not using any zoom when we take the snapshot. We will | 42 // Make sure we are not using any zoom when we take the snapshot. We will |
| 41 // restore the previous zoom level after the snapshot is taken. | 43 // restore the previous zoom level after the snapshot is taken. |
| 42 double old_zoom_level = view->zoomLevel(); | 44 double old_zoom_level = view->zoomLevel(); |
| 43 if (view->zoomLevel() != 0.0) { | 45 if (view->zoomLevel() != 0.0) { |
| 44 view->setZoomLevel(false, 0.0); | 46 view->setZoomLevel(false, 0.0); |
| 45 } | 47 } |
| 46 WebSize old_size = view->size(); | 48 WebSize old_size = view->size(); |
| 47 // TODO(noelutz): not only should we hide all scroll bars but we should also | 49 // TODO(noelutz): not only should we hide all scroll bars but we should also |
| 48 // make sure that all scroll-bars are at the top. | 50 // make sure that all scroll-bars are at the top. |
| 49 view->mainFrame()->setCanHaveScrollbars(false); // always hide scrollbars. | 51 view->mainFrame()->setCanHaveScrollbars(false); // always hide scrollbars. |
| 50 view->resize(view_size); | 52 view->resize(view_size); |
| 51 view->layout(); | 53 view->layout(); |
| 52 view->paint(webkit_glue::ToWebCanvas(&canvas), | 54 view->paint(webkit_glue::ToWebCanvas(canvas), |
| 53 WebRect(0, 0, view_size.width(), view_size.height())); | 55 WebRect(0, 0, view_size.width(), view_size.height())); |
| 54 | 56 |
| 55 SkDevice* device = skia::GetTopDevice(canvas); | 57 SkDevice* device = skia::GetTopDevice(*canvas); |
| 56 | 58 |
| 57 // Now resize the thumbnail to the right size. Note: it is important that we | 59 // Now resize the thumbnail to the right size. Note: it is important that we |
| 58 // use this resize algorithm here. | 60 // use this resize algorithm here. |
| 59 const SkBitmap& bitmap = device->accessBitmap(false); | 61 const SkBitmap& bitmap = device->accessBitmap(false); |
| 60 SkBitmap thumbnail = skia::ImageOperations::Resize( | 62 SkBitmap thumbnail = skia::ImageOperations::Resize( |
| 61 bitmap, | 63 bitmap, |
| 62 skia::ImageOperations::RESIZE_LANCZOS3, | 64 skia::ImageOperations::RESIZE_LANCZOS3, |
| 63 thumbnail_size.width(), | 65 thumbnail_size.width(), |
| 64 thumbnail_size.height()); | 66 thumbnail_size.height()); |
| 65 | 67 |
| 66 // Put things back as they were before. | 68 // Put things back as they were before. |
| 67 if (view->zoomLevel() != old_zoom_level) { | 69 if (view->zoomLevel() != old_zoom_level) { |
| 68 view->setZoomLevel(false, old_zoom_level); | 70 view->setZoomLevel(false, old_zoom_level); |
| 69 } | 71 } |
| 70 // Maybe re-display the scrollbars and resize the view to its old size. | 72 // Maybe re-display the scrollbars and resize the view to its old size. |
| 71 view->mainFrame()->setCanHaveScrollbars( | 73 view->mainFrame()->setCanHaveScrollbars( |
| 72 render_view->ShouldDisplayScrollbars(old_size.width, old_size.height)); | 74 render_view->ShouldDisplayScrollbars(old_size.width, old_size.height)); |
| 73 view->resize(old_size); | 75 view->resize(old_size); |
| 74 | 76 |
| 75 UMA_HISTOGRAM_TIMES("SBClientPhishing.GrabPhishingThumbnail", | 77 UMA_HISTOGRAM_TIMES("SBClientPhishing.GrabPhishingThumbnail", |
| 76 base::TimeTicks::Now() - beginning_time); | 78 base::TimeTicks::Now() - beginning_time); |
| 77 return thumbnail; | 79 return thumbnail; |
| 78 } | 80 } |
| 79 | 81 |
| 80 } // namespace safe_browsing | 82 } // namespace safe_browsing |
| OLD | NEW |