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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/geolocation/omnibox_geolocation_config.h"
6
7 #include <set>
8 #include <string>
9
10 #include "base/logging.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "url/gurl.h"
13
14 namespace {
15
16 NSString* const kEligibleDomainsKey = @"EligibleDomains";
17
18 } // namespace
19
20 @interface OmniboxGeolocationConfig () {
21 // Whitelist of domains eligible for Omnibox geolocation.
22 std::set<std::string> _eligibleDomains;
23 }
24
25 // Loads |eligibleDomains_| from config file.
26 - (void)loadEligibleDomains;
27
28 @end
29
30 @implementation OmniboxGeolocationConfig
31
32 + (OmniboxGeolocationConfig*)sharedInstance {
33 static OmniboxGeolocationConfig* instance =
34 [[OmniboxGeolocationConfig alloc] init];
35 return instance;
36 }
37
38 - (id)init {
39 self =
40 [super initWithAppId:nil version:nil plist:@"OmniboxGeolocation.plist"];
41 if (self) {
42 [self loadEligibleDomains];
43 }
44 return self;
45 }
46
47 - (BOOL)URLHasEligibleDomain:(const GURL&)url {
48 // Here we iterate through the eligible domains and check url.DomainIs() for
49 // each domain rather than extracting url.host() and checking the domain for
50 // membership in |eligibleDomains_|, because GURL::DomainIs() is more robust
51 // and contains logic that we want to reuse.
52 for (const auto& eligibleDomain : _eligibleDomains) {
53 if (url.DomainIs(eligibleDomain.c_str()))
54 return YES;
55 }
56 return NO;
57 }
58
59 #pragma mark - Private
60
61 - (void)loadEligibleDomains {
62 _eligibleDomains.clear();
63
64 NSDictionary* configData = [self dictionaryFromConfig];
65 NSArray* eligibleDomains = [configData objectForKey:kEligibleDomainsKey];
66 if (eligibleDomains) {
67 DCHECK([eligibleDomains isKindOfClass:[NSArray class]]);
68
69 for (NSString* domain in eligibleDomains) {
70 DCHECK([domain isKindOfClass:[NSString class]]);
71 if ([domain length]) {
72 _eligibleDomains.insert(
73 base::SysNSStringToUTF8([domain lowercaseString]));
74 }
75 }
76 }
77
78 DCHECK(!_eligibleDomains.empty());
79 }
80
81 @end
OLDNEW
« 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