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

Unified Diff: ios/chrome/browser/web/mailto_handler.mm

Issue 2852003002: Adds mailto: URL support to app launching. (Closed)
Patch Set: separate migration from auto-default even 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ios/chrome/browser/web/mailto_handler.h ('k') | ios/chrome/browser/web/mailto_handler_gmail.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/web/mailto_handler.mm
diff --git a/ios/chrome/browser/web/mailto_handler.mm b/ios/chrome/browser/web/mailto_handler.mm
new file mode 100644
index 0000000000000000000000000000000000000000..d2982f89c2bf0756771991b65a6c36bb637cd77e
--- /dev/null
+++ b/ios/chrome/browser/web/mailto_handler.mm
@@ -0,0 +1,68 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/web/mailto_handler.h"
+
+#import "base/strings/sys_string_conversions.h"
+#include "url/gurl.h"
+#include "url/url_constants.h"
+
+#import <UIKit/UIKit.h>
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+@implementation MailtoHandler
+@synthesize appName = _appName;
+@synthesize appStoreID = _appStoreID;
+
+- (instancetype)initWithName:(NSString*)appName
+ appStoreID:(NSString*)appStoreID {
+ self = [super init];
+ if (self) {
+ _appName = [appName copy];
+ _appStoreID = [appStoreID copy];
+ }
+ return self;
+}
+
+- (BOOL)isAvailable {
+ NSURL* baseURL = [NSURL URLWithString:[self beginningScheme]];
+ NSURL* testURL = [NSURL
+ URLWithString:[NSString stringWithFormat:@"%@://", [baseURL scheme]]];
+ return [[UIApplication sharedApplication] canOpenURL:testURL];
+}
+
+- (NSString*)beginningScheme {
+ // Subclasses should override this method.
+ return @"mailtohandler:/co?";
+}
+
+- (NSSet<NSString*>*)supportedHeaders {
+ return [NSSet<NSString*>
+ setWithObjects:@"to", @"cc", @"bcc", @"subject", @"body", nil];
+}
+
+- (NSString*)rewriteMailtoURL:(const GURL&)gURL {
+ if (!gURL.SchemeIs(url::kMailToScheme))
+ return nil;
+ NSMutableArray* outParams = [NSMutableArray array];
+ NSString* recipient = base::SysUTF8ToNSString(gURL.path());
+ if ([recipient length]) {
+ [outParams addObject:[NSString stringWithFormat:@"to=%@", recipient]];
+ }
+ NSString* query = base::SysUTF8ToNSString(gURL.query());
+ for (NSString* keyvalue : [query componentsSeparatedByString:@"&"]) {
+ NSArray* pair = [keyvalue componentsSeparatedByString:@"="];
+ if ([pair count] != 2U || ![[self supportedHeaders] containsObject:pair[0]])
+ continue;
+ [outParams
+ addObject:[NSString stringWithFormat:@"%@=%@", pair[0], pair[1]]];
+ }
+ return [NSString stringWithFormat:@"%@%@", [self beginningScheme],
+ [outParams componentsJoinedByString:@"&"]];
+}
+
+@end
« no previous file with comments | « ios/chrome/browser/web/mailto_handler.h ('k') | ios/chrome/browser/web/mailto_handler_gmail.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698