Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Side by Side Diff: ios/chrome/common/physical_web/physical_web_request.mm

Issue 2413923002: Enable lost URL detection in the Physical Web scanner (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 [NSString stringWithUTF8String:google_apis::GetAPIKey().c_str()]; 89 [NSString stringWithUTF8String:google_apis::GetAPIKey().c_str()];
90 [components 90 [components
91 setQueryItems:@[ [NSURLQueryItem queryItemWithName:kKeyQueryItemName 91 setQueryItems:@[ [NSURLQueryItem queryItemWithName:kKeyQueryItemName
92 value:apiKey] ]]; 92 value:apiKey] ]];
93 NSURL* url = [components URL]; 93 NSURL* url = [components URL];
94 request_.reset([[NSMutableURLRequest requestWithURL:url] retain]); 94 request_.reset([[NSMutableURLRequest requestWithURL:url] retain]);
95 [request_ setHTTPMethod:kHTTPPOSTRequestMethod]; 95 [request_ setHTTPMethod:kHTTPPOSTRequestMethod];
96 96
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_ requestURL] 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 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 108 // cause us to fetch metadata for the wrong region in languages such as
109 // Chinese that vary significantly between regions. 109 // Chinese that vary significantly between regions.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 block_.get()(nil, error); 225 block_.get()(nil, error);
226 } 226 }
227 return; 227 return;
228 } 228 }
229 229
230 // Read optional fields. 230 // Read optional fields.
231 NSString* iconString = base::mac::ObjCCast<NSString>(pageInfo[kIconKey]); 231 NSString* iconString = base::mac::ObjCCast<NSString>(pageInfo[kIconKey]);
232 NSString* description = 232 NSString* description =
233 base::mac::ObjCCast<NSString>(pageInfo[kDescriptionKey]); 233 base::mac::ObjCCast<NSString>(pageInfo[kDescriptionKey]);
234 NSString* title = base::mac::ObjCCast<NSString>(pageInfo[kTitleKey]); 234 NSString* title = base::mac::ObjCCast<NSString>(pageInfo[kTitleKey]);
235 NSURL* scannedUrl =
236 scannedUrlString ? [NSURL URLWithString:scannedUrlString] : nil;
237 NSURL* resolvedUrl = 235 NSURL* resolvedUrl =
238 resolvedUrlString ? [NSURL URLWithString:resolvedUrlString] : nil; 236 resolvedUrlString ? [NSURL URLWithString:resolvedUrlString] : nil;
239 NSURL* icon = iconString ? [NSURL URLWithString:iconString] : nil; 237 NSURL* icon = iconString ? [NSURL URLWithString:iconString] : nil;
240 base::scoped_nsobject<PhysicalWebDevice> device([[PhysicalWebDevice alloc] 238 base::scoped_nsobject<PhysicalWebDevice> device([[PhysicalWebDevice alloc]
241 initWithURL:resolvedUrl 239 initWithURL:resolvedUrl
242 requestURL:scannedUrl 240 requestURL:[device_ requestURL]
243 icon:icon 241 icon:icon
244 title:title 242 title:title
245 description:description 243 description:description
246 transmitPower:[device_ transmitPower] 244 transmitPower:[device_ transmitPower]
247 rssi:[device_ rssi] 245 rssi:[device_ rssi]
248 rank:physical_web::kMaxRank]); 246 rank:physical_web::kMaxRank]);
249 if (block_.get() != nil) { 247 if (block_.get() != nil) {
250 block_.get()(device, nil); 248 block_.get()(device, nil);
251 } 249 }
252 } 250 }
253 } 251 }
254 252
255 @end 253 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698