| OLD | NEW |
| 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 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2534 } | 2534 } |
| 2535 | 2535 |
| 2536 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message | 2536 - (BOOL)handleDocumentFaviconsMessage:(base::DictionaryValue*)message |
| 2537 context:(NSDictionary*)context { | 2537 context:(NSDictionary*)context { |
| 2538 base::ListValue* favicons = nullptr; | 2538 base::ListValue* favicons = nullptr; |
| 2539 if (!message->GetList("favicons", &favicons)) { | 2539 if (!message->GetList("favicons", &favicons)) { |
| 2540 DLOG(WARNING) << "JS message parameter not found: favicons"; | 2540 DLOG(WARNING) << "JS message parameter not found: favicons"; |
| 2541 return NO; | 2541 return NO; |
| 2542 } | 2542 } |
| 2543 std::vector<web::FaviconURL> urls; | 2543 std::vector<web::FaviconURL> urls; |
| 2544 BOOL hasFavicon = NO; |
| 2544 for (size_t fav_idx = 0; fav_idx != favicons->GetSize(); ++fav_idx) { | 2545 for (size_t fav_idx = 0; fav_idx != favicons->GetSize(); ++fav_idx) { |
| 2545 base::DictionaryValue* favicon = nullptr; | 2546 base::DictionaryValue* favicon = nullptr; |
| 2546 if (!favicons->GetDictionary(fav_idx, &favicon)) | 2547 if (!favicons->GetDictionary(fav_idx, &favicon)) |
| 2547 return NO; | 2548 return NO; |
| 2548 std::string href; | 2549 std::string href; |
| 2549 std::string rel; | 2550 std::string rel; |
| 2550 if (!favicon->GetString("href", &href)) { | 2551 if (!favicon->GetString("href", &href)) { |
| 2551 DLOG(WARNING) << "JS message parameter not found: href"; | 2552 DLOG(WARNING) << "JS message parameter not found: href"; |
| 2552 return NO; | 2553 return NO; |
| 2553 } | 2554 } |
| 2554 if (!favicon->GetString("rel", &rel)) { | 2555 if (!favicon->GetString("rel", &rel)) { |
| 2555 DLOG(WARNING) << "JS message parameter not found: rel"; | 2556 DLOG(WARNING) << "JS message parameter not found: rel"; |
| 2556 return NO; | 2557 return NO; |
| 2557 } | 2558 } |
| 2559 BOOL isAppleTouch = YES; |
| 2558 web::FaviconURL::IconType icon_type = web::FaviconURL::FAVICON; | 2560 web::FaviconURL::IconType icon_type = web::FaviconURL::FAVICON; |
| 2559 if (rel == "apple-touch-icon") | 2561 if (rel == "apple-touch-icon") |
| 2560 icon_type = web::FaviconURL::TOUCH_ICON; | 2562 icon_type = web::FaviconURL::TOUCH_ICON; |
| 2561 else if (rel == "apple-touch-icon-precomposed") | 2563 else if (rel == "apple-touch-icon-precomposed") |
| 2562 icon_type = web::FaviconURL::TOUCH_PRECOMPOSED_ICON; | 2564 icon_type = web::FaviconURL::TOUCH_PRECOMPOSED_ICON; |
| 2563 urls.push_back( | 2565 else |
| 2564 web::FaviconURL(GURL(href), icon_type, std::vector<gfx::Size>())); | 2566 isAppleTouch = NO; |
| 2567 GURL url = GURL(href); |
| 2568 if (url.is_valid()) { |
| 2569 urls.push_back(web::FaviconURL(url, icon_type, std::vector<gfx::Size>())); |
| 2570 hasFavicon = hasFavicon || !isAppleTouch; |
| 2571 } |
| 2572 } |
| 2573 |
| 2574 if (!hasFavicon) { |
| 2575 // If an HTTP(S)? webpage does not reference a "favicon" of a type different |
| 2576 // from apple touch, then search for a file named "favicon.ico" at the root |
| 2577 // of the website (legacy). http://en.wikipedia.org/wiki/Favicon |
| 2578 id origin = context[kOriginURLKey]; |
| 2579 if (origin) { |
| 2580 NSURL* originNSURL = base::mac::ObjCCastStrict<NSURL>(origin); |
| 2581 GURL originGURL = net::GURLWithNSURL(originNSURL); |
| 2582 if (originGURL.is_valid() && originGURL.SchemeIsHTTPOrHTTPS()) { |
| 2583 GURL::Replacements replacements; |
| 2584 replacements.SetPathStr("/favicon.ico"); |
| 2585 urls.push_back(web::FaviconURL( |
| 2586 originGURL.ReplaceComponents(replacements), |
| 2587 web::FaviconURL::FAVICON, std::vector<gfx::Size>())); |
| 2588 } |
| 2589 } |
| 2565 } | 2590 } |
| 2566 if (!urls.empty()) | 2591 if (!urls.empty()) |
| 2567 _webStateImpl->OnFaviconUrlUpdated(urls); | 2592 _webStateImpl->OnFaviconUrlUpdated(urls); |
| 2568 return YES; | 2593 return YES; |
| 2569 } | 2594 } |
| 2570 | 2595 |
| 2571 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message | 2596 - (BOOL)handleDocumentSubmitMessage:(base::DictionaryValue*)message |
| 2572 context:(NSDictionary*)context { | 2597 context:(NSDictionary*)context { |
| 2573 std::string href; | 2598 std::string href; |
| 2574 if (!message->GetString("href", &href)) { | 2599 if (!message->GetString("href", &href)) { |
| (...skipping 2596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5171 - (NSUInteger)observerCount { | 5196 - (NSUInteger)observerCount { |
| 5172 DCHECK_EQ(_observerBridges.size(), [_observers count]); | 5197 DCHECK_EQ(_observerBridges.size(), [_observers count]); |
| 5173 return [_observers count]; | 5198 return [_observers count]; |
| 5174 } | 5199 } |
| 5175 | 5200 |
| 5176 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { | 5201 - (NSString*)referrerFromNavigationAction:(WKNavigationAction*)action { |
| 5177 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; | 5202 return [action.request valueForHTTPHeaderField:kReferrerHeaderName]; |
| 5178 } | 5203 } |
| 5179 | 5204 |
| 5180 @end | 5205 @end |
| OLD | NEW |