| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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/browser/web/mailto_url_rewriter.h" | 5 #import "ios/chrome/browser/web/mailto_url_rewriter.h" |
| 6 | 6 |
| 7 #import "base/logging.h" | 7 #import "base/logging.h" |
| 8 #import "ios/chrome/browser/web/mailto_handler.h" | 8 #import "ios/chrome/browser/web/mailto_handler.h" |
| 9 #import "ios/chrome/browser/web/mailto_handler_gmail.h" | 9 #import "ios/chrome/browser/web/mailto_handler_gmail.h" |
| 10 #import "ios/chrome/browser/web/mailto_handler_system_mail.h" | 10 #import "ios/chrome/browser/web/mailto_handler_system_mail.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 - (void)migrateLegacyOptions; | 45 - (void)migrateLegacyOptions; |
| 46 | 46 |
| 47 // For users who have not made an explicit choice (kMailtoDefaultHandlerKey | 47 // For users who have not made an explicit choice (kMailtoDefaultHandlerKey |
| 48 // not set), if Gmail is detected, make an explicit choice for the user to | 48 // not set), if Gmail is detected, make an explicit choice for the user to |
| 49 // use Gmail app as the default mailto: handler. | 49 // use Gmail app as the default mailto: handler. |
| 50 - (void)autoDefaultToGmailIfInstalled; | 50 - (void)autoDefaultToGmailIfInstalled; |
| 51 | 51 |
| 52 @end | 52 @end |
| 53 | 53 |
| 54 @implementation MailtoURLRewriter | 54 @implementation MailtoURLRewriter |
| 55 @synthesize observer = _observer; |
| 55 @synthesize handlers = _handlers; | 56 @synthesize handlers = _handlers; |
| 56 | 57 |
| 57 + (NSString*)systemMailApp { | 58 + (NSString*)systemMailApp { |
| 58 // This is the App Store ID for Apple Mail app. | 59 // This is the App Store ID for Apple Mail app. |
| 59 // See https://itunes.apple.com/us/app/mail/id1108187098?mt=8 | 60 // See https://itunes.apple.com/us/app/mail/id1108187098?mt=8 |
| 60 return @"1108187098"; | 61 return @"1108187098"; |
| 61 } | 62 } |
| 62 | 63 |
| 63 - (instancetype)init { | 64 - (instancetype)init { |
| 64 self = [super init]; | 65 self = [super init]; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 } | 84 } |
| 84 | 85 |
| 85 - (NSString*)defaultHandlerID { | 86 - (NSString*)defaultHandlerID { |
| 86 NSString* value = [[NSUserDefaults standardUserDefaults] | 87 NSString* value = [[NSUserDefaults standardUserDefaults] |
| 87 stringForKey:kMailtoDefaultHandlerKey]; | 88 stringForKey:kMailtoDefaultHandlerKey]; |
| 88 return value ? value : [[self class] systemMailApp]; | 89 return value ? value : [[self class] systemMailApp]; |
| 89 } | 90 } |
| 90 | 91 |
| 91 - (void)setDefaultHandlerID:(NSString*)appStoreID { | 92 - (void)setDefaultHandlerID:(NSString*)appStoreID { |
| 92 DCHECK([appStoreID length]); | 93 DCHECK([appStoreID length]); |
| 93 [[NSUserDefaults standardUserDefaults] setObject:appStoreID | 94 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults]; |
| 94 forKey:kMailtoDefaultHandlerKey]; | 95 if ([appStoreID |
| 96 isEqualToString:[defaults objectForKey:kMailtoDefaultHandlerKey]]) |
| 97 return; |
| 98 [defaults setObject:appStoreID forKey:kMailtoDefaultHandlerKey]; |
| 99 [_observer rewriterDidChange:self]; |
| 100 } |
| 101 |
| 102 - (NSString*)defaultHandlerName { |
| 103 NSString* handlerID = [self defaultHandlerID]; |
| 104 MailtoHandler* handler = _handlers[handlerID]; |
| 105 return [handler appName]; |
| 95 } | 106 } |
| 96 | 107 |
| 97 - (NSString*)rewriteMailtoURL:(const GURL&)gURL { | 108 - (NSString*)rewriteMailtoURL:(const GURL&)gURL { |
| 98 NSString* value = [self defaultHandlerID]; | 109 NSString* value = [self defaultHandlerID]; |
| 99 if ([value length]) { | 110 if ([value length]) { |
| 100 MailtoHandler* handler = _handlers[value]; | 111 MailtoHandler* handler = _handlers[value]; |
| 101 if (handler) { | 112 if (handler) { |
| 102 return [handler rewriteMailtoURL:gURL]; | 113 return [handler rewriteMailtoURL:gURL]; |
| 103 } | 114 } |
| 104 } | 115 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 if ([defaults objectForKey:kMailtoDefaultHandlerKey]) | 208 if ([defaults objectForKey:kMailtoDefaultHandlerKey]) |
| 198 return; | 209 return; |
| 199 | 210 |
| 200 NSString* const kGmailAppStoreID = @"422689480"; | 211 NSString* const kGmailAppStoreID = @"422689480"; |
| 201 MailtoHandler* gmailHandler = _handlers[kGmailAppStoreID]; | 212 MailtoHandler* gmailHandler = _handlers[kGmailAppStoreID]; |
| 202 if ([gmailHandler isAvailable]) | 213 if ([gmailHandler isAvailable]) |
| 203 [defaults setObject:kGmailAppStoreID forKey:kMailtoDefaultHandlerKey]; | 214 [defaults setObject:kGmailAppStoreID forKey:kMailtoDefaultHandlerKey]; |
| 204 } | 215 } |
| 205 | 216 |
| 206 @end | 217 @end |
| OLD | NEW |