Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: chrome/browser/cocoa/tab_strip_controller.mm

Issue 184003: Don't show favicons or throbbers for the New Tab page on the Mac.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/cocoa/tab_controller_unittest.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 #import "chrome/browser/cocoa/tab_strip_controller.h" 5 #import "chrome/browser/cocoa/tab_strip_controller.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/mac_util.h" 8 #include "base/mac_util.h"
9 #include "base/sys_string_conversions.h" 9 #include "base/sys_string_conversions.h"
10 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 if (navEntry != NULL) { 641 if (navEntry != NULL) {
642 NavigationEntry::FaviconStatus favIcon = navEntry->favicon(); 642 NavigationEntry::FaviconStatus favIcon = navEntry->favicon();
643 const SkBitmap& bitmap = favIcon.bitmap(); 643 const SkBitmap& bitmap = favIcon.bitmap();
644 if (favIcon.is_valid() && !bitmap.isNull()) 644 if (favIcon.is_valid() && !bitmap.isNull())
645 image = gfx::SkBitmapToNSImage(bitmap); 645 image = gfx::SkBitmapToNSImage(bitmap);
646 } 646 }
647 647
648 // Either we don't have a valid favicon or there was some issue converting it 648 // Either we don't have a valid favicon or there was some issue converting it
649 // from an SkBitmap. Either way, just show the default. 649 // from an SkBitmap. Either way, just show the default.
650 if (!image) { 650 if (!image) {
651 NSBundle* bundle = mac_util::MainAppBundle(); 651 image = nsimage_cache::ImageNamed(@"nav.pdf");
652 image = [[NSImage alloc] initByReferencingFile:
653 [bundle pathForResource:@"nav" ofType:@"pdf"]];
654 [image autorelease];
655 } 652 }
656 653
657 [view setImage:image]; 654 [view setImage:image];
658 return view; 655 return view;
659 } 656 }
660 657
661 // Update the current loading state, replacing the favicon with a throbber, or 658 // Updates the current loading state, replacing the icon view with a favicon,
662 // vice versa. This will get called repeatedly with the same state during a 659 // a throbber, the default icon, or nothing at all.
663 // load, so we need to make sure we're not creating the throbber view over and
664 // over. However, when the page is done, every state change is important.
665 - (void)updateFavIconForContents:(TabContents*)contents 660 - (void)updateFavIconForContents:(TabContents*)contents
666 atIndex:(NSInteger)index { 661 atIndex:(NSInteger)index {
667 if (!contents) 662 if (!contents)
668 return; 663 return;
669 664
670 static NSImage* throbberWaitingImage = 665 static NSImage* throbberWaitingImage =
671 [nsimage_cache::ImageNamed(@"throbber_waiting.png") retain]; 666 [nsimage_cache::ImageNamed(@"throbber_waiting.png") retain];
672 static NSImage* throbberLoadingImage = 667 static NSImage* throbberLoadingImage =
673 [nsimage_cache::ImageNamed(@"throbber.png") retain]; 668 [nsimage_cache::ImageNamed(@"throbber.png") retain];
674 static NSImage* sadFaviconImage = 669 static NSImage* sadFaviconImage =
675 [nsimage_cache::ImageNamed(@"sadfavicon.png") retain]; 670 [nsimage_cache::ImageNamed(@"sadfavicon.png") retain];
676 671
677 TabController* tabController = [tabArray_ objectAtIndex:index]; 672 TabController* tabController = [tabArray_ objectAtIndex:index];
673
674 bool oldHasIcon = [tabController iconView] != nil;
675 bool newHasIcon = contents->ShouldDisplayFavIcon();
676
678 TabLoadingState oldState = [tabController loadingState]; 677 TabLoadingState oldState = [tabController loadingState];
679 TabLoadingState newState = kTabDone; 678 TabLoadingState newState = kTabDone;
680 NSImage* throbberImage = nil; 679 NSImage* throbberImage = nil;
681 if (contents->waiting_for_response()) { 680 if (contents->is_crashed()) {
681 newState = kTabCrashed;
682 newHasIcon = true;
683 } else if (contents->waiting_for_response()) {
682 newState = kTabWaiting; 684 newState = kTabWaiting;
683 throbberImage = throbberWaitingImage; 685 throbberImage = throbberWaitingImage;
684 } else if (contents->is_loading()) { 686 } else if (contents->is_loading()) {
685 newState = kTabLoading; 687 newState = kTabLoading;
686 throbberImage = throbberLoadingImage; 688 throbberImage = throbberLoadingImage;
687 } else if (contents->is_crashed()) {
688 newState = kTabCrashed;
689 } 689 }
690 690
691 if (oldState != newState || newState == kTabDone) { 691 if (oldState != newState)
692 [tabController setLoadingState:newState];
693
694 // While loading, this function is called repeatedly with the same state.
695 // To avoid expensive unnecessary view manipulation, only make changes when
696 // the state is actually changing. When loading is complete (kTabDone),
697 // every call to this function is significant.
698 if (newState == kTabDone || oldState != newState ||
699 oldHasIcon != newHasIcon) {
692 NSView* iconView = nil; 700 NSView* iconView = nil;
693 if (newState == kTabDone) { 701 if (newHasIcon) {
694 iconView = [self favIconImageViewForContents:contents]; 702 if (newState == kTabDone) {
695 } else if (newState == kTabCrashed) { 703 iconView = [self favIconImageViewForContents:contents];
696 NSImage* oldImage = [[self favIconImageViewForContents:contents] image]; 704 } else if (newState == kTabCrashed) {
697 NSRect frame = NSMakeRect(0, 0, 16, 16); 705 NSImage* oldImage = [[self favIconImageViewForContents:contents] image];
698 iconView = [ThrobberView toastThrobberViewWithFrame:frame 706 NSRect frame = NSMakeRect(0, 0, 16, 16);
699 beforeImage:oldImage 707 iconView = [ThrobberView toastThrobberViewWithFrame:frame
700 afterImage:sadFaviconImage]; 708 beforeImage:oldImage
701 } else { 709 afterImage:sadFaviconImage];
702 NSRect frame = NSMakeRect(0, 0, 16, 16); 710 } else {
703 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame 711 NSRect frame = NSMakeRect(0, 0, 16, 16);
704 image:throbberImage]; 712 iconView = [ThrobberView filmstripThrobberViewWithFrame:frame
713 image:throbberImage];
714 }
705 } 715 }
706 716
707 [tabController setLoadingState:newState];
708 [tabController setIconView:iconView]; 717 [tabController setIconView:iconView];
709 } 718 }
710 } 719 }
711 720
712 // Called when a notification is received from the model that the given tab 721 // Called when a notification is received from the model that the given tab
713 // has been updated. |loading| will be YES when we only want to update the 722 // has been updated. |loading| will be YES when we only want to update the
714 // throbber state, not anything else about the (partially) loading tab. 723 // throbber state, not anything else about the (partially) loading tab.
715 - (void)tabChangedWithContents:(TabContents*)contents 724 - (void)tabChangedWithContents:(TabContents*)contents
716 atIndex:(NSInteger)index 725 atIndex:(NSInteger)index
717 loadingOnly:(BOOL)loading { 726 loadingOnly:(BOOL)loading {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
946 BrowserWindowController* controller = 955 BrowserWindowController* controller =
947 (BrowserWindowController*)[[switchView_ window] windowController]; 956 (BrowserWindowController*)[[switchView_ window] windowController];
948 DCHECK(index >= 0); 957 DCHECK(index >= 0);
949 if (index >= 0) { 958 if (index >= 0) {
950 [controller setTab:[self viewAtIndex:index] isDraggable:YES]; 959 [controller setTab:[self viewAtIndex:index] isDraggable:YES];
951 } 960 }
952 } 961 }
953 962
954 963
955 @end 964 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/tab_controller_unittest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698