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/tab_contents/thumbnail_generator.h" | 5 #include "chrome/browser/tab_contents/thumbnail_generator.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 clip_result); | 476 clip_result); |
477 SkIRect src_rect = { clipping_rect.x(), clipping_rect.y(), | 477 SkIRect src_rect = { clipping_rect.x(), clipping_rect.y(), |
478 clipping_rect.right(), clipping_rect.bottom() }; | 478 clipping_rect.right(), clipping_rect.bottom() }; |
479 SkBitmap clipped_bitmap; | 479 SkBitmap clipped_bitmap; |
480 bitmap.extractSubset(&clipped_bitmap, src_rect); | 480 bitmap.extractSubset(&clipped_bitmap, src_rect); |
481 return clipped_bitmap; | 481 return clipped_bitmap; |
482 } | 482 } |
483 | 483 |
484 void ThumbnailGenerator::UpdateThumbnailIfNecessary( | 484 void ThumbnailGenerator::UpdateThumbnailIfNecessary( |
485 WebContents* web_contents) { | 485 WebContents* web_contents) { |
486 // Skip if a pending entry exists. WidgetHidden can be called while navigaing | 486 // Destroying a WebContents may trigger it to be hidden, prompting a snapshot |
487 // pages and this is not a timing when thumbnails should be generated. | 487 // which would be unwise to attempt <http://crbug.com/130097>. If the |
488 // WebContents is in the middle of destruction, do not risk it. | |
489 if (web_contents->IsBeingDestroyed()) | |
mazda
2012/08/30 17:19:18
How about the follwing code to deal with the case
Avi (use Gerrit)
2012/08/30 18:16:26
Is that in addition to this code or to replace it?
mazda
2012/08/30 19:39:22
I meant to replace it.
But when NOTIFICATION_TAB_C
Avi (use Gerrit)
2012/08/30 19:44:16
Adding a temporary dependency to TabContents would
mazda
2012/08/30 20:39:39
Yes, http://crbug.com/130097 was caused by NOTIFIC
| |
490 return; | |
491 // Skip if a pending entry exists. WidgetHidden can be called while navigating | |
492 // pages and this is not a time when thumbnails should be generated. | |
488 if (web_contents->GetController().GetPendingEntry()) | 493 if (web_contents->GetController().GetPendingEntry()) |
489 return; | 494 return; |
490 const GURL& url = web_contents->GetURL(); | 495 const GURL& url = web_contents->GetURL(); |
491 Profile* profile = | 496 Profile* profile = |
492 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 497 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
493 history::TopSites* top_sites = profile->GetTopSites(); | 498 history::TopSites* top_sites = profile->GetTopSites(); |
494 // Skip if we don't need to update the thumbnail. | 499 // Skip if we don't need to update the thumbnail. |
495 if (!ShouldUpdateThumbnail(profile, top_sites, url)) | 500 if (!ShouldUpdateThumbnail(profile, top_sites, url)) |
496 return; | 501 return; |
497 | 502 |
498 AsyncUpdateThumbnail(web_contents); | 503 AsyncUpdateThumbnail(web_contents); |
499 } | 504 } |
500 | 505 |
501 void ThumbnailGenerator::UpdateThumbnail( | 506 void ThumbnailGenerator::UpdateThumbnail( |
502 WebContents* web_contents, const SkBitmap& thumbnail, | 507 WebContents* web_contents, const SkBitmap& thumbnail, |
503 const ClipResult& clip_result) { | 508 const ClipResult& clip_result) { |
504 | |
505 Profile* profile = | 509 Profile* profile = |
506 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 510 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
507 history::TopSites* top_sites = profile->GetTopSites(); | 511 history::TopSites* top_sites = profile->GetTopSites(); |
508 if (!top_sites) | 512 if (!top_sites) |
509 return; | 513 return; |
510 | 514 |
511 // Compute the thumbnail score. | 515 // Compute the thumbnail score. |
512 ThumbnailScore score; | 516 ThumbnailScore score; |
513 score.at_top = | 517 score.at_top = |
514 (web_contents->GetRenderViewHost()->GetLastScrollOffset().y() == 0); | 518 (web_contents->GetRenderViewHost()->GetLastScrollOffset().y() == 0); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
633 void ThumbnailGenerator::DidStartLoading( | 637 void ThumbnailGenerator::DidStartLoading( |
634 content::RenderViewHost* render_view_host) { | 638 content::RenderViewHost* render_view_host) { |
635 load_interrupted_ = false; | 639 load_interrupted_ = false; |
636 } | 640 } |
637 | 641 |
638 void ThumbnailGenerator::StopNavigation() { | 642 void ThumbnailGenerator::StopNavigation() { |
639 // This function gets called when the page loading is interrupted by the | 643 // This function gets called when the page loading is interrupted by the |
640 // stop button. | 644 // stop button. |
641 load_interrupted_ = true; | 645 load_interrupted_ = true; |
642 } | 646 } |
OLD | NEW |