| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chrome/browser/ui/history/favicon_view_provider.h" | 5 #import "ios/chrome/browser/ui/history/favicon_view_provider.h" |
| 6 | 6 |
| 7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
| 8 #include "base/ios/weak_nsobject.h" | 8 #include "base/ios/weak_nsobject.h" |
| 9 #include "base/mac/bind_objc_block.h" | 9 #include "base/mac/bind_objc_block.h" |
| 10 #import "base/mac/foundation_util.h" | 10 #import "base/mac/foundation_util.h" |
| 11 #include "base/mac/objc_property_releaser.h" | 11 #include "base/mac/objc_release_properties.h" |
| 12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/task/cancelable_task_tracker.h" | 16 #include "base/task/cancelable_task_tracker.h" |
| 17 #include "components/favicon/core/fallback_url_util.h" | 17 #include "components/favicon/core/fallback_url_util.h" |
| 18 #include "components/favicon/core/large_icon_service.h" | 18 #include "components/favicon/core/large_icon_service.h" |
| 19 #include "components/favicon_base/fallback_icon_style.h" | 19 #include "components/favicon_base/fallback_icon_style.h" |
| 20 #include "components/favicon_base/favicon_types.h" | 20 #include "components/favicon_base/favicon_types.h" |
| 21 #import "ios/chrome/browser/ui/history/favicon_view.h" | 21 #import "ios/chrome/browser/ui/history/favicon_view.h" |
| 22 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 22 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" | 23 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" |
| 24 #include "skia/ext/skia_utils_ios.h" | 24 #include "skia/ext/skia_utils_ios.h" |
| 25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 26 | 26 |
| 27 @interface FaviconViewProvider () { | 27 @interface FaviconViewProvider () { |
| 28 // Property releaser for FaviconViewProvider. | |
| 29 base::mac::ObjCPropertyReleaser _propertyReleaser_FaviconViewProvider; | |
| 30 // Delegate for handling completion of favicon load. | 28 // Delegate for handling completion of favicon load. |
| 31 base::WeakNSProtocol<id<FaviconViewProviderDelegate>> _delegate; | 29 base::WeakNSProtocol<id<FaviconViewProviderDelegate>> _delegate; |
| 32 // Used to cancel tasks for the LargeIconService. | 30 // Used to cancel tasks for the LargeIconService. |
| 33 base::CancelableTaskTracker _faviconTaskTracker; | 31 base::CancelableTaskTracker _faviconTaskTracker; |
| 34 // View that renders a favicon or a fallback image. | 32 // View that renders a favicon or a fallback image. |
| 35 base::scoped_nsobject<FaviconView> _faviconView; | 33 base::scoped_nsobject<FaviconView> _faviconView; |
| 36 } | 34 } |
| 37 | 35 |
| 38 // Size to render the favicon. | 36 // Size to render the favicon. |
| 39 @property(nonatomic, assign) CGFloat faviconSize; | 37 @property(nonatomic, assign) CGFloat faviconSize; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 66 @synthesize fallbackBackgroundColor = _fallbackBackgroundColor; | 64 @synthesize fallbackBackgroundColor = _fallbackBackgroundColor; |
| 67 @synthesize fallbackTextColor = _fallbackTextColor; | 65 @synthesize fallbackTextColor = _fallbackTextColor; |
| 68 | 66 |
| 69 - (instancetype)initWithURL:(const GURL&)URL | 67 - (instancetype)initWithURL:(const GURL&)URL |
| 70 faviconSize:(CGFloat)faviconSize | 68 faviconSize:(CGFloat)faviconSize |
| 71 minFaviconSize:(CGFloat)minFaviconSize | 69 minFaviconSize:(CGFloat)minFaviconSize |
| 72 largeIconService:(favicon::LargeIconService*)largeIconService | 70 largeIconService:(favicon::LargeIconService*)largeIconService |
| 73 delegate:(id<FaviconViewProviderDelegate>)delegate { | 71 delegate:(id<FaviconViewProviderDelegate>)delegate { |
| 74 self = [super init]; | 72 self = [super init]; |
| 75 if (self) { | 73 if (self) { |
| 76 _propertyReleaser_FaviconViewProvider.Init(self, | |
| 77 [FaviconViewProvider class]); | |
| 78 _faviconSize = faviconSize; | 74 _faviconSize = faviconSize; |
| 79 _delegate.reset(delegate); | 75 _delegate.reset(delegate); |
| 80 _fallbackBackgroundColor = [[UIColor grayColor] retain]; | 76 _fallbackBackgroundColor = [[UIColor grayColor] retain]; |
| 81 _fallbackTextColor = [[UIColor whiteColor] retain]; | 77 _fallbackTextColor = [[UIColor whiteColor] retain]; |
| 82 [self fetchFaviconForURL:URL | 78 [self fetchFaviconForURL:URL |
| 83 size:faviconSize | 79 size:faviconSize |
| 84 minSize:minFaviconSize | 80 minSize:minFaviconSize |
| 85 service:largeIconService]; | 81 service:largeIconService]; |
| 86 } | 82 } |
| 87 return self; | 83 return self; |
| 88 } | 84 } |
| 89 | 85 |
| 90 - (instancetype)init { | 86 - (instancetype)init { |
| 91 NOTREACHED(); | 87 NOTREACHED(); |
| 92 return nil; | 88 return nil; |
| 93 } | 89 } |
| 94 | 90 |
| 91 - (void)dealloc { |
| 92 base::mac::ReleaseProperties(self); |
| 93 [super dealloc]; |
| 94 } |
| 95 |
| 95 - (void)fetchFaviconForURL:(const GURL&)URL | 96 - (void)fetchFaviconForURL:(const GURL&)URL |
| 96 size:(CGFloat)size | 97 size:(CGFloat)size |
| 97 minSize:(CGFloat)minSize | 98 minSize:(CGFloat)minSize |
| 98 service:(favicon::LargeIconService*)largeIconService { | 99 service:(favicon::LargeIconService*)largeIconService { |
| 99 if (!largeIconService) | 100 if (!largeIconService) |
| 100 return; | 101 return; |
| 101 base::WeakNSObject<FaviconViewProvider> weakSelf(self); | 102 base::WeakNSObject<FaviconViewProvider> weakSelf(self); |
| 102 GURL blockURL(URL); | 103 GURL blockURL(URL); |
| 103 void (^faviconBlock)(const favicon_base::LargeIconResult&) = ^( | 104 void (^faviconBlock)(const favicon_base::LargeIconResult&) = ^( |
| 104 const favicon_base::LargeIconResult& result) { | 105 const favicon_base::LargeIconResult& result) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 _faviconView.get().faviconFallbackLabel.textColor = self.fallbackTextColor; | 152 _faviconView.get().faviconFallbackLabel.textColor = self.fallbackTextColor; |
| 152 | 153 |
| 153 CGFloat fontSize = floorf(_faviconSize / 2); | 154 CGFloat fontSize = floorf(_faviconSize / 2); |
| 154 _faviconView.get().faviconFallbackLabel.font = | 155 _faviconView.get().faviconFallbackLabel.font = |
| 155 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:fontSize]; | 156 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:fontSize]; |
| 156 } | 157 } |
| 157 return _faviconView; | 158 return _faviconView; |
| 158 } | 159 } |
| 159 | 160 |
| 160 @end | 161 @end |
| OLD | NEW |