Commit 9816d5ee authored by sdefresne's avatar sdefresne Committed by Commit bot

[iOS] Upstream XCallbackParameters

XCallbackParameters holds the information about an x-callback request from
another application.

BUG=429756

Review URL: https://codereview.chromium.org/1095203006

Cr-Commit-Position: refs/heads/master@{#326793}
parent 36b51750
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_XCALLBACK_PARAMETERS_H_
#define IOS_CHROME_BROWSER_XCALLBACK_PARAMETERS_H_
#import <Foundation/Foundation.h>
#include "url/gurl.h"
// This class contains the defining parameters for an XCallback request from
// another app.
@interface XCallbackParameters : NSObject<NSCoding, NSCopying>
// The id of the calling app.
@property(nonatomic, readonly, copy) NSString* sourceAppId;
// The user visible name of the calling app. Can be nil.
@property(nonatomic, readonly, copy) NSString* sourceAppName;
// x-callback-url::x-success URL. If the app is opened using a x-callback-url
// compliant URL, the value of this parameter is used as callback URL when the
// user taps the back button.
@property(nonatomic, readonly) const GURL& successURL;
// Flag to force the creation of a new tab. Default YES.
@property(nonatomic, readonly) BOOL createNewTab;
- (instancetype)initWithSourceAppId:(NSString*)sourceAppId
sourceAppName:(NSString*)sourceAppName
successURL:(const GURL&)successURL
createNewTab:(BOOL)createNewTab
NS_DESIGNATED_INITIALIZER;
@end
#endif // IOS_CHROME_BROWSER_XCALLBACK_PARAMETERS_H_
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/xcallback_parameters.h"
#include "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
namespace {
NSString* const kSourceAppIdKey = @"sourceAppId";
NSString* const kSourceAppNameKey = @"sourceAppName";
NSString* const kSuccessURLKey = @"successURL";
NSString* const kCreateNewTabKey = @"createNewTab";
}
@interface XCallbackParameters () {
base::scoped_nsobject<NSString> _sourceAppId;
base::scoped_nsobject<NSString> _sourceAppName;
GURL _successURL;
BOOL _createNewTab;
}
@end
@implementation XCallbackParameters
@synthesize successURL = _successURL;
@synthesize createNewTab = _createNewTab;
- (instancetype)initWithSourceAppId:(NSString*)sourceAppId
sourceAppName:(NSString*)sourceAppName
successURL:(const GURL&)successURL
createNewTab:(BOOL)createNewTab {
self = [super init];
if (self) {
_sourceAppId.reset([sourceAppId copy]);
_sourceAppName.reset([sourceAppName copy]);
_successURL = successURL;
_createNewTab = createNewTab;
}
return self;
}
- (NSString*)description {
return [NSString stringWithFormat:@"SourceApp: %@ (%@)\nSuccessURL: %s\n",
_sourceAppName.get(), _sourceAppId.get(),
_successURL.spec().c_str()];
}
- (NSString*)sourceAppId {
return _sourceAppId.get();
}
- (NSString*)sourceAppName {
return _sourceAppName.get();
}
#pragma mark - NSCoding Methods
- (instancetype)initWithCoder:(NSCoder*)aDecoder {
GURL successURL;
NSString* successURLStr = [aDecoder decodeObjectForKey:kSuccessURLKey];
if (successURLStr)
_successURL = GURL(base::SysNSStringToUTF8(successURLStr));
return
[self initWithSourceAppId:[aDecoder decodeObjectForKey:kSourceAppIdKey]
sourceAppName:[aDecoder decodeObjectForKey:kSourceAppNameKey]
successURL:successURL
createNewTab:[aDecoder decodeBoolForKey:kCreateNewTabKey]];
}
- (void)encodeWithCoder:(NSCoder*)aCoder {
[aCoder encodeObject:_sourceAppId forKey:kSourceAppIdKey];
[aCoder encodeObject:_sourceAppName forKey:kSourceAppNameKey];
if (_successURL.is_valid()) {
NSString* successStr = base::SysUTF8ToNSString(_successURL.spec());
[aCoder encodeObject:successStr forKey:kSuccessURLKey];
}
[aCoder encodeBool:_createNewTab forKey:kCreateNewTabKey];
}
#pragma mark - NSCopying Methods
- (instancetype)copyWithZone:(NSZone*)zone {
XCallbackParameters* copy = [[[self class] allocWithZone:zone] init];
copy->_sourceAppId.reset([_sourceAppId copy]);
copy->_sourceAppName.reset([_sourceAppName copy]);
copy->_successURL = _successURL;
copy->_createNewTab = _createNewTab;
return copy;
}
@end
......@@ -236,6 +236,8 @@
'browser/web/dom_altering_lock.mm',
'browser/web_resource/ios_web_resource_service.cc',
'browser/web_resource/ios_web_resource_service.h',
'browser/xcallback_parameters.h',
'browser/xcallback_parameters.mm',
],
},
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment