Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/app/application_delegate/user_activity_handler.h" | 5 #import "ios/chrome/app/application_delegate/user_activity_handler.h" |
| 6 | 6 |
| 7 #import <CoreSpotlight/CoreSpotlight.h> | 7 #import <CoreSpotlight/CoreSpotlight.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include "base/ios/block_types.h" | 10 #include "base/ios/block_types.h" |
| 11 #include "base/ios/ios_util.h" | 11 #include "base/ios/ios_util.h" |
| 12 #include "base/ios/weak_nsobject.h" | |
| 13 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 13 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/user_metrics_action.h" | 14 #include "base/metrics/user_metrics_action.h" |
| 16 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 17 #include "components/handoff/handoff_utility.h" | 16 #include "components/handoff/handoff_utility.h" |
| 18 #import "ios/chrome/app/application_delegate/startup_information.h" | 17 #import "ios/chrome/app/application_delegate/startup_information.h" |
| 19 #import "ios/chrome/app/application_delegate/tab_opening.h" | 18 #import "ios/chrome/app/application_delegate/tab_opening.h" |
| 20 #include "ios/chrome/app/application_mode.h" | 19 #include "ios/chrome/app/application_mode.h" |
| 21 #import "ios/chrome/app/spotlight/actions_spotlight_manager.h" | 20 #import "ios/chrome/app/spotlight/actions_spotlight_manager.h" |
| 22 #import "ios/chrome/app/spotlight/spotlight_util.h" | 21 #import "ios/chrome/app/spotlight/spotlight_util.h" |
| 23 #include "ios/chrome/browser/app_startup_parameters.h" | 22 #include "ios/chrome/browser/app_startup_parameters.h" |
| 24 #include "ios/chrome/browser/chrome_url_constants.h" | 23 #include "ios/chrome/browser/chrome_url_constants.h" |
| 25 #include "ios/chrome/browser/experimental_flags.h" | 24 #include "ios/chrome/browser/experimental_flags.h" |
| 26 #include "ios/chrome/browser/metrics/first_user_action_recorder.h" | 25 #include "ios/chrome/browser/metrics/first_user_action_recorder.h" |
| 27 #import "ios/chrome/browser/tabs/tab.h" | 26 #import "ios/chrome/browser/tabs/tab.h" |
| 28 #import "ios/chrome/browser/tabs/tab_model.h" | 27 #import "ios/chrome/browser/tabs/tab_model.h" |
| 29 #import "ios/chrome/browser/u2f/u2f_controller.h" | 28 #import "ios/chrome/browser/u2f/u2f_controller.h" |
| 30 #import "ios/chrome/browser/ui/main/browser_view_information.h" | 29 #import "ios/chrome/browser/ui/main/browser_view_information.h" |
| 31 #import "net/base/mac/url_conversions.h" | 30 #import "net/base/mac/url_conversions.h" |
| 32 #include "ui/base/page_transition_types.h" | 31 #include "ui/base/page_transition_types.h" |
| 33 #include "url/gurl.h" | 32 #include "url/gurl.h" |
| 34 | 33 |
|
sdefresne
2017/01/17 14:48:29
Do you forgot to add ARC guards here?
stkhapugin
2017/01/17 14:53:55
Done.
| |
| 35 using base::UserMetricsAction; | 34 using base::UserMetricsAction; |
| 36 | 35 |
| 37 namespace { | 36 namespace { |
| 38 // Constants for 3D touch application static shortcuts. | 37 // Constants for 3D touch application static shortcuts. |
| 39 NSString* const kShortcutNewTab = @"OpenNewTab"; | 38 NSString* const kShortcutNewTab = @"OpenNewTab"; |
| 40 NSString* const kShortcutNewIncognitoTab = @"OpenIncognitoTab"; | 39 NSString* const kShortcutNewIncognitoTab = @"OpenIncognitoTab"; |
| 41 NSString* const kShortcutVoiceSearch = @"OpenVoiceSearch"; | 40 NSString* const kShortcutVoiceSearch = @"OpenVoiceSearch"; |
| 42 NSString* const kShortcutQRScanner = @"OpenQRScanner"; | 41 NSString* const kShortcutQRScanner = @"OpenQRScanner"; |
| 43 } // namespace | 42 } // namespace |
| 44 | 43 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 69 handoff::Origin origin = handoff::OriginFromString(originString); | 68 handoff::Origin origin = handoff::OriginFromString(originString); |
| 70 UMA_HISTOGRAM_ENUMERATION("IOS.Handoff.Origin", origin, | 69 UMA_HISTOGRAM_ENUMERATION("IOS.Handoff.Origin", origin, |
| 71 handoff::ORIGIN_COUNT); | 70 handoff::ORIGIN_COUNT); |
| 72 } else if ([userActivity.activityType | 71 } else if ([userActivity.activityType |
| 73 isEqualToString:NSUserActivityTypeBrowsingWeb]) { | 72 isEqualToString:NSUserActivityTypeBrowsingWeb]) { |
| 74 // App was launched as the result of a Universal Link navigation. The value | 73 // App was launched as the result of a Universal Link navigation. The value |
| 75 // of userActivity.webpageURL is not used. The only supported action | 74 // of userActivity.webpageURL is not used. The only supported action |
| 76 // at this time is opening a New Tab Page. | 75 // at this time is opening a New Tab Page. |
| 77 GURL newTabURL(kChromeUINewTabURL); | 76 GURL newTabURL(kChromeUINewTabURL); |
| 78 webpageURL = net::NSURLWithGURL(newTabURL); | 77 webpageURL = net::NSURLWithGURL(newTabURL); |
| 79 base::scoped_nsobject<AppStartupParameters> startupParams( | 78 AppStartupParameters* startupParams = |
| 80 [[AppStartupParameters alloc] initWithExternalURL:newTabURL]); | 79 [[AppStartupParameters alloc] initWithExternalURL:newTabURL]; |
| 81 [startupInformation setStartupParameters:startupParams]; | 80 [startupInformation setStartupParameters:startupParams]; |
| 82 base::RecordAction(base::UserMetricsAction("IOSLaunchedByUniversalLink")); | 81 base::RecordAction(base::UserMetricsAction("IOSLaunchedByUniversalLink")); |
| 83 } else if (spotlight::IsSpotlightAvailable() && | 82 } else if (spotlight::IsSpotlightAvailable() && |
| 84 [userActivity.activityType | 83 [userActivity.activityType |
| 85 isEqualToString:CSSearchableItemActionType]) { | 84 isEqualToString:CSSearchableItemActionType]) { |
| 86 // App was launched by iOS as the result of a tap on a Spotlight Search | 85 // App was launched by iOS as the result of a tap on a Spotlight Search |
| 87 // result. | 86 // result. |
| 88 NSString* itemID = | 87 NSString* itemID = |
| 89 [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier]; | 88 [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier]; |
| 90 spotlight::Domain domain = spotlight::SpotlightDomainFromString(itemID); | 89 spotlight::Domain domain = spotlight::SpotlightDomainFromString(itemID); |
| 91 if (domain == spotlight::DOMAIN_ACTIONS && | 90 if (domain == spotlight::DOMAIN_ACTIONS && |
| 92 !experimental_flags::IsSpotlightActionsEnabled()) { | 91 !experimental_flags::IsSpotlightActionsEnabled()) { |
| 93 return NO; | 92 return NO; |
| 94 } | 93 } |
| 95 UMA_HISTOGRAM_ENUMERATION("IOS.Spotlight.Origin", domain, | 94 UMA_HISTOGRAM_ENUMERATION("IOS.Spotlight.Origin", domain, |
| 96 spotlight::DOMAIN_COUNT); | 95 spotlight::DOMAIN_COUNT); |
| 97 | 96 |
| 98 if (!itemID) { | 97 if (!itemID) { |
| 99 return NO; | 98 return NO; |
| 100 } | 99 } |
| 101 if (domain == spotlight::DOMAIN_ACTIONS) { | 100 if (domain == spotlight::DOMAIN_ACTIONS) { |
| 102 webpageURL = | 101 webpageURL = |
| 103 [NSURL URLWithString:base::SysUTF8ToNSString(kChromeUINewTabURL)]; | 102 [NSURL URLWithString:base::SysUTF8ToNSString(kChromeUINewTabURL)]; |
| 104 base::scoped_nsobject<AppStartupParameters> startupParams( | 103 AppStartupParameters* startupParams = [[AppStartupParameters alloc] |
| 105 [[AppStartupParameters alloc] | 104 initWithExternalURL:GURL(kChromeUINewTabURL)]; |
| 106 initWithExternalURL:GURL(kChromeUINewTabURL)]); | |
| 107 BOOL startupParamsSet = spotlight::SetStartupParametersForSpotlightAction( | 105 BOOL startupParamsSet = spotlight::SetStartupParametersForSpotlightAction( |
| 108 itemID, startupParams); | 106 itemID, startupParams); |
| 109 if (!startupParamsSet) { | 107 if (!startupParamsSet) { |
| 110 return NO; | 108 return NO; |
| 111 } | 109 } |
| 112 [startupInformation setStartupParameters:startupParams]; | 110 [startupInformation setStartupParameters:startupParams]; |
| 113 } else if (!webpageURL && base::ios::IsRunningOnIOS10OrLater()) { | 111 } else if (!webpageURL && base::ios::IsRunningOnIOS10OrLater()) { |
| 114 // spotlight::GetURLForSpotlightItemID uses CSSearchQuery, which is only | 112 // spotlight::GetURLForSpotlightItemID uses CSSearchQuery, which is only |
| 115 // supported from iOS 10. | 113 // supported from iOS 10. |
| 116 spotlight::GetURLForSpotlightItemID(itemID, ^(NSURL* contentURL) { | 114 spotlight::GetURLForSpotlightItemID(itemID, ^(NSURL* contentURL) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 167 setStartupParameters:nil]; | 165 setStartupParameters:nil]; |
| 168 }]; | 166 }]; |
| 169 return YES; | 167 return YES; |
| 170 } | 168 } |
| 171 | 169 |
| 172 // Don't record the first action as a user action, since it will not be | 170 // Don't record the first action as a user action, since it will not be |
| 173 // initiated by the user. | 171 // initiated by the user. |
| 174 [startupInformation resetFirstUserActionRecorder]; | 172 [startupInformation resetFirstUserActionRecorder]; |
| 175 | 173 |
| 176 if (![startupInformation startupParameters]) { | 174 if (![startupInformation startupParameters]) { |
| 177 base::scoped_nsobject<AppStartupParameters> startupParams( | 175 AppStartupParameters* startupParams = |
| 178 [[AppStartupParameters alloc] initWithExternalURL:webpageGURL]); | 176 [[AppStartupParameters alloc] initWithExternalURL:webpageGURL]; |
| 179 [startupInformation setStartupParameters:startupParams]; | 177 [startupInformation setStartupParameters:startupParams]; |
| 180 } | 178 } |
| 181 return YES; | 179 return YES; |
| 182 } | 180 } |
| 183 | 181 |
| 184 + (void)performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem | 182 + (void)performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem |
| 185 completionHandler:(void (^)(BOOL succeeded))completionHandler | 183 completionHandler:(void (^)(BOOL succeeded))completionHandler |
| 186 tabOpener:(id<TabOpening>)tabOpener | 184 tabOpener:(id<TabOpening>)tabOpener |
| 187 startupInformation:(id<StartupInformation>)startupInformation | 185 startupInformation:(id<StartupInformation>)startupInformation |
| 188 browserViewInformation: | 186 browserViewInformation: |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 249 } | 247 } |
| 250 } | 248 } |
| 251 | 249 |
| 252 #pragma mark - Internal methods. | 250 #pragma mark - Internal methods. |
| 253 | 251 |
| 254 + (BOOL)handleShortcutItem:(UIApplicationShortcutItem*)shortcutItem | 252 + (BOOL)handleShortcutItem:(UIApplicationShortcutItem*)shortcutItem |
| 255 startupInformation:(id<StartupInformation>)startupInformation { | 253 startupInformation:(id<StartupInformation>)startupInformation { |
| 256 if ([startupInformation isPresentingFirstRunUI]) | 254 if ([startupInformation isPresentingFirstRunUI]) |
| 257 return NO; | 255 return NO; |
| 258 | 256 |
| 259 base::scoped_nsobject<AppStartupParameters> startupParams( | 257 AppStartupParameters* startupParams = [[AppStartupParameters alloc] |
| 260 [[AppStartupParameters alloc] | 258 initWithExternalURL:GURL(kChromeUINewTabURL)]; |
| 261 initWithExternalURL:GURL(kChromeUINewTabURL)]); | |
| 262 | 259 |
| 263 if ([shortcutItem.type isEqualToString:kShortcutNewTab]) { | 260 if ([shortcutItem.type isEqualToString:kShortcutNewTab]) { |
| 264 base::RecordAction(UserMetricsAction("ApplicationShortcut.NewTabPressed")); | 261 base::RecordAction(UserMetricsAction("ApplicationShortcut.NewTabPressed")); |
| 265 [startupInformation setStartupParameters:startupParams]; | 262 [startupInformation setStartupParameters:startupParams]; |
| 266 return YES; | 263 return YES; |
| 267 | 264 |
| 268 } else if ([shortcutItem.type isEqualToString:kShortcutNewIncognitoTab]) { | 265 } else if ([shortcutItem.type isEqualToString:kShortcutNewIncognitoTab]) { |
| 269 base::RecordAction( | 266 base::RecordAction( |
| 270 UserMetricsAction("ApplicationShortcut.NewIncognitoTabPressed")); | 267 UserMetricsAction("ApplicationShortcut.NewIncognitoTabPressed")); |
| 271 [startupParams setLaunchInIncognito:YES]; | 268 [startupParams setLaunchInIncognito:YES]; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 311 for (Tab* tab in tabModel) { | 308 for (Tab* tab in tabModel) { |
| 312 if ([tab.tabId isEqualToString:tabID]) { | 309 if ([tab.tabId isEqualToString:tabID]) { |
| 313 [tab evaluateU2FResultFromURL:URL]; | 310 [tab evaluateU2FResultFromURL:URL]; |
| 314 return; | 311 return; |
| 315 } | 312 } |
| 316 } | 313 } |
| 317 } | 314 } |
| 318 } | 315 } |
| 319 | 316 |
| 320 @end | 317 @end |
| OLD | NEW |