Fix deprecatation warning when building for recent SDKs on iOS/OS X.

Fixes the following compilation warning when using recent version of
the iOS or OS X SDK by using the recommended new API:

../../breakpad/src/common/mac/HTTPMultipartUpload.m:56:10: error: 'stringByAddingPercentEscapesUsingEncoding:' is deprecated: first deprecated in iOS 9.0 - Use -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid. [-Werror,-Wdeprecated-declarations]
    [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
         ^
CFURLCreateStringByAddingPercentEscapes

../../breakpad/src/common/mac/HTTPMultipartUpload.m:207:29: error: 'sendSynchronousRequest:returningResponse:error:' is deprecated: first deprecated in iOS 9.0 - Use [NSURLSession dataTaskWithRequest:completionHandler:] (see NSURLSession.h [-Werror,-Wdeprecated-declarations]
    data = [NSURLConnection sendSynchronousRequest:req
                            ^

../../breakpad/src/client/mac/handler/minidump_generator.cc:158:6: error: 'CFPropertyListCreateFromXMLData' is deprecated: first deprecated in iOS 8.0 - Use CFPropertyListCreateWithData instead. [-Werror,-Wdeprecated-declarations]
    (CFPropertyListCreateFromXMLData(NULL, data, kCFPropertyListImmutable,
     ^

BUG=https://bugs.chromium.org/p/google-breakpad/issues/detail?id=675
BUG=569158
R=mark@chromium.org

Review URL: https://codereview.chromium.org/1563223004 .
This commit is contained in:
Sylvain Defresne 2016-01-07 19:48:21 +01:00
parent bcf4cc2f9a
commit 98bea93a3e
2 changed files with 62 additions and 10 deletions

View File

@ -154,9 +154,9 @@ void MinidumpGenerator::GatherSystemInformation() {
if (!data) { if (!data) {
return; return;
} }
CFDictionaryRef list = static_cast<CFDictionaryRef> CFDictionaryRef list =
(CFPropertyListCreateFromXMLData(NULL, data, kCFPropertyListImmutable, static_cast<CFDictionaryRef>(CFPropertyListCreateWithData(
NULL)); NULL, data, kCFPropertyListImmutable, NULL, NULL));
CFRelease(data); CFRelease(data);
if (!list) { if (!list) {
return; return;

View File

@ -30,6 +30,62 @@
#import "HTTPMultipartUpload.h" #import "HTTPMultipartUpload.h"
#import "GTMDefines.h" #import "GTMDefines.h"
#include <Availability.h>
#include <AvailabilityMacros.h>
// As -[NSString stringByAddingPercentEscapesUsingEncoding:] has been
// deprecated with iOS 9.0 / OS X 10.11 SDKs, this function re-implements it
// using -[NSString stringByAddingPercentEncodingWithAllowedCharacters:] when
// using those SDKs.
static NSString *PercentEncodeNSString(NSString *key) {
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && defined(__IPHONE_9_0) && \
__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0) || \
(defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
defined(MAC_OS_X_VERSION_10_11) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11)
return [key stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet alphanumericCharacterSet]];
#else
return [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
#endif
}
// As -[NSURLConnection sendSynchronousRequest:returningResponse:error:] has
// been deprecated with iOS 9.0 / OS X 10.11 SDKs, this function re-implements
// it using -[NSURLSession dataTaskWithRequest:completionHandler:] when using
// those SDKs.
static NSData *SendSynchronousNSURLRequest(NSURLRequest *req,
NSURLResponse **response,
NSError **error) {
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && defined(__IPHONE_9_0) && \
__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0) || \
(defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
defined(MAC_OS_X_VERSION_10_11) && \
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11)
__block NSData* result = nil;
dispatch_semaphore_t wait_semaphone = dispatch_semaphore_create(0);
[[[NSURLSession sharedSession]
dataTaskWithRequest:req
completionHandler:^(NSData *data, NSURLResponse *resp,
NSError *err) {
if (error)
*error = err;
if (response)
*response = resp;
if (err == nil)
result = data;
dispatch_semaphore_signal(wait_semaphone);
}] resume];
dispatch_semaphore_wait(wait_semaphone, DISPATCH_TIME_FOREVER);
dispatch_release(wait_semaphone);
return result;
#else
return [NSURLConnection sendSynchronousRequest:req
returningResponse:response
error:error];
#endif
}
@interface HTTPMultipartUpload(PrivateMethods) @interface HTTPMultipartUpload(PrivateMethods)
- (NSString *)multipartBoundary; - (NSString *)multipartBoundary;
// Each of the following methods will append the starting multipart boundary, // Each of the following methods will append the starting multipart boundary,
@ -52,8 +108,7 @@
//============================================================================= //=============================================================================
- (NSData *)formDataForKey:(NSString *)key value:(NSString *)value { - (NSData *)formDataForKey:(NSString *)key value:(NSString *)value {
NSString *escaped = NSString *escaped = PercentEncodeNSString(key);
[key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *fmt = NSString *fmt =
@"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n%@\r\n"; @"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n%@\r\n";
NSString *form = [NSString stringWithFormat:fmt, boundary_, escaped, value]; NSString *form = [NSString stringWithFormat:fmt, boundary_, escaped, value];
@ -64,8 +119,7 @@
//============================================================================= //=============================================================================
- (NSData *)formDataForFileContents:(NSData *)contents name:(NSString *)name { - (NSData *)formDataForFileContents:(NSData *)contents name:(NSString *)name {
NSMutableData *data = [NSMutableData data]; NSMutableData *data = [NSMutableData data];
NSString *escaped = NSString *escaped = PercentEncodeNSString(name);
[name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *fmt = @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; " NSString *fmt = @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; "
"filename=\"minidump.dmp\"\r\nContent-Type: application/octet-stream\r\n\r\n"; "filename=\"minidump.dmp\"\r\nContent-Type: application/octet-stream\r\n\r\n";
NSString *pre = [NSString stringWithFormat:fmt, boundary_, escaped]; NSString *pre = [NSString stringWithFormat:fmt, boundary_, escaped];
@ -196,9 +250,7 @@
[[req HTTPBody] writeToURL:[req URL] options:0 error:error]; [[req HTTPBody] writeToURL:[req URL] options:0 error:error];
} else { } else {
NSURLResponse *response = nil; NSURLResponse *response = nil;
data = [NSURLConnection sendSynchronousRequest:req data = SendSynchronousNSURLRequest(req, &response, error);
returningResponse:&response
error:error];
response_ = (NSHTTPURLResponse *)[response retain]; response_ = (NSHTTPURLResponse *)[response retain];
} }
[req release]; [req release];