| 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 "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/history/top_sites.h" | 9 #include "chrome/browser/history/top_sites.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size()); | 399 gfx::Rect copy_rect = gfx::Rect(view->GetViewBounds().size()); |
| 400 // Clip the pixels that will commonly hold a scrollbar, which looks bad in | 400 // Clip the pixels that will commonly hold a scrollbar, which looks bad in |
| 401 // thumbnails. | 401 // thumbnails. |
| 402 int scrollbar_size = gfx::scrollbar_size(); | 402 int scrollbar_size = gfx::scrollbar_size(); |
| 403 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); | 403 copy_rect.Inset(0, 0, scrollbar_size, scrollbar_size); |
| 404 ClipResult clip_result = ThumbnailTabHelper::kUnprocessed; | 404 ClipResult clip_result = ThumbnailTabHelper::kUnprocessed; |
| 405 copy_rect = GetClippingRect(copy_rect.size(), | 405 copy_rect = GetClippingRect(copy_rect.size(), |
| 406 gfx::Size(kThumbnailWidth, kThumbnailHeight), | 406 gfx::Size(kThumbnailWidth, kThumbnailHeight), |
| 407 &clip_result); | 407 &clip_result); |
| 408 gfx::Size copy_size = GetCopySizeForThumbnail(view); | 408 gfx::Size copy_size = GetCopySizeForThumbnail(view); |
| 409 skia::PlatformCanvas* temp_canvas = new skia::PlatformCanvas; | 409 skia::PlatformBitmap* temp_bitmap = new skia::PlatformBitmap; |
| 410 render_widget_host->CopyFromBackingStore( | 410 render_widget_host->CopyFromBackingStore( |
| 411 copy_rect, | 411 copy_rect, |
| 412 copy_size, | 412 copy_size, |
| 413 base::Bind(&ThumbnailTabHelper::UpdateThumbnailWithCanvas, | 413 base::Bind(&ThumbnailTabHelper::UpdateThumbnailWithCanvas, |
| 414 weak_factory_.GetWeakPtr(), | 414 weak_factory_.GetWeakPtr(), |
| 415 web_contents, | 415 web_contents, |
| 416 clip_result, | 416 clip_result, |
| 417 base::Owned(temp_canvas)), | 417 base::Owned(temp_bitmap)), |
| 418 temp_canvas); | 418 temp_bitmap); |
| 419 } | 419 } |
| 420 | 420 |
| 421 void ThumbnailTabHelper::UpdateThumbnailWithBitmap( | 421 void ThumbnailTabHelper::UpdateThumbnailWithBitmap( |
| 422 WebContents* web_contents, | 422 WebContents* web_contents, |
| 423 ClipResult clip_result, | 423 ClipResult clip_result, |
| 424 const SkBitmap& bitmap) { | 424 const SkBitmap& bitmap) { |
| 425 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 425 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 426 if (bitmap.isNull() || bitmap.empty()) | 426 if (bitmap.isNull() || bitmap.empty()) |
| 427 return; | 427 return; |
| 428 | 428 |
| 429 SkBitmap thumbnail = CreateThumbnail(bitmap, | 429 SkBitmap thumbnail = CreateThumbnail(bitmap, |
| 430 GetThumbnailSizeInPixel(), | 430 GetThumbnailSizeInPixel(), |
| 431 &clip_result); | 431 &clip_result); |
| 432 UpdateThumbnail(web_contents, thumbnail, clip_result); | 432 UpdateThumbnail(web_contents, thumbnail, clip_result); |
| 433 } | 433 } |
| 434 | 434 |
| 435 void ThumbnailTabHelper::UpdateThumbnailWithCanvas( | 435 void ThumbnailTabHelper::UpdateThumbnailWithCanvas( |
| 436 WebContents* web_contents, | 436 WebContents* web_contents, |
| 437 ClipResult clip_result, | 437 ClipResult clip_result, |
| 438 skia::PlatformCanvas* temp_canvas, | 438 skia::PlatformBitmap* temp_bitmap, |
| 439 bool succeeded) { | 439 bool succeeded) { |
| 440 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 440 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 441 if (!succeeded) | 441 if (!succeeded) |
| 442 return; | 442 return; |
| 443 | 443 |
| 444 SkBitmap bitmap = skia::GetTopDevice(*temp_canvas)->accessBitmap(false); | 444 SkBitmap bitmap = temp_bitmap->GetBitmap(); |
| 445 UpdateThumbnailWithBitmap(web_contents, clip_result, bitmap); | 445 UpdateThumbnailWithBitmap(web_contents, clip_result, bitmap); |
| 446 } | 446 } |
| 447 | 447 |
| 448 bool ThumbnailTabHelper::ShouldUpdateThumbnail(Profile* profile, | 448 bool ThumbnailTabHelper::ShouldUpdateThumbnail(Profile* profile, |
| 449 history::TopSites* top_sites, | 449 history::TopSites* top_sites, |
| 450 const GURL& url) { | 450 const GURL& url) { |
| 451 if (!profile || !top_sites) | 451 if (!profile || !top_sites) |
| 452 return false; | 452 return false; |
| 453 // Skip if it's in the incognito mode. | 453 // Skip if it's in the incognito mode. |
| 454 if (profile->IsOffTheRecord()) | 454 if (profile->IsOffTheRecord()) |
| (...skipping 22 matching lines...) Expand all Loading... |
| 477 void ThumbnailTabHelper::DidStartLoading( | 477 void ThumbnailTabHelper::DidStartLoading( |
| 478 content::RenderViewHost* render_view_host) { | 478 content::RenderViewHost* render_view_host) { |
| 479 load_interrupted_ = false; | 479 load_interrupted_ = false; |
| 480 } | 480 } |
| 481 | 481 |
| 482 void ThumbnailTabHelper::StopNavigation() { | 482 void ThumbnailTabHelper::StopNavigation() { |
| 483 // This function gets called when the page loading is interrupted by the | 483 // This function gets called when the page loading is interrupted by the |
| 484 // stop button. | 484 // stop button. |
| 485 load_interrupted_ = true; | 485 load_interrupted_ = true; |
| 486 } | 486 } |
| OLD | NEW |