| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/permissions/permission_context_base.h" | 5 #include "chrome/browser/permissions/permission_context_base.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
| 22 #include "components/variations/variations_associated_data.h" | 22 #include "components/variations/variations_associated_data.h" |
| 23 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/render_frame_host.h" | 24 #include "content/public/browser/render_frame_host.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/common/origin_util.h" | 26 #include "content/public/common/origin_util.h" |
| 27 | 27 |
| 28 #if defined(OS_ANDROID) | 28 #if defined(OS_ANDROID) |
| 29 #include "chrome/browser/permissions/permission_queue_controller.h" | 29 #include "chrome/browser/permissions/permission_queue_controller.h" |
| 30 #else | 30 #else |
| 31 #include "chrome/browser/permissions/permission_bubble_request_impl.h" | 31 #include "chrome/browser/permissions/permission_request_impl.h" |
| 32 #include "chrome/browser/permissions/permission_request_manager.h" | 32 #include "chrome/browser/permissions/permission_request_manager.h" |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 // static | 35 // static |
| 36 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = | 36 const char PermissionContextBase::kPermissionsKillSwitchFieldStudy[] = |
| 37 "PermissionsKillSwitch"; | 37 "PermissionsKillSwitch"; |
| 38 // static | 38 // static |
| 39 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = | 39 const char PermissionContextBase::kPermissionsKillSwitchBlockedValue[] = |
| 40 "blocked"; | 40 "blocked"; |
| 41 | 41 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 void PermissionContextBase::CancelPermissionRequest( | 145 void PermissionContextBase::CancelPermissionRequest( |
| 146 content::WebContents* web_contents, | 146 content::WebContents* web_contents, |
| 147 const PermissionRequestID& id) { | 147 const PermissionRequestID& id) { |
| 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 148 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 149 | 149 |
| 150 #if defined(OS_ANDROID) | 150 #if defined(OS_ANDROID) |
| 151 GetQueueController()->CancelInfoBarRequest(id); | 151 GetQueueController()->CancelInfoBarRequest(id); |
| 152 #else | 152 #else |
| 153 PermissionBubbleRequest* cancelling = pending_bubbles_.get(id.ToString()); | 153 PermissionRequest* cancelling = pending_requests_.get(id.ToString()); |
| 154 if (cancelling != NULL && web_contents != NULL && | 154 if (cancelling != NULL && web_contents != NULL && |
| 155 PermissionRequestManager::FromWebContents(web_contents) != NULL) { | 155 PermissionRequestManager::FromWebContents(web_contents) != NULL) { |
| 156 PermissionRequestManager::FromWebContents(web_contents) | 156 PermissionRequestManager::FromWebContents(web_contents) |
| 157 ->CancelRequest(cancelling); | 157 ->CancelRequest(cancelling); |
| 158 } | 158 } |
| 159 #endif | 159 #endif |
| 160 } | 160 } |
| 161 | 161 |
| 162 void PermissionContextBase::DecidePermission( | 162 void PermissionContextBase::DecidePermission( |
| 163 content::WebContents* web_contents, | 163 content::WebContents* web_contents, |
| 164 const PermissionRequestID& id, | 164 const PermissionRequestID& id, |
| 165 const GURL& requesting_origin, | 165 const GURL& requesting_origin, |
| 166 const GURL& embedding_origin, | 166 const GURL& embedding_origin, |
| 167 const BrowserPermissionCallback& callback) { | 167 const BrowserPermissionCallback& callback) { |
| 168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 168 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 169 | 169 |
| 170 #if !defined(OS_ANDROID) | 170 #if !defined(OS_ANDROID) |
| 171 PermissionRequestManager* permission_request_manager = | 171 PermissionRequestManager* permission_request_manager = |
| 172 PermissionRequestManager::FromWebContents(web_contents); | 172 PermissionRequestManager::FromWebContents(web_contents); |
| 173 // TODO(felt): sometimes |permission_request_manager| is null. This check is | 173 // TODO(felt): sometimes |permission_request_manager| is null. This check is |
| 174 // meant to prevent crashes. See crbug.com/457091. | 174 // meant to prevent crashes. See crbug.com/457091. |
| 175 if (!permission_request_manager) | 175 if (!permission_request_manager) |
| 176 return; | 176 return; |
| 177 std::unique_ptr<PermissionBubbleRequest> request_ptr( | 177 std::unique_ptr<PermissionRequest> request_ptr(new PermissionRequestImpl( |
| 178 new PermissionBubbleRequestImpl( | |
| 179 requesting_origin, permission_type_, | 178 requesting_origin, permission_type_, |
| 180 base::Bind(&PermissionContextBase::PermissionDecided, | 179 base::Bind(&PermissionContextBase::PermissionDecided, |
| 181 weak_factory_.GetWeakPtr(), id, requesting_origin, | 180 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 182 embedding_origin, callback), | 181 embedding_origin, callback), |
| 183 base::Bind(&PermissionContextBase::CleanUpBubble, | 182 base::Bind(&PermissionContextBase::CleanUpRequest, |
| 184 weak_factory_.GetWeakPtr(), id))); | 183 weak_factory_.GetWeakPtr(), id))); |
| 185 PermissionBubbleRequest* request = request_ptr.get(); | 184 PermissionRequest* request = request_ptr.get(); |
| 186 | 185 |
| 187 bool inserted = | 186 bool inserted = |
| 188 pending_bubbles_.add(id.ToString(), std::move(request_ptr)).second; | 187 pending_requests_.add(id.ToString(), std::move(request_ptr)).second; |
| 189 DCHECK(inserted) << "Duplicate id " << id.ToString(); | 188 DCHECK(inserted) << "Duplicate id " << id.ToString(); |
| 190 permission_request_manager->AddRequest(request); | 189 permission_request_manager->AddRequest(request); |
| 191 #else | 190 #else |
| 192 GetQueueController()->CreateInfoBarRequest( | 191 GetQueueController()->CreateInfoBarRequest( |
| 193 id, requesting_origin, embedding_origin, | 192 id, requesting_origin, embedding_origin, |
| 194 base::Bind(&PermissionContextBase::PermissionDecided, | 193 base::Bind(&PermissionContextBase::PermissionDecided, |
| 195 weak_factory_.GetWeakPtr(), id, requesting_origin, | 194 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 196 embedding_origin, callback, | 195 embedding_origin, callback, |
| 197 // the queue controller takes care of persisting the | 196 // the queue controller takes care of persisting the |
| 198 // permission | 197 // permission |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 if (content_setting == CONTENT_SETTING_DEFAULT) { | 254 if (content_setting == CONTENT_SETTING_DEFAULT) { |
| 256 content_setting = | 255 content_setting = |
| 257 HostContentSettingsMapFactory::GetForProfile(profile_) | 256 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 258 ->GetDefaultContentSetting(content_settings_type_, nullptr); | 257 ->GetDefaultContentSetting(content_settings_type_, nullptr); |
| 259 } | 258 } |
| 260 | 259 |
| 261 DCHECK_NE(content_setting, CONTENT_SETTING_DEFAULT); | 260 DCHECK_NE(content_setting, CONTENT_SETTING_DEFAULT); |
| 262 callback.Run(content_setting); | 261 callback.Run(content_setting); |
| 263 } | 262 } |
| 264 | 263 |
| 265 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) { | 264 void PermissionContextBase::CleanUpRequest(const PermissionRequestID& id) { |
| 266 size_t success = pending_bubbles_.erase(id.ToString()); | 265 size_t success = pending_requests_.erase(id.ToString()); |
| 267 DCHECK(success == 1) << "Missing request " << id.ToString(); | 266 DCHECK(success == 1) << "Missing request " << id.ToString(); |
| 268 } | 267 } |
| 269 | 268 |
| 270 void PermissionContextBase::UpdateContentSetting( | 269 void PermissionContextBase::UpdateContentSetting( |
| 271 const GURL& requesting_origin, | 270 const GURL& requesting_origin, |
| 272 const GURL& embedding_origin, | 271 const GURL& embedding_origin, |
| 273 ContentSetting content_setting) { | 272 ContentSetting content_setting) { |
| 274 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); | 273 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); |
| 275 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); | 274 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); |
| 276 DCHECK(content_setting == CONTENT_SETTING_ALLOW || | 275 DCHECK(content_setting == CONTENT_SETTING_ALLOW || |
| 277 content_setting == CONTENT_SETTING_BLOCK); | 276 content_setting == CONTENT_SETTING_BLOCK); |
| 278 | 277 |
| 279 HostContentSettingsMapFactory::GetForProfile(profile_) | 278 HostContentSettingsMapFactory::GetForProfile(profile_) |
| 280 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, | 279 ->SetContentSettingDefaultScope(requesting_origin, embedding_origin, |
| 281 content_settings_type_, std::string(), | 280 content_settings_type_, std::string(), |
| 282 content_setting); | 281 content_setting); |
| 283 } | 282 } |
| 284 | 283 |
| 285 bool PermissionContextBase::IsPermissionKillSwitchOn() const { | 284 bool PermissionContextBase::IsPermissionKillSwitchOn() const { |
| 286 const std::string param = variations::GetVariationParamValue( | 285 const std::string param = variations::GetVariationParamValue( |
| 287 kPermissionsKillSwitchFieldStudy, | 286 kPermissionsKillSwitchFieldStudy, |
| 288 PermissionUtil::GetPermissionString(permission_type_)); | 287 PermissionUtil::GetPermissionString(permission_type_)); |
| 289 | 288 |
| 290 return param == kPermissionsKillSwitchBlockedValue; | 289 return param == kPermissionsKillSwitchBlockedValue; |
| 291 } | 290 } |
| OLD | NEW |