Chromium Code Reviews| Index: chrome/renderer/render_view.cc |
| diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc |
| index 9b71058a5375da46a4f53eb6786e1754e80be856..6cad6a36b3c7a3ad954636c4f5d57613ba5ef291 100644 |
| --- a/chrome/renderer/render_view.cc |
| +++ b/chrome/renderer/render_view.cc |
| @@ -42,7 +42,6 @@ |
| #include "chrome/common/pepper_plugin_registry.h" |
| #include "chrome/common/render_messages.h" |
| #include "chrome/common/renderer_preferences.h" |
| -#include "chrome/common/thumbnail_score.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/common/web_apps.h" |
| #include "chrome/common/window_container_type.h" |
| @@ -283,20 +282,11 @@ using webkit_glue::WebAccessibility; |
| typedef std::map<WebKit::WebView*, RenderView*> ViewMap; |
| static base::LazyInstance<ViewMap> g_view_map(base::LINKER_INITIALIZED); |
| -// define to write the time necessary for thumbnail/DOM text retrieval, |
| -// respectively, into the system debug log |
| -// #define TIME_TEXT_RETRIEVAL |
| - |
| // maximum number of characters in the document to index, any text beyond this |
| // point will be clipped |
| static const size_t kMaxIndexChars = 65535; |
| -// Size of the thumbnails that we'll generate |
| -static const int kThumbnailWidth = 212; |
| -static const int kThumbnailHeight = 132; |
| - |
| -// Delay in milliseconds that we'll wait before capturing the page contents |
| -// and thumbnail. |
| +// Delay in milliseconds that we'll wait before capturing the page contents. |
| static const int kDelayForCaptureMs = 500; |
| // Typically, we capture the page data once the page is loaded. |
| @@ -345,19 +335,6 @@ static bool PaintViewIntoCanvas(WebView* view, |
| return true; |
| } |
| -// Calculates how "boring" a thumbnail is. The boring score is the |
| -// 0,1 ranged percentage of pixels that are the most common |
| -// luma. Higher boring scores indicate that a higher percentage of a |
| -// bitmap are all the same brightness. |
| -static double CalculateBoringScore(SkBitmap* bitmap) { |
| - int histogram[256] = {0}; |
| - color_utils::BuildLumaHistogram(bitmap, histogram); |
| - |
| - int color_count = *std::max_element(histogram, histogram + 256); |
| - int pixel_count = bitmap->width() * bitmap->height(); |
| - return static_cast<double>(color_count) / pixel_count; |
| -} |
| - |
| // True if |frame| contains content that is white-listed for content settings. |
| static bool IsWhitelistedForContentSettings(WebFrame* frame) { |
| WebSecurityOrigin origin = frame->securityOrigin(); |
| @@ -963,7 +940,6 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { |
| bool handled = true; |
| IPC_BEGIN_MESSAGE_MAP(RenderView, message) |
| - IPC_MESSAGE_HANDLER(ViewMsg_CaptureThumbnail, OnCaptureThumbnail) |
| IPC_MESSAGE_HANDLER(ViewMsg_CaptureSnapshot, OnCaptureSnapshot) |
| IPC_MESSAGE_HANDLER(ViewMsg_PrintPages, OnPrintPages) |
| IPC_MESSAGE_HANDLER(ViewMsg_PrintingDone, OnPrintingDone) |
| @@ -1102,29 +1078,6 @@ bool RenderView::OnMessageReceived(const IPC::Message& message) { |
| return handled; |
| } |
| -void RenderView::OnCaptureThumbnail() { |
| - WebFrame* main_frame = webview()->mainFrame(); |
| - if (!main_frame) |
| - return; |
| - |
| - // get the URL for this page |
| - GURL url(main_frame->url()); |
| - if (url.is_empty()) |
| - return; |
| - |
| - if (size_.IsEmpty()) |
| - return; // Don't create an empty thumbnail! |
| - |
| - ThumbnailScore score; |
| - SkBitmap thumbnail; |
| - if (!CaptureThumbnail(webview(), kThumbnailWidth, kThumbnailHeight, |
| - &thumbnail, &score)) |
| - return; |
| - |
| - // send the thumbnail message to the browser process |
| - Send(new ViewHostMsg_Thumbnail(routing_id_, url, score, thumbnail)); |
| -} |
| - |
| void RenderView::OnCaptureSnapshot() { |
| SkBitmap snapshot; |
| bool error = false; |
| @@ -1206,7 +1159,7 @@ void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| return; |
| // Don't index/capture pages that failed to load. This only checks the top |
| - // level frame so the thumbnail may contain a frame that failed to load. |
| + // level frame. |
| WebDataSource* ds = main_frame->dataSource(); |
| if (ds && ds->hasUnreachableURL()) |
| return; |
| @@ -1241,8 +1194,6 @@ void RenderView::CapturePageInfo(int load_id, bool preliminary_capture) { |
| TranslateHelper::IsPageTranslatable(&document))); |
| } |
| - OnCaptureThumbnail(); |
| - |
| if (phishing_delegate_.get()) |
| phishing_delegate_->FinishedLoad(&contents); |
| } |
| @@ -1278,75 +1229,6 @@ void RenderView::CaptureText(WebFrame* frame, string16* contents) { |
| } |
| } |
| -bool RenderView::CaptureThumbnail(WebView* view, |
|
brettw
2011/01/18 18:25:42
I think we probably want to keep the old code and
satorux1
2011/01/19 01:36:36
That's a great idea. I'll change it accordingly.
|
| - int w, |
| - int h, |
| - SkBitmap* thumbnail, |
| - ThumbnailScore* score) { |
| - base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| - |
| - skia::PlatformCanvas canvas; |
| - |
| - // Paint |view| into |canvas|. |
| - if (!PaintViewIntoCanvas(view, canvas)) |
| - return false; |
| - |
| - skia::BitmapPlatformDevice& device = |
| - static_cast<skia::BitmapPlatformDevice&>(canvas.getTopPlatformDevice()); |
| - |
| - const SkBitmap& src_bmp = device.accessBitmap(false); |
| - |
| - SkRect dest_rect = { 0, 0, SkIntToScalar(w), SkIntToScalar(h) }; |
| - float dest_aspect = dest_rect.width() / dest_rect.height(); |
| - |
| - // Get the src rect so that we can preserve the aspect ratio while filling |
| - // the destination. |
| - SkIRect src_rect; |
| - if (src_bmp.width() < dest_rect.width() || |
| - src_bmp.height() < dest_rect.height()) { |
| - // Source image is smaller: we clip the part of source image within the |
| - // dest rect, and then stretch it to fill the dest rect. We don't respect |
| - // the aspect ratio in this case. |
| - src_rect.set(0, 0, static_cast<S16CPU>(dest_rect.width()), |
| - static_cast<S16CPU>(dest_rect.height())); |
| - score->good_clipping = false; |
| - } else { |
| - float src_aspect = static_cast<float>(src_bmp.width()) / src_bmp.height(); |
| - if (src_aspect > dest_aspect) { |
| - // Wider than tall, clip horizontally: we center the smaller thumbnail in |
| - // the wider screen. |
| - S16CPU new_width = static_cast<S16CPU>(src_bmp.height() * dest_aspect); |
| - S16CPU x_offset = (src_bmp.width() - new_width) / 2; |
| - src_rect.set(x_offset, 0, new_width + x_offset, src_bmp.height()); |
| - score->good_clipping = false; |
| - } else { |
| - src_rect.set(0, 0, src_bmp.width(), |
| - static_cast<S16CPU>(src_bmp.width() / dest_aspect)); |
| - score->good_clipping = true; |
| - } |
| - } |
| - |
| - score->at_top = (view->mainFrame()->scrollOffset().height == 0); |
| - |
| - SkBitmap subset; |
| - device.accessBitmap(false).extractSubset(&subset, src_rect); |
| - |
| - // First do a fast downsample by powers of two to get close to the final size. |
| - SkBitmap downsampled_subset = |
| - SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h); |
| - |
| - // Do a high-quality resize from the downscaled size to the final size. |
| - *thumbnail = skia::ImageOperations::Resize( |
| - downsampled_subset, skia::ImageOperations::RESIZE_LANCZOS3, w, h); |
| - |
| - score->boring_score = CalculateBoringScore(thumbnail); |
| - |
| - HISTOGRAM_TIMES("Renderer4.Thumbnail", |
| - base::TimeTicks::Now() - beginning_time); |
| - |
| - return true; |
| -} |
| - |
| bool RenderView::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { |
| base::TimeTicks beginning_time = base::TimeTicks::Now(); |
| @@ -5091,6 +4973,10 @@ void RenderView::DidInitiatePaint() { |
| current_oldstyle_pepper_plugins_.begin(); |
| i != current_oldstyle_pepper_plugins_.end(); ++i) |
| (*i)->RenderViewInitiatedPaint(); |
| + |
| + WebKit::WebSize scroll_offset = webview()->mainFrame()->scrollOffset(); |
| + gfx::Size gfx_scroll_offset(scroll_offset.width, scroll_offset.height); |
| + Send(new ViewHostMsg_UpdateScrollOffset(routing_id_, gfx_scroll_offset)); |
|
brettw
2011/01/18 18:25:42
If you need something in RenderWidget, you can jus
satorux1
2011/01/19 01:36:36
Sounds like a good idea. I'll give it a try.
|
| } |
| void RenderView::DidFlushPaint() { |