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

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: typo 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
« no previous file with comments | « ios/chrome/common/physical_web/physical_web_scanner.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..02c5d0c0c03d6f1fb5c979a23eb6c11217c30bd8 100644
--- a/ios/chrome/common/physical_web/physical_web_scanner.mm
+++ b/ios/chrome/common/physical_web/physical_web_scanner.mm
@@ -4,20 +4,21 @@
#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/memory/ptr_util.h"
#include "base/strings/sys_string_conversions.h"
+#include "base/values.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 +150,30 @@ enum BeaconType {
}];
}
+- (std::unique_ptr<base::ListValue>)metadata {
+ auto metadataList = base::MakeUnique<base::ListValue>();
+
+ for (PhysicalWebDevice* device in [self devices]) {
+ 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]);
+
+ auto metadataItem = base::MakeUnique<base::DictionaryValue>();
+ metadataItem->SetString("scannedUrl", scannedUrl);
+ metadataItem->SetString("resolvedUrl", resolvedUrl);
+ metadataItem->SetString("icon", icon);
+ metadataItem->SetString("title", title);
+ metadataItem->SetString("description", description);
+ metadataList->Append(std::move(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
requestURL:nil
icon:nil
title:nil
« no previous file with comments | « ios/chrome/common/physical_web/physical_web_scanner.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698