OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" | 5 #include "chrome/browser/thumbnails/thumbnail_tab_helper.h" |
6 | 6 |
7 #include "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" | 9 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" |
10 #include "chrome/browser/thumbnails/thumbnail_service.h" | 10 #include "chrome/browser/thumbnails/thumbnail_service.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 // Feed the constructed thumbnail to the thumbnail service. | 56 // Feed the constructed thumbnail to the thumbnail service. |
57 void UpdateThumbnail(const ThumbnailingContext& context, | 57 void UpdateThumbnail(const ThumbnailingContext& context, |
58 const SkBitmap& thumbnail) { | 58 const SkBitmap& thumbnail) { |
59 gfx::Image image = gfx::Image::CreateFrom1xBitmap(thumbnail); | 59 gfx::Image image = gfx::Image::CreateFrom1xBitmap(thumbnail); |
60 context.service->SetPageThumbnail(context, image); | 60 context.service->SetPageThumbnail(context, image); |
61 VLOG(1) << "Thumbnail taken for " << context.url << ": " | 61 VLOG(1) << "Thumbnail taken for " << context.url << ": " |
62 << context.score.ToString(); | 62 << context.score.ToString(); |
63 } | 63 } |
64 | 64 |
65 void ProcessCapturedBitmap(ThumbnailingContext* context, | 65 void ProcessCapturedBitmap(scoped_refptr<ThumbnailingContext> context, |
66 ThumbnailingAlgorithm* algorithm, | 66 scoped_refptr<ThumbnailingAlgorithm> algorithm, |
67 bool succeeded, | 67 bool succeeded, |
68 const SkBitmap& bitmap) { | 68 const SkBitmap& bitmap) { |
69 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 69 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
70 if (!succeeded) | 70 if (!succeeded) |
71 return; | 71 return; |
72 | 72 |
73 algorithm->ProcessBitmap(context, base::Bind(&UpdateThumbnail), bitmap); | 73 algorithm->ProcessBitmap(context, base::Bind(&UpdateThumbnail), bitmap); |
74 } | 74 } |
75 | 75 |
76 void GotSnapshotFromRenderer(base::Callback<void(const SkBitmap&)> callback, | 76 void GotSnapshotFromRenderer(base::Callback<void(const SkBitmap&)> callback, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 gfx::Size copy_size; | 108 gfx::Size copy_size; |
109 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); | 109 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); |
110 | 110 |
111 if (copy_rect.IsEmpty()) | 111 if (copy_rect.IsEmpty()) |
112 return; | 112 return; |
113 | 113 |
114 context->clip_result = algorithm->GetCanvasCopyInfo( | 114 context->clip_result = algorithm->GetCanvasCopyInfo( |
115 copy_rect.size(), | 115 copy_rect.size(), |
116 ui::GetScaleFactorForNativeView(view->GetNativeView()), | 116 ui::GetScaleFactorForNativeView(view->GetNativeView()), |
117 ©_rect, | 117 ©_rect, |
118 ©_size); | 118 &context->requested_copy_size); |
119 | 119 |
120 render_widget_host->CopyFromBackingStore( | 120 render_widget_host->CopyFromBackingStore( |
121 copy_rect, | 121 copy_rect, |
122 copy_size, | 122 context->requested_copy_size, |
123 base::Bind(&ProcessCapturedBitmap, context, algorithm)); | 123 base::Bind(&ProcessCapturedBitmap, context, algorithm)); |
124 } | 124 } |
125 | 125 |
126 } // namespace | 126 } // namespace |
127 | 127 |
128 ThumbnailTabHelper::ThumbnailTabHelper(content::WebContents* contents) | 128 ThumbnailTabHelper::ThumbnailTabHelper(content::WebContents* contents) |
129 : content::WebContentsObserver(contents), | 129 : content::WebContentsObserver(contents), |
130 enabled_(true), | 130 enabled_(true), |
131 load_interrupted_(false) { | 131 load_interrupted_(false) { |
132 // Even though we deal in RenderWidgetHosts, we only care about its | 132 // Even though we deal in RenderWidgetHosts, we only care about its |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, | 234 content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED, |
235 content::Source<RenderWidgetHost>(renderer)); | 235 content::Source<RenderWidgetHost>(renderer)); |
236 } | 236 } |
237 } | 237 } |
238 | 238 |
239 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { | 239 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { |
240 if (!enabled_) | 240 if (!enabled_) |
241 return; | 241 return; |
242 UpdateThumbnailIfNecessary(web_contents()); | 242 UpdateThumbnailIfNecessary(web_contents()); |
243 } | 243 } |
244 | |
OLD | NEW |