Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: ios/chrome/app/application_delegate/user_activity_handler.mm

Issue 2621943002: [ObjC ARC] Converts ios/chrome/app/application_delegate:application_delegate_internal to ARC. (Closed)
Patch Set: comment Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/app/application_delegate/url_opener.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
34 #if !defined(__has_feature) || !__has_feature(objc_arc)
35 #error "This file requires ARC support."
36 #endif
37
35 using base::UserMetricsAction; 38 using base::UserMetricsAction;
36 39
37 namespace { 40 namespace {
38 // Constants for 3D touch application static shortcuts. 41 // Constants for 3D touch application static shortcuts.
39 NSString* const kShortcutNewTab = @"OpenNewTab"; 42 NSString* const kShortcutNewTab = @"OpenNewTab";
40 NSString* const kShortcutNewIncognitoTab = @"OpenIncognitoTab"; 43 NSString* const kShortcutNewIncognitoTab = @"OpenIncognitoTab";
41 NSString* const kShortcutVoiceSearch = @"OpenVoiceSearch"; 44 NSString* const kShortcutVoiceSearch = @"OpenVoiceSearch";
42 NSString* const kShortcutQRScanner = @"OpenQRScanner"; 45 NSString* const kShortcutQRScanner = @"OpenQRScanner";
43 } // namespace 46 } // namespace
44 47
(...skipping 24 matching lines...) Expand all
69 handoff::Origin origin = handoff::OriginFromString(originString); 72 handoff::Origin origin = handoff::OriginFromString(originString);
70 UMA_HISTOGRAM_ENUMERATION("IOS.Handoff.Origin", origin, 73 UMA_HISTOGRAM_ENUMERATION("IOS.Handoff.Origin", origin,
71 handoff::ORIGIN_COUNT); 74 handoff::ORIGIN_COUNT);
72 } else if ([userActivity.activityType 75 } else if ([userActivity.activityType
73 isEqualToString:NSUserActivityTypeBrowsingWeb]) { 76 isEqualToString:NSUserActivityTypeBrowsingWeb]) {
74 // App was launched as the result of a Universal Link navigation. The value 77 // App was launched as the result of a Universal Link navigation. The value
75 // of userActivity.webpageURL is not used. The only supported action 78 // of userActivity.webpageURL is not used. The only supported action
76 // at this time is opening a New Tab Page. 79 // at this time is opening a New Tab Page.
77 GURL newTabURL(kChromeUINewTabURL); 80 GURL newTabURL(kChromeUINewTabURL);
78 webpageURL = net::NSURLWithGURL(newTabURL); 81 webpageURL = net::NSURLWithGURL(newTabURL);
79 base::scoped_nsobject<AppStartupParameters> startupParams( 82 AppStartupParameters* startupParams =
80 [[AppStartupParameters alloc] initWithExternalURL:newTabURL]); 83 [[AppStartupParameters alloc] initWithExternalURL:newTabURL];
81 [startupInformation setStartupParameters:startupParams]; 84 [startupInformation setStartupParameters:startupParams];
82 base::RecordAction(base::UserMetricsAction("IOSLaunchedByUniversalLink")); 85 base::RecordAction(base::UserMetricsAction("IOSLaunchedByUniversalLink"));
83 } else if (spotlight::IsSpotlightAvailable() && 86 } else if (spotlight::IsSpotlightAvailable() &&
84 [userActivity.activityType 87 [userActivity.activityType
85 isEqualToString:CSSearchableItemActionType]) { 88 isEqualToString:CSSearchableItemActionType]) {
86 // App was launched by iOS as the result of a tap on a Spotlight Search 89 // App was launched by iOS as the result of a tap on a Spotlight Search
87 // result. 90 // result.
88 NSString* itemID = 91 NSString* itemID =
89 [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier]; 92 [userActivity.userInfo objectForKey:CSSearchableItemActivityIdentifier];
90 spotlight::Domain domain = spotlight::SpotlightDomainFromString(itemID); 93 spotlight::Domain domain = spotlight::SpotlightDomainFromString(itemID);
91 if (domain == spotlight::DOMAIN_ACTIONS && 94 if (domain == spotlight::DOMAIN_ACTIONS &&
92 !experimental_flags::IsSpotlightActionsEnabled()) { 95 !experimental_flags::IsSpotlightActionsEnabled()) {
93 return NO; 96 return NO;
94 } 97 }
95 UMA_HISTOGRAM_ENUMERATION("IOS.Spotlight.Origin", domain, 98 UMA_HISTOGRAM_ENUMERATION("IOS.Spotlight.Origin", domain,
96 spotlight::DOMAIN_COUNT); 99 spotlight::DOMAIN_COUNT);
97 100
98 if (!itemID) { 101 if (!itemID) {
99 return NO; 102 return NO;
100 } 103 }
101 if (domain == spotlight::DOMAIN_ACTIONS) { 104 if (domain == spotlight::DOMAIN_ACTIONS) {
102 webpageURL = 105 webpageURL =
103 [NSURL URLWithString:base::SysUTF8ToNSString(kChromeUINewTabURL)]; 106 [NSURL URLWithString:base::SysUTF8ToNSString(kChromeUINewTabURL)];
104 base::scoped_nsobject<AppStartupParameters> startupParams( 107 AppStartupParameters* startupParams = [[AppStartupParameters alloc]
105 [[AppStartupParameters alloc] 108 initWithExternalURL:GURL(kChromeUINewTabURL)];
106 initWithExternalURL:GURL(kChromeUINewTabURL)]);
107 BOOL startupParamsSet = spotlight::SetStartupParametersForSpotlightAction( 109 BOOL startupParamsSet = spotlight::SetStartupParametersForSpotlightAction(
108 itemID, startupParams); 110 itemID, startupParams);
109 if (!startupParamsSet) { 111 if (!startupParamsSet) {
110 return NO; 112 return NO;
111 } 113 }
112 [startupInformation setStartupParameters:startupParams]; 114 [startupInformation setStartupParameters:startupParams];
113 } else if (!webpageURL && base::ios::IsRunningOnIOS10OrLater()) { 115 } else if (!webpageURL && base::ios::IsRunningOnIOS10OrLater()) {
114 // spotlight::GetURLForSpotlightItemID uses CSSearchQuery, which is only 116 // spotlight::GetURLForSpotlightItemID uses CSSearchQuery, which is only
115 // supported from iOS 10. 117 // supported from iOS 10.
116 spotlight::GetURLForSpotlightItemID(itemID, ^(NSURL* contentURL) { 118 spotlight::GetURLForSpotlightItemID(itemID, ^(NSURL* contentURL) {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 setStartupParameters:nil]; 169 setStartupParameters:nil];
168 }]; 170 }];
169 return YES; 171 return YES;
170 } 172 }
171 173
172 // Don't record the first action as a user action, since it will not be 174 // Don't record the first action as a user action, since it will not be
173 // initiated by the user. 175 // initiated by the user.
174 [startupInformation resetFirstUserActionRecorder]; 176 [startupInformation resetFirstUserActionRecorder];
175 177
176 if (![startupInformation startupParameters]) { 178 if (![startupInformation startupParameters]) {
177 base::scoped_nsobject<AppStartupParameters> startupParams( 179 AppStartupParameters* startupParams =
178 [[AppStartupParameters alloc] initWithExternalURL:webpageGURL]); 180 [[AppStartupParameters alloc] initWithExternalURL:webpageGURL];
179 [startupInformation setStartupParameters:startupParams]; 181 [startupInformation setStartupParameters:startupParams];
180 } 182 }
181 return YES; 183 return YES;
182 } 184 }
183 185
184 + (void)performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem 186 + (void)performActionForShortcutItem:(UIApplicationShortcutItem*)shortcutItem
185 completionHandler:(void (^)(BOOL succeeded))completionHandler 187 completionHandler:(void (^)(BOOL succeeded))completionHandler
186 tabOpener:(id<TabOpening>)tabOpener 188 tabOpener:(id<TabOpening>)tabOpener
187 startupInformation:(id<StartupInformation>)startupInformation 189 startupInformation:(id<StartupInformation>)startupInformation
188 browserViewInformation: 190 browserViewInformation:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 } 251 }
250 } 252 }
251 253
252 #pragma mark - Internal methods. 254 #pragma mark - Internal methods.
253 255
254 + (BOOL)handleShortcutItem:(UIApplicationShortcutItem*)shortcutItem 256 + (BOOL)handleShortcutItem:(UIApplicationShortcutItem*)shortcutItem
255 startupInformation:(id<StartupInformation>)startupInformation { 257 startupInformation:(id<StartupInformation>)startupInformation {
256 if ([startupInformation isPresentingFirstRunUI]) 258 if ([startupInformation isPresentingFirstRunUI])
257 return NO; 259 return NO;
258 260
259 base::scoped_nsobject<AppStartupParameters> startupParams( 261 AppStartupParameters* startupParams = [[AppStartupParameters alloc]
260 [[AppStartupParameters alloc] 262 initWithExternalURL:GURL(kChromeUINewTabURL)];
261 initWithExternalURL:GURL(kChromeUINewTabURL)]);
262 263
263 if ([shortcutItem.type isEqualToString:kShortcutNewTab]) { 264 if ([shortcutItem.type isEqualToString:kShortcutNewTab]) {
264 base::RecordAction(UserMetricsAction("ApplicationShortcut.NewTabPressed")); 265 base::RecordAction(UserMetricsAction("ApplicationShortcut.NewTabPressed"));
265 [startupInformation setStartupParameters:startupParams]; 266 [startupInformation setStartupParameters:startupParams];
266 return YES; 267 return YES;
267 268
268 } else if ([shortcutItem.type isEqualToString:kShortcutNewIncognitoTab]) { 269 } else if ([shortcutItem.type isEqualToString:kShortcutNewIncognitoTab]) {
269 base::RecordAction( 270 base::RecordAction(
270 UserMetricsAction("ApplicationShortcut.NewIncognitoTabPressed")); 271 UserMetricsAction("ApplicationShortcut.NewIncognitoTabPressed"));
271 [startupParams setLaunchInIncognito:YES]; 272 [startupParams setLaunchInIncognito:YES];
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 for (Tab* tab in tabModel) { 312 for (Tab* tab in tabModel) {
312 if ([tab.tabId isEqualToString:tabID]) { 313 if ([tab.tabId isEqualToString:tabID]) {
313 [tab evaluateU2FResultFromURL:URL]; 314 [tab evaluateU2FResultFromURL:URL];
314 return; 315 return;
315 } 316 }
316 } 317 }
317 } 318 }
318 } 319 }
319 320
320 @end 321 @end
OLDNEW
« no previous file with comments | « ios/chrome/app/application_delegate/url_opener.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698