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 SkCanvas* canvas = skia::CreatePlatformCanvas(view_size.width(), | 35 skia::RefPtr<SkCanvas> canvas = skia::CreatePlatformCanvas( |
36 view_size.height(), true, 0, | 36 view_size.width(), |
37 skia::RETURN_NULL_ON_FAILURE); | 37 view_size.height(), true, 0, |
| 38 skia::RETURN_NULL_ON_FAILURE); |
38 if (!canvas) | 39 if (!canvas) |
39 return SkBitmap(); | 40 return SkBitmap(); |
40 SkAutoUnref au(canvas); | |
41 | 41 |
42 // 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 |
43 // restore the previous zoom level after the snapshot is taken. | 43 // restore the previous zoom level after the snapshot is taken. |
44 double old_zoom_level = view->zoomLevel(); | 44 double old_zoom_level = view->zoomLevel(); |
45 if (view->zoomLevel() != 0.0) { | 45 if (view->zoomLevel() != 0.0) { |
46 view->setZoomLevel(false, 0.0); | 46 view->setZoomLevel(false, 0.0); |
47 } | 47 } |
48 WebSize old_size = view->size(); | 48 WebSize old_size = view->size(); |
49 // 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 |
50 // make sure that all scroll-bars are at the top. | 50 // make sure that all scroll-bars are at the top. |
51 view->mainFrame()->setCanHaveScrollbars(false); // always hide scrollbars. | 51 view->mainFrame()->setCanHaveScrollbars(false); // always hide scrollbars. |
52 view->resize(view_size); | 52 view->resize(view_size); |
53 view->layout(); | 53 view->layout(); |
54 view->paint(webkit_glue::ToWebCanvas(canvas), | 54 view->paint(webkit_glue::ToWebCanvas(canvas.get()), |
55 WebRect(0, 0, view_size.width(), view_size.height())); | 55 WebRect(0, 0, view_size.width(), view_size.height())); |
56 | 56 |
57 SkDevice* device = skia::GetTopDevice(*canvas); | 57 SkDevice* device = skia::GetTopDevice(*canvas); |
58 | 58 |
59 // 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 |
60 // use this resize algorithm here. | 60 // use this resize algorithm here. |
61 const SkBitmap& bitmap = device->accessBitmap(false); | 61 const SkBitmap& bitmap = device->accessBitmap(false); |
62 SkBitmap thumbnail = skia::ImageOperations::Resize( | 62 SkBitmap thumbnail = skia::ImageOperations::Resize( |
63 bitmap, | 63 bitmap, |
64 skia::ImageOperations::RESIZE_LANCZOS3, | 64 skia::ImageOperations::RESIZE_LANCZOS3, |
65 thumbnail_size.width(), | 65 thumbnail_size.width(), |
66 thumbnail_size.height()); | 66 thumbnail_size.height()); |
67 | 67 |
68 // Put things back as they were before. | 68 // Put things back as they were before. |
69 if (view->zoomLevel() != old_zoom_level) { | 69 if (view->zoomLevel() != old_zoom_level) { |
70 view->setZoomLevel(false, old_zoom_level); | 70 view->setZoomLevel(false, old_zoom_level); |
71 } | 71 } |
72 // 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. |
73 view->mainFrame()->setCanHaveScrollbars( | 73 view->mainFrame()->setCanHaveScrollbars( |
74 render_view->ShouldDisplayScrollbars(old_size.width, old_size.height)); | 74 render_view->ShouldDisplayScrollbars(old_size.width, old_size.height)); |
75 view->resize(old_size); | 75 view->resize(old_size); |
76 | 76 |
77 UMA_HISTOGRAM_TIMES("SBClientPhishing.GrabPhishingThumbnail", | 77 UMA_HISTOGRAM_TIMES("SBClientPhishing.GrabPhishingThumbnail", |
78 base::TimeTicks::Now() - beginning_time); | 78 base::TimeTicks::Now() - beginning_time); |
79 return thumbnail; | 79 return thumbnail; |
80 } | 80 } |
81 | 81 |
82 } // namespace safe_browsing | 82 } // namespace safe_browsing |
OLD | NEW |