| 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" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 GeolocationPermissionContextAndroid::GeolocationPermissionContextAndroid( | 83 GeolocationPermissionContextAndroid::GeolocationPermissionContextAndroid( |
| 84 Profile* profile) | 84 Profile* profile) |
| 85 : GeolocationPermissionContext(profile), | 85 : GeolocationPermissionContext(profile), |
| 86 location_settings_(new LocationSettingsImpl()), | 86 location_settings_(new LocationSettingsImpl()), |
| 87 permission_update_infobar_(nullptr), | 87 permission_update_infobar_(nullptr), |
| 88 weak_factory_(this) {} | 88 weak_factory_(this) {} |
| 89 | 89 |
| 90 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() { | 90 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() { |
| 91 } | 91 } |
| 92 | 92 |
| 93 ContentSetting GeolocationPermissionContextAndroid::GetPermissionStatusInternal( | 93 PermissionResult |
| 94 GeolocationPermissionContextAndroid::GetPermissionStatusInternal( |
| 94 content::RenderFrameHost* render_frame_host, | 95 content::RenderFrameHost* render_frame_host, |
| 95 const GURL& requesting_origin, | 96 const GURL& requesting_origin, |
| 96 const GURL& embedding_origin) const { | 97 const GURL& embedding_origin) const { |
| 97 ContentSetting value = | 98 PermissionResult result = |
| 98 GeolocationPermissionContext::GetPermissionStatusInternal( | 99 GeolocationPermissionContext::GetPermissionStatusInternal( |
| 99 render_frame_host, requesting_origin, embedding_origin); | 100 render_frame_host, requesting_origin, embedding_origin); |
| 100 | 101 |
| 101 if (value == CONTENT_SETTING_ASK && requesting_origin == embedding_origin) { | 102 if (result.content_setting == CONTENT_SETTING_ASK && |
| 103 requesting_origin == embedding_origin) { |
| 102 // Consult the DSE Geolocation setting. Note that this only needs to be | 104 // Consult the DSE Geolocation setting. Note that this only needs to be |
| 103 // consulted when the content setting is ASK. In the other cases (ALLOW or | 105 // consulted when the content setting is ASK. In the other cases (ALLOW or |
| 104 // BLOCK) checking the setting is redundant, as the setting is kept | 106 // BLOCK) checking the setting is redundant, as the setting is kept |
| 105 // consistent with the content setting. | 107 // consistent with the content setting. |
| 106 SearchGeolocationService* search_helper = | 108 SearchGeolocationService* search_helper = |
| 107 SearchGeolocationService::Factory::GetForBrowserContext(profile()); | 109 SearchGeolocationService::Factory::GetForBrowserContext(profile()); |
| 108 | 110 |
| 109 // If the user is incognito, use the DSE Geolocation setting from the | 111 // If the user is incognito, use the DSE Geolocation setting from the |
| 110 // original profile - but only if it is BLOCK. | 112 // original profile - but only if it is BLOCK. |
| 111 if (!search_helper) { | 113 if (!search_helper) { |
| 112 DCHECK(profile()->IsOffTheRecord()); | 114 DCHECK(profile()->IsOffTheRecord()); |
| 113 search_helper = SearchGeolocationService::Factory::GetForBrowserContext( | 115 search_helper = SearchGeolocationService::Factory::GetForBrowserContext( |
| 114 profile()->GetOriginalProfile()); | 116 profile()->GetOriginalProfile()); |
| 115 } | 117 } |
| 116 | 118 |
| 117 if (search_helper && | 119 if (search_helper && |
| 118 search_helper->UseDSEGeolocationSetting( | 120 search_helper->UseDSEGeolocationSetting( |
| 119 url::Origin(embedding_origin))) { | 121 url::Origin(embedding_origin))) { |
| 120 if (!search_helper->GetDSEGeolocationSetting()) { | 122 if (!search_helper->GetDSEGeolocationSetting()) { |
| 121 // If the DSE setting is off, always return BLOCK. | 123 // If the DSE setting is off, always return BLOCK. |
| 122 value = CONTENT_SETTING_BLOCK; | 124 result.content_setting = CONTENT_SETTING_BLOCK; |
| 123 } else if (!profile()->IsOffTheRecord()) { | 125 } else if (!profile()->IsOffTheRecord()) { |
| 124 // Otherwise, return ALLOW only if this is not incognito. | 126 // Otherwise, return ALLOW only if this is not incognito. |
| 125 value = CONTENT_SETTING_ALLOW; | 127 result.content_setting = CONTENT_SETTING_ALLOW; |
| 126 } | 128 } |
| 127 } | 129 } |
| 128 } | 130 } |
| 129 | 131 |
| 130 return value; | 132 return result; |
| 131 } | 133 } |
| 132 | 134 |
| 133 // static | 135 // static |
| 134 void GeolocationPermissionContextAndroid::AddDayOffsetForTesting(int days) { | 136 void GeolocationPermissionContextAndroid::AddDayOffsetForTesting(int days) { |
| 135 g_day_offset_for_testing += days; | 137 g_day_offset_for_testing += days; |
| 136 } | 138 } |
| 137 | 139 |
| 138 // static | 140 // static |
| 139 void GeolocationPermissionContextAndroid::SetDSEOriginForTesting( | 141 void GeolocationPermissionContextAndroid::SetDSEOriginForTesting( |
| 140 const char* dse_origin) { | 142 const char* dse_origin) { |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 // The tab helper can be null in tests. | 504 // The tab helper can be null in tests. |
| 503 if (disclosure_helper) | 505 if (disclosure_helper) |
| 504 disclosure_helper->MaybeShowDisclosureForAPIAccess(requesting_origin); | 506 disclosure_helper->MaybeShowDisclosureForAPIAccess(requesting_origin); |
| 505 } | 507 } |
| 506 } | 508 } |
| 507 | 509 |
| 508 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( | 510 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( |
| 509 std::unique_ptr<LocationSettings> settings) { | 511 std::unique_ptr<LocationSettings> settings) { |
| 510 location_settings_ = std::move(settings); | 512 location_settings_ = std::move(settings); |
| 511 } | 513 } |
| OLD | NEW |