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

Unified Diff: components/favicon/ios/web_favicon_driver.cc

Issue 1064823002: Componentize FaviconTabHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@favicon-notification
Patch Set: Fix BUILD.gn Created 5 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 | « components/favicon/ios/web_favicon_driver.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/favicon/ios/web_favicon_driver.cc
diff --git a/components/favicon/ios/web_favicon_driver.cc b/components/favicon/ios/web_favicon_driver.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b4eaac7cfc30c24c6013d5b3d5c7ec3c17c0418b
--- /dev/null
+++ b/components/favicon/ios/web_favicon_driver.cc
@@ -0,0 +1,122 @@
+// Copyright 2015 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 "components/favicon/ios/web_favicon_driver.h"
+
+#include "base/bind.h"
+#include "components/favicon/core/favicon_url.h"
+#include "components/favicon/ios/favicon_url_util.h"
+#include "ios/web/public/browser_state.h"
+#include "ios/web/public/favicon_status.h"
+#include "ios/web/public/navigation_item.h"
+#include "ios/web/public/navigation_manager.h"
+#include "ios/web/public/web_state/web_state.h"
+#include "ui/gfx/image/image.h"
+
+DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver);
+
+namespace favicon {
+
+// static
+void WebFaviconDriver::CreateForWebState(
+ web::WebState* web_state,
+ FaviconService* favicon_service,
+ history::HistoryService* history_service,
+ bookmarks::BookmarkModel* bookmark_model) {
+ if (FromWebState(web_state))
+ return;
+
+ web_state->SetUserData(UserDataKey(),
+ new WebFaviconDriver(web_state, favicon_service,
+ history_service, bookmark_model));
+}
+
+gfx::Image WebFaviconDriver::GetFavicon() const {
+ web::NavigationItem* item =
+ web_state()->GetNavigationManager()->GetLastCommittedItem();
+ return item ? item->GetFavicon().image : gfx::Image();
+}
+
+bool WebFaviconDriver::FaviconIsValid() const {
+ web::NavigationItem* item =
+ web_state()->GetNavigationManager()->GetLastCommittedItem();
+ return item ? item->GetFavicon().valid : false;
+}
+
+int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) {
+ if (WasUnableToDownloadFavicon(url)) {
+ DVLOG(1) << "Skip Failed FavIcon: " << url;
+ return 0;
+ }
+
+ return web_state()->DownloadImage(
+ url, true, max_image_size, false,
+ base::Bind(&FaviconDriverImpl::DidDownloadFavicon,
+ base::Unretained(this)));
+}
+
+bool WebFaviconDriver::IsOffTheRecord() {
+ DCHECK(web_state());
+ return web_state()->GetBrowserState()->IsOffTheRecord();
+}
+
+GURL WebFaviconDriver::GetActiveURL() {
+ web::NavigationItem* item =
+ web_state()->GetNavigationManager()->GetVisibleItem();
+ return item ? item->GetURL() : GURL();
+}
+
+base::string16 WebFaviconDriver::GetActiveTitle() {
+ web::NavigationItem* item =
+ web_state()->GetNavigationManager()->GetVisibleItem();
+ return item ? item->GetTitle() : base::string16();
+}
+
+bool WebFaviconDriver::GetActiveFaviconValidity() {
+ return GetFaviconStatus().valid;
+}
+
+void WebFaviconDriver::SetActiveFaviconValidity(bool validity) {
+ GetFaviconStatus().valid = validity;
+}
+
+GURL WebFaviconDriver::GetActiveFaviconURL() {
+ return GetFaviconStatus().url;
+}
+
+void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) {
+ GetFaviconStatus().url = url;
+}
+
+gfx::Image WebFaviconDriver::GetActiveFaviconImage() {
+ return GetFaviconStatus().image;
+}
+
+void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) {
+ GetFaviconStatus().image = image;
+}
+
+web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() {
+ DCHECK(web_state()->GetNavigationManager()->GetVisibleItem());
+ return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon();
+}
+
+WebFaviconDriver::WebFaviconDriver(web::WebState* web_state,
+ FaviconService* favicon_service,
+ history::HistoryService* history_service,
+ bookmarks::BookmarkModel* bookmark_model)
+ : web::WebStateObserver(web_state),
+ FaviconDriverImpl(favicon_service, history_service, bookmark_model) {
+}
+
+WebFaviconDriver::~WebFaviconDriver() {
+}
+
+void WebFaviconDriver::FaviconURLUpdated(
+ const std::vector<web::FaviconURL>& candidates) {
+ DCHECK(!candidates.empty());
+ OnUpdateFaviconURL(FaviconURLsFromWebFaviconURLs(candidates));
+}
+
+} // namespace favicon
« no previous file with comments | « components/favicon/ios/web_favicon_driver.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698