Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_permission_context_android.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/feature_list.h" | 11 #include "base/feature_list.h" |
| 12 #include "base/metrics/histogram_functions.h" | 12 #include "base/metrics/histogram_functions.h" |
| 13 #include "chrome/browser/android/location_settings.h" | 13 #include "chrome/browser/android/location_settings.h" |
| 14 #include "chrome/browser/android/location_settings_impl.h" | 14 #include "chrome/browser/android/location_settings_impl.h" |
| 15 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h" | 15 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h" |
| 16 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " | 16 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " |
| 17 #include "chrome/browser/permissions/permission_request_id.h" | 17 #include "chrome/browser/permissions/permission_request_id.h" |
| 18 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" | 18 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/search_engines/template_url_service_factory.h" | 20 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 21 #include "chrome/browser/ui/android/tab_model/tab_model.h" | |
| 22 #include "chrome/browser/ui/android/tab_model/tab_model_list.h" | |
| 21 #include "chrome/common/chrome_features.h" | 23 #include "chrome/common/chrome_features.h" |
| 22 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 23 #include "components/infobars/core/infobar.h" | 25 #include "components/infobars/core/infobar.h" |
| 24 #include "components/prefs/pref_registry_simple.h" | 26 #include "components/prefs/pref_registry_simple.h" |
| 25 #include "components/prefs/pref_service.h" | 27 #include "components/prefs/pref_service.h" |
| 26 #include "components/search_engines/template_url.h" | 28 #include "components/search_engines/template_url.h" |
| 27 #include "components/search_engines/template_url_service.h" | 29 #include "components/search_engines/template_url_service.h" |
| 28 #include "content/public/browser/browser_thread.h" | 30 #include "content/public/browser/browser_thread.h" |
| 29 #include "content/public/browser/render_frame_host.h" | 31 #include "content/public/browser/render_frame_host.h" |
| 30 #include "content/public/browser/web_contents.h" | 32 #include "content/public/browser/web_contents.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 return; | 232 return; |
| 231 } | 233 } |
| 232 | 234 |
| 233 LogLocationSettingsMetric(kLocationSettingsShowMetricBase, | 235 LogLocationSettingsMetric(kLocationSettingsShowMetricBase, |
| 234 is_default_search, | 236 is_default_search, |
| 235 LocationSettingsBackOffLevel(is_default_search)); | 237 LocationSettingsBackOffLevel(is_default_search)); |
| 236 content::WebContents* web_contents = | 238 content::WebContents* web_contents = |
| 237 content::WebContents::FromRenderFrameHost( | 239 content::WebContents::FromRenderFrameHost( |
| 238 content::RenderFrameHost::FromID(id.render_process_id(), | 240 content::RenderFrameHost::FromID(id.render_process_id(), |
| 239 id.render_frame_id())); | 241 id.render_frame_id())); |
| 242 | |
| 243 // Only show the location settings dialog if the current tab is for | |
| 244 // |web_contents|. Note, the TabModel will be null in unit tests. | |
| 245 TabModel* tab_model = TabModelList::GetTabModelForWebContents(web_contents); | |
| 246 if (tab_model && tab_model->GetActiveWebContents() != web_contents) { | |
|
Ted C
2017/04/13 15:47:08
I wonder if this should be !tab_model ||
Though t
benwells
2017/04/14 00:13:53
It was like this originally, but it broke some tes
| |
| 247 FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, | |
| 248 callback, false /* persist */, | |
| 249 CONTENT_SETTING_BLOCK); | |
| 250 // This case should be very rare, so just pretend it was a denied prompt | |
| 251 // for metrics purposes. | |
| 252 LogLocationSettingsMetric( | |
| 253 kLocationSettingsDenyMetricBase, is_default_search, | |
| 254 LocationSettingsBackOffLevel(is_default_search)); | |
| 255 return; | |
| 256 } | |
| 257 | |
| 240 location_settings_->PromptToEnableSystemLocationSetting( | 258 location_settings_->PromptToEnableSystemLocationSetting( |
| 241 is_default_search ? SEARCH : DEFAULT, web_contents, | 259 is_default_search ? SEARCH : DEFAULT, web_contents, |
| 242 base::BindOnce( | 260 base::BindOnce( |
| 243 &GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown, | 261 &GeolocationPermissionContextAndroid::OnLocationSettingsDialogShown, |
| 244 weak_factory_.GetWeakPtr(), id, requesting_origin, embedding_origin, | 262 weak_factory_.GetWeakPtr(), id, requesting_origin, embedding_origin, |
| 245 callback, persist, content_setting)); | 263 callback, persist, content_setting)); |
| 246 return; | 264 return; |
| 247 } | 265 } |
| 248 | 266 |
| 249 FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback, | 267 FinishNotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 485 // The tab helper can be null in tests. | 503 // The tab helper can be null in tests. |
| 486 if (disclosure_helper) | 504 if (disclosure_helper) |
| 487 disclosure_helper->MaybeShowDisclosure(requesting_origin); | 505 disclosure_helper->MaybeShowDisclosure(requesting_origin); |
| 488 } | 506 } |
| 489 } | 507 } |
| 490 | 508 |
| 491 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( | 509 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( |
| 492 std::unique_ptr<LocationSettings> settings) { | 510 std::unique_ptr<LocationSettings> settings) { |
| 493 location_settings_ = std::move(settings); | 511 location_settings_ = std::move(settings); |
| 494 } | 512 } |
| OLD | NEW |