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

Unified Diff: ios/chrome/common/physical_web/physical_web_scanner.mm

Issue 2113473002: Add a Physical Web data source (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move data source instance to ApplicationContext Created 4 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/common/physical_web/physical_web_scanner.mm
diff --git a/ios/chrome/common/physical_web/physical_web_scanner.mm b/ios/chrome/common/physical_web/physical_web_scanner.mm
index 2457f225a5cacc46102e6ce517f596118ddb774e..c9765be542f1fba3d690ba565e3cdfdefcec0fd8 100644
--- a/ios/chrome/common/physical_web/physical_web_scanner.mm
+++ b/ios/chrome/common/physical_web/physical_web_scanner.mm
@@ -4,20 +4,19 @@
#import "ios/chrome/common/physical_web/physical_web_scanner.h"
+#import <CoreBluetooth/CoreBluetooth.h>
+
#include <string>
#include <vector>
-#import <CoreBluetooth/CoreBluetooth.h>
-
-#include "base/ios/weak_nsobject.h"
+#import "base/ios/weak_nsobject.h"
#include "base/logging.h"
-#include "base/mac/scoped_nsobject.h"
-#include "base/macros.h"
+#import "base/mac/scoped_nsobject.h"
#include "base/strings/sys_string_conversions.h"
#include "device/bluetooth/uribeacon/uri_encoder.h"
-#include "ios/chrome/common/physical_web/physical_web_device.h"
+#import "ios/chrome/common/physical_web/physical_web_device.h"
#import "ios/chrome/common/physical_web/physical_web_request.h"
-#include "ios/chrome/common/physical_web/physical_web_types.h"
+#import "ios/chrome/common/physical_web/physical_web_types.h"
namespace {
@@ -149,6 +148,32 @@ enum BeaconType {
}];
}
+- (std::unique_ptr<base::ListValue>)metadata {
+ 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.
+
+ NSInteger deviceCount = [[self devices] count];
+ for (int i = 0; i < deviceCount; ++i) {
+ PhysicalWebDevice* device = [[self devices] objectAtIndex:i];
+ std::string scannedUrl =
+ base::SysNSStringToUTF8([[device requestURL] absoluteString]);
+ std::string resolvedUrl =
+ base::SysNSStringToUTF8([[device url] absoluteString]);
+ std::string icon = base::SysNSStringToUTF8([[device icon] absoluteString]);
+ std::string title = base::SysNSStringToUTF8([device title]);
+ std::string description = base::SysNSStringToUTF8([device description]);
+
+ 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.
+ metadataItem->SetString("scannedUrl", scannedUrl);
+ metadataItem->SetString("resolvedUrl", resolvedUrl);
+ metadataItem->SetString("icon", icon);
+ metadataItem->SetString("title", title);
+ metadataItem->SetString("description", description);
+ metadataList->Append(metadataItem);
+ }
+
+ return metadataList;
+}
+
- (void)setNetworkRequestEnabled:(BOOL)enabled {
if (networkRequestEnabled_ == enabled) {
return;
@@ -294,7 +319,13 @@ enum BeaconType {
std::string utf8URI;
device::DecodeUriBeaconUri(encodedURI, utf8URI);
NSString* uriString = base::SysUTF8ToNSString(utf8URI);
- return [[PhysicalWebDevice alloc] initWithURL:[NSURL URLWithString:uriString]
+ NSURL* url = [NSURL URLWithString:uriString];
+
+ // Ensure URL is valid.
+ if (!url)
+ return nil;
+
+ return [[PhysicalWebDevice alloc] initWithURL:url
mattreynolds 2016/08/04 00:56:13 Bug fix to prevent us from crashing when beacons b
requestURL:nil
icon:nil
title:nil

Powered by Google App Engine
This is Rietveld 408576698