| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/external_app_launcher.h" | 5 #import "ios/chrome/browser/web/external_app_launcher.h" |
| 6 | 6 |
| 7 #include "base/ios/ios_util.h" | 7 #include "base/ios/ios_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "components/strings/grit/components_strings.h" | 11 #include "components/strings/grit/components_strings.h" |
| 12 #include "ios/chrome/browser/experimental_flags.h" | 12 #include "ios/chrome/browser/experimental_flags.h" |
| 13 #import "ios/chrome/browser/open_url_util.h" | 13 #import "ios/chrome/browser/open_url_util.h" |
| 14 #import "ios/chrome/browser/web/mailto_url_rewriter.h" |
| 14 #include "ios/chrome/grit/ios_strings.h" | 15 #include "ios/chrome/grit/ios_strings.h" |
| 15 #import "net/base/mac/url_conversions.h" | 16 #import "net/base/mac/url_conversions.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 19 #include "url/url_constants.h" |
| 18 | 20 |
| 19 #if !defined(__has_feature) || !__has_feature(objc_arc) | 21 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 20 #error "This file requires ARC support." | 22 #error "This file requires ARC support." |
| 21 #endif | 23 #endif |
| 22 | 24 |
| 23 namespace { | 25 namespace { |
| 24 | 26 |
| 25 typedef void (^AlertHandler)(UIAlertAction* action); | 27 typedef void (^AlertHandler)(UIAlertAction* action); |
| 26 | 28 |
| 27 // Returns a set of NSStrings that are URL schemes for iTunes Stores. | 29 // Returns a set of NSStrings that are URL schemes for iTunes Stores. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 45 } | 47 } |
| 46 | 48 |
| 47 // Logs an entry for |Tab.ExternalApplicationOpened|. If the user decided to | 49 // Logs an entry for |Tab.ExternalApplicationOpened|. If the user decided to |
| 48 // open in an external app, pass true. Otherwise, if the user cancelled the | 50 // open in an external app, pass true. Otherwise, if the user cancelled the |
| 49 // opening, pass false. | 51 // opening, pass false. |
| 50 void RecordExternalApplicationOpened(bool opened) { | 52 void RecordExternalApplicationOpened(bool opened) { |
| 51 UMA_HISTOGRAM_BOOLEAN("Tab.ExternalApplicationOpened", opened); | 53 UMA_HISTOGRAM_BOOLEAN("Tab.ExternalApplicationOpened", opened); |
| 52 } | 54 } |
| 53 | 55 |
| 54 // Returns whether gURL has the scheme of a URL that initiates a call. | 56 // Returns whether gURL has the scheme of a URL that initiates a call. |
| 55 BOOL UrlHasPhoneCallScheme(const GURL& gURL) { | 57 bool UrlHasPhoneCallScheme(const GURL& gURL) { |
| 56 return gURL.SchemeIs("tel") || gURL.SchemeIs("facetime") || | 58 return gURL.SchemeIs("tel") || gURL.SchemeIs("facetime") || |
| 57 gURL.SchemeIs("facetime-audio"); | 59 gURL.SchemeIs("facetime-audio"); |
| 58 } | 60 } |
| 59 | 61 |
| 60 // Returns a string to be used as the label for the prompt's action button. | 62 // Returns a string to be used as the label for the prompt's action button. |
| 61 NSString* PromptActionString(NSString* scheme) { | 63 NSString* PromptActionString(NSString* scheme) { |
| 62 if ([scheme isEqualToString:@"facetime"]) | 64 if ([scheme isEqualToString:@"facetime"]) |
| 63 return l10n_util::GetNSString(IDS_IOS_FACETIME_BUTTON); | 65 return l10n_util::GetNSString(IDS_IOS_FACETIME_BUTTON); |
| 64 else if ([scheme isEqualToString:@"tel"] || | 66 else if ([scheme isEqualToString:@"tel"] || |
| 65 [scheme isEqualToString:@"facetime-audio"]) | 67 [scheme isEqualToString:@"facetime-audio"]) |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 // Prompt user to open itunes when opening it is not a result of a link | 181 // Prompt user to open itunes when opening it is not a result of a link |
| 180 // click. | 182 // click. |
| 181 if (!linkClicked && UrlHasAppStoreScheme(gURL)) { | 183 if (!linkClicked && UrlHasAppStoreScheme(gURL)) { |
| 182 [self performSelector:@selector(openExternalAppWithPromptForURL:) | 184 [self performSelector:@selector(openExternalAppWithPromptForURL:) |
| 183 withObject:URL | 185 withObject:URL |
| 184 afterDelay:0.0]; | 186 afterDelay:0.0]; |
| 185 return YES; | 187 return YES; |
| 186 } | 188 } |
| 187 } | 189 } |
| 188 | 190 |
| 191 // Replaces |URL| with a rewritten URL if it is of mailto: scheme. |
| 192 if (!experimental_flags::IsNativeAppLauncherEnabled() && |
| 193 gURL.SchemeIs(url::kMailToScheme)) { |
| 194 MailtoURLRewriter* rewriter = |
| 195 [[MailtoURLRewriter alloc] initWithStandardHandlers]; |
| 196 NSString* launchURL = [rewriter rewriteMailtoURL:gURL]; |
| 197 if (launchURL) { |
| 198 UMA_HISTOGRAM_BOOLEAN("MailtoURLRewriter.Rewritten", true); |
| 199 URL = [NSURL URLWithString:launchURL]; |
| 200 } else { |
| 201 UMA_HISTOGRAM_BOOLEAN("MailtoURLRewriter.Rewritten", false); |
| 202 } |
| 203 } |
| 204 |
| 189 // If the following call returns YES, an external application is about to be | 205 // If the following call returns YES, an external application is about to be |
| 190 // launched and Chrome will go into the background now. | 206 // launched and Chrome will go into the background now. |
| 191 // TODO(crbug.com/622735): This call still needs to be updated. | 207 // TODO(crbug.com/622735): This call still needs to be updated. |
| 192 // It's heavily nested so some refactoring is needed. | 208 // It's heavily nested so some refactoring is needed. |
| 193 return [[UIApplication sharedApplication] openURL:URL]; | 209 return [[UIApplication sharedApplication] openURL:URL]; |
| 194 } | 210 } |
| 195 | 211 |
| 196 @end | 212 @end |
| OLD | NEW |