| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/physical_web/physical_web_request.h" | 5 #import "ios/chrome/common/physical_web/physical_web_request.h" |
| 6 | 6 |
| 7 #include "base/ios/weak_nsobject.h" | 7 #include "base/ios/weak_nsobject.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 // body of the POST request. | 97 // body of the POST request. |
| 98 NSDictionary* jsonBody = | 98 NSDictionary* jsonBody = |
| 99 @{ kUrlsKey : @[ @{kUrlKey : [[device_ url] absoluteString]} ] }; | 99 @{ kUrlsKey : @[ @{kUrlKey : [[device_ url] absoluteString]} ] }; |
| 100 [request_ setHTTPBody:[NSJSONSerialization dataWithJSONObject:jsonBody | 100 [request_ setHTTPBody:[NSJSONSerialization dataWithJSONObject:jsonBody |
| 101 options:0 | 101 options:0 |
| 102 error:NULL]]; | 102 error:NULL]]; |
| 103 [request_ setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; | 103 [request_ setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; |
| 104 [request_ setValue:base::SysUTF8ToNSString(GetUserAgent()) | 104 [request_ setValue:base::SysUTF8ToNSString(GetUserAgent()) |
| 105 forHTTPHeaderField:@"User-Agent"]; | 105 forHTTPHeaderField:@"User-Agent"]; |
| 106 | 106 |
| 107 // Set the Accept-Language header from the locale language code. This may |
| 108 // cause us to fetch metadata for the wrong region in languages such as |
| 109 // Chinese that vary significantly between regions. |
| 110 // TODO(mattreynolds): Use the same Accept-Language string as WKWebView. |
| 111 NSString* acceptLanguage = |
| 112 [[NSLocale currentLocale] objectForKey:NSLocaleLanguageCode]; |
| 113 [request_ setValue:acceptLanguage forHTTPHeaderField:@"Acccept-Language"]; |
| 114 |
| 107 startDate_.reset([[NSDate date] retain]); | 115 startDate_.reset([[NSDate date] retain]); |
| 108 // Starts the request. | 116 // Starts the request. |
| 109 NSURLSession* session = | 117 NSURLSession* session = |
| 110 [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration | 118 [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration |
| 111 ephemeralSessionConfiguration] | 119 ephemeralSessionConfiguration] |
| 112 delegate:nil | 120 delegate:nil |
| 113 delegateQueue:[NSOperationQueue mainQueue]]; | 121 delegateQueue:[NSOperationQueue mainQueue]]; |
| 114 base::WeakNSObject<PhysicalWebRequest> weakSelf(self); | 122 base::WeakNSObject<PhysicalWebRequest> weakSelf(self); |
| 115 SessionCompletionProceduralBlock completionHandler = | 123 SessionCompletionProceduralBlock completionHandler = |
| 116 ^(NSData* data, NSURLResponse* response, NSError* error) { | 124 ^(NSData* data, NSURLResponse* response, NSError* error) { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 transmitPower:[device_ transmitPower] | 246 transmitPower:[device_ transmitPower] |
| 239 rssi:[device_ rssi] | 247 rssi:[device_ rssi] |
| 240 rank:physical_web::kMaxRank]); | 248 rank:physical_web::kMaxRank]); |
| 241 if (block_.get() != nil) { | 249 if (block_.get() != nil) { |
| 242 block_.get()(device, nil); | 250 block_.get()(device, nil); |
| 243 } | 251 } |
| 244 } | 252 } |
| 245 } | 253 } |
| 246 | 254 |
| 247 @end | 255 @end |
| OLD | NEW |