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 bfd1a409a7a6624dcfb42133386a6988f6321aae..4dca0f21c017f626abe9503a96989b82b7948ac9 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" |
@@ -2232,6 +2234,38 @@ void TabContents::GenerateKeywordIfNecessary( |
url_model->Add(new_url); |
} |
+void TabContents::UpdateThumbnailIfNecessary(const GURL& url) { |
brettw
2011/01/21 00:09:17
I'm always trying to get people to not add stuff t
satorux1
2011/01/21 04:53:43
That's a good idea. Moved accordingly.
|
+ 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; |
+} |
+ |
void TabContents::OnUserGesture() { |
// See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. |
DownloadRequestLimiter* limiter = |
@@ -2378,6 +2412,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, |