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/spotlight/actions_spotlight_manager.h" | 5 #import "ios/chrome/app/spotlight/actions_spotlight_manager.h" |
6 | 6 |
7 #import <CoreSpotlight/CoreSpotlight.h> | 7 #import <CoreSpotlight/CoreSpotlight.h> |
8 | 8 |
9 #include "base/ios/weak_nsobject.h" | 9 #include "base/ios/weak_nsobject.h" |
10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
153 NSString* newTabTitle = | 153 NSString* newTabTitle = |
154 l10n_util::GetNSString(IDS_IOS_APPLICATION_SHORTCUT_NEWTAB_TITLE); | 154 l10n_util::GetNSString(IDS_IOS_APPLICATION_SHORTCUT_NEWTAB_TITLE); |
155 NSString* newTabAction = | 155 NSString* newTabAction = |
156 base::SysUTF8ToNSString(spotlight::kSpotlightActionNewTab); | 156 base::SysUTF8ToNSString(spotlight::kSpotlightActionNewTab); |
157 | 157 |
158 NSString* incognitoTitle = l10n_util::GetNSString( | 158 NSString* incognitoTitle = l10n_util::GetNSString( |
159 IDS_IOS_APPLICATION_SHORTCUT_NEWINCOGNITOTAB_TITLE); | 159 IDS_IOS_APPLICATION_SHORTCUT_NEWINCOGNITOTAB_TITLE); |
160 NSString* incognitoAction = base::SysUTF8ToNSString( | 160 NSString* incognitoAction = base::SysUTF8ToNSString( |
161 spotlight::kSpotlightActionNewIncognitoTab); | 161 spotlight::kSpotlightActionNewIncognitoTab); |
162 | 162 |
163 NSMutableArray* spotlightItems = [NSMutableArray | 163 NSString* qrScannerTitle = l10n_util::GetNSString( |
164 arrayWithObjects:[strongSelf getItemForAction:voiceSearchAction | 164 IDS_IOS_APPLICATION_SHORTCUT_QR_SCANNER_TITLE); |
165 title:voiceSearchTitle], | 165 NSString* qrScannerAction = |
166 [strongSelf getItemForAction:newTabAction | 166 base::SysUTF8ToNSString(spotlight::kSpotlightActionQRScanner); |
167 title:newTabTitle], | |
168 [strongSelf getItemForAction:incognitoAction | |
169 title:incognitoTitle], | |
170 nil]; | |
171 | 167 |
172 if (experimental_flags::IsQRCodeReaderEnabled()) { | 168 NSArray* spotlightItems = @[ |
173 NSString* qrScannerTitle = l10n_util::GetNSString( | 169 [strongSelf getItemForAction:voiceSearchAction |
174 IDS_IOS_APPLICATION_SHORTCUT_QR_SCANNER_TITLE); | 170 title:voiceSearchTitle], |
175 NSString* qrScannerAction = | 171 [strongSelf getItemForAction:newTabAction title:newTabTitle], |
176 base::SysUTF8ToNSString(spotlight::kSpotlightActionQRScanner); | 172 [strongSelf getItemForAction:incognitoAction title:incognitoTitle], |
177 | 173 [strongSelf getItemForAction:qrScannerAction title:qrScannerTitle], |
178 [spotlightItems | 174 nil |
sdefresne
2017/02/03 15:47:28
NSArray cannot store "nil" IIRC. Remove.
| |
179 addObject:[strongSelf getItemForAction:qrScannerAction | 175 ]; |
180 title:qrScannerTitle]]; | |
181 } | |
182 | 176 |
183 [[CSSearchableIndex defaultSearchableIndex] | 177 [[CSSearchableIndex defaultSearchableIndex] |
184 indexSearchableItems:spotlightItems | 178 indexSearchableItems:spotlightItems |
185 completionHandler:nil]; | 179 completionHandler:nil]; |
186 }); | 180 }); |
187 }]; | 181 }]; |
188 } | 182 } |
189 | 183 |
190 - (CSSearchableItem*)getItemForAction:(NSString*)action title:(NSString*)title { | 184 - (CSSearchableItem*)getItemForAction:(NSString*)action title:(NSString*)title { |
191 base::scoped_nsobject<CSSearchableItemAttributeSet> attributeSet( | 185 base::scoped_nsobject<CSSearchableItemAttributeSet> attributeSet( |
192 [[CSSearchableItemAttributeSet alloc] | 186 [[CSSearchableItemAttributeSet alloc] |
193 initWithItemContentType:spotlight::StringFromSpotlightDomain( | 187 initWithItemContentType:spotlight::StringFromSpotlightDomain( |
194 spotlight::DOMAIN_ACTIONS)]); | 188 spotlight::DOMAIN_ACTIONS)]); |
195 [attributeSet setTitle:title]; | 189 [attributeSet setTitle:title]; |
196 [attributeSet setDisplayName:title]; | 190 [attributeSet setDisplayName:title]; |
197 | 191 |
198 NSString* domainID = | 192 NSString* domainID = |
199 spotlight::StringFromSpotlightDomain(spotlight::DOMAIN_ACTIONS); | 193 spotlight::StringFromSpotlightDomain(spotlight::DOMAIN_ACTIONS); |
200 NSString* itemID = [NSString stringWithFormat:@"%@.%@", domainID, action]; | 194 NSString* itemID = [NSString stringWithFormat:@"%@.%@", domainID, action]; |
201 | 195 |
202 return [self spotlightItemWithItemID:itemID attributeSet:attributeSet]; | 196 return [self spotlightItemWithItemID:itemID attributeSet:attributeSet]; |
203 } | 197 } |
204 | 198 |
205 @end | 199 @end |
OLD | NEW |