| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 - (NSString*)defaultHandlerName { | 106 - (NSString*)defaultHandlerName { |
| 107 NSString* handlerID = [self defaultHandlerID]; | 107 NSString* handlerID = [self defaultHandlerID]; |
| 108 MailtoHandler* handler = _handlers[handlerID]; | 108 MailtoHandler* handler = _handlers[handlerID]; |
| 109 return [handler appName]; | 109 return [handler appName]; |
| 110 } | 110 } |
| 111 | 111 |
| 112 - (NSString*)rewriteMailtoURL:(const GURL&)gURL { | 112 - (NSString*)rewriteMailtoURL:(const GURL&)gURL { |
| 113 NSString* value = [self defaultHandlerID]; | 113 NSString* value = [self defaultHandlerID]; |
| 114 if ([value length]) { | 114 if ([value length]) { |
| 115 MailtoHandler* handler = _handlers[value]; | 115 MailtoHandler* handler = _handlers[value]; |
| 116 if (handler) { | 116 if ([handler isAvailable]) { |
| 117 return [handler rewriteMailtoURL:gURL]; | 117 return [handler rewriteMailtoURL:gURL]; |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 return nil; | 120 return nil; |
| 121 } | 121 } |
| 122 | 122 |
| 123 #pragma mark - Private | 123 #pragma mark - Private |
| 124 | 124 |
| 125 + (void)resetDefaultHandlerIDForTesting { | 125 + (void)resetDefaultHandlerIDForTesting { |
| 126 [[NSUserDefaults standardUserDefaults] | 126 [[NSUserDefaults standardUserDefaults] |
| 127 removeObjectForKey:kMailtoDefaultHandlerKey]; | 127 removeObjectForKey:kMailtoDefaultHandlerKey]; |
| 128 } | 128 } |
| 129 | 129 |
| 130 - (void)addMailtoApps:(NSArray<MailtoHandler*>*)handlerApps { | 130 - (void)addMailtoApps:(NSArray<MailtoHandler*>*)handlerApps { |
| 131 for (MailtoHandler* app in handlerApps) { | 131 for (MailtoHandler* app in handlerApps) { |
| 132 if ([app isAvailable]) | 132 [_handlers setObject:app forKey:[app appStoreID]]; |
| 133 [_handlers setObject:app forKey:[app appStoreID]]; | |
| 134 } | 133 } |
| 135 [self migrateLegacyOptions]; | 134 [self migrateLegacyOptions]; |
| 136 [self autoDefaultToGmailIfInstalled]; | 135 [self autoDefaultToGmailIfInstalled]; |
| 137 } | 136 } |
| 138 | 137 |
| 139 // | 138 // |
| 140 // Implements the migration logic for users of previous versions of Google | 139 // Implements the migration logic for users of previous versions of Google |
| 141 // Chrome which supports Google Native App Launcher. The goal is to preserve | 140 // Chrome which supports Google Native App Launcher. The goal is to preserve |
| 142 // the previous behavior and support user choice of non-system provided Mail | 141 // the previous behavior and support user choice of non-system provided Mail |
| 143 // client apps. System-provided Mail client app will be referred to as | 142 // client apps. System-provided Mail client app will be referred to as |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 if ([defaults objectForKey:kMailtoDefaultHandlerKey]) | 211 if ([defaults objectForKey:kMailtoDefaultHandlerKey]) |
| 213 return; | 212 return; |
| 214 | 213 |
| 215 NSString* const kGmailAppStoreID = @"422689480"; | 214 NSString* const kGmailAppStoreID = @"422689480"; |
| 216 MailtoHandler* gmailHandler = _handlers[kGmailAppStoreID]; | 215 MailtoHandler* gmailHandler = _handlers[kGmailAppStoreID]; |
| 217 if ([gmailHandler isAvailable]) | 216 if ([gmailHandler isAvailable]) |
| 218 [defaults setObject:kGmailAppStoreID forKey:kMailtoDefaultHandlerKey]; | 217 [defaults setObject:kGmailAppStoreID forKey:kMailtoDefaultHandlerKey]; |
| 219 } | 218 } |
| 220 | 219 |
| 221 @end | 220 @end |
| OLD | NEW |