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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/web/web_state/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <WebKit/WebKit.h> 7 #import <WebKit/WebKit.h>
8 8
9 #import <objc/runtime.h> 9 #import <objc/runtime.h>
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 2524 matching lines...) Expand 10 before | Expand all | Expand 10 after
2535 } 2535 }
2536 2536
2537 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message 2537 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message
2538 context:(NSDictionary*)context { 2538 context:(NSDictionary*)context {
2539 base::ListValue* favicons = nullptr; 2539 base::ListValue* favicons = nullptr;
2540 if (!message->GetList("favicons", &favicons)) { 2540 if (!message->GetList("favicons", &favicons)) {
2541 DLOG(WARNING) << "JS message parameter not found: favicons"; 2541 DLOG(WARNING) << "JS message parameter not found: favicons";
2542 return NO; 2542 return NO;
2543 } 2543 }
2544 std::vector<web::FaviconURL> urls; 2544 std::vector<web::FaviconURL> urls;
2545 BOOL hasFavicon = NO;
2545 for (size_t fav_idx = 0; fav_idx != favicons->GetSize(); ++fav_idx) { 2546 for (size_t fav_idx = 0; fav_idx != favicons->GetSize(); ++fav_idx) {
2546 base::DictionaryValue* favicon = nullptr; 2547 base::DictionaryValue* favicon = nullptr;
2547 if (!favicons->GetDictionary(fav_idx, &favicon)) 2548 if (!favicons->GetDictionary(fav_idx, &favicon))
2548 return NO; 2549 return NO;
2549 std::string href; 2550 std::string href;
2550 std::string rel; 2551 std::string rel;
2551 if (!favicon->GetString("href", &href)) { 2552 if (!favicon->GetString("href", &href)) {
2552 DLOG(WARNING) << "JS message parameter not found: href"; 2553 DLOG(WARNING) << "JS message parameter not found: href";
2553 return NO; 2554 return NO;
2554 } 2555 }
2555 if (!favicon->GetString("rel", &rel)) { 2556 if (!favicon->GetString("rel", &rel)) {
2556 DLOG(WARNING) << "JS message parameter not found: rel"; 2557 DLOG(WARNING) << "JS message parameter not found: rel";
2557 return NO; 2558 return NO;
2558 } 2559 }
2560 BOOL isAppleTouch = YES;
2559 web::FaviconURL::IconType icon_type = web::FaviconURL::FAVICON; 2561 web::FaviconURL::IconType icon_type = web::FaviconURL::FAVICON;
2560 if (rel == "apple-touch-icon") 2562 if (rel == "apple-touch-icon")
2561 icon_type = web::FaviconURL::TOUCH_ICON; 2563 icon_type = web::FaviconURL::TOUCH_ICON;
2562 else if (rel == "apple-touch-icon-precomposed") 2564 else if (rel == "apple-touch-icon-precomposed")
2563 icon_type = web::FaviconURL::TOUCH_PRECOMPOSED_ICON; 2565 icon_type = web::FaviconURL::TOUCH_PRECOMPOSED_ICON;
2564 urls.push_back( 2566 else
2565 web::FaviconURL(GURL(href), icon_type, std::vector<gfx::Size>())); 2567 isAppleTouch = NO;
2568 GURL url = GURL(href);
2569 if (url.is_valid()) {
2570 urls.push_back(web::FaviconURL(url, icon_type, std::vector<gfx::Size>()));
2571 hasFavicon = hasFavicon || !isAppleTouch;
2572 }
2573 }
2574 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.
2575 id origin = context[kOriginURLKey];
2576 if (origin) {
2577 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.
2578 if ([originURL.scheme isEqualToString:@"http"] ||
2579 [originURL.scheme isEqualToString:@"https"]) {
2580 NSURLComponents* URLComponents = [[NSURLComponents alloc] init];
2581 URLComponents.scheme = originURL.scheme;
2582 URLComponents.host = originURL.host;
2583 URLComponents.path = @"/favicon.ico";
2584 NSURL* defaultFaviconURL = URLComponents.URL;
2585 urls.push_back(web::FaviconURL(net::GURLWithNSURL(defaultFaviconURL),
2586 web::FaviconURL::FAVICON,
2587 std::vector<gfx::Size>()));
2588 }
2589 }
2566 } 2590 }
2567 if (!urls.empty()) 2591 if (!urls.empty())
2568 _webStateImpl->OnFaviconUrlUpdated(urls); 2592 _webStateImpl->OnFaviconUrlUpdated(urls);
2569 return YES; 2593 return YES;
2570 } 2594 }
2571 2595
2572 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message 2596 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message
2573 context:(NSDictionary*)context { 2597 context:(NSDictionary*)context {
2574 std::string href; 2598 std::string href;
2575 if (!message->GetString("href", &href)) { 2599 if (!message->GetString("href", &href)) {
(...skipping 2588 matching lines...) Expand 10 before | Expand all | Expand 10 after
5164 - (NSUInteger)observerCount { 5188 - (NSUInteger)observerCount {
5165 DCHECK_EQ(_observerBridges.size(), [_observers count]); 5189 DCHECK_EQ(_observerBridges.size(), [_observers count]);
5166 return [_observers count]; 5190 return [_observers count];
5167 } 5191 }
5168 5192
5169 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { 5193 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action {
5170 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; 5194 return [action.request valueForHTTPHeaderField:kReferrerHeaderName];
5171 } 5195 }
5172 5196
5173 @end 5197 @end
OLDNEW
« 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