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/weak_nsobject.h" | 8 #include "base/ios/weak_nsobject.h" |
8 #include "base/logging.h" | 9 #include "base/logging.h" |
9 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
11 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
12 #include "ios/chrome/browser/experimental_flags.h" | 13 #include "ios/chrome/browser/experimental_flags.h" |
13 #import "ios/chrome/browser/open_url_util.h" | 14 #import "ios/chrome/browser/open_url_util.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" |
(...skipping 28 matching lines...) Expand all Loading... | |
45 // opening, pass false. | 46 // opening, pass false. |
46 void RecordExternalApplicationOpened(bool opened) { | 47 void RecordExternalApplicationOpened(bool opened) { |
47 UMA_HISTOGRAM_BOOLEAN("Tab.ExternalApplicationOpened", opened); | 48 UMA_HISTOGRAM_BOOLEAN("Tab.ExternalApplicationOpened", opened); |
48 } | 49 } |
49 | 50 |
50 } // namespace | 51 } // namespace |
51 | 52 |
52 @interface ExternalAppLauncher () | 53 @interface ExternalAppLauncher () |
53 // Returns the Phone/FaceTime call argument from |URL|. | 54 // Returns the Phone/FaceTime call argument from |URL|. |
54 + (NSString*)formatCallArgument:(NSURL*)URL; | 55 + (NSString*)formatCallArgument:(NSURL*)URL; |
55 // Ask user for confirmation before dialing FaceTime destination. | 56 // Ask user for confirmation before dialing Phone or FaceTime destinations. |
56 - (void)openFaceTimePromptForURL:(NSURL*)telURL; | 57 - (void)openPromptForURL:(NSURL*)telURL; |
Eugene But (OOO till 7-30)
2017/04/13 22:47:30
s/telURL/URL ?
pkl (ping after 24h if needed)
2017/04/14 00:34:50
Done.
| |
57 // Ask user for confirmation before moving to external app. | 58 // Ask user for confirmation before moving to external app. |
58 - (void)openExternalAppWithPromptForURL:(NSURL*)URL; | 59 - (void)openExternalAppWithPromptForURL:(NSURL*)URL; |
59 // Presents a configured alert controller on the root view controller. | 60 // Presents a configured alert controller on the root view controller. |
60 - (void)presentAlertControllerWithMessage:(NSString*)message | 61 - (void)presentAlertControllerWithMessage:(NSString*)message |
61 openTitle:(NSString*)openTitle | 62 openTitle:(NSString*)openTitle |
62 openHandler:(AlertHandler)openHandler | 63 openHandler:(AlertHandler)openHandler |
63 cancelHandler:(AlertHandler)cancelHandler; | 64 cancelHandler:(AlertHandler)cancelHandler; |
64 @end | 65 @end |
65 | 66 |
66 @implementation ExternalAppLauncher | 67 @implementation ExternalAppLauncher |
(...skipping 22 matching lines...) Expand all Loading... | |
89 openTitle:openTitle | 90 openTitle:openTitle |
90 openHandler:^(UIAlertAction* action) { | 91 openHandler:^(UIAlertAction* action) { |
91 RecordExternalApplicationOpened(true); | 92 RecordExternalApplicationOpened(true); |
92 OpenUrlWithCompletionHandler(URL, nil); | 93 OpenUrlWithCompletionHandler(URL, nil); |
93 } | 94 } |
94 cancelHandler:^(UIAlertAction* action) { | 95 cancelHandler:^(UIAlertAction* action) { |
95 RecordExternalApplicationOpened(false); | 96 RecordExternalApplicationOpened(false); |
96 }]; | 97 }]; |
97 } | 98 } |
98 | 99 |
99 - (void)openFaceTimePromptForURL:(NSURL*)URL { | 100 - (void)openPromptForURL:(NSURL*)URL { |
100 NSString* openTitle = l10n_util::GetNSString(IDS_IOS_FACETIME_BUTTON); | 101 NSString* openTitle = [URL.scheme isEqualToString:@"facetime"] |
Eugene But (OOO till 7-30)
2017/04/13 22:47:30
Do you want to DCHECK that URL.scheme is ether fac
pkl (ping after 24h if needed)
2017/04/14 00:34:50
Refactored into a anonymous function and do the NO
| |
102 ? l10n_util::GetNSString(IDS_IOS_FACETIME_BUTTON) | |
103 : l10n_util::GetNSString(IDS_IOS_PHONE_CALL_BUTTON); | |
101 [self presentAlertControllerWithMessage:[[self class] formatCallArgument:URL] | 104 [self presentAlertControllerWithMessage:[[self class] formatCallArgument:URL] |
102 openTitle:openTitle | 105 openTitle:openTitle |
103 openHandler:^(UIAlertAction* action) { | 106 openHandler:^(UIAlertAction* action) { |
104 OpenUrlWithCompletionHandler(URL, nil); | 107 OpenUrlWithCompletionHandler(URL, nil); |
105 } | 108 } |
106 cancelHandler:nil]; | 109 cancelHandler:nil]; |
107 } | 110 } |
108 | 111 |
109 - (void)presentAlertControllerWithMessage:(NSString*)message | 112 - (void)presentAlertControllerWithMessage:(NSString*)message |
110 openTitle:(NSString*)openTitle | 113 openTitle:(NSString*)openTitle |
(...skipping 18 matching lines...) Expand all Loading... | |
129 presentViewController:alertController | 132 presentViewController:alertController |
130 animated:YES | 133 animated:YES |
131 completion:nil]; | 134 completion:nil]; |
132 } | 135 } |
133 | 136 |
134 - (BOOL)openURL:(const GURL&)gURL linkClicked:(BOOL)linkClicked { | 137 - (BOOL)openURL:(const GURL&)gURL linkClicked:(BOOL)linkClicked { |
135 if (!gURL.is_valid() || !gURL.has_scheme()) | 138 if (!gURL.is_valid() || !gURL.has_scheme()) |
136 return NO; | 139 return NO; |
137 NSURL* URL = net::NSURLWithGURL(gURL); | 140 NSURL* URL = net::NSURLWithGURL(gURL); |
138 | 141 |
139 if (gURL.SchemeIs("facetime") || gURL.SchemeIs("facetime-audio")) { | 142 // iOS 10.3.2 introduced new prompts when facetime: and facetime-audio: |
143 // URL schemes are opened. It is no longer necessary for Chrome to present | |
144 // another prompt before the system-provided prompt. | |
145 if (!base::ios::IsRunningOnOrLater(10, 3, 2) && | |
146 (gURL.SchemeIs("tel") || gURL.SchemeIs("facetime") || | |
Eugene But (OOO till 7-30)
2017/04/13 22:47:30
Do you want to create constants for these custom u
pkl (ping after 24h if needed)
2017/04/14 00:34:50
Refactored so all the strings are nearby to not cl
| |
147 gURL.SchemeIs("facetime-audio"))) { | |
140 // Showing an alert view immediately has a side-effect where focus is | 148 // Showing an alert view immediately has a side-effect where focus is |
141 // taken from the UIWebView so quickly that mouseup events are lost and | 149 // taken from the UIWebView so quickly that mouseup events are lost and |
142 // buttons get 'stuck' in the on position. The solution is to defer | 150 // buttons get 'stuck' in the on position. The solution is to defer |
143 // showing the view. | 151 // showing the view. |
144 [self performSelector:@selector(openFaceTimePromptForURL:) | 152 [self performSelector:@selector(openPromptForURL:) |
145 withObject:URL | 153 withObject:URL |
146 afterDelay:0.0]; | 154 afterDelay:0.0]; |
147 return YES; | 155 return YES; |
148 } | 156 } |
149 | 157 |
150 // Use telprompt instead of tel because telprompt returns user back to | |
151 // Chrome after phone call is completed/aborted. | |
152 if (gURL.SchemeIs("tel")) { | |
153 GURL::Replacements replacements; | |
154 replacements.SetSchemeStr("telprompt"); | |
155 URL = net::NSURLWithGURL(gURL.ReplaceComponents(replacements)); | |
156 DCHECK([[URL scheme] isEqualToString:@"telprompt"]); | |
157 } | |
158 | |
159 // Don't open external application if chrome is not active. | 158 // Don't open external application if chrome is not active. |
160 if ([[UIApplication sharedApplication] applicationState] != | 159 if ([[UIApplication sharedApplication] applicationState] != |
161 UIApplicationStateActive) | 160 UIApplicationStateActive) |
162 return NO; | 161 return NO; |
163 | 162 |
164 if (experimental_flags::IsExternalApplicationPromptEnabled()) { | 163 if (experimental_flags::IsExternalApplicationPromptEnabled()) { |
165 // Prompt user to open itunes when opening it is not a result of a link | 164 // Prompt user to open itunes when opening it is not a result of a link |
166 // click. | 165 // click. |
167 if (!linkClicked && UrlHasAppStoreScheme(gURL)) { | 166 if (!linkClicked && UrlHasAppStoreScheme(gURL)) { |
168 [self performSelector:@selector(openExternalAppWithPromptForURL:) | 167 [self performSelector:@selector(openExternalAppWithPromptForURL:) |
169 withObject:URL | 168 withObject:URL |
170 afterDelay:0.0]; | 169 afterDelay:0.0]; |
171 return YES; | 170 return YES; |
172 } | 171 } |
173 } | 172 } |
174 | 173 |
175 // If the following call returns YES, an external application is about to be | 174 // If the following call returns YES, an external application is about to be |
176 // launched and Chrome will go into the background now. | 175 // launched and Chrome will go into the background now. |
177 // TODO(crbug.com/622735): This call still needs to be updated. | 176 // TODO(crbug.com/622735): This call still needs to be updated. |
178 // It's heavily nested so some refactoring is needed. | 177 // It's heavily nested so some refactoring is needed. |
179 return [[UIApplication sharedApplication] openURL:URL]; | 178 return [[UIApplication sharedApplication] openURL:URL]; |
180 } | 179 } |
181 | 180 |
182 @end | 181 @end |
OLD | NEW |