| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/geolocation/geolocation_settings_state.h" | 5 #include "chrome/browser/geolocation/geolocation_settings_state.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" | 8 #include "chrome/browser/geolocation/geolocation_content_settings_map.h" |
| 9 #include "chrome/browser/pref_service.h" | 9 #include "chrome/browser/pref_service.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 state_map_.clear(); | 43 state_map_.clear(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void GeolocationSettingsState::GetDetailedInfo( | 46 void GeolocationSettingsState::GetDetailedInfo( |
| 47 FormattedHostsPerState* formatted_hosts_per_state, | 47 FormattedHostsPerState* formatted_hosts_per_state, |
| 48 unsigned int* tab_state_flags) const { | 48 unsigned int* tab_state_flags) const { |
| 49 DCHECK(tab_state_flags); | 49 DCHECK(tab_state_flags); |
| 50 DCHECK(embedder_url_.is_valid()); | 50 DCHECK(embedder_url_.is_valid()); |
| 51 const ContentSetting default_setting = | 51 const ContentSetting default_setting = |
| 52 profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting(); | 52 profile_->GetGeolocationContentSettingsMap()->GetDefaultContentSetting(); |
| 53 std::set<std::string> formatted_hosts; |
| 54 std::set<std::string> repeated_formatted_hosts; |
| 55 |
| 56 // Build a set of repeated formatted hosts |
| 57 for (StateMap::const_iterator i(state_map_.begin()); |
| 58 i != state_map_.end(); ++i) { |
| 59 std::string formatted_host = GURLToFormattedHost(i->first); |
| 60 if (!formatted_hosts.insert(formatted_host).second) { |
| 61 repeated_formatted_hosts.insert(formatted_host); |
| 62 } |
| 63 } |
| 64 |
| 53 for (StateMap::const_iterator i(state_map_.begin()); | 65 for (StateMap::const_iterator i(state_map_.begin()); |
| 54 i != state_map_.end(); ++i) { | 66 i != state_map_.end(); ++i) { |
| 55 if (i->second == CONTENT_SETTING_ALLOW) | 67 if (i->second == CONTENT_SETTING_ALLOW) |
| 56 *tab_state_flags |= TABSTATE_HAS_ANY_ALLOWED; | 68 *tab_state_flags |= TABSTATE_HAS_ANY_ALLOWED; |
| 57 if (formatted_hosts_per_state) { | 69 if (formatted_hosts_per_state) { |
| 58 (*formatted_hosts_per_state)[i->second].insert( | 70 std::string formatted_host = GURLToFormattedHost(i->first); |
| 59 GURLToFormattedHost(i->first)); | 71 std::string final_formatted_host = |
| 72 repeated_formatted_hosts.find(formatted_host) == |
| 73 repeated_formatted_hosts.end() ? |
| 74 formatted_host : |
| 75 i->first.spec(); |
| 76 (*formatted_hosts_per_state)[i->second].insert(final_formatted_host); |
| 60 } | 77 } |
| 61 | 78 |
| 62 const ContentSetting saved_setting = | 79 const ContentSetting saved_setting = |
| 63 profile_->GetGeolocationContentSettingsMap()->GetContentSetting( | 80 profile_->GetGeolocationContentSettingsMap()->GetContentSetting( |
| 64 i->first, embedder_url_); | 81 i->first, embedder_url_); |
| 65 if (saved_setting != default_setting) | 82 if (saved_setting != default_setting) |
| 66 *tab_state_flags |= TABSTATE_HAS_EXCEPTION; | 83 *tab_state_flags |= TABSTATE_HAS_EXCEPTION; |
| 67 if (saved_setting != i->second) | 84 if (saved_setting != i->second) |
| 68 *tab_state_flags |= TABSTATE_HAS_CHANGED; | 85 *tab_state_flags |= TABSTATE_HAS_CHANGED; |
| 69 if (saved_setting != CONTENT_SETTING_ASK) | 86 if (saved_setting != CONTENT_SETTING_ASK) |
| 70 *tab_state_flags |= TABSTATE_HAS_ANY_ICON; | 87 *tab_state_flags |= TABSTATE_HAS_ANY_ICON; |
| 71 } | 88 } |
| 72 } | 89 } |
| 73 | 90 |
| 74 std::string GeolocationSettingsState::GURLToFormattedHost( | 91 std::string GeolocationSettingsState::GURLToFormattedHost( |
| 75 const GURL& url) const { | 92 const GURL& url) const { |
| 76 std::wstring display_host_wide; | 93 std::wstring display_host_wide; |
| 77 net::AppendFormattedHost( | 94 net::AppendFormattedHost( |
| 78 url, UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), | 95 url, UTF8ToWide(profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)), |
| 79 &display_host_wide, NULL, NULL); | 96 &display_host_wide, NULL, NULL); |
| 80 return WideToUTF8(display_host_wide); | 97 return WideToUTF8(display_host_wide); |
| 81 } | 98 } |
| OLD | NEW |