| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 void PermissionContextBase::CancelPermissionRequest( | 146 void PermissionContextBase::CancelPermissionRequest( |
| 147 content::WebContents* web_contents, | 147 content::WebContents* web_contents, |
| 148 const PermissionRequestID& id) { | 148 const PermissionRequestID& id) { |
| 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 149 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 150 | 150 |
| 151 #if defined(OS_ANDROID) | 151 #if defined(OS_ANDROID) |
| 152 GetQueueController()->CancelInfoBarRequest(id); | 152 GetQueueController()->CancelInfoBarRequest(id); |
| 153 #else | 153 #else |
| 154 PermissionBubbleRequest* cancelling = pending_bubbles_.get(id.ToString()); | 154 PermissionBubbleRequest* cancelling = pending_bubbles_.get(id.ToString()); |
| 155 if (cancelling != NULL && web_contents != NULL && | 155 if (cancelling != NULL && web_contents != NULL && |
| 156 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { | 156 PermissionRequestManager::FromWebContents(web_contents) != NULL) { |
| 157 PermissionBubbleManager::FromWebContents(web_contents) | 157 PermissionRequestManager::FromWebContents(web_contents) |
| 158 ->CancelRequest(cancelling); | 158 ->CancelRequest(cancelling); |
| 159 } | 159 } |
| 160 #endif | 160 #endif |
| 161 } | 161 } |
| 162 | 162 |
| 163 void PermissionContextBase::DecidePermission( | 163 void PermissionContextBase::DecidePermission( |
| 164 content::WebContents* web_contents, | 164 content::WebContents* web_contents, |
| 165 const PermissionRequestID& id, | 165 const PermissionRequestID& id, |
| 166 const GURL& requesting_origin, | 166 const GURL& requesting_origin, |
| 167 const GURL& embedding_origin, | 167 const GURL& embedding_origin, |
| 168 bool user_gesture, | 168 bool user_gesture, |
| 169 const BrowserPermissionCallback& callback) { | 169 const BrowserPermissionCallback& callback) { |
| 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 170 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 171 | 171 |
| 172 #if !defined(OS_ANDROID) | 172 #if !defined(OS_ANDROID) |
| 173 PermissionBubbleManager* bubble_manager = | 173 PermissionRequestManager* permission_request_manager = |
| 174 PermissionBubbleManager::FromWebContents(web_contents); | 174 PermissionRequestManager::FromWebContents(web_contents); |
| 175 // TODO(felt): sometimes |bubble_manager| is null. This check is meant to | 175 // TODO(felt): sometimes |permission_request_manager| is null. This check is |
| 176 // prevent crashes. See crbug.com/457091. | 176 // meant to prevent crashes. See crbug.com/457091. |
| 177 if (!bubble_manager) | 177 if (!permission_request_manager) |
| 178 return; | 178 return; |
| 179 std::unique_ptr<PermissionBubbleRequest> request_ptr( | 179 std::unique_ptr<PermissionBubbleRequest> request_ptr( |
| 180 new PermissionBubbleRequestImpl( | 180 new PermissionBubbleRequestImpl( |
| 181 requesting_origin, permission_type_, | 181 requesting_origin, permission_type_, |
| 182 base::Bind(&PermissionContextBase::PermissionDecided, | 182 base::Bind(&PermissionContextBase::PermissionDecided, |
| 183 weak_factory_.GetWeakPtr(), id, requesting_origin, | 183 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 184 embedding_origin, callback), | 184 embedding_origin, callback), |
| 185 base::Bind(&PermissionContextBase::CleanUpBubble, | 185 base::Bind(&PermissionContextBase::CleanUpBubble, |
| 186 weak_factory_.GetWeakPtr(), id))); | 186 weak_factory_.GetWeakPtr(), id))); |
| 187 PermissionBubbleRequest* request = request_ptr.get(); | 187 PermissionBubbleRequest* request = request_ptr.get(); |
| 188 | 188 |
| 189 bool inserted = | 189 bool inserted = |
| 190 pending_bubbles_.add(id.ToString(), std::move(request_ptr)).second; | 190 pending_bubbles_.add(id.ToString(), std::move(request_ptr)).second; |
| 191 DCHECK(inserted) << "Duplicate id " << id.ToString(); | 191 DCHECK(inserted) << "Duplicate id " << id.ToString(); |
| 192 bubble_manager->AddRequest(request); | 192 permission_request_manager->AddRequest(request); |
| 193 #else | 193 #else |
| 194 GetQueueController()->CreateInfoBarRequest( | 194 GetQueueController()->CreateInfoBarRequest( |
| 195 id, requesting_origin, embedding_origin, | 195 id, requesting_origin, embedding_origin, |
| 196 base::Bind(&PermissionContextBase::PermissionDecided, | 196 base::Bind(&PermissionContextBase::PermissionDecided, |
| 197 weak_factory_.GetWeakPtr(), id, requesting_origin, | 197 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 198 embedding_origin, callback, | 198 embedding_origin, callback, |
| 199 // the queue controller takes care of persisting the | 199 // the queue controller takes care of persisting the |
| 200 // permission | 200 // permission |
| 201 false)); | 201 false)); |
| 202 #endif | 202 #endif |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 content_setting); | 284 content_setting); |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool PermissionContextBase::IsPermissionKillSwitchOn() const { | 287 bool PermissionContextBase::IsPermissionKillSwitchOn() const { |
| 288 const std::string param = variations::GetVariationParamValue( | 288 const std::string param = variations::GetVariationParamValue( |
| 289 kPermissionsKillSwitchFieldStudy, | 289 kPermissionsKillSwitchFieldStudy, |
| 290 PermissionUtil::GetPermissionString(permission_type_)); | 290 PermissionUtil::GetPermissionString(permission_type_)); |
| 291 | 291 |
| 292 return param == kPermissionsKillSwitchBlockedValue; | 292 return param == kPermissionsKillSwitchBlockedValue; |
| 293 } | 293 } |
| OLD | NEW |