| 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 11 matching lines...) Expand all Loading... |
| 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_bubble_request_impl.h" |
| 32 #include "chrome/browser/ui/website_settings/permission_bubble_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 |
| 42 PermissionContextBase::PermissionContextBase( | 42 PermissionContextBase::PermissionContextBase( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 PermissionBubbleRequest* cancelling = pending_bubbles_.get(id.ToString()); |
| 154 if (cancelling != NULL && web_contents != NULL && | 154 if (cancelling != NULL && web_contents != NULL && |
| 155 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { | 155 PermissionRequestManager::FromWebContents(web_contents) != NULL) { |
| 156 PermissionBubbleManager::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 PermissionBubbleManager* bubble_manager = | 171 PermissionRequestManager* permission_request_manager = |
| 172 PermissionBubbleManager::FromWebContents(web_contents); | 172 PermissionRequestManager::FromWebContents(web_contents); |
| 173 // TODO(felt): sometimes |bubble_manager| is null. This check is meant to | 173 // TODO(felt): sometimes |permission_request_manager| is null. This check is |
| 174 // prevent crashes. See crbug.com/457091. | 174 // meant to prevent crashes. See crbug.com/457091. |
| 175 if (!bubble_manager) | 175 if (!permission_request_manager) |
| 176 return; | 176 return; |
| 177 std::unique_ptr<PermissionBubbleRequest> request_ptr( | 177 std::unique_ptr<PermissionBubbleRequest> request_ptr( |
| 178 new PermissionBubbleRequestImpl( | 178 new PermissionBubbleRequestImpl( |
| 179 requesting_origin, permission_type_, | 179 requesting_origin, permission_type_, |
| 180 base::Bind(&PermissionContextBase::PermissionDecided, | 180 base::Bind(&PermissionContextBase::PermissionDecided, |
| 181 weak_factory_.GetWeakPtr(), id, requesting_origin, | 181 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 182 embedding_origin, callback), | 182 embedding_origin, callback), |
| 183 base::Bind(&PermissionContextBase::CleanUpBubble, | 183 base::Bind(&PermissionContextBase::CleanUpBubble, |
| 184 weak_factory_.GetWeakPtr(), id))); | 184 weak_factory_.GetWeakPtr(), id))); |
| 185 PermissionBubbleRequest* request = request_ptr.get(); | 185 PermissionBubbleRequest* request = request_ptr.get(); |
| 186 | 186 |
| 187 bool inserted = | 187 bool inserted = |
| 188 pending_bubbles_.add(id.ToString(), std::move(request_ptr)).second; | 188 pending_bubbles_.add(id.ToString(), std::move(request_ptr)).second; |
| 189 DCHECK(inserted) << "Duplicate id " << id.ToString(); | 189 DCHECK(inserted) << "Duplicate id " << id.ToString(); |
| 190 bubble_manager->AddRequest(request); | 190 permission_request_manager->AddRequest(request); |
| 191 #else | 191 #else |
| 192 GetQueueController()->CreateInfoBarRequest( | 192 GetQueueController()->CreateInfoBarRequest( |
| 193 id, requesting_origin, embedding_origin, | 193 id, requesting_origin, embedding_origin, |
| 194 base::Bind(&PermissionContextBase::PermissionDecided, | 194 base::Bind(&PermissionContextBase::PermissionDecided, |
| 195 weak_factory_.GetWeakPtr(), id, requesting_origin, | 195 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 196 embedding_origin, callback, | 196 embedding_origin, callback, |
| 197 // the queue controller takes care of persisting the | 197 // the queue controller takes care of persisting the |
| 198 // permission | 198 // permission |
| 199 false)); | 199 false)); |
| 200 #endif | 200 #endif |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 content_setting); | 282 content_setting); |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool PermissionContextBase::IsPermissionKillSwitchOn() const { | 285 bool PermissionContextBase::IsPermissionKillSwitchOn() const { |
| 286 const std::string param = variations::GetVariationParamValue( | 286 const std::string param = variations::GetVariationParamValue( |
| 287 kPermissionsKillSwitchFieldStudy, | 287 kPermissionsKillSwitchFieldStudy, |
| 288 PermissionUtil::GetPermissionString(permission_type_)); | 288 PermissionUtil::GetPermissionString(permission_type_)); |
| 289 | 289 |
| 290 return param == kPermissionsKillSwitchBlockedValue; | 290 return param == kPermissionsKillSwitchBlockedValue; |
| 291 } | 291 } |
| OLD | NEW |