| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 ThumbnailingAlgorithm* algorithm, | 66 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, |
| 77 bool success, |
| 78 const SkBitmap& bitmap) { |
| 79 if (success) |
| 80 callback.Run(bitmap); |
| 81 } |
| 82 |
| 76 void AsyncProcessThumbnail(content::WebContents* web_contents, | 83 void AsyncProcessThumbnail(content::WebContents* web_contents, |
| 77 scoped_refptr<ThumbnailingContext> context, | 84 scoped_refptr<ThumbnailingContext> context, |
| 78 scoped_refptr<ThumbnailingAlgorithm> algorithm) { | 85 scoped_refptr<ThumbnailingAlgorithm> algorithm) { |
| 79 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 86 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 80 RenderWidgetHost* render_widget_host = web_contents->GetRenderViewHost(); | 87 RenderWidgetHost* render_widget_host = web_contents->GetRenderViewHost(); |
| 81 content::RenderWidgetHostView* view = render_widget_host->GetView(); | 88 content::RenderWidgetHostView* view = render_widget_host->GetView(); |
| 82 if (!view) | 89 if (!view) |
| 83 return; | 90 return; |
| 84 if (!view->IsSurfaceAvailableForCopy()) { | 91 if (!view->IsSurfaceAvailableForCopy()) { |
| 85 #if defined(OS_WIN) | 92 // On Windows XP and possibly due to driver issues, neither the backing |
| 86 // On Windows XP, neither the backing store nor the compositing surface is | 93 // store nor the compositing surface is available in the browser when |
| 87 // available in the browser when accelerated compositing is active, so ask | 94 // accelerated compositing is active, so ask the renderer to send a snapshot |
| 88 // the renderer to send a snapshot for creating the thumbnail. | 95 // for creating the thumbnail. |
| 89 if (base::win::GetVersion() < base::win::VERSION_VISTA) { | 96 render_widget_host->GetSnapshotFromRenderer( |
| 90 gfx::Size view_size = | 97 gfx::Rect(), |
| 91 render_widget_host->GetView()->GetViewBounds().size(); | 98 base::Bind(GotSnapshotFromRenderer, base::Bind( |
| 92 g_browser_process->GetRenderWidgetSnapshotTaker()->AskForSnapshot( | 99 &ThumbnailingAlgorithm::ProcessBitmap, |
| 93 render_widget_host, | 100 algorithm, context, base::Bind(&UpdateThumbnail)))); |
| 94 base::Bind(&ThumbnailingAlgorithm::ProcessBitmap, | |
| 95 algorithm, context, base::Bind(&UpdateThumbnail)), | |
| 96 view_size, | |
| 97 view_size); | |
| 98 } | |
| 99 #endif | |
| 100 return; | 101 return; |
| 101 } | 102 } |
| 102 | 103 |
| 103 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size()); | 104 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size()); |
| 104 // Clip the pixels that will commonly hold a scrollbar, which looks bad in | 105 // Clip the pixels that will commonly hold a scrollbar, which looks bad in |
| 105 // thumbnails. | 106 // thumbnails. |
| 106 int scrollbar_size = gfx::scrollbar_size(); | 107 int scrollbar_size = gfx::scrollbar_size(); |
| 107 gfx::Size copy_size; | 108 gfx::Size copy_size; |
| 108 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); | 109 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); |
| 109 | 110 |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 content::Source<RenderWidgetHost>(renderer)); | 237 content::Source<RenderWidgetHost>(renderer)); |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 | 240 |
| 240 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { | 241 void ThumbnailTabHelper::WidgetHidden(RenderWidgetHost* widget) { |
| 241 if (!enabled_) | 242 if (!enabled_) |
| 242 return; | 243 return; |
| 243 UpdateThumbnailIfNecessary(web_contents()); | 244 UpdateThumbnailIfNecessary(web_contents()); |
| 244 } | 245 } |
| 245 | 246 |
| OLD | NEW |