Chromium Code Reviews| 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> | |
| 8 | |
| 7 #include <string> | 9 #include <string> |
| 8 #include <vector> | 10 #include <vector> |
| 9 | 11 |
| 10 #import <CoreBluetooth/CoreBluetooth.h> | 12 #import "base/ios/weak_nsobject.h" |
| 11 | |
| 12 #include "base/ios/weak_nsobject.h" | |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #import "base/mac/scoped_nsobject.h" |
| 15 #include "base/macros.h" | |
| 16 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 17 #include "device/bluetooth/uribeacon/uri_encoder.h" | 16 #include "device/bluetooth/uribeacon/uri_encoder.h" |
| 18 #include "ios/chrome/common/physical_web/physical_web_device.h" | 17 #import "ios/chrome/common/physical_web/physical_web_device.h" |
| 19 #import "ios/chrome/common/physical_web/physical_web_request.h" | 18 #import "ios/chrome/common/physical_web/physical_web_request.h" |
| 20 #include "ios/chrome/common/physical_web/physical_web_types.h" | 19 #import "ios/chrome/common/physical_web/physical_web_types.h" |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| 23 | 22 |
| 24 NSString* const kUriBeaconServiceUUID = @"FED8"; | 23 NSString* const kUriBeaconServiceUUID = @"FED8"; |
| 25 NSString* const kEddystoneBeaconServiceUUID = @"FEAA"; | 24 NSString* const kEddystoneBeaconServiceUUID = @"FEAA"; |
| 26 | 25 |
| 27 enum BeaconType { | 26 enum BeaconType { |
| 28 BEACON_TYPE_NONE, | 27 BEACON_TYPE_NONE, |
| 29 BEACON_TYPE_URIBEACON, | 28 BEACON_TYPE_URIBEACON, |
| 30 BEACON_TYPE_EDDYSTONE, | 29 BEACON_TYPE_EDDYSTONE, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 if ([device1 rank] > [device2 rank]) { | 141 if ([device1 rank] > [device2 rank]) { |
| 143 return NSOrderedDescending; | 142 return NSOrderedDescending; |
| 144 } | 143 } |
| 145 if ([device1 rank] < [device2 rank]) { | 144 if ([device1 rank] < [device2 rank]) { |
| 146 return NSOrderedAscending; | 145 return NSOrderedAscending; |
| 147 } | 146 } |
| 148 return NSOrderedSame; | 147 return NSOrderedSame; |
| 149 }]; | 148 }]; |
| 150 } | 149 } |
| 151 | 150 |
| 151 - (std::unique_ptr<base::ListValue>)metadata { | |
| 152 std::unique_ptr<base::ListValue> metadataList(new base::ListValue()); | |
|
sdefresne
2016/08/04 19:23:48
auto metadataList = base::MakeUniquePtr<base::List
mattreynolds
2016/08/04 21:14:34
Done.
| |
| 153 | |
| 154 NSInteger deviceCount = [[self devices] count]; | |
| 155 for (int i = 0; i < deviceCount; ++i) { | |
| 156 PhysicalWebDevice* device = [[self devices] objectAtIndex:i]; | |
| 157 std::string scannedUrl = | |
| 158 base::SysNSStringToUTF8([[device requestURL] absoluteString]); | |
| 159 std::string resolvedUrl = | |
| 160 base::SysNSStringToUTF8([[device url] absoluteString]); | |
| 161 std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]); | |
| 162 std::string title = base::SysNSStringToUTF8([device title]); | |
| 163 std::string description = base::SysNSStringToUTF8([device description]); | |
| 164 | |
| 165 base::DictionaryValue* metadataItem = new base::DictionaryValue(); | |
|
sdefresne
2016/08/04 19:23:48
auto metadataItem = base::MakeUnique<base::Diction
mattreynolds
2016/08/04 21:14:34
Done.
| |
| 166 metadataItem->SetString("scannedUrl", scannedUrl); | |
| 167 metadataItem->SetString("resolvedUrl", resolvedUrl); | |
| 168 metadataItem->SetString("icon", icon); | |
| 169 metadataItem->SetString("title", title); | |
| 170 metadataItem->SetString("description", description); | |
| 171 metadataList->Append(metadataItem); | |
| 172 } | |
| 173 | |
| 174 return metadataList; | |
| 175 } | |
| 176 | |
| 152 - (void)setNetworkRequestEnabled:(BOOL)enabled { | 177 - (void)setNetworkRequestEnabled:(BOOL)enabled { |
| 153 if (networkRequestEnabled_ == enabled) { | 178 if (networkRequestEnabled_ == enabled) { |
| 154 return; | 179 return; |
| 155 } | 180 } |
| 156 networkRequestEnabled_ = enabled; | 181 networkRequestEnabled_ = enabled; |
| 157 if (!networkRequestEnabled_) | 182 if (!networkRequestEnabled_) |
| 158 return; | 183 return; |
| 159 | 184 |
| 160 // Sends the pending requests. | 185 // Sends the pending requests. |
| 161 for (PhysicalWebDevice* device in unresolvedDevices_.get()) { | 186 for (PhysicalWebDevice* device in unresolvedDevices_.get()) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 287 // TX Power in the UriBeacon advertising packet is the received power at 0 | 312 // TX Power in the UriBeacon advertising packet is the received power at 0 |
| 288 // meters. The Transmit Power Level represents the transmit power level in | 313 // meters. The Transmit Power Level represents the transmit power level in |
| 289 // dBm, and the value ranges from -100 dBm to +20 dBm to a resolution of 1 | 314 // dBm, and the value ranges from -100 dBm to +20 dBm to a resolution of 1 |
| 290 // dBm. | 315 // dBm. |
| 291 int transmitPower = static_cast<char>(bytes[1]); | 316 int transmitPower = static_cast<char>(bytes[1]); |
| 292 // - scheme and URL are at offset 2. | 317 // - scheme and URL are at offset 2. |
| 293 std::vector<uint8_t> encodedURI(&bytes[2], &bytes[[data length]]); | 318 std::vector<uint8_t> encodedURI(&bytes[2], &bytes[[data length]]); |
| 294 std::string utf8URI; | 319 std::string utf8URI; |
| 295 device::DecodeUriBeaconUri(encodedURI, utf8URI); | 320 device::DecodeUriBeaconUri(encodedURI, utf8URI); |
| 296 NSString* uriString = base::SysUTF8ToNSString(utf8URI); | 321 NSString* uriString = base::SysUTF8ToNSString(utf8URI); |
| 297 return [[PhysicalWebDevice alloc] initWithURL:[NSURL URLWithString:uriString] | 322 NSURL* url = [NSURL URLWithString:uriString]; |
| 323 | |
| 324 // Ensure URL is valid. | |
| 325 if (!url) | |
| 326 return nil; | |
| 327 | |
| 328 return [[PhysicalWebDevice alloc] initWithURL:url | |
|
mattreynolds
2016/08/04 00:56:13
Bug fix to prevent us from crashing when beacons b
| |
| 298 requestURL:nil | 329 requestURL:nil |
| 299 icon:nil | 330 icon:nil |
| 300 title:nil | 331 title:nil |
| 301 description:nil | 332 description:nil |
| 302 transmitPower:transmitPower | 333 transmitPower:transmitPower |
| 303 rssi:rssi | 334 rssi:rssi |
| 304 rank:physical_web::kMaxRank]; | 335 rank:physical_web::kMaxRank]; |
| 305 } | 336 } |
| 306 | 337 |
| 307 - (void)requestMetadataForDevice:(PhysicalWebDevice*)device { | 338 - (void)requestMetadataForDevice:(PhysicalWebDevice*)device { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 321 [strongSelf.get()->devices_ addObject:device]; | 352 [strongSelf.get()->devices_ addObject:device]; |
| 322 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; | 353 [strongSelf.get()->delegate_ scannerUpdatedDevices:weakSelf]; |
| 323 [strongSelf.get()->finalUrls_ addObject:[device url]]; | 354 [strongSelf.get()->finalUrls_ addObject:[device url]]; |
| 324 } | 355 } |
| 325 } | 356 } |
| 326 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; | 357 [strongSelf.get()->pendingRequests_ removeObject:strongRequest]; |
| 327 }]; | 358 }]; |
| 328 } | 359 } |
| 329 | 360 |
| 330 @end | 361 @end |
| OLD | NEW |