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

Side by Side Diff: ios/chrome/browser/web/mailto_handler.mm

Issue 2852003002: Adds mailto: URL support to app launching. (Closed)
Patch Set: clean up convertLegacyOptions logic some more Created 3 years, 7 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
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/web/mailto_handler.h"
6
7 #import "base/strings/sys_string_conversions.h"
8 #include "url/gurl.h"
9 #include "url/url_constants.h"
10
11 #import <UIKit/UIKit.h>
12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
17 @implementation MailtoHandler
18 @synthesize appName = _appName;
19 @synthesize appStoreID = _appStoreID;
20
21 - (instancetype)initWithName:(NSString*)appName
22 appStoreID:(NSString*)appStoreID {
23 self = [super init];
24 if (self) {
25 _appName = [appName copy];
26 _appStoreID = [appStoreID copy];
27 }
28 return self;
29 }
30
31 - (BOOL)isAvailable {
32 NSURL* baseURL = [NSURL URLWithString:[self beginningScheme]];
33 NSURL* testURL = [NSURL
34 URLWithString:[NSString stringWithFormat:@"%@://", [baseURL scheme]]];
35 return [[UIApplication sharedApplication] canOpenURL:testURL];
36 }
37
38 - (NSString*)beginningScheme {
39 // Subclasses should override this method.
40 return @"mailtohandler:/co?";
41 }
42
43 - (NSSet*)supportedHeaders {
44 return [NSSet setWithObjects:@"to", @"cc", @"bcc", @"subject", @"body", nil];
45 }
46
47 - (NSString*)rewriteMailtoURL:(const GURL&)gURL {
48 if (!gURL.SchemeIs(url::kMailToScheme))
49 return nil;
50 NSMutableArray* outParams = [NSMutableArray array];
51 NSString* recipient = base::SysUTF8ToNSString(gURL.path());
52 if ([recipient length]) {
53 [outParams addObject:[NSString stringWithFormat:@"to=%@", recipient]];
54 }
55 NSString* query = base::SysUTF8ToNSString(gURL.query());
56 for (NSString* keyvalue : [query componentsSeparatedByString:@"&"]) {
57 NSArray* pair = [keyvalue componentsSeparatedByString:@"="];
58 if ([pair count] != 2U || ![[self supportedHeaders] containsObject:pair[0]])
59 continue;
60 [outParams
61 addObject:[NSString stringWithFormat:@"%@=%@", pair[0], pair[1]]];
62 }
63 return [NSString stringWithFormat:@"%@%@", [self beginningScheme],
64 [outParams componentsJoinedByString:@"&"]];
65 }
66
67 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698