| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/activity_services/activity_service_controller.h" | 5 #import "ios/chrome/browser/ui/activity_services/activity_service_controller.h" |
| 6 | 6 |
| 7 #import <MobileCoreServices/MobileCoreServices.h> | 7 #import <MobileCoreServices/MobileCoreServices.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 controller:controller]]; | 113 controller:controller]]; |
| 114 | 114 |
| 115 // Reading List and Print activities refer to iOS' version of these. | 115 // Reading List and Print activities refer to iOS' version of these. |
| 116 // Chrome-specific implementations of these two activities are provided below | 116 // Chrome-specific implementations of these two activities are provided below |
| 117 // in applicationActivitiesForData:controller: | 117 // in applicationActivitiesForData:controller: |
| 118 NSArray* excludedActivityTypes = @[ | 118 NSArray* excludedActivityTypes = @[ |
| 119 UIActivityTypeAddToReadingList, UIActivityTypePrint, | 119 UIActivityTypeAddToReadingList, UIActivityTypePrint, |
| 120 UIActivityTypeSaveToCameraRoll | 120 UIActivityTypeSaveToCameraRoll |
| 121 ]; | 121 ]; |
| 122 [activityViewController_ setExcludedActivityTypes:excludedActivityTypes]; | 122 [activityViewController_ setExcludedActivityTypes:excludedActivityTypes]; |
| 123 // Although |completionWithItemsHandler:...| is not present in the iOS | 123 |
| 124 // documentation, it is mentioned in the WWDC presentations (specifically | |
| 125 // 217_creating_extensions_for_ios_and_os_x_part_2.pdf) and available in | |
| 126 // header file UIKit.framework/UIActivityViewController.h as @property. | |
| 127 DCHECK([activityViewController_ | |
| 128 respondsToSelector:@selector(setCompletionWithItemsHandler:)]); | |
| 129 __weak ActivityServiceController* weakSelf = self; | 124 __weak ActivityServiceController* weakSelf = self; |
| 130 [activityViewController_ setCompletionWithItemsHandler:^( | 125 [activityViewController_ setCompletionWithItemsHandler:^( |
| 131 NSString* activityType, BOOL completed, | 126 NSString* activityType, BOOL completed, |
| 132 NSArray* returnedItems, NSError* activityError) { | 127 NSArray* returnedItems, NSError* activityError) { |
| 133 [weakSelf shareFinishedWithActivityType:activityType | 128 [weakSelf shareFinishedWithActivityType:activityType |
| 134 completed:completed | 129 completed:completed |
| 135 returnedItems:returnedItems | 130 returnedItems:returnedItems |
| 136 error:activityError]; | 131 error:activityError]; |
| 137 }]; | 132 }]; |
| 138 | 133 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 167 : ShareTo::ShareResult::SHARE_CANCEL; | 162 : ShareTo::ShareResult::SHARE_CANCEL; |
| 168 if (activity_type_util::IsPasswordAppExActivity(activityType)) { | 163 if (activity_type_util::IsPasswordAppExActivity(activityType)) { |
| 169 // A compatible Password Management App Extension was invoked. | 164 // A compatible Password Management App Extension was invoked. |
| 170 shouldResetUI = [self processItemsReturnedFromActivity:activityType | 165 shouldResetUI = [self processItemsReturnedFromActivity:activityType |
| 171 status:shareResult | 166 status:shareResult |
| 172 items:returnedItems]; | 167 items:returnedItems]; |
| 173 } else { | 168 } else { |
| 174 activity_type_util::ActivityType type = | 169 activity_type_util::ActivityType type = |
| 175 activity_type_util::TypeFromString(activityType); | 170 activity_type_util::TypeFromString(activityType); |
| 176 activity_type_util::RecordMetricForActivity(type); | 171 activity_type_util::RecordMetricForActivity(type); |
| 177 NSString* successMessage = | 172 NSString* completionMessage = |
| 178 activity_type_util::SuccessMessageForActivity(type); | 173 activity_type_util::CompletionMessageForActivity(type); |
| 179 [shareToDelegate_ shareDidComplete:shareResult | 174 [shareToDelegate_ shareDidComplete:shareResult |
| 180 successMessage:successMessage]; | 175 completionMessage:completionMessage]; |
| 181 } | 176 } |
| 182 } else { | 177 } else { |
| 183 [shareToDelegate_ shareDidComplete:ShareTo::ShareResult::SHARE_CANCEL | 178 [shareToDelegate_ shareDidComplete:ShareTo::ShareResult::SHARE_CANCEL |
| 184 successMessage:nil]; | 179 completionMessage:nil]; |
| 185 } | 180 } |
| 186 if (shouldResetUI) | 181 if (shouldResetUI) |
| 187 [self resetUserInterface]; | 182 [self resetUserInterface]; |
| 188 } | 183 } |
| 189 | 184 |
| 190 - (NSArray*)activityItemsForData:(ShareToData*)data { | 185 - (NSArray*)activityItemsForData:(ShareToData*)data { |
| 191 NSMutableArray* activityItems = [NSMutableArray array]; | 186 NSMutableArray* activityItems = [NSMutableArray array]; |
| 192 // ShareToData object guarantees that there is a NSURL. | 187 // ShareToData object guarantees that there is a NSURL. |
| 193 DCHECK(data.nsurl); | 188 DCHECK(data.nsurl); |
| 194 | 189 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 hasItemConformingToTypeIdentifier:(NSString*)kUTTypePropertyList]) | 248 hasItemConformingToTypeIdentifier:(NSString*)kUTTypePropertyList]) |
| 254 itemProvider = nil; | 249 itemProvider = nil; |
| 255 } | 250 } |
| 256 } | 251 } |
| 257 if (!itemProvider) { | 252 if (!itemProvider) { |
| 258 // ShareToDelegate callback method must still be called on incorrect | 253 // ShareToDelegate callback method must still be called on incorrect |
| 259 // |extensionItems|. | 254 // |extensionItems|. |
| 260 [shareToDelegate_ passwordAppExDidFinish:ShareTo::ShareResult::SHARE_ERROR | 255 [shareToDelegate_ passwordAppExDidFinish:ShareTo::ShareResult::SHARE_ERROR |
| 261 username:nil | 256 username:nil |
| 262 password:nil | 257 password:nil |
| 263 successMessage:nil]; | 258 completionMessage:nil]; |
| 264 return YES; | 259 return YES; |
| 265 } | 260 } |
| 266 | 261 |
| 267 // |completionHandler| is the block that will be executed once the | 262 // |completionHandler| is the block that will be executed once the |
| 268 // property list has been loaded from the attachment. | 263 // property list has been loaded from the attachment. |
| 269 void (^completionHandler)(id, NSError*) = ^(id item, NSError* error) { | 264 void (^completionHandler)(id, NSError*) = ^(id item, NSError* error) { |
| 270 ShareTo::ShareResult activityResult = result; | 265 ShareTo::ShareResult activityResult = result; |
| 271 NSString* username = nil; | 266 NSString* username = nil; |
| 272 NSString* password = nil; | 267 NSString* password = nil; |
| 273 NSString* message = nil; | 268 NSString* message = nil; |
| 274 NSDictionary* loginDictionary = base::mac::ObjCCast<NSDictionary>(item); | 269 NSDictionary* loginDictionary = base::mac::ObjCCast<NSDictionary>(item); |
| 275 if (error || !loginDictionary) { | 270 if (error || !loginDictionary) { |
| 276 activityResult = ShareTo::ShareResult::SHARE_ERROR; | 271 activityResult = ShareTo::ShareResult::SHARE_ERROR; |
| 277 } else { | 272 } else { |
| 278 username = loginDictionary[activity_services::kPasswordAppExUsernameKey]; | 273 username = loginDictionary[activity_services::kPasswordAppExUsernameKey]; |
| 279 password = loginDictionary[activity_services::kPasswordAppExPasswordKey]; | 274 password = loginDictionary[activity_services::kPasswordAppExPasswordKey]; |
| 280 activity_type_util::ActivityType type = | 275 activity_type_util::ActivityType type = |
| 281 activity_type_util::TypeFromString(activityType); | 276 activity_type_util::TypeFromString(activityType); |
| 282 activity_type_util::RecordMetricForActivity(type); | 277 activity_type_util::RecordMetricForActivity(type); |
| 283 message = activity_type_util::SuccessMessageForActivity(type); | 278 message = activity_type_util::CompletionMessageForActivity(type); |
| 284 } | 279 } |
| 285 [shareToDelegate_ passwordAppExDidFinish:activityResult | 280 [shareToDelegate_ passwordAppExDidFinish:activityResult |
| 286 username:username | 281 username:username |
| 287 password:password | 282 password:password |
| 288 successMessage:message]; | 283 completionMessage:message]; |
| 289 // Controller state can be reset only after delegate has processed the | 284 // Controller state can be reset only after delegate has processed the |
| 290 // item returned from the App Extension. | 285 // item returned from the App Extension. |
| 291 [self resetUserInterface]; | 286 [self resetUserInterface]; |
| 292 }; | 287 }; |
| 293 [itemProvider loadItemForTypeIdentifier:(NSString*)kUTTypePropertyList | 288 [itemProvider loadItemForTypeIdentifier:(NSString*)kUTTypePropertyList |
| 294 options:nil | 289 options:nil |
| 295 completionHandler:completionHandler]; | 290 completionHandler:completionHandler]; |
| 296 return NO; | 291 return NO; |
| 297 } | 292 } |
| 298 | 293 |
| 299 #pragma mark - For Testing | 294 #pragma mark - For Testing |
| 300 | 295 |
| 301 - (void)setShareToDelegateForTesting:(id<ShareToDelegate>)delegate { | 296 - (void)setShareToDelegateForTesting:(id<ShareToDelegate>)delegate { |
| 302 shareToDelegate_ = delegate; | 297 shareToDelegate_ = delegate; |
| 303 } | 298 } |
| 304 | 299 |
| 305 @end | 300 @end |
| OLD | NEW |