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

Side by Side Diff: ios/chrome/share_extension/share_extension_view.mm

Issue 2608913002: Handle invalid URLs in share extension. (Closed)
Patch Set: adding gambard as OWNER 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 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/share_extension/share_extension_view.h" 5 #import "ios/chrome/share_extension/share_extension_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "ios/chrome/share_extension/ui_util.h" 8 #import "ios/chrome/share_extension/ui_util.h"
9 9
10 #if !defined(__has_feature) || !__has_feature(objc_arc) 10 #if !defined(__has_feature) || !__has_feature(objc_arc)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 #pragma mark - Share Extension View 50 #pragma mark - Share Extension View
51 51
52 @interface ShareExtensionView () { 52 @interface ShareExtensionView () {
53 __weak id<ShareExtensionViewActionTarget> _target; 53 __weak id<ShareExtensionViewActionTarget> _target;
54 } 54 }
55 55
56 // Keep strong references of the views that need to be updated. 56 // Keep strong references of the views that need to be updated.
57 @property(nonatomic, strong) UILabel* titleLabel; 57 @property(nonatomic, strong) UILabel* titleLabel;
58 @property(nonatomic, strong) UILabel* URLLabel; 58 @property(nonatomic, strong) UILabel* URLLabel;
59 @property(nonatomic, strong) UIImageView* screenshotView; 59 @property(nonatomic, strong) UIImageView* screenshotView;
60 @property(nonatomic, strong) UIStackView* itemStack;
60 61
61 // View creation helpers. 62 // View creation helpers.
62 // Returns a view containing the shared items (title, URL, screenshot). This 63 // Returns a view containing the shared items (title, URL, screenshot). This
63 // method will set the ivars. 64 // method will set the ivars.
64 - (UIView*)sharedItemView; 65 - (UIView*)sharedItemView;
65 66
66 // Returns a button containing the with title |title| and action |selector| on 67 // Returns a button containing the with title |title| and action |selector| on
67 // |_target|. 68 // |_target|.
68 - (UIButton*)buttonWithTitle:(NSString*)title selector:(SEL)selector; 69 - (UIButton*)buttonWithTitle:(NSString*)title selector:(SEL)selector;
69 70
70 // Returns a view containing a divider with vibrancy effect. 71 // Returns a view containing a divider with vibrancy effect.
71 - (UIView*)dividerViewWithVibrancy:(UIVisualEffect*)vibrancyEffect; 72 - (UIView*)dividerViewWithVibrancy:(UIVisualEffect*)vibrancyEffect;
72 73
73 // Returns a navigationBar. 74 // Returns a navigationBar.
74 - (UINavigationBar*)navigationBar; 75 - (UINavigationBar*)navigationBar;
75 76
76 @end 77 @end
77 78
78 @implementation ShareExtensionView 79 @implementation ShareExtensionView
79 80
80 @synthesize titleLabel = _titleLabel; 81 @synthesize titleLabel = _titleLabel;
81 @synthesize URLLabel = _URLLabel; 82 @synthesize URLLabel = _URLLabel;
82 @synthesize screenshotView = _screenshotView; 83 @synthesize screenshotView = _screenshotView;
84 @synthesize itemStack = _itemStack;
83 85
84 #pragma mark - Lifecycle 86 #pragma mark - Lifecycle
85 87
86 - (instancetype)initWithActionTarget: 88 - (instancetype)initWithActionTarget:
87 (id<ShareExtensionViewActionTarget>)target { 89 (id<ShareExtensionViewActionTarget>)target {
88 self = [super initWithFrame:CGRectZero]; 90 self = [super initWithFrame:CGRectZero];
89 if (self) { 91 if (self) {
90 DCHECK(target); 92 DCHECK(target);
91 _target = target; 93 _target = target;
92 94
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 [_URLLabel setNumberOfLines:3]; 156 [_URLLabel setNumberOfLines:3];
155 [_URLLabel setLineBreakMode:NSLineBreakByWordWrapping]; 157 [_URLLabel setLineBreakMode:NSLineBreakByWordWrapping];
156 [_URLLabel setFont:[UIFont systemFontOfSize:12]]; 158 [_URLLabel setFont:[UIFont systemFontOfSize:12]];
157 159
158 // Screenshot view. Image will be filled by |setScreenshot:| when available. 160 // Screenshot view. Image will be filled by |setScreenshot:| when available.
159 _screenshotView = [[UIImageView alloc] initWithFrame:CGRectZero]; 161 _screenshotView = [[UIImageView alloc] initWithFrame:CGRectZero];
160 [_screenshotView.widthAnchor 162 [_screenshotView.widthAnchor
161 constraintLessThanOrEqualToConstant:kScreenshotSize] 163 constraintLessThanOrEqualToConstant:kScreenshotSize]
162 .active = YES; 164 .active = YES;
163 [_screenshotView.heightAnchor 165 [_screenshotView.heightAnchor
164 constraintLessThanOrEqualToConstant:kScreenshotSize] 166 constraintEqualToAnchor:_screenshotView.widthAnchor]
165 .active = YES; 167 .active = YES;
166 [_screenshotView setContentMode:UIViewContentModeScaleAspectFill]; 168 [_screenshotView setContentMode:UIViewContentModeScaleAspectFill];
169 [_screenshotView setClipsToBounds:YES];
167 [_screenshotView setHidden:YES]; 170 [_screenshotView setHidden:YES];
168 171
169 // |_screenshotView| should take as much space as needed. Lower compression 172 // |_screenshotView| should take as much space as needed. Lower compression
170 // resistance of the other elements. 173 // resistance of the other elements.
171 [_titleLabel 174 [_titleLabel
172 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow 175 setContentCompressionResistancePriority:UILayoutPriorityDefaultLow
173 forAxis:UILayoutConstraintAxisHorizontal]; 176 forAxis:UILayoutConstraintAxisHorizontal];
174 [_titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh 177 [_titleLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh
175 forAxis:UILayoutConstraintAxisVertical]; 178 forAxis:UILayoutConstraintAxisVertical];
176 [_URLLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh 179 [_URLLabel setContentHuggingPriority:UILayoutPriorityDefaultHigh
(...skipping 21 matching lines...) Expand all
198 201
199 [titleURLStack.centerYAnchor 202 [titleURLStack.centerYAnchor
200 constraintEqualToAnchor:titleURLContainer.centerYAnchor] 203 constraintEqualToAnchor:titleURLContainer.centerYAnchor]
201 .active = YES; 204 .active = YES;
202 [titleURLStack.centerXAnchor 205 [titleURLStack.centerXAnchor
203 constraintEqualToAnchor:titleURLContainer.centerXAnchor] 206 constraintEqualToAnchor:titleURLContainer.centerXAnchor]
204 .active = YES; 207 .active = YES;
205 [titleURLStack.widthAnchor 208 [titleURLStack.widthAnchor
206 constraintEqualToAnchor:titleURLContainer.widthAnchor] 209 constraintEqualToAnchor:titleURLContainer.widthAnchor]
207 .active = YES; 210 .active = YES;
211 [titleURLStack
212 setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh
213 forAxis:UILayoutConstraintAxisVertical];
208 214
209 UIStackView* itemStack = [[UIStackView alloc] 215 _itemStack =
210 initWithArrangedSubviews:@[ titleURLContainer, _screenshotView ]]; 216 [[UIStackView alloc] initWithArrangedSubviews:@[ titleURLContainer ]];
211 [itemStack setAxis:UILayoutConstraintAxisHorizontal]; 217 [_itemStack setAxis:UILayoutConstraintAxisHorizontal];
212 [itemStack setLayoutMargins:UIEdgeInsetsMake(kShareExtensionPadding, 218 [_itemStack setLayoutMargins:UIEdgeInsetsMake(kShareExtensionPadding,
213 kShareExtensionPadding, 219 kShareExtensionPadding,
214 kShareExtensionPadding, 220 kShareExtensionPadding,
215 kShareExtensionPadding)]; 221 kShareExtensionPadding)];
216 [itemStack setLayoutMarginsRelativeArrangement:YES]; 222 [_itemStack setLayoutMarginsRelativeArrangement:YES];
217 [itemStack setSpacing:kShareExtensionPadding]; 223 [_itemStack setSpacing:kShareExtensionPadding];
218 224
219 [_titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 225 [_titleLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
220 [_URLLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 226 [_URLLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
221 [_screenshotView setTranslatesAutoresizingMaskIntoConstraints:NO]; 227 [_screenshotView setTranslatesAutoresizingMaskIntoConstraints:NO];
222 [titleURLStack setTranslatesAutoresizingMaskIntoConstraints:NO]; 228 [titleURLStack setTranslatesAutoresizingMaskIntoConstraints:NO];
223 [itemStack setTranslatesAutoresizingMaskIntoConstraints:NO]; 229 [_itemStack setTranslatesAutoresizingMaskIntoConstraints:NO];
224 230
225 return itemStack; 231 return _itemStack;
226 } 232 }
227 233
228 - (UIView*)dividerViewWithVibrancy:(UIVisualEffect*)vibrancyEffect { 234 - (UIView*)dividerViewWithVibrancy:(UIVisualEffect*)vibrancyEffect {
229 UIVisualEffectView* dividerVibrancy = 235 UIVisualEffectView* dividerVibrancy =
230 [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect]; 236 [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
231 UIView* divider = [[UIView alloc] initWithFrame:CGRectZero]; 237 UIView* divider = [[UIView alloc] initWithFrame:CGRectZero];
232 [divider setBackgroundColor:[UIColor colorWithWhite:0 alpha:kLowAlpha]]; 238 [divider setBackgroundColor:[UIColor colorWithWhite:0 alpha:kLowAlpha]];
233 [[dividerVibrancy contentView] addSubview:divider]; 239 [[dividerVibrancy contentView] addSubview:divider];
234 [dividerVibrancy setTranslatesAutoresizingMaskIntoConstraints:NO]; 240 [dividerVibrancy setTranslatesAutoresizingMaskIntoConstraints:NO];
235 [divider setTranslatesAutoresizingMaskIntoConstraints:NO]; 241 [divider setTranslatesAutoresizingMaskIntoConstraints:NO];
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 [[self URLLabel] setText:[URL absoluteString]]; 301 [[self URLLabel] setText:[URL absoluteString]];
296 } 302 }
297 303
298 - (void)setTitle:(NSString*)title { 304 - (void)setTitle:(NSString*)title {
299 [[self titleLabel] setText:title]; 305 [[self titleLabel] setText:title];
300 } 306 }
301 307
302 - (void)setScreenshot:(UIImage*)screenshot { 308 - (void)setScreenshot:(UIImage*)screenshot {
303 [[self screenshotView] setHidden:NO]; 309 [[self screenshotView] setHidden:NO];
304 [[self screenshotView] setImage:screenshot]; 310 [[self screenshotView] setImage:screenshot];
311 [[self itemStack] addArrangedSubview:[self screenshotView]];
305 } 312 }
306 313
307 @end 314 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698