diff options
Diffstat (limited to 'chrome')
25 files changed, 400 insertions, 61 deletions
diff --git a/chrome/browser/aeropeek_manager.cc b/chrome/browser/aeropeek_manager.cc index 7c1d3d5..55ba475 100644 --- a/chrome/browser/aeropeek_manager.cc +++ b/chrome/browser/aeropeek_manager.cc @@ -17,6 +17,7 @@ #include "base/win/windows_version.h" #include "chrome/browser/app_icon_win.h" #include "chrome/browser/browser_process.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/tab_contents/thumbnail_generator.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser_list.h" @@ -1069,7 +1070,7 @@ void AeroPeekManager::CreateAeroPeekWindowIfNecessary(TabContentsWrapper* tab, GetTabID(tab->tab_contents()), foreground, tab->tab_contents()->GetTitle(), - tab->tab_contents()->GetFavicon()); + tab->favicon_tab_helper()->GetFavicon()); tab_list_.push_back(window); } @@ -1174,7 +1175,7 @@ void AeroPeekManager::TabChangedAt(TabContentsWrapper* contents, // hurting the rendering performance. (These functions just save the // information needed for handling update requests from Windows.) window->SetTitle(contents->tab_contents()->GetTitle()); - window->SetFavicon(contents->tab_contents()->GetFavicon()); + window->SetFavicon(contents->favicon_tab_helper()->GetFavicon()); window->Update(contents->tab_contents()->is_loading()); } diff --git a/chrome/browser/extensions/extension_tabs_module.cc b/chrome/browser/extensions/extension_tabs_module.cc index df2baf2..90db625 100644 --- a/chrome/browser/extensions/extension_tabs_module.cc +++ b/chrome/browser/extensions/extension_tabs_module.cc @@ -8,6 +8,7 @@ #include <vector> #include "base/base64.h" +#include "base/memory/ref_counted_memory.h" #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/stringprintf.h" diff --git a/chrome/browser/favicon/favicon_tab_helper.cc b/chrome/browser/favicon/favicon_tab_helper.cc index f6908fb..ecaa29b 100644 --- a/chrome/browser/favicon/favicon_tab_helper.cc +++ b/chrome/browser/favicon/favicon_tab_helper.cc @@ -6,7 +6,12 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/favicon/favicon_handler.h" +#include "chrome/browser/history/history.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/common/icon_messages.h" +#include "content/browser/tab_contents/tab_contents.h" +#include "content/browser/webui/web_ui.h" +#include "ui/gfx/codec/png_codec.h" FaviconTabHelper::FaviconTabHelper(TabContents* tab_contents) : TabContentsObserver(tab_contents) { @@ -26,6 +31,73 @@ void FaviconTabHelper::FetchFavicon(const GURL& url) { touch_icon_handler_->FetchFavicon(url); } +SkBitmap FaviconTabHelper::GetFavicon() const { + // Like GetTitle(), we also want to use the favicon for the last committed + // entry rather than a pending navigation entry. + const NavigationController& controller = tab_contents()->controller(); + NavigationEntry* entry = controller.GetTransientEntry(); + if (entry) + return entry->favicon().bitmap(); + + entry = controller.GetLastCommittedEntry(); + if (entry) + return entry->favicon().bitmap(); + return SkBitmap(); +} + +bool FaviconTabHelper::FaviconIsValid() const { + const NavigationController& controller = tab_contents()->controller(); + NavigationEntry* entry = controller.GetTransientEntry(); + if (entry) + return entry->favicon().is_valid(); + + entry = controller.GetLastCommittedEntry(); + if (entry) + return entry->favicon().is_valid(); + + return false; +} + +bool FaviconTabHelper::ShouldDisplayFavicon() { + // Always display a throbber during pending loads. + const NavigationController& controller = tab_contents()->controller(); + if (controller.GetLastCommittedEntry() && controller.pending_entry()) + return true; + + WebUI* web_ui = tab_contents()->GetWebUIForCurrentState(); + if (web_ui) + return !web_ui->hide_favicon(); + return true; +} + +void FaviconTabHelper::SaveFavicon() { + NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); + if (!entry || entry->url().is_empty()) + return; + + // Make sure the page is in history, otherwise adding the favicon does + // nothing. + HistoryService* history = tab_contents()->profile()-> + GetOriginalProfile()->GetHistoryService(Profile::IMPLICIT_ACCESS); + if (!history) + return; + history->AddPageNoVisitForBookmark(entry->url()); + + FaviconService* service = tab_contents()->profile()-> + GetOriginalProfile()->GetFaviconService(Profile::IMPLICIT_ACCESS); + if (!service) + return; + const NavigationEntry::FaviconStatus& favicon(entry->favicon()); + if (!favicon.is_valid() || favicon.url().is_empty() || + favicon.bitmap().empty()) { + return; + } + std::vector<unsigned char> image_data; + gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data); + service->SetFavicon( + entry->url(), favicon.url(), image_data, history::FAVICON); +} + int FaviconTabHelper::DownloadImage(const GURL& image_url, int image_size, history::IconType icon_type, @@ -39,6 +111,25 @@ int FaviconTabHelper::DownloadImage(const GURL& image_url, return 0; } +void FaviconTabHelper::NavigateToPendingEntry( + const GURL& url, + NavigationController::ReloadType reload_type) { + if (reload_type != NavigationController::NO_RELOAD && + !tab_contents()->profile()->IsOffTheRecord()) { + FaviconService* favicon_service = + tab_contents()->profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); + if (favicon_service) + favicon_service->SetFaviconOutOfDateForPage(url); + } +} + +void FaviconTabHelper::DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) { + // Get the favicon, either from history or request it from the net. + FetchFavicon(details.entry->url()); +} + bool FaviconTabHelper::OnMessageReceived(const IPC::Message& message) { bool message_handled = true; IPC_BEGIN_MESSAGE_MAP(FaviconTabHelper, message) diff --git a/chrome/browser/favicon/favicon_tab_helper.h b/chrome/browser/favicon/favicon_tab_helper.h index 64064f4..a558848 100644 --- a/chrome/browser/favicon/favicon_tab_helper.h +++ b/chrome/browser/favicon/favicon_tab_helper.h @@ -15,7 +15,6 @@ class FaviconHandler; class NavigationEntry; -class Profile; class RefCountedMemory; class SkBitmap; class TabContents; @@ -37,6 +36,22 @@ class FaviconTabHelper : public TabContentsObserver { // Initiates loading the favicon for the specified url. void FetchFavicon(const GURL& url); + // Returns the favicon for this tab, or IDR_DEFAULT_FAVICON if the tab does + // not have a favicon. The default implementation uses the current navigation + // entry. This will return an isNull bitmap if there are no navigation + // entries, which should rarely happen. + SkBitmap GetFavicon() const; + + // Returns true if we are not using the default favicon. + bool FaviconIsValid() const; + + // Returns whether the favicon should be displayed. If this returns false, no + // space is provided for the favicon, and the favicon is never displayed. + virtual bool ShouldDisplayFavicon(); + + // Saves the favicon for the current page. + void SaveFavicon(); + // Initiates loading an image from given |image_url|. Returns a download id // for caller to track the request. When download completes, |callback| is // called with the three params: the download_id, a boolean flag to indicate @@ -57,6 +72,12 @@ class FaviconTabHelper : public TabContentsObserver { private: // TabContentsObserver overrides. + virtual void NavigateToPendingEntry( + const GURL& url, + NavigationController::ReloadType reload_type) OVERRIDE; + virtual void DidNavigateMainFramePostCommit( + const NavigationController::LoadCommittedDetails& details, + const ViewHostMsg_FrameNavigate_Params& params) OVERRIDE; virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; void OnDidDownloadFavicon(int id, diff --git a/chrome/browser/prerender/prerender_manager.cc b/chrome/browser/prerender/prerender_manager.cc index 93fff74..c545f11 100644 --- a/chrome/browser/prerender/prerender_manager.cc +++ b/chrome/browser/prerender/prerender_manager.cc @@ -9,6 +9,7 @@ #include "base/metrics/histogram.h" #include "base/time.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/prerender/prerender_contents.h" #include "chrome/browser/prerender/prerender_final_status.h" #include "chrome/browser/profiles/profile.h" @@ -486,7 +487,10 @@ bool PrerenderManager::MaybeUsePreloadedPageOld(TabContents* tab_contents, if (!icon_url.is_empty()) { std::vector<FaviconURL> urls; urls.push_back(FaviconURL(icon_url, FaviconURL::FAVICON)); - tab_contents->favicon_helper().OnUpdateFaviconURL( + // TODO(avi): move prerendering to use TCWs; remove this. + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); + wrapper->favicon_tab_helper()->OnUpdateFaviconURL( prerender_contents->page_id(), urls); } diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc index 8e98c9d..9e7daf3 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager/task_manager_resource_providers.cc @@ -20,6 +20,7 @@ #include "chrome/browser/extensions/extension_host.h" #include "chrome/browser/extensions/extension_process_manager.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/notifications/balloon_collection.h" #include "chrome/browser/notifications/balloon_host.h" #include "chrome/browser/notifications/notification_ui_manager.h" @@ -205,7 +206,7 @@ string16 TaskManagerTabContentsResource::GetTitle() const { } SkBitmap TaskManagerTabContentsResource::GetIcon() const { - return tab_contents_->tab_contents()->GetFavicon(); + return tab_contents_->favicon_tab_helper()->GetFavicon(); } TabContentsWrapper* TaskManagerTabContentsResource::GetTabContents() const { diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index ed185a4..bc4bd8d 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -48,6 +48,7 @@ #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tab_helper.h" #include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_util.h" @@ -815,10 +816,10 @@ bool Browser::GetSavedMaximizedState() const { } SkBitmap Browser::GetCurrentPageIcon() const { - TabContents* contents = GetSelectedTabContents(); + TabContentsWrapper* contents = GetSelectedTabContentsWrapper(); // |contents| can be NULL since GetCurrentPageIcon() is called by the window // during the window's creation (before tabs have been added). - return contents ? contents->GetFavicon() : SkBitmap(); + return contents ? contents->favicon_tab_helper()->GetFavicon() : SkBitmap(); } string16 Browser::GetWindowTitleForCurrentTab() const { @@ -964,6 +965,7 @@ int Browser::GetIndexOfController( TabContentsWrapper* Browser::GetSelectedTabContentsWrapper() const { return tabstrip_model()->GetSelectedTabContents(); } + TabContentsWrapper* Browser::GetTabContentsWrapperAt(int index) const { return tabstrip_model()->GetTabContentsAt(index); } @@ -1591,13 +1593,13 @@ void Browser::BookmarkCurrentPage() { GURL url; string16 title; - TabContents* tab = GetSelectedTabContents(); - bookmark_utils::GetURLAndTitleToBookmark(tab, &url, &title); + TabContentsWrapper* tab = GetSelectedTabContentsWrapper(); + bookmark_utils::GetURLAndTitleToBookmark(tab->tab_contents(), &url, &title); bool was_bookmarked = model->IsBookmarked(url); if (!was_bookmarked && profile_->IsOffTheRecord()) { // If we're incognito the favicon may not have been saved. Save it now // so that bookmarks have an icon for the page. - tab->SaveFavicon(); + tab->favicon_tab_helper()->SaveFavicon(); } model->SetURLStarred(url, title, true); // Make sure the model actually added a bookmark before showing the star. A diff --git a/chrome/browser/ui/cocoa/hung_renderer_controller.mm b/chrome/browser/ui/cocoa/hung_renderer_controller.mm index 3334bfe..6be12ca 100644 --- a/chrome/browser/ui/cocoa/hung_renderer_controller.mm +++ b/chrome/browser/ui/cocoa/hung_renderer_controller.mm @@ -147,7 +147,7 @@ HungRendererController* g_instance = NULL; if (title.empty()) title = TabContentsWrapper::GetDefaultTitle(); [titles addObject:base::SysUTF16ToNSString(title)]; - [favicons addObject:mac::FaviconForTabContents(it->tab_contents())]; + [favicons addObject:mac::FaviconForTabContents(*it)]; } } hungTitles_.reset([titles copy]); diff --git a/chrome/browser/ui/cocoa/tab_contents/favicon_util.h b/chrome/browser/ui/cocoa/tab_contents/favicon_util.h index 051ef8c..2996745 100644 --- a/chrome/browser/ui/cocoa/tab_contents/favicon_util.h +++ b/chrome/browser/ui/cocoa/tab_contents/favicon_util.h @@ -6,14 +6,14 @@ #define CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_FAVICON_UTIL_H_ @class NSImage; -class TabContents; +class TabContentsWrapper; namespace mac { -// Returns an autoreleased favicon for a given TabContents. If |contents| is -// NULL or there's no favicon for the NavigationEntry, this will return the +// Returns an autoreleased favicon for a given TabContentsWrapper. If |contents| +// is NULL or there's no favicon for the NavigationEntry, this will return the // default image. -NSImage* FaviconForTabContents(TabContents* contents); +NSImage* FaviconForTabContents(TabContentsWrapper* contents); } // namespace mac diff --git a/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm b/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm index 3fcba52..580f9ca 100644 --- a/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm +++ b/chrome/browser/ui/cocoa/tab_contents/favicon_util.mm @@ -8,20 +8,20 @@ #include "app/mac/nsimage_cache.h" #include "base/mac/mac_util.h" -#include "content/browser/tab_contents/tab_contents.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "skia/ext/skia_utils_mac.h" namespace mac { -NSImage* FaviconForTabContents(TabContents* contents) { +NSImage* FaviconForTabContents(TabContentsWrapper* contents) { // TabContents returns IDR_DEFAULT_FAVICON, which is a rasterized version of // the Mac PDF. Use the PDF so the icon in the Omnibox matches the default // favicon. - if (contents && contents->FaviconIsValid()) { + if (contents && contents->favicon_tab_helper()->FaviconIsValid()) { CGColorSpaceRef color_space = base::mac::GetSystemColorSpace(); - NSImage* image = - gfx::SkBitmapToNSImageWithColorSpace(contents->GetFavicon(), - color_space); + NSImage* image = gfx::SkBitmapToNSImageWithColorSpace( + contents->favicon_tab_helper()->GetFavicon(), color_space); // The |image| could be nil if the bitmap is null. In that case, fallback // to the default image. if (image) { diff --git a/chrome/browser/ui/cocoa/tabpose_window.mm b/chrome/browser/ui/cocoa/tabpose_window.mm index bf9e8c3..a8ba03e1 100644 --- a/chrome/browser/ui/cocoa/tabpose_window.mm +++ b/chrome/browser/ui/cocoa/tabpose_window.mm @@ -505,7 +505,7 @@ NSImage* Tile::favicon() const { if (bitmap) return gfx::SkBitmapToNSImage(*bitmap); } - return mac::FaviconForTabContents(contents_->tab_contents()); + return mac::FaviconForTabContents(contents_); } NSRect Tile::GetTitleStartRectRelativeTo(const Tile& tile) const { diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm index 63b8e2a..958d98b 100644 --- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm +++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm @@ -17,19 +17,19 @@ #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/autocomplete/autocomplete_classifier.h" #include "chrome/browser/autocomplete/autocomplete_match.h" +#include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/extensions/extension_tab_helper.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" +#include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" -#include "chrome/browser/debugger/devtools_window.h" -#include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/sidebar/sidebar_container.h" #include "chrome/browser/sidebar/sidebar_manager.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/tabs/tab_strip_selection_model.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_navigator.h" -#include "chrome/browser/ui/find_bar/find_tab_helper.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/constrained_window_mac.h" #import "chrome/browser/ui/cocoa/image_button_cell.h" @@ -44,9 +44,10 @@ #import "chrome/browser/ui/cocoa/tracking_area.h" #include "chrome/browser/ui/find_bar/find_bar.h" #include "chrome/browser/ui/find_bar/find_bar_controller.h" -#include "chrome/browser/ui/title_prefix_matcher.h" +#include "chrome/browser/ui/find_bar/find_tab_helper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/tabs/tab_menu_model.h" +#include "chrome/browser/ui/title_prefix_matcher.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "content/browser/tab_contents/navigation_controller.h" @@ -155,7 +156,7 @@ private: - (void)addSubviewToPermanentList:(NSView*)aView; - (void)regenerateSubviewList; - (NSInteger)indexForContentsView:(NSView*)view; -- (void)updateFaviconForContents:(TabContents*)contents +- (void)updateFaviconForContents:(TabContentsWrapper*)contents atIndex:(NSInteger)modelIndex; - (void)layoutTabsWithAnimation:(BOOL)animate regenerateSubviews:(BOOL)doUpdate; @@ -1192,7 +1193,7 @@ class NotificationBridge : public NotificationObserver { // dragging a tab out into a new window, we have to put the tab's favicon // into the right state up front as we won't be told to do it from anywhere // else. - [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; + [self updateFaviconForContents:contents atIndex:modelIndex]; [self updateCommonTitlePrefix]; @@ -1407,16 +1408,14 @@ class NotificationBridge : public NotificationObserver { // A helper routine for creating an NSImageView to hold the favicon or app icon // for |contents|. -- (NSImageView*)iconImageViewForContents:(TabContents*)contents { - TabContentsWrapper* wrapper = - TabContentsWrapper::GetCurrentWrapperForContents(contents); - BOOL isApp = wrapper->extension_tab_helper()->is_app(); +- (NSImageView*)iconImageViewForContents:(TabContentsWrapper*)contents { + BOOL isApp = contents->extension_tab_helper()->is_app(); NSImage* image = nil; // Favicons come from the renderer, and the renderer draws everything in the // system color space. CGColorSpaceRef colorSpace = base::mac::GetSystemColorSpace(); if (isApp) { - SkBitmap* icon = wrapper->extension_tab_helper()->GetExtensionAppIcon(); + SkBitmap* icon = contents->extension_tab_helper()->GetExtensionAppIcon(); if (icon) image = gfx::SkBitmapToNSImageWithColorSpace(*icon, colorSpace); } else { @@ -1435,7 +1434,7 @@ class NotificationBridge : public NotificationObserver { // Updates the current loading state, replacing the icon view with a favicon, // a throbber, the default icon, or nothing at all. -- (void)updateFaviconForContents:(TabContents*)contents +- (void)updateFaviconForContents:(TabContentsWrapper*)contents atIndex:(NSInteger)modelIndex { if (!contents) return; @@ -1455,19 +1454,19 @@ class NotificationBridge : public NotificationObserver { TabController* tabController = [tabArray_ objectAtIndex:index]; bool oldHasIcon = [tabController iconView] != nil; - bool newHasIcon = contents->ShouldDisplayFavicon() || + bool newHasIcon = contents->favicon_tab_helper()->ShouldDisplayFavicon() || tabStripModel_->IsMiniTab(modelIndex); // Always show icon if mini. TabLoadingState oldState = [tabController loadingState]; TabLoadingState newState = kTabDone; NSImage* throbberImage = nil; - if (contents->is_crashed()) { + if (contents->tab_contents()->is_crashed()) { newState = kTabCrashed; newHasIcon = true; - } else if (contents->waiting_for_response()) { + } else if (contents->tab_contents()->waiting_for_response()) { newState = kTabWaiting; throbberImage = throbberWaitingImage; - } else if (contents->is_loading()) { + } else if (contents->tab_contents()->is_loading()) { newState = kTabLoading; throbberImage = throbberLoadingImage; } @@ -1527,7 +1526,7 @@ class NotificationBridge : public NotificationObserver { if (change != TabStripModelObserver::LOADING_ONLY) [self setTabTitle:tabController withContents:contents->tab_contents()]; - [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; + [self updateFaviconForContents:contents atIndex:modelIndex]; TabContentsController* updatedController = [tabContentsArray_ objectAtIndex:index]; @@ -1584,7 +1583,7 @@ class NotificationBridge : public NotificationObserver { [tabController setPinned:tabStripModel_->IsTabPinned(modelIndex)]; [tabController setApp:tabStripModel_->IsAppTab(modelIndex)]; [tabController setUrl:contents->tab_contents()->GetURL()]; - [self updateFaviconForContents:contents->tab_contents() atIndex:modelIndex]; + [self updateFaviconForContents:contents atIndex:modelIndex]; // If the tab is being restored and it's pinned, the mini state is set after // the tab has already been rendered, so re-layout the tabstrip. In all other // cases, the state is set before the tab is rendered so this isn't needed. diff --git a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc index b46dda6..43767c3 100644 --- a/chrome/browser/ui/content_settings/content_setting_bubble_model.cc +++ b/chrome/browser/ui/content_settings/content_setting_bubble_model.cc @@ -7,6 +7,7 @@ #include "base/command_line.h" #include "base/utf_string_conversions.h" #include "chrome/browser/content_settings/host_content_settings_map.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/geolocation/geolocation_content_settings_map.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" @@ -395,7 +396,7 @@ class ContentSettingPopupBubbleModel : public ContentSettingSingleRadioGroup { title = l10n_util::GetStringUTF8(IDS_TAB_LOADING_TITLE); PopupItem popup_item; popup_item.title = title; - popup_item.bitmap = (*i)->tab_contents()->GetFavicon(); + popup_item.bitmap = (*i)->favicon_tab_helper()->GetFavicon(); popup_item.tab_contents = (*i); add_popup(popup_item); } diff --git a/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc b/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc index 237d89c..aac3e5a 100644 --- a/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc +++ b/chrome/browser/ui/gtk/hung_renderer_dialog_gtk.cc @@ -8,6 +8,7 @@ #include "base/process_util.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/gtk/gtk_util.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -156,7 +157,7 @@ void HungRendererDialogGtk::ShowForTabContents(TabContents* hung_contents) { std::string title = UTF16ToUTF8(it->tab_contents()->GetTitle()); if (title.empty()) title = UTF16ToUTF8(TabContentsWrapper::GetDefaultTitle()); - SkBitmap favicon = it->tab_contents()->GetFavicon(); + SkBitmap favicon = it->favicon_tab_helper()->GetFavicon(); GdkPixbuf* pixbuf = NULL; if (favicon.width() > 0) diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk.cc b/chrome/browser/ui/gtk/location_bar_view_gtk.cc index 37d7411..65cafac 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk.cc @@ -22,6 +22,7 @@ #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_tabs_module.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" @@ -558,7 +559,7 @@ void LocationBarViewGtk::OnSetFocus() { } SkBitmap LocationBarViewGtk::GetFavicon() const { - return GetTabContents()->GetFavicon(); + return GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); } string16 LocationBarViewGtk::GetTitle() const { diff --git a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc index ebc60c8..9394154 100644 --- a/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/ui/gtk/tabs/tab_renderer_gtk.cc @@ -10,6 +10,7 @@ #include "base/utf_string_conversions.h" #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/extension_tab_helper.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/gtk/bookmarks/bookmark_utils_gtk.h" @@ -287,6 +288,8 @@ void TabRendererGtk::UpdateData(TabContents* contents, bool app, bool loading_only) { DCHECK(contents); + TabContentsWrapper* wrapper = + TabContentsWrapper::GetCurrentWrapperForContents(contents); theme_service_ = GtkThemeService::GetFrom(contents->profile()); if (!loading_only) { @@ -300,7 +303,7 @@ void TabRendererGtk::UpdateData(TabContents* contents, if (app_icon) data_.favicon = *app_icon; else - data_.favicon = contents->GetFavicon(); + data_.favicon = wrapper->favicon_tab_helper()->GetFavicon(); data_.app = app; // This is kind of a hacky way to determine whether our icon is the default @@ -317,7 +320,7 @@ void TabRendererGtk::UpdateData(TabContents* contents, // Loading state also involves whether we show the favicon, since that's where // we display the throbber. data_.loading = contents->is_loading(); - data_.show_icon = contents->ShouldDisplayFavicon(); + data_.show_icon = wrapper->favicon_tab_helper()->ShouldDisplayFavicon(); } void TabRendererGtk::UpdateFromModel() { diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc index 5da386f7..6f16c26 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.cc @@ -15,6 +15,7 @@ #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_delegate.h" #include "chrome/browser/extensions/extension_tab_helper.h" #include "chrome/browser/extensions/extension_webnavigation_api.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/file_select_helper.h" #include "chrome/browser/history/history.h" #include "chrome/browser/history/top_sites.h" @@ -71,6 +72,7 @@ TabContentsWrapper::TabContentsWrapper(TabContents* contents) blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this)); download_tab_helper_.reset(new DownloadTabHelper(contents)); extension_tab_helper_.reset(new ExtensionTabHelper(this)); + favicon_tab_helper_.reset(new FaviconTabHelper(contents)); find_tab_helper_.reset(new FindTabHelper(contents)); password_manager_delegate_.reset(new PasswordManagerDelegateImpl(contents)); password_manager_.reset( diff --git a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h index 46ae069..d34ea40 100644 --- a/chrome/browser/ui/tab_contents/tab_contents_wrapper.h +++ b/chrome/browser/ui/tab_contents/tab_contents_wrapper.h @@ -32,6 +32,7 @@ class DownloadTabHelper; class Extension; class ExtensionTabHelper; class ExtensionWebNavigationTabObserver; +class FaviconTabHelper; class FileSelectObserver; class FindTabHelper; class NavigationController; @@ -130,6 +131,8 @@ class TabContentsWrapper : public NotificationObserver, FindTabHelper* find_tab_helper() { return find_tab_helper_.get(); } + FaviconTabHelper* favicon_tab_helper() { return favicon_tab_helper_.get(); } + PasswordManager* password_manager() { return password_manager_.get(); } printing::PrintViewManager* print_view_manager() { @@ -196,7 +199,7 @@ class TabContentsWrapper : public NotificationObserver, bool is_starred_; // Shows an info-bar to users when they search from a known search engine and - // have never used the monibox for search before. + // have never used the omnibox for search before. scoped_ptr<OmniboxSearchHint> omnibox_search_hint_; // Tab Helpers --------------------------------------------------------------- @@ -209,6 +212,7 @@ class TabContentsWrapper : public NotificationObserver, scoped_ptr<BlockedContentTabHelper> blocked_content_tab_helper_; scoped_ptr<DownloadTabHelper> download_tab_helper_; scoped_ptr<ExtensionTabHelper> extension_tab_helper_; + scoped_ptr<FaviconTabHelper> favicon_tab_helper_; scoped_ptr<FindTabHelper> find_tab_helper_; // PasswordManager and its delegate. The delegate must outlive the manager, diff --git a/chrome/browser/ui/views/create_application_shortcut_view.cc b/chrome/browser/ui/views/create_application_shortcut_view.cc index ffee0fb..eef988f 100644 --- a/chrome/browser/ui/views/create_application_shortcut_view.cc +++ b/chrome/browser/ui/views/create_application_shortcut_view.cc @@ -8,6 +8,7 @@ #include "base/utf_string_conversions.h" #include "base/win/windows_version.h" #include "chrome/browser/extensions/extension_tab_helper.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/prefs/pref_service.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -453,7 +454,7 @@ void CreateUrlApplicationShortcutView::FetchIcon() { pending_download_ = new IconDownloadCallbackFunctor(this); DCHECK(pending_download_); - tab_contents_->tab_contents()->favicon_helper().DownloadImage( + tab_contents_->favicon_tab_helper()->DownloadImage( unprocessed_icons_.back().url, std::max(unprocessed_icons_.back().width, unprocessed_icons_.back().height), diff --git a/chrome/browser/ui/views/hung_renderer_view.cc b/chrome/browser/ui/views/hung_renderer_view.cc index 89db727..2db7e15 100644 --- a/chrome/browser/ui/views/hung_renderer_view.cc +++ b/chrome/browser/ui/views/hung_renderer_view.cc @@ -6,6 +6,7 @@ #include "base/i18n/rtl.h" #include "base/utf_string_conversions.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/common/chrome_constants.h" @@ -55,7 +56,7 @@ class HungPagesTableModel : public views::GroupTableModel { virtual void GetGroupRangeForItem(int item, views::GroupRange* range); private: - typedef std::vector<TabContents*> TabContentsVector; + typedef std::vector<TabContentsWrapper*> TabContentsVector; TabContentsVector tab_contentses_; ui::TableModelObserver* observer_; @@ -77,7 +78,7 @@ void HungPagesTableModel::InitForTabContents(TabContents* hung_contents) { for (TabContentsIterator it; !it.done(); ++it) { if (it->tab_contents()->GetRenderProcessHost() == hung_contents->GetRenderProcessHost()) - tab_contentses_.push_back((*it)->tab_contents()); + tab_contentses_.push_back(*it); } // The world is different. if (observer_) @@ -93,7 +94,7 @@ int HungPagesTableModel::RowCount() { string16 HungPagesTableModel::GetText(int row, int column_id) { DCHECK(row >= 0 && row < RowCount()); - string16 title = tab_contentses_[row]->GetTitle(); + string16 title = tab_contentses_[row]->tab_contents()->GetTitle(); if (title.empty()) title = TabContentsWrapper::GetDefaultTitle(); // TODO(xji): Consider adding a special case if the title text is a URL, @@ -105,7 +106,7 @@ string16 HungPagesTableModel::GetText(int row, int column_id) { SkBitmap HungPagesTableModel::GetIcon(int row) { DCHECK(row >= 0 && row < RowCount()); - return tab_contentses_.at(row)->GetFavicon(); + return tab_contentses_.at(row)->favicon_tab_helper()->GetFavicon(); } void HungPagesTableModel::SetObserver(ui::TableModelObserver* observer) { diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 90eaf29..31c680f 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -17,6 +17,7 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extension_service.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/search_engines/template_url.h" @@ -838,7 +839,7 @@ void LocationBarView::OnSetFocus() { } SkBitmap LocationBarView::GetFavicon() const { - return GetTabContentsFromDelegate(delegate_)->GetFavicon(); + return delegate_->GetTabContentsWrapper()->favicon_tab_helper()->GetFavicon(); } string16 LocationBarView::GetTitle() const { @@ -1040,11 +1041,13 @@ void LocationBarView::WriteDragDataForView(views::View* sender, DCHECK_NE(GetDragOperationsForView(sender, press_pt), ui::DragDropTypes::DRAG_NONE); - TabContents* tab_contents = GetTabContentsFromDelegate(delegate_); + TabContentsWrapper* tab_contents = delegate_->GetTabContentsWrapper(); DCHECK(tab_contents); - drag_utils::SetURLAndDragImage(tab_contents->GetURL(), - UTF16ToWideHack(tab_contents->GetTitle()), - tab_contents->GetFavicon(), data); + drag_utils::SetURLAndDragImage( + tab_contents->tab_contents()->GetURL(), + UTF16ToWideHack(tab_contents->tab_contents()->GetTitle()), + tab_contents->favicon_tab_helper()->GetFavicon(), + data); } int LocationBarView::GetDragOperationsForView(views::View* sender, diff --git a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc index f713844..b77e496 100644 --- a/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc +++ b/chrome/browser/ui/views/tabs/browser_tab_strip_controller.cc @@ -7,6 +7,7 @@ #include "base/auto_reset.h" #include "base/command_line.h" #include "chrome/browser/extensions/extension_tab_helper.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/ui/browser.h" @@ -417,14 +418,14 @@ void BrowserTabStripController::SetTabRendererDataFromModel( if (app_icon) data->favicon = *app_icon; else - data->favicon = contents->GetFavicon(); + data->favicon = wrapper->favicon_tab_helper()->GetFavicon(); data->network_state = TabContentsNetworkState(contents); data->title = contents->GetTitle(); data->url = contents->GetURL(); data->loading = contents->is_loading(); data->crashed_status = contents->crashed_status(); data->incognito = contents->profile()->IsOffTheRecord(); - data->show_icon = contents->ShouldDisplayFavicon(); + data->show_icon = wrapper->favicon_tab_helper()->ShouldDisplayFavicon(); data->mini = model_->IsMiniTab(model_index); data->blocked = model_->IsTabBlocked(model_index); data->app = wrapper->extension_tab_helper()->is_app(); diff --git a/chrome/browser/ui/web_applications/web_app_ui.cc b/chrome/browser/ui/web_applications/web_app_ui.cc index 746679d..b125963 100644 --- a/chrome/browser/ui/web_applications/web_app_ui.cc +++ b/chrome/browser/ui/web_applications/web_app_ui.cc @@ -9,6 +9,7 @@ #include "base/task.h" #include "base/win/windows_version.h" #include "chrome/browser/extensions/extension_tab_helper.h" +#include "chrome/browser/favicon/favicon_tab_helper.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" @@ -133,7 +134,7 @@ void UpdateShortcutWorker::DownloadIcon() { return; } - tab_contents_->tab_contents()->favicon_helper().DownloadImage( + tab_contents_->favicon_tab_helper()->DownloadImage( unprocessed_icons_.back().url, std::max(unprocessed_icons_.back().width, unprocessed_icons_.back().height), @@ -304,7 +305,7 @@ void GetShortcutInfoForTab(TabContentsWrapper* tab_contents_wrapper, tab_contents->GetTitle()) : app_info.title; info->description = app_info.description; - info->favicon = tab_contents->GetFavicon(); + info->favicon = tab_contents_wrapper->favicon_tab_helper()->GetFavicon(); } void UpdateShortcutForTabContents(TabContentsWrapper* tab_contents) { diff --git a/chrome/browser/ui/webui/web_ui_unittest.cc b/chrome/browser/ui/webui/web_ui_unittest.cc new file mode 100644 index 0000000..0d4543c --- /dev/null +++ b/chrome/browser/ui/webui/web_ui_unittest.cc @@ -0,0 +1,200 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/favicon/favicon_tab_helper.h" +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" +#include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" +#include "chrome/common/url_constants.h" +#include "chrome/test/testing_profile.h" +#include "content/browser/browser_thread.h" +#include "content/browser/site_instance.h" +#include "content/browser/tab_contents/navigation_controller.h" +#include "content/browser/tab_contents/test_tab_contents.h" +#include "testing/gtest/include/gtest/gtest.h" + +class WebUITest : public TabContentsWrapperTestHarness { + public: + WebUITest() : ui_thread_(BrowserThread::UI, MessageLoop::current()) {} + + // Tests navigating with a Web UI from a fresh (nothing pending or committed) + // state, through pending, committed, then another navigation. The first page + // ID that we should use is passed as a parameter. We'll use the next two + // values. This must be increasing for the life of the tests. + static void DoNavigationTest(TabContentsWrapper* wrapper, int page_id) { + TabContents* contents = wrapper->tab_contents(); + NavigationController* controller = &contents->controller(); + + // Start a pending load. + GURL new_tab_url(chrome::kChromeUINewTabURL); + controller->LoadURL(new_tab_url, GURL(), PageTransition::LINK); + + // The navigation entry should be pending with no committed entry. + ASSERT_TRUE(controller->pending_entry()); + ASSERT_FALSE(controller->GetLastCommittedEntry()); + + // Check the things the pending Web UI should have set. + EXPECT_FALSE(contents->ShouldDisplayURL()); + EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_TRUE(contents->ShouldShowBookmarkBar()); + EXPECT_TRUE(contents->FocusLocationBarByDefault()); + + // Now commit the load. + static_cast<TestRenderViewHost*>( + contents->render_view_host())->SendNavigate(page_id, new_tab_url); + + // The same flags should be set as before now that the load has committed. + EXPECT_FALSE(contents->ShouldDisplayURL()); + EXPECT_FALSE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_TRUE(contents->ShouldShowBookmarkBar()); + EXPECT_TRUE(contents->FocusLocationBarByDefault()); + + // Start a pending navigation to a regular page. + GURL next_url("http://google.com/"); + controller->LoadURL(next_url, GURL(), PageTransition::LINK); + + // Check the flags. Some should reflect the new page (URL, title), some + // should reflect the old one (bookmark bar) until it has committed. + EXPECT_TRUE(contents->ShouldDisplayURL()); + EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_TRUE(contents->ShouldShowBookmarkBar()); + EXPECT_FALSE(contents->FocusLocationBarByDefault()); + + // Commit the regular page load. Note that we must send it to the "pending" + // RenderViewHost if there is one, since this transition will also cause a + // process transition, and our RVH pointer will be the "committed" one. + // In the second call to this function from WebUIToStandard, it won't + // actually be pending, which is the point of this test. + if (contents->render_manager()->pending_render_view_host()) { + static_cast<TestRenderViewHost*>( + contents->render_manager()->pending_render_view_host())->SendNavigate( + page_id + 1, next_url); + } else { + static_cast<TestRenderViewHost*>( + contents->render_view_host())->SendNavigate(page_id + 1, next_url); + } + + // The state should now reflect a regular page. + EXPECT_TRUE(contents->ShouldDisplayURL()); + EXPECT_TRUE(wrapper->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_FALSE(contents->ShouldShowBookmarkBar()); + EXPECT_FALSE(contents->FocusLocationBarByDefault()); + } + + private: + BrowserThread ui_thread_; + + DISALLOW_COPY_AND_ASSIGN(WebUITest); +}; + +// Tests that the New Tab Page flags are correctly set and propogated by +// TabContents when we first navigate to a Web UI page, then to a standard +// non-DOM-UI page. +TEST_F(WebUITest, WebUIToStandard) { + DoNavigationTest(contents_wrapper(), 1); + + // Test the case where we're not doing the initial navigation. This is + // slightly different than the very-first-navigation case since the + // SiteInstance will be the same (the original TabContents must still be + // alive), which will trigger different behavior in RenderViewHostManager. + TestTabContents* contents2 = new TestTabContents(profile_.get(), NULL); + TabContentsWrapper wrapper2(contents2); + + DoNavigationTest(&wrapper2, 101); +} + +TEST_F(WebUITest, WebUIToWebUI) { + // Do a load (this state is tested above). + GURL new_tab_url(chrome::kChromeUINewTabURL); + controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); + rvh()->SendNavigate(1, new_tab_url); + + // Start another pending load of the new tab page. + controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); + rvh()->SendNavigate(2, new_tab_url); + + // The flags should be the same as the non-pending state. + EXPECT_FALSE(contents()->ShouldDisplayURL()); + EXPECT_FALSE( + contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_TRUE(contents()->ShouldShowBookmarkBar()); + EXPECT_TRUE(contents()->FocusLocationBarByDefault()); +} + +TEST_F(WebUITest, StandardToWebUI) { + // Start a pending navigation to a regular page. + GURL std_url("http://google.com/"); + + controller().LoadURL(std_url, GURL(), PageTransition::LINK); + + // The state should now reflect the default. + EXPECT_TRUE(contents()->ShouldDisplayURL()); + EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); + EXPECT_FALSE(contents()->FocusLocationBarByDefault()); + + // Commit the load, the state should be the same. + rvh()->SendNavigate(1, std_url); + EXPECT_TRUE(contents()->ShouldDisplayURL()); + EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); + EXPECT_FALSE(contents()->FocusLocationBarByDefault()); + + // Start a pending load for a WebUI. + GURL new_tab_url(chrome::kChromeUINewTabURL); + controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); + EXPECT_FALSE(contents()->ShouldDisplayURL()); + EXPECT_TRUE(contents_wrapper()->favicon_tab_helper()->ShouldDisplayFavicon()); + EXPECT_FALSE(contents()->ShouldShowBookmarkBar()); + EXPECT_TRUE(contents()->FocusLocationBarByDefault()); + + // Committing Web UI is tested above. +} + +class TabContentsForFocusTest : public TestTabContents { + public: + TabContentsForFocusTest(Profile* profile, SiteInstance* instance) + : TestTabContents(profile, instance), focus_called_(0) { + } + + virtual void SetFocusToLocationBar(bool select_all) { ++focus_called_; } + int focus_called() const { return focus_called_; } + + private: + int focus_called_; +}; + +TEST_F(WebUITest, FocusOnNavigate) { + // Setup. |tc| will be used to track when we try to focus the location bar. + TabContentsForFocusTest* tc = new TabContentsForFocusTest( + contents()->profile(), + SiteInstance::CreateSiteInstance(contents()->profile())); + tc->controller().CopyStateFrom(controller()); + SetContents(tc); + int page_id = 200; + + // Load the NTP. + GURL new_tab_url(chrome::kChromeUINewTabURL); + controller().LoadURL(new_tab_url, GURL(), PageTransition::LINK); + rvh()->SendNavigate(page_id, new_tab_url); + + // Navigate to another page. + GURL next_url("http://google.com/"); + int next_page_id = page_id + 1; + controller().LoadURL(next_url, GURL(), PageTransition::LINK); + pending_rvh()->SendNavigate(next_page_id, next_url); + + // Navigate back. Should focus the location bar. + int focus_called = tc->focus_called(); + ASSERT_TRUE(controller().CanGoBack()); + controller().GoBack(); + pending_rvh()->SendNavigate(page_id, new_tab_url); + EXPECT_LT(focus_called, tc->focus_called()); + + // Navigate forward. Shouldn't focus the location bar. + focus_called = tc->focus_called(); + ASSERT_TRUE(controller().CanGoForward()); + controller().GoForward(); + pending_rvh()->SendNavigate(next_page_id, next_url); + EXPECT_EQ(focus_called, tc->focus_called()); +} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index d97d2d74..bb20efa 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1776,6 +1776,7 @@ 'browser/ui/webui/print_preview_ui_html_source_unittest.cc', 'browser/ui/webui/sync_internals_ui_unittest.cc', 'browser/ui/webui/theme_source_unittest.cc', + 'browser/ui/webui/web_ui_unittest.cc', 'browser/ui/window_sizer_unittest.cc', 'browser/ui/window_snapshot/window_snapshot_mac_unittest.mm', 'browser/user_style_sheet_watcher_unittest.cc', @@ -1898,7 +1899,6 @@ '../content/browser/tab_contents/navigation_controller_unittest.cc', '../content/browser/tab_contents/navigation_entry_unittest.cc', '../content/browser/tab_contents/render_view_host_manager_unittest.cc', - '../content/browser/webui/web_ui_unittest.cc', '../content/common/font_descriptor_mac_unittest.mm', '../content/common/gpu/gpu_feature_flags_unittest.cc', '../content/common/gpu/gpu_info_unittest.cc', |