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

Unified Diff: ios/web/web_state/ui/crw_web_controller.mm

Issue 2880723002: Favicon url is used only if it is valid (Closed)
Patch Set: Add the default favicon in native code Created 3 years, 7 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
Index: ios/web/web_state/ui/crw_web_controller.mm
diff --git a/ios/web/web_state/ui/crw_web_controller.mm b/ios/web/web_state/ui/crw_web_controller.mm
index 8b17115ffff239e137ea52f7dc8c6d7228fe2a37..21150c262e09b218e31b8d7db9fa98a370238de7 100644
--- a/ios/web/web_state/ui/crw_web_controller.mm
+++ b/ios/web/web_state/ui/crw_web_controller.mm
@@ -2542,6 +2542,7 @@ registerLoadRequestForURL:(const GURL&)requestURL
return NO;
}
std::vector<web::FaviconURL> urls;
+ BOOL hasFavicon = NO;
for (size_t fav_idx = 0; fav_idx != favicons->GetSize(); ++fav_idx) {
base::DictionaryValue* favicon = nullptr;
if (!favicons->GetDictionary(fav_idx, &favicon))
@@ -2556,13 +2557,36 @@ registerLoadRequestForURL:(const GURL&)requestURL
DLOG(WARNING) << "JS message parameter not found: rel";
return NO;
}
+ BOOL isAppleTouch = YES;
web::FaviconURL::IconType icon_type = web::FaviconURL::FAVICON;
if (rel == "apple-touch-icon")
icon_type = web::FaviconURL::TOUCH_ICON;
else if (rel == "apple-touch-icon-precomposed")
icon_type = web::FaviconURL::TOUCH_PRECOMPOSED_ICON;
- urls.push_back(
- web::FaviconURL(GURL(href), icon_type, std::vector<gfx::Size>()));
+ else
+ isAppleTouch = NO;
+ GURL url = GURL(href);
+ if (url.is_valid()) {
+ urls.push_back(web::FaviconURL(url, icon_type, std::vector<gfx::Size>()));
+ hasFavicon = hasFavicon || !isAppleTouch;
+ }
+ }
+ if (!hasFavicon) {
Eugene But (OOO till 7-30) 2017/05/17 14:18:19 Do you need this variable? Do you want to use |if
gambard 2017/05/17 16:05:37 The javascript code added the default favicon only
Eugene But (OOO till 7-30) 2017/05/17 18:30:18 Thanks for explanation. Could you please specify t
gambard 2017/05/18 07:20:56 Done.
+ id origin = context[kOriginURLKey];
+ if (origin) {
+ NSURL* originURL = base::mac::ObjCCastStrict<NSURL>(origin);
Eugene But (OOO till 7-30) 2017/05/17 14:18:19 Could you please convert this to GURL and use GURL
Eugene But (OOO till 7-30) 2017/05/17 14:18:19 Do you want to move comments from JS which explain
gambard 2017/05/17 16:05:37 Done.
gambard 2017/05/17 16:05:37 Done.
+ if ([originURL.scheme isEqualToString:@"http"] ||
+ [originURL.scheme isEqualToString:@"https"]) {
+ NSURLComponents* URLComponents = [[NSURLComponents alloc] init];
+ URLComponents.scheme = originURL.scheme;
+ URLComponents.host = originURL.host;
+ URLComponents.path = @"/favicon.ico";
+ NSURL* defaultFaviconURL = URLComponents.URL;
+ urls.push_back(web::FaviconURL(net::GURLWithNSURL(defaultFaviconURL),
+ web::FaviconURL::FAVICON,
+ std::vector<gfx::Size>()));
+ }
+ }
}
if (!urls.empty())
_webStateImpl->OnFaviconUrlUpdated(urls);
« ios/web/web_state/favicon_callbacks_inttest.mm ('K') | « ios/web/web_state/js/resources/common.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698