Chromium Code Reviews| 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/media/webrtc/media_stream_devices_controller.h" | |
| 10 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android .h" | 9 #include "chrome/browser/permissions/grouped_permission_infobar_delegate_android .h" |
| 11 #include "chrome/browser/permissions/permission_request.h" | 10 #include "chrome/browser/permissions/permission_request.h" |
| 12 #include "chrome/browser/permissions/permission_request_id.h" | |
| 13 #include "components/infobars/core/infobar.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 | 11 |
| 16 PermissionPromptAndroid::PermissionPromptAndroid( | 12 PermissionPromptAndroid::PermissionPromptAndroid( |
| 17 content::WebContents* web_contents) | 13 content::WebContents* web_contents) |
| 18 : web_contents_(web_contents), delegate_(nullptr), infobar_(nullptr) { | 14 : web_contents_(web_contents), delegate_(nullptr) { |
| 19 DCHECK(web_contents); | 15 DCHECK(web_contents); |
| 20 } | 16 } |
| 21 | 17 |
| 22 PermissionPromptAndroid::~PermissionPromptAndroid() { | 18 PermissionPromptAndroid::~PermissionPromptAndroid() {} |
| 23 if (infobar_) { | |
| 24 GroupedPermissionInfoBarDelegate* infobar_delegate = | |
| 25 static_cast<GroupedPermissionInfoBarDelegate*>(infobar_->delegate()); | |
| 26 infobar_delegate->PermissionPromptDestroyed(); | |
| 27 } | |
| 28 } | |
| 29 | 19 |
| 30 void PermissionPromptAndroid::SetDelegate(Delegate* delegate) { | 20 void PermissionPromptAndroid::SetDelegate(Delegate* delegate) { |
| 31 delegate_ = delegate; | 21 delegate_ = delegate; |
| 32 } | 22 } |
| 33 | 23 |
| 34 void PermissionPromptAndroid::Show( | 24 void PermissionPromptAndroid::Show( |
| 35 const std::vector<PermissionRequest*>& requests, | 25 const std::vector<PermissionRequest*>& requests, |
| 36 const std::vector<bool>& values) { | 26 const std::vector<bool>& values) { |
| 37 InfoBarService* infobar_service = | 27 InfoBarService* infobar_service = |
| 38 InfoBarService::FromWebContents(web_contents_); | 28 InfoBarService::FromWebContents(web_contents_); |
| 39 if (!infobar_service) | 29 if (!infobar_service) |
| 40 return; | 30 return; |
| 41 | 31 |
| 42 requests_ = requests; | 32 requests_ = requests; |
| 43 infobar_ = GroupedPermissionInfoBarDelegate::Create(this, infobar_service, | 33 GroupedPermissionInfoBarDelegate::Create(this, infobar_service, |
| 44 requests[0]->GetOrigin()); | 34 requests[0]->GetOrigin()); |
| 45 } | 35 } |
| 46 | 36 |
| 47 bool PermissionPromptAndroid::CanAcceptRequestUpdate() { | 37 bool PermissionPromptAndroid::CanAcceptRequestUpdate() { |
| 48 return false; | 38 return false; |
| 49 } | 39 } |
| 50 | 40 |
| 51 void PermissionPromptAndroid::Hide() { | 41 void PermissionPromptAndroid::Hide() { |
| 52 InfoBarService* infobar_service = | 42 // No-op. Hide() is called in three cases: |
| 53 InfoBarService::FromWebContents(web_contents_); | 43 // - After the user resolves a prompt. The infobar manager will hide the |
| 54 if (infobar_ && infobar_service) { | 44 // prompt for us. |
| 55 infobar_service->RemoveInfoBar(infobar_); | 45 // - DidFinishNavigation, etc. The infobar manager handles this. |
| 56 } | 46 // - PermissionManager::CancelRequest(). As CanAcceptRequestUpdate() returns |
| 57 infobar_ = nullptr; | 47 // false, it doesn't call into here and instead dummies out the callbacks. |
|
benwells
2017/03/20 03:00:43
This feels brittle - e.g. someone might add a new
Timothy Loh
2017/03/20 04:00:41
If we don't remove this pointer, then we'd need to
| |
| 58 } | 48 } |
| 59 | 49 |
| 60 bool PermissionPromptAndroid::IsVisible() { | 50 bool PermissionPromptAndroid::IsVisible() { |
| 61 return infobar_ != nullptr; | 51 return !requests_.empty(); |
| 62 } | 52 } |
| 63 | 53 |
| 64 void PermissionPromptAndroid::UpdateAnchorPosition() { | 54 void PermissionPromptAndroid::UpdateAnchorPosition() { |
| 65 NOTREACHED() << "UpdateAnchorPosition is not implemented"; | 55 NOTREACHED() << "UpdateAnchorPosition is not implemented"; |
| 66 } | 56 } |
| 67 | 57 |
| 68 gfx::NativeWindow PermissionPromptAndroid::GetNativeWindow() { | 58 gfx::NativeWindow PermissionPromptAndroid::GetNativeWindow() { |
| 69 NOTREACHED() << "GetNativeWindow is not implemented"; | 59 NOTREACHED() << "GetNativeWindow is not implemented"; |
| 70 return nullptr; | 60 return nullptr; |
| 71 } | 61 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 108 size_t position) const { | 98 size_t position) const { |
| 109 DCHECK_LT(position, requests_.size()); | 99 DCHECK_LT(position, requests_.size()); |
| 110 return requests_[position]->GetMessageTextFragment(); | 100 return requests_[position]->GetMessageTextFragment(); |
| 111 } | 101 } |
| 112 | 102 |
| 113 // static | 103 // static |
| 114 std::unique_ptr<PermissionPrompt> PermissionPrompt::Create( | 104 std::unique_ptr<PermissionPrompt> PermissionPrompt::Create( |
| 115 content::WebContents* web_contents) { | 105 content::WebContents* web_contents) { |
| 116 return base::MakeUnique<PermissionPromptAndroid>(web_contents); | 106 return base::MakeUnique<PermissionPromptAndroid>(web_contents); |
| 117 } | 107 } |
| OLD | NEW |