| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/android/search_geolocation/search_geolocation_service.h
" | 5 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h
" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/feature_list.h" | 8 #include "base/feature_list.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur
e_tab_helper.h" | 10 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur
e_tab_helper.h" |
| 11 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 12 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 14 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 15 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
| 15 #include "chrome/common/chrome_features.h" | 16 #include "chrome/common/chrome_features.h" |
| 16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
| 17 #include "components/content_settings/core/browser/content_settings_utils.h" | 18 #include "components/content_settings/core/browser/content_settings_utils.h" |
| 18 #include "components/content_settings/core/browser/host_content_settings_map.h" | 19 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 19 #include "components/content_settings/core/common/content_settings_types.h" | 20 #include "components/content_settings/core/common/content_settings_types.h" |
| 20 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 21 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 22 #include "components/pref_registry/pref_registry_syncable.h" |
| 22 #include "components/prefs/pref_service.h" | 23 #include "components/prefs/pref_service.h" |
| 23 #include "components/search_engines/template_url.h" | 24 #include "components/search_engines/template_url.h" |
| 24 #include "components/search_engines/template_url_service.h" | 25 #include "components/search_engines/template_url_service.h" |
| 25 #include "components/search_engines/template_url_service_observer.h" | 26 #include "components/search_engines/template_url_service_observer.h" |
| 27 #include "components/web_resource/web_resource_pref_names.h" |
| 26 #include "url/gurl.h" | 28 #include "url/gurl.h" |
| 27 #include "url/url_constants.h" | 29 #include "url/url_constants.h" |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 const char kIsGoogleSearchEngineKey[] = "is_google_search_engine"; | 33 const char kIsGoogleSearchEngineKey[] = "is_google_search_engine"; |
| 32 const char kDSESettingKey[] = "dse_setting"; | 34 const char kDSESettingKey[] = "dse_setting"; |
| 33 | 35 |
| 34 // Default implementation of SearchEngineDelegate that is used for production | 36 // Default implementation of SearchEngineDelegate that is used for production |
| 35 // code. | 37 // code. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 // become invalid either by changes being made to enterprise policy, or while | 153 // become invalid either by changes being made to enterprise policy, or while |
| 152 // the flag to enable consistent search geolocation was off. | 154 // the flag to enable consistent search geolocation was off. |
| 153 EnsureDSEGeolocationSettingIsValid(); | 155 EnsureDSEGeolocationSettingIsValid(); |
| 154 } | 156 } |
| 155 | 157 |
| 156 bool SearchGeolocationService::UseDSEGeolocationSetting( | 158 bool SearchGeolocationService::UseDSEGeolocationSetting( |
| 157 const url::Origin& requesting_origin) { | 159 const url::Origin& requesting_origin) { |
| 158 if (!UseConsistentSearchGeolocation()) | 160 if (!UseConsistentSearchGeolocation()) |
| 159 return false; | 161 return false; |
| 160 | 162 |
| 163 // Don't use the DSE setting until the EULA has been acceptd. This prevents |
| 164 // the disclosure being shown on the privacy policy before accepting the UELA, |
| 165 // and would also stop the privacy policy ever getting geolocation access by |
| 166 // default. |
| 167 if (g_browser_process && g_browser_process->local_state() && |
| 168 !g_browser_process->local_state()->GetBoolean(prefs::kEulaAccepted)) { |
| 169 return false; |
| 170 } |
| 171 |
| 161 if (requesting_origin.scheme() != url::kHttpsScheme) | 172 if (requesting_origin.scheme() != url::kHttpsScheme) |
| 162 return false; | 173 return false; |
| 163 | 174 |
| 164 if (!requesting_origin.IsSameOriginWith(delegate_->GetGoogleDSECCTLD())) | 175 if (!requesting_origin.IsSameOriginWith(delegate_->GetGoogleDSECCTLD())) |
| 165 return false; | 176 return false; |
| 166 | 177 |
| 167 // If the content setting for the DSE CCTLD is controlled by policy, and is st | 178 // If the content setting for the DSE CCTLD is controlled by policy, and is st |
| 168 // to ASK, don't use the DSE geolocation setting. | 179 // to ASK, don't use the DSE geolocation setting. |
| 169 if (!IsContentSettingUserSettable() && | 180 if (!IsContentSettingUserSettable() && |
| 170 GetCurrentContentSetting() == CONTENT_SETTING_ASK) { | 181 GetCurrentContentSetting() == CONTENT_SETTING_ASK) { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 bool SearchGeolocationService::UseConsistentSearchGeolocation() { | 323 bool SearchGeolocationService::UseConsistentSearchGeolocation() { |
| 313 return base::FeatureList::IsEnabled(features::kConsistentOmniboxGeolocation); | 324 return base::FeatureList::IsEnabled(features::kConsistentOmniboxGeolocation); |
| 314 } | 325 } |
| 315 | 326 |
| 316 void SearchGeolocationService::SetSearchEngineDelegateForTest( | 327 void SearchGeolocationService::SetSearchEngineDelegateForTest( |
| 317 std::unique_ptr<SearchEngineDelegate> delegate) { | 328 std::unique_ptr<SearchEngineDelegate> delegate) { |
| 318 delegate_ = std::move(delegate); | 329 delegate_ = std::move(delegate); |
| 319 delegate_->SetDSEChangedCallback(base::Bind( | 330 delegate_->SetDSEChangedCallback(base::Bind( |
| 320 &SearchGeolocationService::OnDSEChanged, base::Unretained(this))); | 331 &SearchGeolocationService::OnDSEChanged, base::Unretained(this))); |
| 321 } | 332 } |
| OLD | NEW |