iOS web browser with a focus on security and privacy
1/*
2 * Endless
3 * Copyright (c) 2018 joshua stein <jcs@jcs.org>
4 *
5 * See LICENSE file for redistribution terms.
6 */
7
8#import <MobileCoreServices/MobileCoreServices.h>
9#import "ShareViewController.h"
10
11@implementation ShareViewController
12{
13 NSURL *url;
14}
15
16- (id)init
17{
18 if (self = [super init])
19 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
20
21 return self;
22}
23
24- (void)keyboardWillShow:(NSNotification *)note
25{
26 [self.view endEditing:true];
27}
28
29- (BOOL)isContentValid
30{
31 NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
32 for (NSItemProvider *itemProvider in item.attachments) {
33 if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
34 [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:@{} completionHandler:^(id<NSSecureCoding> _Nullable item, NSError * _Null_unspecified error) {
35 self->url = (NSURL *)item;
36 }];
37 }
38 }
39
40 return YES;
41}
42
43- (void)didSelectPost
44{
45}
46
47- (NSArray *)configurationItems
48{
49 NSString *eurl = [url absoluteString];
50 NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^http(s)?://" options:NSRegularExpressionCaseInsensitive error:nil];
51 eurl = [regex stringByReplacingMatchesInString:eurl options:0 range:NSMakeRange(0, [eurl length]) withTemplate:@"endlesshttp$1://"];
52 if ([eurl containsString:@"endlesshttp"]) {
53 UIResponder *responder = self;
54 while (responder) {
55 if ([responder respondsToSelector: @selector(openURL:)]) {
56 [responder performSelector: @selector(openURL:) withObject:[NSURL URLWithString:eurl]];
57 }
58 responder = [responder nextResponder];
59 }
60
61 [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
62 }
63
64 return @[];
65}
66
67@end