summaryrefslogtreecommitdiffstats
path: root/chrome/browser/geolocation
diff options
context:
space:
mode:
authorbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-02 12:05:02 +0000
committerbulach@chromium.org <bulach@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-02 12:05:02 +0000
commita40c8dbc97b4a8f8499b703300da65fe053e95c2 (patch)
tree116ed772092c58f06d9b2ad3730192991baee798 /chrome/browser/geolocation
parent9eea71c4710393b3bed637382b3f82ec5eb60d2e (diff)
downloadchromium_src-a40c8dbc97b4a8f8499b703300da65fe053e95c2.zip
chromium_src-a40c8dbc97b4a8f8499b703300da65fe053e95c2.tar.gz
chromium_src-a40c8dbc97b4a8f8499b703300da65fe053e95c2.tar.bz2
URLs with repeated domain names requesting tracking information
Check URLs for repeated domain names then if there are any repeated show the port information of the URL as before if you had two of the same domain allowed/blocked only one would show in the bubble. Also added some unit tests for it. (landing on behalf of allanwoj. original review at http://codereview.chromium.org/2832044/show). BUG=40163 TEST=Two requests within a tab for tracking information with same domain but different port eg http://www.example.com and https://www.example.com A test fixture called ShowPortOnSameDomain is in GeolocationSettingsStateTests Review URL: http://codereview.chromium.org/2847045 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51521 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/geolocation')
-rw-r--r--chrome/browser/geolocation/geolocation_settings_state.cc21
-rw-r--r--chrome/browser/geolocation/geolocation_settings_state_unittest.cc63
2 files changed, 82 insertions, 2 deletions
diff --git a/chrome/browser/geolocation/geolocation_settings_state.cc b/chrome/browser/geolocation/geolocation_settings_state.cc
index f246598..6f8548e 100644
--- a/chrome/browser/geolocation/geolocation_settings_state.cc
+++ b/chrome/browser/geolocation/geolocation_settings_state.cc
@@ -50,13 +50,30 @@ void GeolocationSettingsState::GetDetailedInfo(
DCHECK(embedder_url_.is_valid());
const ContentSetting default_setting =
profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting();
+ std::set<std::string> formatted_hosts;
+ std::set<std::string> repeated_formatted_hosts;
+
+ // Build a set of repeated formatted hosts
+ for (StateMap::const_iterator i(state_map_.begin());
+ i != state_map_.end(); ++i) {
+ std::string formatted_host = GURLToFormattedHost(i->first);
+ if (!formatted_hosts.insert(formatted_host).second) {
+ repeated_formatted_hosts.insert(formatted_host);
+ }
+ }
+
for (StateMap::const_iterator i(state_map_.begin());
i != state_map_.end(); ++i) {
if (i->second == CONTENT_SETTING_ALLOW)
*tab_state_flags |= TABSTATE_HAS_ANY_ALLOWED;
if (formatted_hosts_per_state) {
- (*formatted_hosts_per_state)[i->second].insert(
- GURLToFormattedHost(i->first));
+ std::string formatted_host = GURLToFormattedHost(i->first);
+ std::string final_formatted_host =
+ repeated_formatted_hosts.find(formatted_host) ==
+ repeated_formatted_hosts.end() ?
+ formatted_host :
+ i->first.spec();
+ (*formatted_hosts_per_state)[i->second].insert(final_formatted_host);
}
const ContentSetting saved_setting =
diff --git a/chrome/browser/geolocation/geolocation_settings_state_unittest.cc b/chrome/browser/geolocation/geolocation_settings_state_unittest.cc
index f7c9c17..f001ed2 100644
--- a/chrome/browser/geolocation/geolocation_settings_state_unittest.cc
+++ b/chrome/browser/geolocation/geolocation_settings_state_unittest.cc
@@ -119,4 +119,67 @@ TEST_F(GeolocationSettingsStateTests, ClearOnNewOrigin) {
EXPECT_EQ(0U, tab_state_flags);
}
+TEST_F(GeolocationSettingsStateTests, ShowPortOnSameHost) {
+ TestingProfile profile;
+ GeolocationSettingsState state(&profile);
+ GURL url_0("http://www.example.com");
+
+ NavigationEntry entry;
+ entry.set_url(url_0);
+ NavigationController::LoadCommittedDetails load_committed_details;
+ load_committed_details.entry = &entry;
+ state.DidNavigate(load_committed_details);
+
+ profile.GetGeolocationContentSettingsMap()->SetContentSetting(
+ url_0, url_0, CONTENT_SETTING_ALLOW);
+ state.OnGeolocationPermissionSet(url_0, true);
+
+ GURL url_1("https://www.example.com");
+ profile.GetGeolocationContentSettingsMap()->SetContentSetting(
+ url_1, url_0, CONTENT_SETTING_ALLOW);
+ state.OnGeolocationPermissionSet(url_1, true);
+
+ GURL url_2("http://www.example1.com");
+ profile.GetGeolocationContentSettingsMap()->SetContentSetting(
+ url_2, url_0, CONTENT_SETTING_ALLOW);
+ state.OnGeolocationPermissionSet(url_2, true);
+
+ GeolocationSettingsState::StateMap state_map =
+ state.state_map();
+ EXPECT_EQ(3U, state_map.size());
+
+ GeolocationSettingsState::FormattedHostsPerState formatted_host_per_state;
+ unsigned int tab_state_flags = 0;
+ state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
+
+ EXPECT_EQ(3U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
+ EXPECT_EQ(1U,
+ formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
+ url_0.spec()));
+ EXPECT_EQ(1U,
+ formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
+ url_1.spec()));
+ EXPECT_EQ(1U,
+ formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
+ url_2.host()));
+
+ state.OnGeolocationPermissionSet(url_1, false);
+ formatted_host_per_state.clear();
+ tab_state_flags = 0;
+ state.GetDetailedInfo(&formatted_host_per_state, &tab_state_flags);
+
+ EXPECT_EQ(2U, formatted_host_per_state[CONTENT_SETTING_ALLOW].size());
+ EXPECT_EQ(1U,
+ formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
+ url_0.spec()));
+ EXPECT_EQ(1U,
+ formatted_host_per_state[CONTENT_SETTING_ALLOW].count(
+ url_2.host()));
+ EXPECT_EQ(1U, formatted_host_per_state[CONTENT_SETTING_BLOCK].size());
+ EXPECT_EQ(1U,
+ formatted_host_per_state[CONTENT_SETTING_BLOCK].count(
+ url_1.spec()));
+}
+
+
} // namespace