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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « components/favicon/ios/web_favicon_driver.h ('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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/favicon/ios/web_favicon_driver.h"
6
7 #include "base/bind.h"
8 #include "components/favicon/core/favicon_url.h"
9 #include "components/favicon/ios/favicon_url_util.h"
10 #include "ios/web/public/browser_state.h"
11 #include "ios/web/public/favicon_status.h"
12 #include "ios/web/public/navigation_item.h"
13 #include "ios/web/public/navigation_manager.h"
14 #include "ios/web/public/web_state/web_state.h"
15 #include "ui/gfx/image/image.h"
16
17 DEFINE_WEB_STATE_USER_DATA_KEY(favicon::WebFaviconDriver);
18
19 namespace favicon {
20
21 // static
22 void WebFaviconDriver::CreateForWebState(
23 web::WebState* web_state,
24 FaviconService* favicon_service,
25 history::HistoryService* history_service,
26 bookmarks::BookmarkModel* bookmark_model) {
27 if (FromWebState(web_state))
28 return;
29
30 web_state->SetUserData(UserDataKey(),
31 new WebFaviconDriver(web_state, favicon_service,
32 history_service, bookmark_model));
33 }
34
35 gfx::Image WebFaviconDriver::GetFavicon() const {
36 web::NavigationItem* item =
37 web_state()->GetNavigationManager()->GetLastCommittedItem();
38 return item ? item->GetFavicon().image : gfx::Image();
39 }
40
41 bool WebFaviconDriver::FaviconIsValid() const {
42 web::NavigationItem* item =
43 web_state()->GetNavigationManager()->GetLastCommittedItem();
44 return item ? item->GetFavicon().valid : false;
45 }
46
47 int WebFaviconDriver::StartDownload(const GURL& url, int max_image_size) {
48 if (WasUnableToDownloadFavicon(url)) {
49 DVLOG(1) << "Skip Failed FavIcon: " << url;
50 return 0;
51 }
52
53 return web_state()->DownloadImage(
54 url, true, max_image_size, false,
55 base::Bind(&FaviconDriverImpl::DidDownloadFavicon,
56 base::Unretained(this)));
57 }
58
59 bool WebFaviconDriver::IsOffTheRecord() {
60 DCHECK(web_state());
61 return web_state()->GetBrowserState()->IsOffTheRecord();
62 }
63
64 GURL WebFaviconDriver::GetActiveURL() {
65 web::NavigationItem* item =
66 web_state()->GetNavigationManager()->GetVisibleItem();
67 return item ? item->GetURL() : GURL();
68 }
69
70 base::string16 WebFaviconDriver::GetActiveTitle() {
71 web::NavigationItem* item =
72 web_state()->GetNavigationManager()->GetVisibleItem();
73 return item ? item->GetTitle() : base::string16();
74 }
75
76 bool WebFaviconDriver::GetActiveFaviconValidity() {
77 return GetFaviconStatus().valid;
78 }
79
80 void WebFaviconDriver::SetActiveFaviconValidity(bool validity) {
81 GetFaviconStatus().valid = validity;
82 }
83
84 GURL WebFaviconDriver::GetActiveFaviconURL() {
85 return GetFaviconStatus().url;
86 }
87
88 void WebFaviconDriver::SetActiveFaviconURL(const GURL& url) {
89 GetFaviconStatus().url = url;
90 }
91
92 gfx::Image WebFaviconDriver::GetActiveFaviconImage() {
93 return GetFaviconStatus().image;
94 }
95
96 void WebFaviconDriver::SetActiveFaviconImage(const gfx::Image& image) {
97 GetFaviconStatus().image = image;
98 }
99
100 web::FaviconStatus& WebFaviconDriver::GetFaviconStatus() {
101 DCHECK(web_state()->GetNavigationManager()->GetVisibleItem());
102 return web_state()->GetNavigationManager()->GetVisibleItem()->GetFavicon();
103 }
104
105 WebFaviconDriver::WebFaviconDriver(web::WebState* web_state,
106 FaviconService* favicon_service,
107 history::HistoryService* history_service,
108 bookmarks::BookmarkModel* bookmark_model)
109 : web::WebStateObserver(web_state),
110 FaviconDriverImpl(favicon_service, history_service, bookmark_model) {
111 }
112
113 WebFaviconDriver::~WebFaviconDriver() {
114 }
115
116 void WebFaviconDriver::FaviconURLUpdated(
117 const std::vector<web::FaviconURL>& candidates) {
118 DCHECK(!candidates.empty());
119 OnUpdateFaviconURL(FaviconURLsFromWebFaviconURLs(candidates));
120 }
121
122 } // namespace favicon
OLDNEW
« 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