From 6f07b607e67124c44b4545cd6eaf86b4020fc4ad Mon Sep 17 00:00:00 2001 From: "mazda@chromium.org" Date: Fri, 5 Oct 2012 01:32:01 +0000 Subject: [PATCH] Remove renderer side thumbnailing code. BUG=138002 TEST=build succeeds Review URL: https://chromiumcodereview.appspot.com/11050017 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160282 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/chrome_content_browser_client.cc | 1 - chrome/browser/history/history_tab_helper.cc | 18 ---- chrome/browser/history/history_tab_helper.h | 5 - chrome/browser/ui/tab_contents/tab_contents.cc | 8 +- chrome/chrome_common.gypi | 2 - chrome/common/chrome_switches.cc | 5 - chrome/common/chrome_switches.h | 1 - chrome/common/render_messages.h | 15 --- chrome/common/thumbnail_support.cc | 13 --- chrome/common/thumbnail_support.h | 15 --- chrome/renderer/chrome_render_view_observer.cc | 134 ------------------------ chrome/renderer/chrome_render_view_observer.h | 9 -- 12 files changed, 2 insertions(+), 224 deletions(-) delete mode 100644 chrome/common/thumbnail_support.cc delete mode 100644 chrome/common/thumbnail_support.h diff --git a/chrome/browser/chrome_content_browser_client.cc b/chrome/browser/chrome_content_browser_client.cc index 0892145a7182..d417f7f789d8 100644 --- a/chrome/browser/chrome_content_browser_client.cc +++ b/chrome/browser/chrome_content_browser_client.cc @@ -905,7 +905,6 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( switches::kDisableAsynchronousSpellChecking, switches::kDisableBundledPpapiFlash, switches::kDisableExtensionsResourceWhitelist, - switches::kDisableInBrowserThumbnailing, switches::kDisableScriptedPrintThrottling, switches::kDumpHistogramsOnExit, switches::kEnableBenchmarking, diff --git a/chrome/browser/history/history_tab_helper.cc b/chrome/browser/history/history_tab_helper.cc index e576958859bf..5c383732565e 100644 --- a/chrome/browser/history/history_tab_helper.cc +++ b/chrome/browser/history/history_tab_helper.cc @@ -8,7 +8,6 @@ #include "chrome/browser/history/history.h" #include "chrome/browser/history/history_service_factory.h" -#include "chrome/browser/history/top_sites.h" #include "chrome/browser/instant/instant_loader.h" #include "chrome/browser/prerender/prerender_contents.h" #include "chrome/browser/prerender/prerender_manager.h" @@ -86,7 +85,6 @@ bool HistoryTabHelper::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(HistoryTabHelper, message) IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PageContents, OnPageContents) - IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Thumbnail, OnThumbnail) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() @@ -183,22 +181,6 @@ void HistoryTabHelper::OnPageContents(const GURL& url, #endif } -void HistoryTabHelper::OnThumbnail(const GURL& url, - const ThumbnailScore& score, - const SkBitmap& bitmap) { - Profile* profile = - Profile::FromBrowserContext(web_contents()->GetBrowserContext()); - if (profile->IsOffTheRecord()) - return; - - // Tell History about this thumbnail. - history::TopSites* ts = profile->GetTopSites(); - if (ts) { - gfx::Image thumbnail(bitmap); - ts->SetPageThumbnail(url, &thumbnail, score); - } -} - HistoryService* HistoryTabHelper::GetHistoryService() { Profile* profile = Profile::FromBrowserContext(web_contents()->GetBrowserContext()); diff --git a/chrome/browser/history/history_tab_helper.h b/chrome/browser/history/history_tab_helper.h index 05c92c9a41ad..7f1ab6e778e1 100644 --- a/chrome/browser/history/history_tab_helper.h +++ b/chrome/browser/history/history_tab_helper.h @@ -13,8 +13,6 @@ #include "content/public/browser/web_contents_observer.h" class HistoryService; -class SkBitmap; -struct ThumbnailScore; namespace history { struct HistoryAddPageArgs; @@ -65,9 +63,6 @@ class HistoryTabHelper : public content::WebContentsObserver, void OnPageContents(const GURL& url, int32 page_id, const string16& contents); - void OnThumbnail(const GURL& url, - const ThumbnailScore& score, - const SkBitmap& bitmap); // Helper function to return the history service. May return NULL. HistoryService* GetHistoryService(); diff --git a/chrome/browser/ui/tab_contents/tab_contents.cc b/chrome/browser/ui/tab_contents/tab_contents.cc index 072578258d12..c9f5c280df3b 100644 --- a/chrome/browser/ui/tab_contents/tab_contents.cc +++ b/chrome/browser/ui/tab_contents/tab_contents.cc @@ -54,7 +54,6 @@ #include "chrome/browser/view_type_utils.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_switches.h" -#include "chrome/common/thumbnail_support.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/web_contents.h" @@ -180,11 +179,8 @@ TabContents::TabContents(WebContents* contents) printing::PrintViewManager::CreateForWebContents(contents); #endif - // Start the in-browser thumbnailing if the feature is enabled. - if (ShouldEnableInBrowserThumbnailing()) { - thumbnail_generator_.reset(new ThumbnailGenerator); - thumbnail_generator_->StartThumbnailing(web_contents_.get()); - } + thumbnail_generator_.reset(new ThumbnailGenerator); + thumbnail_generator_->StartThumbnailing(web_contents_.get()); #if defined(ENABLE_ONE_CLICK_SIGNIN) // If this is not an incognito window, setup to handle one-click login. diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index 0d38ce1ea2ae..592fb6442813 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -314,8 +314,6 @@ 'common/switch_utils.h', 'common/thumbnail_score.cc', 'common/thumbnail_score.h', - 'common/thumbnail_support.cc', - 'common/thumbnail_support.h', 'common/time_format.cc', 'common/time_format.h', 'common/url_constants.cc', diff --git a/chrome/common/chrome_switches.cc b/chrome/common/chrome_switches.cc index 6028a2a8b64f..b195d0a4ee61 100644 --- a/chrome/common/chrome_switches.cc +++ b/chrome/common/chrome_switches.cc @@ -326,11 +326,6 @@ const char kDisableFlashSandbox[] = "disable-flash-sandbox"; const char kDisableImprovedDownloadProtection[] = "disable-improved-download-protection"; -// Disables the in-browser thumbnailing, which is more efficient than the -// in-renderer thumbnailing, as we can use more information to determine if we -// need to update thumbnails. -const char kDisableInBrowserThumbnailing[] = "disable-in-browser-thumbnailing"; - // Disable the Infinite Cache. const char kDisableInfiniteCache[] = "disable-infinite-cache"; diff --git a/chrome/common/chrome_switches.h b/chrome/common/chrome_switches.h index c252ab8550ef..5db6625dd6da 100644 --- a/chrome/common/chrome_switches.h +++ b/chrome/common/chrome_switches.h @@ -95,7 +95,6 @@ extern const char kDisableExtensionsResourceWhitelist[]; extern const char kDisableExtensions[]; extern const char kDisableFlashSandbox[]; extern const char kDisableImprovedDownloadProtection[]; -extern const char kDisableInBrowserThumbnailing[]; extern const char kDisableInfiniteCache[]; extern const char kDisableInternalFlash[]; extern const char kDisableIPv6[]; diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index 7479a05be8bb..f4521aa13c88 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -22,7 +22,6 @@ #include "chrome/common/instant_types.h" #include "chrome/common/nacl_types.h" #include "chrome/common/search_provider.h" -#include "chrome/common/thumbnail_score.h" #include "chrome/common/translate_errors.h" #include "content/public/common/common_param_traits.h" #include "ipc/ipc_channel_handle.h" @@ -172,13 +171,6 @@ IPC_STRUCT_TRAITS_BEGIN(RendererContentSettingRules) IPC_STRUCT_TRAITS_MEMBER(script_rules) IPC_STRUCT_TRAITS_END() -IPC_STRUCT_TRAITS_BEGIN(ThumbnailScore) - IPC_STRUCT_TRAITS_MEMBER(boring_score) - IPC_STRUCT_TRAITS_MEMBER(good_clipping) - IPC_STRUCT_TRAITS_MEMBER(at_top) - IPC_STRUCT_TRAITS_MEMBER(time_at_snapshot) -IPC_STRUCT_TRAITS_END() - IPC_STRUCT_TRAITS_BEGIN(WebKit::WebCache::ResourceTypeStat) IPC_STRUCT_TRAITS_MEMBER(count) IPC_STRUCT_TRAITS_MEMBER(size) @@ -500,13 +492,6 @@ IPC_MESSAGE_ROUTED0(ChromeViewHostMsg_OpenAboutPlugins) IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_CouldNotLoadPlugin, FilePath /* plugin_path */) -// Specifies the URL as the first parameter (a wstring) and thumbnail as -// binary data as the second parameter. -IPC_MESSAGE_ROUTED3(ChromeViewHostMsg_Thumbnail, - GURL /* url */, - ThumbnailScore /* score */, - SkBitmap /* bitmap */) - // Send a snapshot of the tab contents to the render host. IPC_MESSAGE_ROUTED1(ChromeViewHostMsg_Snapshot, SkBitmap /* bitmap */) diff --git a/chrome/common/thumbnail_support.cc b/chrome/common/thumbnail_support.cc deleted file mode 100644 index e64eaa185f9c..000000000000 --- a/chrome/common/thumbnail_support.cc +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/common/thumbnail_support.h" - -#include "base/command_line.h" -#include "chrome/common/chrome_switches.h" - -bool ShouldEnableInBrowserThumbnailing() { - return !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableInBrowserThumbnailing); -} diff --git a/chrome/common/thumbnail_support.h b/chrome/common/thumbnail_support.h deleted file mode 100644 index afddb63d1ff8..000000000000 --- a/chrome/common/thumbnail_support.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_COMMON_THUMBNAIL_SUPPORT_H_ -#define CHROME_COMMON_THUMBNAIL_SUPPORT_H_ - -// TODO(mazda): Remove this file once in-browser thumbnailing is supported on -// all platforms. - -// Returns true if in-browser thumbnailing is supported and not disabled by the -// command line flag. -bool ShouldEnableInBrowserThumbnailing(); - -#endif // CHROME_COMMON_THUMBNAIL_SUPPORT_H_ diff --git a/chrome/renderer/chrome_render_view_observer.cc b/chrome/renderer/chrome_render_view_observer.cc index eca2e80cba2f..9e930a926857 100644 --- a/chrome/renderer/chrome_render_view_observer.cc +++ b/chrome/renderer/chrome_render_view_observer.cc @@ -16,8 +16,6 @@ #include "chrome/common/icon_messages.h" #include "chrome/common/prerender_messages.h" #include "chrome/common/render_messages.h" -#include "chrome/common/thumbnail_score.h" -#include "chrome/common/thumbnail_support.h" #include "chrome/common/url_constants.h" #include "chrome/renderer/chrome_render_process_observer.h" #include "chrome/renderer/content_settings_observer.h" @@ -34,7 +32,6 @@ #include "content/public/renderer/render_view.h" #include "content/public/renderer/content_renderer_client.h" #include "net/base/data_url.h" -#include "skia/ext/image_operations.h" #include "skia/ext/platform_canvas.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" @@ -48,7 +45,6 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" -#include "ui/gfx/color_utils.h" #include "ui/gfx/favicon_size.h" #include "ui/gfx/size.h" #include "ui/gfx/skbitmap_operations.h" @@ -93,10 +89,6 @@ static const int kDelayForForcedCaptureMs = 6000; // 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; - // Constants for UMA statistic collection. static const char kWWWDotGoogleDotCom[] = "www.google.com"; static const char kMailDotGoogleDotCom[] = "mail.google.com"; @@ -175,19 +167,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(color_count) / pixel_count; -} - static FaviconURL::IconType ToFaviconType(WebIconURL::Type type) { switch (type) { case WebIconURL::TypeFavicon: @@ -897,12 +876,6 @@ void ChromeRenderViewObserver::CapturePageInfo(bool preliminary_capture) { contents)); } - // Generate the thumbnail here if the in-browser thumbnailing isn't - // enabled. TODO(mazda): Remove this and related code once in-browser - // thumbnailing is supported on all platforms (http://crbug.com/120003). - if (!ShouldEnableInBrowserThumbnailing()) - CaptureThumbnail(); - #if defined(ENABLE_SAFE_BROWSING) // Will swap out the string. if (phishing_classifier_) @@ -942,113 +915,6 @@ void ChromeRenderViewObserver::CaptureText(WebFrame* frame, } } -void ChromeRenderViewObserver::CaptureThumbnail() { - WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); - if (!main_frame) - return; - - // get the URL for this page - GURL url(main_frame->document().url()); - if (url.is_empty()) - return; - - if (render_view()->GetSize().IsEmpty()) - return; // Don't create an empty thumbnail! - - TRACE_EVENT0("renderer", "ChromeRenderViewObserver::CaptureThumbnail"); - - ThumbnailScore score; - SkBitmap thumbnail; - if (!CaptureFrameThumbnail(render_view()->GetWebView(), kThumbnailWidth, - kThumbnailHeight, &thumbnail, &score)) - return; - - // send the thumbnail message to the browser process - Send(new ChromeViewHostMsg_Thumbnail(routing_id(), url, score, thumbnail)); -} - -bool ChromeRenderViewObserver::CaptureFrameThumbnail(WebView* view, - int w, - int h, - SkBitmap* thumbnail, - ThumbnailScore* score) { - base::TimeTicks beginning_time = base::TimeTicks::Now(); - - skia::PlatformCanvas canvas; - - { - TRACE_EVENT0("renderer", - "ChromeRenderViewObserver::CaptureFrameThumbnail::PaintViewIntoCanvas"); - // Paint |view| into |canvas|. - if (!PaintViewIntoCanvas(view, canvas)) - return false; - } - - SkDevice* device = skia::GetTopDevice(canvas); - - const SkBitmap& src_bmp = device->accessBitmap(false); - // Cut off the vertical scrollbars (if any). - int src_bmp_width = view->mainFrame()->contentsSize().width; - - 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(dest_rect.width()), - static_cast(dest_rect.height())); - score->good_clipping = false; - } else { - float src_aspect = static_cast(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(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 = (src_aspect < ThumbnailScore::kTooWideAspectRatio); - } else { - src_rect.set(0, 0, src_bmp_width, - static_cast(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); - - TRACE_EVENT_BEGIN0("renderer", - "ChromeRenderViewObserver::CaptureFrameThumbnail::DownsampleByTwo"); - // First do a fast downsample by powers of two to get close to the final size. - SkBitmap downsampled_subset = - SkBitmapOperations::DownsampleByTwoUntilSize(subset, w, h); - TRACE_EVENT_END0("renderer", - "ChromeRenderViewObserver::CaptureFrameThumbnail::DownsampleByTwo"); - - { - TRACE_EVENT0("renderer", - "ChromeRenderViewObserver::CaptureFrameThumbnail::DownsampleLanczos3"); - // 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 ChromeRenderViewObserver::CaptureSnapshot(WebView* view, SkBitmap* snapshot) { base::TimeTicks beginning_time = base::TimeTicks::Now(); diff --git a/chrome/renderer/chrome_render_view_observer.h b/chrome/renderer/chrome_render_view_observer.h index e8328ee34636..00d5d8fa64d5 100644 --- a/chrome/renderer/chrome_render_view_observer.h +++ b/chrome/renderer/chrome_render_view_observer.h @@ -22,7 +22,6 @@ class ContentSettingsObserver; class ExternalHostBindings; class SkBitmap; class TranslateHelper; -struct ThumbnailScore; class WebViewColorOverlay; class WebViewAnimatingOverlay; @@ -157,14 +156,6 @@ class ChromeRenderViewObserver : public content::RenderViewObserver, // maximum amount kMaxIndexChars will be placed into the given buffer. void CaptureText(WebKit::WebFrame* frame, string16* contents); - void CaptureThumbnail(); - - // Creates a thumbnail of |frame|'s contents resized to (|w|, |h|) - // and puts that in |thumbnail|. Thumbnail metadata goes in |score|. - bool CaptureFrameThumbnail(WebKit::WebView* view, int w, int h, - SkBitmap* thumbnail, - ThumbnailScore* score); - // Capture a snapshot of a view. This is used to allow an extension // to get a snapshot of a tab using chrome.tabs.captureVisibleTab(). bool CaptureSnapshot(WebKit::WebView* view, SkBitmap* snapshot); -- 2.11.4.GIT