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..b12970102f1e4a9e96ac10d65d26d0805708608d 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::kBoringScore); |
+ ThumbnailGenerator::ThumbnailResult result; |
+ SkBitmap thumbnail = generator->GetThumbnailForRendererWithOptions( |
+ render_view_host(), options, &result); |
+ // Failed to generate a thumbnail. Maybe the tab is in the background? |
+ if (thumbnail.isNull()) |
+ return; |
+ |
+ ThumbnailScore score; |
+ score.at_top = (render_view_host()->last_scroll_offset().height() == 0); |
+ score.boring_score = result.boring_score; |
+ score.good_clipping = |
+ (result.clip_result == ThumbnailGenerator::kTallerThanWide || |
+ result.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 = |
@@ -2370,6 +2406,8 @@ void TabContents::OnPageContents(const GURL& url, |
NotificationType::TAB_LANGUAGE_DETERMINED, |
Source<TabContents>(this), |
Details<std::string>(&lang)); |
+ |
+ UpdateThumbnailIfNecessary(url); |
} |
void TabContents::OnPageTranslated(int32 page_id, |
@@ -2708,18 +2746,6 @@ void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) { |
delegate()->UpdateTargetURL(this, url); |
} |
-void TabContents::UpdateThumbnail(const GURL& url, |
- const SkBitmap& bitmap, |
- const ThumbnailScore& score) { |
- if (profile()->IsOffTheRecord()) |
- return; |
- |
- // Tell History about this thumbnail |
- history::TopSites* ts = profile()->GetTopSites(); |
- if (ts) |
- ts->SetPageThumbnail(url, bitmap, score); |
-} |
- |
void TabContents::UpdateInspectorSetting(const std::string& key, |
const std::string& value) { |
RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value); |