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

Unified Diff: ios/chrome/browser/geolocation/omnibox_geolocation_config.mm

Issue 1103293002: [iOS] Upstream iOS geolocation code (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review comments Created 5 years, 8 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/browser/geolocation/omnibox_geolocation_config.mm
diff --git a/ios/chrome/browser/geolocation/omnibox_geolocation_config.mm b/ios/chrome/browser/geolocation/omnibox_geolocation_config.mm
new file mode 100644
index 0000000000000000000000000000000000000000..6a56ae4f6a9ceb9616710baaaabb1f72642292d1
--- /dev/null
+++ b/ios/chrome/browser/geolocation/omnibox_geolocation_config.mm
@@ -0,0 +1,81 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h"
+
+#include <set>
+#include <string>
+
+#include "base/logging.h"
+#include "base/strings/sys_string_conversions.h"
+#include "url/gurl.h"
+
+namespace {
+
+NSString* const kEligibleDomainsKey = @"EligibleDomains";
+
+} // namespace
+
+@interface OmniboxGeolocationConfig () {
+ // Whitelist of domains eligible for Omnibox geolocation.
+ std::set<std::string> _eligibleDomains;
+}
+
+// Loads |eligibleDomains_| from config file.
+- (void)loadEligibleDomains;
+
+@end
+
+@implementation OmniboxGeolocationConfig
+
++ (OmniboxGeolocationConfig*)sharedInstance {
+ static OmniboxGeolocationConfig* instance =
+ [[OmniboxGeolocationConfig alloc] init];
+ return instance;
+}
+
+- (id)init {
+ self =
+ [super initWithAppId:nil version:nil plist:@"OmniboxGeolocation.plist"];
+ if (self) {
+ [self loadEligibleDomains];
+ }
+ return self;
+}
+
+- (BOOL)URLHasEligibleDomain:(const GURL&)url {
+ // Here we iterate through the eligible domains and check url.DomainIs() for
+ // each domain rather than extracting url.host() and checking the domain for
+ // membership in |eligibleDomains_|, because GURL::DomainIs() is more robust
+ // and contains logic that we want to reuse.
+ for (const auto& eligibleDomain : _eligibleDomains) {
+ if (url.DomainIs(eligibleDomain.c_str()))
+ return YES;
+ }
+ return NO;
+}
+
+#pragma mark - Private
+
+- (void)loadEligibleDomains {
+ _eligibleDomains.clear();
+
+ NSDictionary* configData = [self dictionaryFromConfig];
+ NSArray* eligibleDomains = [configData objectForKey:kEligibleDomainsKey];
+ if (eligibleDomains) {
+ DCHECK([eligibleDomains isKindOfClass:[NSArray class]]);
+
+ for (NSString* domain in eligibleDomains) {
+ DCHECK([domain isKindOfClass:[NSString class]]);
+ if ([domain length]) {
+ _eligibleDomains.insert(
+ base::SysNSStringToUTF8([domain lowercaseString]));
+ }
+ }
+ }
+
+ DCHECK(!_eligibleDomains.empty());
+}
+
+@end
« no previous file with comments | « ios/chrome/browser/geolocation/omnibox_geolocation_config.h ('k') | ios/chrome/browser/geolocation/test_location_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698