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

Unified Diff: content/browser/tab_contents/tab_contents.cc

Issue 6814029: Revert 80519 - Move favicon from TabContents to TabContentsWrapper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/tab_contents/tab_contents.h ('k') | content/browser/tab_contents/tab_contents_observer.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/tab_contents/tab_contents.cc
===================================================================
--- content/browser/tab_contents/tab_contents.cc (revision 80859)
+++ content/browser/tab_contents/tab_contents.cc (working copy)
@@ -28,6 +28,7 @@
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/download/download_request_limiter.h"
#include "chrome/browser/external_protocol_handler.h"
+#include "chrome/browser/favicon_service.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/history/history.h"
#include "chrome/browser/history/history_types.h"
@@ -370,6 +371,7 @@
}
void TabContents::AddObservers() {
+ favicon_helper_.reset(new FaviconHelper(this));
desktop_notification_handler_.reset(
new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
plugin_observer_.reset(new PluginObserver(this));
@@ -513,6 +515,42 @@
return true;
}
+SkBitmap TabContents::GetFavicon() const {
+ // Like GetTitle(), we also want to use the favicon for the last committed
+ // entry rather than a pending navigation entry.
+ NavigationEntry* entry = controller_.GetTransientEntry();
+ if (entry)
+ return entry->favicon().bitmap();
+
+ entry = controller_.GetLastCommittedEntry();
+ if (entry)
+ return entry->favicon().bitmap();
+ return SkBitmap();
+}
+
+bool TabContents::FaviconIsValid() const {
+ NavigationEntry* entry = controller_.GetTransientEntry();
+ if (entry)
+ return entry->favicon().is_valid();
+
+ entry = controller_.GetLastCommittedEntry();
+ if (entry)
+ return entry->favicon().is_valid();
+
+ return false;
+}
+
+bool TabContents::ShouldDisplayFavicon() {
+ // Always display a throbber during pending loads.
+ if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
+ return true;
+
+ WebUI* web_ui = GetWebUIForCurrentState();
+ if (web_ui)
+ return !web_ui->hide_favicon();
+ return true;
+}
+
void TabContents::AddObserver(TabContentsObserver* observer) {
observers_.AddObserver(observer);
}
@@ -664,9 +702,16 @@
}
// Notify observers about navigation.
- FOR_EACH_OBSERVER(TabContentsObserver, observers_,
- NavigateToPendingEntry(entry.url(), reload_type));
+ FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
+ if (reload_type != NavigationController::NO_RELOAD &&
+ !profile()->IsOffTheRecord()) {
+ FaviconService* favicon_service =
+ profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
+ if (favicon_service)
+ favicon_service->SetFaviconOutOfDateForPage(entry.url());
+ }
+
return true;
}
@@ -699,6 +744,34 @@
delegate_->ShowPageInfo(profile(), url, ssl, show_history);
}
+void TabContents::SaveFavicon() {
+ NavigationEntry* entry = controller_.GetActiveEntry();
+ if (!entry || entry->url().is_empty())
+ return;
+
+ // Make sure the page is in history, otherwise adding the favicon does
+ // nothing.
+ HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
+ Profile::IMPLICIT_ACCESS);
+ if (!history)
+ return;
+ history->AddPageNoVisitForBookmark(entry->url());
+
+ FaviconService* service = 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);
+}
+
ConstrainedWindow* TabContents::CreateConstrainedDialog(
ConstrainedWindowDelegate* delegate) {
ConstrainedWindow* window =
@@ -1488,6 +1561,9 @@
// Allow the new page to set the title again.
received_page_title_ = false;
+ // Get the favicon, either from history or request it from the net.
+ favicon_helper_->FetchFavicon(details.entry->url());
+
// Clear all page actions, blocked content notifications and browser actions
// for this tab, unless this is an in-page navigation.
if (!details.is_in_page) {
« no previous file with comments | « content/browser/tab_contents/tab_contents.h ('k') | content/browser/tab_contents/tab_contents_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698