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

Unified Diff: ios/chrome/browser/ui/activity_services/share_to_data.mm

Issue 2645653003: Expose thumbnails of pages to iOS share extensions. (Closed)
Patch Set: Addressed comments, fixed tests. Created 3 years, 11 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/chrome/browser/ui/activity_services/share_to_data.mm
diff --git a/ios/chrome/browser/ui/activity_services/share_to_data.mm b/ios/chrome/browser/ui/activity_services/share_to_data.mm
index 40018418250c8ae64248d14381fe36cf3005777c..5ea3b13e7773a5500716c200286c4ee2c7535df2 100644
--- a/ios/chrome/browser/ui/activity_services/share_to_data.mm
+++ b/ios/chrome/browser/ui/activity_services/share_to_data.mm
@@ -38,6 +38,7 @@
@synthesize title = title_;
@synthesize image = image_;
+@synthesize thumbnailGenerator = thumbnailGenerator_;
@synthesize isOriginalTitle = isOriginalTitle_;
@synthesize isPagePrintable = isPagePrintable_;
@@ -47,9 +48,10 @@
}
- (id)initWithURL:(const GURL&)url
- title:(NSString*)title
- isOriginalTitle:(BOOL)isOriginalTitle
- isPagePrintable:(BOOL)isPagePrintable {
+ title:(NSString*)title
+ isOriginalTitle:(BOOL)isOriginalTitle
+ isPagePrintable:(BOOL)isPagePrintable
+ thumbnailGenerator:(ThumbnailGeneratorBlock)thumbnailGenerator {
DCHECK(url.is_valid());
DCHECK(title);
self = [super init];
@@ -58,6 +60,7 @@
self.title = title;
self.isOriginalTitle = isOriginalTitle;
self.isPagePrintable = isPagePrintable;
+ self.thumbnailGenerator = thumbnailGenerator;
}
return self;
}
@@ -71,24 +74,23 @@
}
- (BOOL)isEqual:(id)object {
+ // Used for testing.
if (![object isMemberOfClass:self.class])
return NO;
DCHECK(self.url.is_valid());
DCHECK(self.title);
ShareToData* other = (ShareToData*)object;
+ CGSize size = CGSizeMake(40, 40);
Olivier 2017/01/24 16:54:05 Add comment. Block are equal if they give the same
jif 2017/01/25 15:17:29 Ack. I moved the code which makes this comment obs
+ NSData* thumbnailData =
+ UIImagePNGRepresentation(self.thumbnailGenerator(size));
+ NSData* otherThumbnailData =
+ UIImagePNGRepresentation(other.thumbnailGenerator(size));
+ BOOL thumbnailDataIsEqual = thumbnailData == otherThumbnailData ||
Olivier 2017/01/24 16:54:05 I don't think I see anywhere in tests where this c
jif 2017/01/25 15:17:29 Done. The bitmap comparison is used in the bvc_uni
+ [thumbnailData isEqual:otherThumbnailData];
return self.url == other.url && [self.title isEqual:other.title] &&
self.image == other.image &&
- self.isOriginalTitle == other.isOriginalTitle;
-}
-
-- (NSUInteger)hash {
- DCHECK(self.url.is_valid());
- DCHECK(self.title);
- const NSUInteger kPrime = 31;
- NSString* urlString = base::SysUTF8ToNSString(self.url.spec());
- return kPrime * kPrime * kPrime * urlString.hash +
- kPrime * kPrime * self.title.hash + kPrime * self.image.hash +
- (self.isOriginalTitle ? 0 : 1);
+ self.isOriginalTitle == other.isOriginalTitle &&
+ self.isPagePrintable == other.isPagePrintable && thumbnailDataIsEqual;
}
@end

Powered by Google App Engine
This is Rietveld 408576698