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

Side by Side Diff: ios/chrome/browser/ui/activity_services/chrome_activity_item_source.mm

Issue 2645653003: Expose thumbnails of pages to iOS share extensions. (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/activity_services/chrome_activity_item_source.h" 5 #import "ios/chrome/browser/ui/activity_services/chrome_activity_item_source.h"
6 6
7 #import <MobileCoreServices/MobileCoreServices.h> 7 #import <MobileCoreServices/MobileCoreServices.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #import "ios/chrome/browser/ui/activity_services/activity_type_util.h" 10 #import "ios/chrome/browser/ui/activity_services/activity_type_util.h"
11 #import "ios/chrome/browser/ui/activity_services/appex_constants.h" 11 #import "ios/chrome/browser/ui/activity_services/appex_constants.h"
12 12
13 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support." 14 #error "This file requires ARC support."
15 #endif 15 #endif
16 16
17 #pragma mark - UIActivityURLSource
18
19 @interface UIActivityURLSource () {
20 // The shared subject.
21 NSString* _subject;
22 // The shared url.
23 NSURL* _url;
24 }
25
26 @end
27
28 @implementation UIActivityURLSource
29
30 - (instancetype)init {
31 NOTREACHED();
32 return nil;
33 }
34
35 - (instancetype)initWithURL:(NSURL*)url subject:(NSString*)subject {
36 DCHECK(subject);
37 DCHECK(url);
38 self = [super init];
39 if (self) {
40 _subject = [subject copy];
41 _url = url;
42 }
43 return self;
44 }
45
46 #pragma mark - UIActivityItemSource
47
48 - (id)activityViewController:(UIActivityViewController*)activityViewController
49 itemForActivityType:(NSString*)activityType {
50 return _url;
51 }
52
53 - (id)activityViewControllerPlaceholderItem:
54 (UIActivityViewController*)activityViewController {
55 return _url;
56 }
57
58 - (NSString*)activityViewController:
59 (UIActivityViewController*)activityViewController
60 subjectForActivityType:(NSString*)activityType {
61 return _subject;
62 }
63
64 @end
65
66 #pragma mark - UIActivityTextSource 17 #pragma mark - UIActivityTextSource
67 18
68 @interface UIActivityTextSource () { 19 @interface UIActivityTextSource () {
69 // The shared text. 20 // The shared text.
70 NSString* _text; 21 NSString* _text;
71 } 22 }
72 23
73 @end 24 @end
74 25
75 @implementation UIActivityTextSource 26 @implementation UIActivityTextSource
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 return _image; 101 return _image;
151 } 102 }
152 103
153 @end 104 @end
154 105
155 #pragma mark - UIActivityFindLoginActionSource 106 #pragma mark - UIActivityFindLoginActionSource
156 107
157 @interface UIActivityFindLoginActionSource () { 108 @interface UIActivityFindLoginActionSource () {
158 NSString* _subject; 109 NSString* _subject;
159 NSURL* _url; 110 NSURL* _url;
111 ThumbnailGenerator _thumbnailGenerator;
160 } 112 }
161 @end 113 @end
162 114
163 @implementation UIActivityFindLoginActionSource 115 @implementation UIActivityFindLoginActionSource
164 116
165 - (instancetype)init { 117 - (instancetype)init {
166 NOTREACHED(); 118 NOTREACHED();
167 return nil; 119 return nil;
168 } 120 }
169 121
170 - (instancetype)initWithURL:(NSURL*)url subject:(NSString*)subject { 122 - (instancetype)initWithURL:(NSURL*)url
123 subject:(NSString*)subject
124 thumbnailGenerator:(ThumbnailGenerator)thumbnailGenerator {
171 DCHECK(url); 125 DCHECK(url);
172 DCHECK(subject); 126 DCHECK(subject);
127 DCHECK(thumbnailGenerator);
173 self = [super init]; 128 self = [super init];
174 if (self) { 129 if (self) {
175 _url = url; 130 _url = url;
176 _subject = [subject copy]; 131 _subject = [subject copy];
132 _thumbnailGenerator = thumbnailGenerator;
177 } 133 }
178 return self; 134 return self;
179 } 135 }
180 136
181 #pragma mark - UIActivityItemSource 137 #pragma mark - UIActivityItemSource
182 138
183 - (id)activityViewControllerPlaceholderItem: 139 - (id)activityViewControllerPlaceholderItem:
184 (UIActivityViewController*)activityViewController { 140 (UIActivityViewController*)activityViewController {
185 // Return the current URL as a placeholder 141 // Return the current URL as a placeholder
186 return _url; 142 return _url;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // after user made a choice of which AppEx to run, this method may be called 188 // after user made a choice of which AppEx to run, this method may be called
233 // with |activityType| equals to the bundle ID of the AppEx selected. 189 // with |activityType| equals to the bundle ID of the AppEx selected.
234 // Default action is to return @"public.url" UTType. 190 // Default action is to return @"public.url" UTType.
235 if (!activityType || 191 if (!activityType ||
236 activity_type_util::PasswordAppExActivityVersion(activityType)) { 192 activity_type_util::PasswordAppExActivityVersion(activityType)) {
237 return findLoginType; 193 return findLoginType;
238 } 194 }
239 return (NSString*)kUTTypeURL; 195 return (NSString*)kUTTypeURL;
240 } 196 }
241 197
198 - (UIImage*)activityViewController:
199 (UIActivityViewController*)activityViewController
200 thumbnailImageForActivityType:(UIActivityType)activityType
201 suggestedSize:(CGSize)size {
202 return _thumbnailGenerator(size);
Olivier 2017/01/20 20:41:59 What happens if the block is nil? (it may work...
jif 2017/01/24 10:29:50 _thumbnailGenerator can't be nil (see DCHECK in in
203 }
204
242 @end 205 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698