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_scanner.h" | 5 #import "ios/chrome/common/physical_web/physical_web_scanner.h" |
6 | 6 |
7 #import <CoreBluetooth/CoreBluetooth.h> | 7 #import <CoreBluetooth/CoreBluetooth.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #import "base/ios/weak_nsobject.h" | 12 #import "base/ios/weak_nsobject.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #import "base/mac/scoped_nsobject.h" | 14 #import "base/mac/scoped_nsobject.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/strings/sys_string_conversions.h" | 16 #include "base/strings/sys_string_conversions.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "components/physical_web/data_source/physical_web_data_source.h" | 18 #include "components/physical_web/data_source/physical_web_data_source.h" |
19 #include "device/bluetooth/uribeacon/uri_encoder.h" | 19 #include "device/bluetooth/uribeacon/uri_encoder.h" |
20 #import "ios/chrome/common/physical_web/physical_web_device.h" | 20 #import "ios/chrome/common/physical_web/physical_web_device.h" |
21 #import "ios/chrome/common/physical_web/physical_web_request.h" | 21 #import "ios/chrome/common/physical_web/physical_web_request.h" |
22 #import "ios/chrome/common/physical_web/physical_web_types.h" | 22 #import "ios/chrome/common/physical_web/physical_web_types.h" |
| 23 #include "url/gurl.h" |
23 | 24 |
24 #if !defined(__has_feature) || !__has_feature(objc_arc) | 25 #if !defined(__has_feature) || !__has_feature(objc_arc) |
25 #error "This file requires ARC support." | 26 #error "This file requires ARC support." |
26 #endif | 27 #endif |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 NSString* const kUriBeaconServiceUUID = @"FED8"; | 31 NSString* const kUriBeaconServiceUUID = @"FED8"; |
31 NSString* const kEddystoneBeaconServiceUUID = @"FEAA"; | 32 NSString* const kEddystoneBeaconServiceUUID = @"FEAA"; |
32 | 33 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 return NSOrderedDescending; | 179 return NSOrderedDescending; |
179 } | 180 } |
180 if ([device1 rank] < [device2 rank]) { | 181 if ([device1 rank] < [device2 rank]) { |
181 return NSOrderedAscending; | 182 return NSOrderedAscending; |
182 } | 183 } |
183 return NSOrderedSame; | 184 return NSOrderedSame; |
184 }]; | 185 }]; |
185 } | 186 } |
186 | 187 |
187 - (std::unique_ptr<base::ListValue>)metadata { | 188 - (std::unique_ptr<base::ListValue>)metadata { |
188 auto metadataList = base::MakeUnique<base::ListValue>(); | 189 auto metadataRet = base::MakeUnique<base::ListValue>(); |
189 | 190 |
190 for (PhysicalWebDevice* device in [self devices]) { | 191 for (PhysicalWebDevice* device in [self devices]) { |
191 std::string scannedUrl = | 192 std::string scannedUrl = |
192 base::SysNSStringToUTF8([[device requestURL] absoluteString]); | 193 base::SysNSStringToUTF8([[device requestURL] absoluteString]); |
193 std::string resolvedUrl = | 194 std::string resolvedUrl = |
194 base::SysNSStringToUTF8([[device url] absoluteString]); | 195 base::SysNSStringToUTF8([[device url] absoluteString]); |
195 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]); | 196 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]); |
196 std::string title = base::SysNSStringToUTF8([device title]); | 197 std::string title = base::SysNSStringToUTF8([device title]); |
197 std::string description = base::SysNSStringToUTF8([device description]); | 198 std::string description = base::SysNSStringToUTF8([device description]); |
198 | 199 |
199 auto metadataItem = base::MakeUnique<base::DictionaryValue>(); | 200 auto metadataItem = base::MakeUnique<base::DictionaryValue>(); |
200 metadataItem->SetString(physical_web::kScannedUrlKey, scannedUrl); | 201 metadataItem->SetString(physical_web::kScannedUrlKey, scannedUrl); |
201 metadataItem->SetString(physical_web::kResolvedUrlKey, resolvedUrl); | 202 metadataItem->SetString(physical_web::kResolvedUrlKey, resolvedUrl); |
202 metadataItem->SetString(physical_web::kIconUrlKey, icon); | 203 metadataItem->SetString(physical_web::kIconUrlKey, icon); |
203 metadataItem->SetString(physical_web::kTitleKey, title); | 204 metadataItem->SetString(physical_web::kTitleKey, title); |
204 metadataItem->SetString(physical_web::kDescriptionKey, description); | 205 metadataItem->SetString(physical_web::kDescriptionKey, description); |
205 metadataList->Append(std::move(metadataItem)); | 206 metadataRet->Append(std::move(metadataItem)); |
206 } | 207 } |
207 | 208 |
208 return metadataList; | 209 return metadataRet; |
| 210 } |
| 211 |
| 212 - (std::unique_ptr<physical_web::MetadataList>)metadataList { |
| 213 auto metadataRet = base::MakeUnique<physical_web::MetadataList>(); |
| 214 |
| 215 for (PhysicalWebDevice* device in [self devices]) { |
| 216 std::string scannedUrl = |
| 217 base::SysNSStringToUTF8([[device requestURL] absoluteString]); |
| 218 std::string resolvedUrl = |
| 219 base::SysNSStringToUTF8([[device url] absoluteString]); |
| 220 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]); |
| 221 std::string title = base::SysNSStringToUTF8([device title]); |
| 222 std::string description = base::SysNSStringToUTF8([device description]); |
| 223 |
| 224 physical_web::Metadata metadataItem; |
| 225 metadataItem.scanned_url = GURL(scannedUrl); |
| 226 metadataItem.resolved_url = GURL(resolvedUrl); |
| 227 metadataItem.icon_url = GURL(icon); |
| 228 metadataItem.title = title; |
| 229 metadataItem.description = description; |
| 230 metadataRet->push_back(std::move(metadataItem)); |
| 231 } |
| 232 |
| 233 return metadataRet; |
209 } | 234 } |
210 | 235 |
211 - (void)setNetworkRequestEnabled:(BOOL)enabled { | 236 - (void)setNetworkRequestEnabled:(BOOL)enabled { |
212 if (networkRequestEnabled_ == enabled) { | 237 if (networkRequestEnabled_ == enabled) { |
213 return; | 238 return; |
214 } | 239 } |
215 networkRequestEnabled_ = enabled; | 240 networkRequestEnabled_ = enabled; |
216 if (!networkRequestEnabled_) | 241 if (!networkRequestEnabled_) |
217 return; | 242 return; |
218 | 243 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 [strongSelf.get()->devices_ addObject:device]; | 517 [strongSelf.get()->devices_ addObject:device]; |
493 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; | 518 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; |
494 [strongSelf.get()->finalUrls_ addObject:[device url]]; | 519 [strongSelf.get()->finalUrls_ addObject:[device url]]; |
495 } | 520 } |
496 } | 521 } |
497 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; | 522 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; |
498 }]; | 523 }]; |
499 } | 524 } |
500 | 525 |
501 @end | 526 @end |
OLD | NEW |