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 "chrome/browser/android/location_settings.h" | 11 #include "chrome/browser/android/location_settings.h" |
| 12 #include "chrome/browser/android/location_settings_impl.h" | 12 #include "chrome/browser/android/location_settings_impl.h" |
| 13 #include "chrome/browser/android/search_geolocation/search_geolocation_disclosur e_tab_helper.h" | |
| 13 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " | 14 #include "chrome/browser/android/search_geolocation/search_geolocation_service.h " |
| 14 #include "chrome/browser/permissions/permission_request_id.h" | 15 #include "chrome/browser/permissions/permission_request_id.h" |
| 15 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" | 16 #include "chrome/browser/permissions/permission_update_infobar_delegate_android. h" |
| 16 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 17 #include "components/infobars/core/infobar.h" | 18 #include "components/infobars/core/infobar.h" |
| 18 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 GeolocationPermissionContextAndroid:: | 23 GeolocationPermissionContextAndroid:: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 return value; | 56 return value; |
| 56 } | 57 } |
| 57 | 58 |
| 58 void GeolocationPermissionContextAndroid::RequestPermission( | 59 void GeolocationPermissionContextAndroid::RequestPermission( |
| 59 content::WebContents* web_contents, | 60 content::WebContents* web_contents, |
| 60 const PermissionRequestID& id, | 61 const PermissionRequestID& id, |
| 61 const GURL& requesting_frame_origin, | 62 const GURL& requesting_frame_origin, |
| 62 bool user_gesture, | 63 bool user_gesture, |
| 63 const BrowserPermissionCallback& callback) { | 64 const BrowserPermissionCallback& callback) { |
| 64 if (!location_settings_->CanSitesRequestLocationPermission(web_contents)) { | 65 if (!location_settings_->CanSitesRequestLocationPermission(web_contents)) { |
| 65 PermissionDecided(id, requesting_frame_origin, | 66 PermissionDecided(web_contents, id, requesting_frame_origin, |
| 66 web_contents->GetLastCommittedURL().GetOrigin(), | 67 web_contents->GetLastCommittedURL().GetOrigin(), |
| 67 user_gesture, callback, false /* persist */, | 68 user_gesture, callback, false /* persist */, |
| 68 CONTENT_SETTING_BLOCK); | 69 CONTENT_SETTING_BLOCK); |
| 69 return; | 70 return; |
| 70 } | 71 } |
| 71 | 72 |
| 72 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); | 73 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
| 73 ContentSetting content_setting = | 74 ContentSetting content_setting = |
| 74 GeolocationPermissionContext::GetPermissionStatus(requesting_frame_origin, | 75 GeolocationPermissionContext::GetPermissionStatus(requesting_frame_origin, |
| 75 embedding_origin); | 76 embedding_origin); |
| 76 std::vector<ContentSettingsType> content_settings_types; | 77 std::vector<ContentSettingsType> content_settings_types; |
| 77 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_GEOLOCATION); | 78 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 78 if (content_setting == CONTENT_SETTING_ALLOW && | 79 if (content_setting == CONTENT_SETTING_ALLOW && |
| 79 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( | 80 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar( |
| 80 web_contents, content_settings_types)) { | 81 web_contents, content_settings_types)) { |
| 81 permission_update_infobar_ = PermissionUpdateInfoBarDelegate::Create( | 82 permission_update_infobar_ = PermissionUpdateInfoBarDelegate::Create( |
| 82 web_contents, content_settings_types, | 83 web_contents, content_settings_types, |
| 83 base::Bind( | 84 base::Bind(&GeolocationPermissionContextAndroid:: |
| 84 &GeolocationPermissionContextAndroid | 85 HandleUpdateAndroidPermissions, |
| 85 ::HandleUpdateAndroidPermissions, | 86 weak_factory_.GetWeakPtr(), web_contents, id, |
| 86 weak_factory_.GetWeakPtr(), id, requesting_frame_origin, | 87 requesting_frame_origin, embedding_origin, callback)); |
| 87 embedding_origin, callback)); | |
| 88 | 88 |
| 89 return; | 89 return; |
| 90 } | 90 } |
| 91 | 91 |
| 92 GeolocationPermissionContext::RequestPermission( | 92 GeolocationPermissionContext::RequestPermission( |
| 93 web_contents, id, requesting_frame_origin, user_gesture, callback); | 93 web_contents, id, requesting_frame_origin, user_gesture, callback); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void GeolocationPermissionContextAndroid::CancelPermissionRequest( | 96 void GeolocationPermissionContextAndroid::CancelPermissionRequest( |
| 97 content::WebContents* web_contents, | 97 content::WebContents* web_contents, |
| 98 const PermissionRequestID& id) { | 98 const PermissionRequestID& id) { |
| 99 if (permission_update_infobar_) { | 99 if (permission_update_infobar_) { |
| 100 permission_update_infobar_->RemoveSelf(); | 100 permission_update_infobar_->RemoveSelf(); |
| 101 permission_update_infobar_ = nullptr; | 101 permission_update_infobar_ = nullptr; |
| 102 } | 102 } |
| 103 | 103 |
| 104 GeolocationPermissionContext::CancelPermissionRequest(web_contents, id); | 104 GeolocationPermissionContext::CancelPermissionRequest(web_contents, id); |
| 105 } | 105 } |
| 106 | 106 |
| 107 void GeolocationPermissionContextAndroid::NotifyPermissionSet( | |
| 108 content::WebContents* web_contents, | |
| 109 const PermissionRequestID& id, | |
| 110 const GURL& requesting_origin, | |
| 111 const GURL& embedding_origin, | |
| 112 const BrowserPermissionCallback& callback, | |
| 113 bool persist, | |
| 114 ContentSetting content_setting) { | |
| 115 GeolocationPermissionContext::NotifyPermissionSet( | |
| 116 web_contents, id, requesting_origin, embedding_origin, callback, persist, | |
|
raymes
2017/01/12 00:17:12
You can actually get at the web_contents from Perm
benwells
2017/01/12 01:04:17
Ah ... that would make this change a lot simpler.
raymes
2017/01/12 01:41:17
I would lean toward not passing it and just grabbi
benwells
2017/01/12 04:13:49
Done.
| |
| 117 content_setting); | |
| 118 | |
| 119 // If this is the default search origin, and the DSE Geolocation setting is | |
| 120 // being used, potentially show the disclosure. | |
| 121 if (requesting_origin == embedding_origin) { | |
| 122 // Consult the DSE Geolocation setting. Note that this only needs to be | |
| 123 // consulted when the content setting is ASK. In the other cases (ALLOW or | |
| 124 // BLOCK) checking the setting is redundant, as the setting is kept | |
| 125 // consistent with the content setting. | |
|
raymes
2017/01/12 00:17:12
Is this comment needed/accurate?
benwells
2017/01/12 04:13:49
Done.
| |
| 126 SearchGeolocationService* search_helper = | |
| 127 SearchGeolocationService::Factory::GetForBrowserContext(profile()); | |
| 128 if (search_helper && | |
| 129 search_helper->UseDSEGeolocationSetting( | |
| 130 url::Origin(embedding_origin))) { | |
| 131 SearchGeolocationDisclosureTabHelper::FromWebContents(web_contents) | |
| 132 ->MaybeShowDisclosureForAPIUsage(requesting_origin); | |
| 133 } | |
| 134 } | |
| 135 } | |
| 136 | |
| 107 void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions( | 137 void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions( |
| 138 content::WebContents* web_contents, | |
| 108 const PermissionRequestID& id, | 139 const PermissionRequestID& id, |
| 109 const GURL& requesting_frame_origin, | 140 const GURL& requesting_frame_origin, |
| 110 const GURL& embedding_origin, | 141 const GURL& embedding_origin, |
| 111 const BrowserPermissionCallback& callback, | 142 const BrowserPermissionCallback& callback, |
| 112 bool permissions_updated) { | 143 bool permissions_updated) { |
| 113 permission_update_infobar_ = nullptr; | 144 permission_update_infobar_ = nullptr; |
| 114 | 145 |
| 115 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 146 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 116 ContentSetting new_setting = permissions_updated | 147 ContentSetting new_setting = permissions_updated |
| 117 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 148 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 118 | 149 |
| 119 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback, | 150 NotifyPermissionSet(web_contents, id, requesting_frame_origin, |
| 120 false /* persist */, new_setting); | 151 embedding_origin, callback, false /* persist */, |
| 152 new_setting); | |
| 121 } | 153 } |
| 122 | 154 |
| 123 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( | 155 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting( |
| 124 std::unique_ptr<LocationSettings> settings) { | 156 std::unique_ptr<LocationSettings> settings) { |
| 125 location_settings_ = std::move(settings); | 157 location_settings_ = std::move(settings); |
| 126 } | 158 } |
| OLD | NEW |