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

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

Issue 2852003002: Adds mailto: URL support to app launching. (Closed)
Patch Set: rebase 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 // This should be implemented by subclasses.
33 NOTREACHED();
34 return NO;
35 }
36
37 - (NSString*)beginningScheme {
38 // Subclasses should override this method.
39 return @"mailtohandler:/co?";
40 }
41
42 - (NSSet*)supportedHeaders {
43 return [NSSet setWithObjects:@"to", @"from", @"cc", @"subject", @"body", nil];
44 }
45
46 - (NSString*)rewriteMailtoURL:(const GURL&)gURL {
47 if (!gURL.SchemeIs(url::kMailToScheme))
48 return nil;
49 NSMutableArray* outParams = [NSMutableArray array];
50 NSString* recipient = base::SysUTF8ToNSString(gURL.path());
51 if ([recipient length]) {
52 [outParams addObject:[NSString stringWithFormat:@"to=%@", recipient]];
53 }
54 NSString* query = base::SysUTF8ToNSString(gURL.query());
55 for (NSString* keyvalue : [query componentsSeparatedByString:@"&"]) {
56 NSArray* pair = [keyvalue componentsSeparatedByString:@"="];
57 if ([pair count] == 0U || [pair count] > 2U)
jif 2017/05/04 14:08:47 Do we really want to handle the case where [pair c
pkl (ping after 24h if needed) 2017/05/04 22:25:59 Good point. Checked some mailto query params docs
58 continue;
59 if (![[self supportedHeaders] containsObject:pair[0]])
60 continue;
61 if ([pair count] == 1) {
62 [outParams addObject:pair[0]];
63 } else if ([pair count] == 2) {
64 [outParams
65 addObject:[NSString stringWithFormat:@"%@=%@", pair[0], pair[1]]];
66 }
67 }
68 return [NSString stringWithFormat:@"%@%@", [self beginningScheme],
69 [outParams componentsJoinedByString:@"&"]];
70 }
71
72 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698