OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/xcallback_parameters.h" |
| 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
| 8 #include "base/strings/sys_string_conversions.h" |
| 9 |
| 10 namespace { |
| 11 NSString* const kSourceAppIdKey = @"sourceAppId"; |
| 12 NSString* const kSourceAppNameKey = @"sourceAppName"; |
| 13 NSString* const kSuccessURLKey = @"successURL"; |
| 14 NSString* const kCreateNewTabKey = @"createNewTab"; |
| 15 } |
| 16 |
| 17 @interface XCallbackParameters () { |
| 18 base::scoped_nsobject<NSString> _sourceAppId; |
| 19 base::scoped_nsobject<NSString> _sourceAppName; |
| 20 GURL _successURL; |
| 21 BOOL _createNewTab; |
| 22 } |
| 23 @end |
| 24 |
| 25 @implementation XCallbackParameters |
| 26 |
| 27 @synthesize successURL = _successURL; |
| 28 @synthesize createNewTab = _createNewTab; |
| 29 |
| 30 - (instancetype)initWithSourceAppId:(NSString*)sourceAppId |
| 31 sourceAppName:(NSString*)sourceAppName |
| 32 successURL:(const GURL&)successURL |
| 33 createNewTab:(BOOL)createNewTab { |
| 34 self = [super init]; |
| 35 if (self) { |
| 36 _sourceAppId.reset([sourceAppId copy]); |
| 37 _sourceAppName.reset([sourceAppName copy]); |
| 38 _successURL = successURL; |
| 39 _createNewTab = createNewTab; |
| 40 } |
| 41 return self; |
| 42 } |
| 43 |
| 44 - (NSString*)description { |
| 45 return [NSString stringWithFormat:@"SourceApp: %@ (%@)\nSuccessURL: %s\n", |
| 46 _sourceAppName.get(), _sourceAppId.get(), |
| 47 _successURL.spec().c_str()]; |
| 48 } |
| 49 |
| 50 - (NSString*)sourceAppId { |
| 51 return _sourceAppId.get(); |
| 52 } |
| 53 |
| 54 - (NSString*)sourceAppName { |
| 55 return _sourceAppName.get(); |
| 56 } |
| 57 |
| 58 #pragma mark - NSCoding Methods |
| 59 |
| 60 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
| 61 GURL successURL; |
| 62 NSString* successURLStr = [aDecoder decodeObjectForKey:kSuccessURLKey]; |
| 63 if (successURLStr) |
| 64 _successURL = GURL(base::SysNSStringToUTF8(successURLStr)); |
| 65 |
| 66 return |
| 67 [self initWithSourceAppId:[aDecoder decodeObjectForKey:kSourceAppIdKey] |
| 68 sourceAppName:[aDecoder decodeObjectForKey:kSourceAppNameKey] |
| 69 successURL:successURL |
| 70 createNewTab:[aDecoder decodeBoolForKey:kCreateNewTabKey]]; |
| 71 } |
| 72 |
| 73 - (void)encodeWithCoder:(NSCoder*)aCoder { |
| 74 [aCoder encodeObject:_sourceAppId forKey:kSourceAppIdKey]; |
| 75 [aCoder encodeObject:_sourceAppName forKey:kSourceAppNameKey]; |
| 76 if (_successURL.is_valid()) { |
| 77 NSString* successStr = base::SysUTF8ToNSString(_successURL.spec()); |
| 78 [aCoder encodeObject:successStr forKey:kSuccessURLKey]; |
| 79 } |
| 80 [aCoder encodeBool:_createNewTab forKey:kCreateNewTabKey]; |
| 81 } |
| 82 |
| 83 #pragma mark - NSCopying Methods |
| 84 |
| 85 - (instancetype)copyWithZone:(NSZone*)zone { |
| 86 XCallbackParameters* copy = [[[self class] allocWithZone:zone] init]; |
| 87 copy->_sourceAppId.reset([_sourceAppId copy]); |
| 88 copy->_sourceAppName.reset([_sourceAppName copy]); |
| 89 copy->_successURL = _successURL; |
| 90 copy->_createNewTab = _createNewTab; |
| 91 return copy; |
| 92 } |
| 93 |
| 94 @end |
OLD | NEW |