OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_prompt_android.h" | 5 #include "chrome/browser/permissions/permission_prompt_android.h" |
6 | 6 |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "chrome/browser/infobars/infobar_service.h" | 8 #include "chrome/browser/infobars/infobar_service.h" |
9 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android
.h" | 9 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android
.h" |
| 10 #include "chrome/browser/permissions/permission_dialog_delegate.h" |
10 #include "chrome/browser/permissions/permission_request.h" | 11 #include "chrome/browser/permissions/permission_request.h" |
11 | 12 |
12 PermissionPromptAndroid::PermissionPromptAndroid( | 13 PermissionPromptAndroid::PermissionPromptAndroid( |
13 content::WebContents* web_contents) | 14 content::WebContents* web_contents) |
14 : web_contents_(web_contents), delegate_(nullptr) { | 15 : web_contents_(web_contents), delegate_(nullptr) { |
15 DCHECK(web_contents); | 16 DCHECK(web_contents); |
16 } | 17 } |
17 | 18 |
18 PermissionPromptAndroid::~PermissionPromptAndroid() {} | 19 PermissionPromptAndroid::~PermissionPromptAndroid() {} |
19 | 20 |
20 void PermissionPromptAndroid::SetDelegate(Delegate* delegate) { | 21 void PermissionPromptAndroid::SetDelegate(Delegate* delegate) { |
21 delegate_ = delegate; | 22 delegate_ = delegate; |
22 } | 23 } |
23 | 24 |
24 void PermissionPromptAndroid::Show() { | 25 void PermissionPromptAndroid::Show() { |
| 26 // Grouped permission requests are not yet supported in dialogs. |
| 27 // TODO(timloh): Handle grouped media permissions (camera + microphone). |
| 28 if (delegate_->Requests().size() == 1) { |
| 29 bool has_gesture = delegate_->Requests()[0]->GetGestureType() == |
| 30 PermissionRequestGestureType::GESTURE; |
| 31 if (PermissionDialogDelegate::ShouldShowDialog(has_gesture)) { |
| 32 PermissionDialogDelegate::Create(web_contents_, this); |
| 33 return; |
| 34 } |
| 35 } |
| 36 |
25 InfoBarService* infobar_service = | 37 InfoBarService* infobar_service = |
26 InfoBarService::FromWebContents(web_contents_); | 38 InfoBarService::FromWebContents(web_contents_); |
27 if (!infobar_service) | 39 if (!infobar_service) |
28 return; | 40 return; |
29 | 41 |
30 GroupedPermissionInfoBarDelegate::Create( | 42 GroupedPermissionInfoBarDelegate::Create( |
31 this, infobar_service, delegate_->Requests()[0]->GetOrigin()); | 43 this, infobar_service, delegate_->Requests()[0]->GetOrigin()); |
32 } | 44 } |
33 | 45 |
34 bool PermissionPromptAndroid::CanAcceptRequestUpdate() { | 46 bool PermissionPromptAndroid::CanAcceptRequestUpdate() { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 const std::vector<PermissionRequest*>& requests = delegate_->Requests(); | 108 const std::vector<PermissionRequest*>& requests = delegate_->Requests(); |
97 DCHECK_LT(position, requests.size()); | 109 DCHECK_LT(position, requests.size()); |
98 return requests[position]->GetMessageTextFragment(); | 110 return requests[position]->GetMessageTextFragment(); |
99 } | 111 } |
100 | 112 |
101 // static | 113 // static |
102 std::unique_ptr<PermissionPrompt> PermissionPrompt::Create( | 114 std::unique_ptr<PermissionPrompt> PermissionPrompt::Create( |
103 content::WebContents* web_contents) { | 115 content::WebContents* web_contents) { |
104 return base::MakeUnique<PermissionPromptAndroid>(web_contents); | 116 return base::MakeUnique<PermissionPromptAndroid>(web_contents); |
105 } | 117 } |
OLD | NEW |