Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: chrome/browser/tab_contents/tab_contents.cc

Issue 6246007: Generate thumbnails in the browser process. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: minor cleanup Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.h ('k') | chrome/browser/tab_contents/thumbnail_generator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/tab_contents/tab_contents.cc
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index 5c838f318c5b4e4bac17ef05b0211f65fecfaca4..d4a84ec4b572c3382dcc0a3f13f0efccf67b47d8 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -75,6 +75,7 @@
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
#include "chrome/browser/tab_contents/tab_contents_view.h"
+#include "chrome/browser/tab_contents/thumbnail_generator.h"
#include "chrome/browser/tab_contents/web_navigation_observer.h"
#include "chrome/browser/translate/page_translated_details.h"
#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
@@ -93,6 +94,7 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/render_messages_params.h"
+#include "chrome/common/thumbnail_score.h"
#include "chrome/common/url_constants.h"
#include "gfx/codec/png_codec.h"
#include "grit/chromium_strings.h"
@@ -2224,6 +2226,40 @@ void TabContents::GenerateKeywordIfNecessary(
url_model->Add(new_url);
}
+void TabContents::UpdateThumbnailIfNecessary(const GURL& url) {
+ if (profile()->IsOffTheRecord() ||
+ (url.SchemeIs("chrome") && url.host() == "newtab"))
+ return;
+ // TODO(satorux): Add more conditions here to avoid unnecessary
+ // thumbnail generation.
+
+ ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
+ const int options = ThumbnailGenerator::kClippedThumbnail;
+ ThumbnailGenerator::ClipResult clip_result = ThumbnailGenerator::kNotClipped;
+ SkBitmap thumbnail = generator->GetThumbnailForRendererWithOptions(
+ render_view_host(), options, &clip_result);
+ // Failed to generate a thumbnail. Maybe the tab is in the background?
+ if (thumbnail.isNull())
+ return;
+
+ // Compute the thumbnail score.
+ ThumbnailScore score;
+ score.at_top = (render_view_host()->last_scroll_offset().height() == 0);
+ score.boring_score = ThumbnailGenerator::CalculateBoringScore(&thumbnail);
+ score.good_clipping =
+ (clip_result == ThumbnailGenerator::kTallerThanWide ||
+ clip_result == ThumbnailGenerator::kNotClipped);
+
+ history::TopSites* top_sites = profile()->GetTopSites();
+ top_sites->SetPageThumbnail(url, thumbnail, score);
+ VLOG(1) << "Thumbnail taken for " << url
+ << ", at_top: " << score.at_top
+ << ", boring_score: " << score.boring_score
+ << ", good_clipping: " << score.good_clipping;
+}
+
brettw 2011/01/20 00:30:51 Style nit: probably don't need these extra lines h
satorux1 2011/01/20 05:43:39 Done.
+
+
void TabContents::OnUserGesture() {
// See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
DownloadRequestLimiter* limiter =
@@ -2370,6 +2406,12 @@ void TabContents::OnPageContents(const GURL& url,
NotificationType::TAB_LANGUAGE_DETERMINED,
Source<TabContents>(this),
Details<std::string>(&lang));
+
+ // Generate the thumbnail here if the in-browser thumbnailing is enabled.
+ if (CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableInBrowserThumbnailing)) {
+ UpdateThumbnailIfNecessary(url);
+ }
}
void TabContents::OnPageTranslated(int32 page_id,
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.h ('k') | chrome/browser/tab_contents/thumbnail_generator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698