Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/permissions/permission_prompt_android.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.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" | |
| 11 #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 | |
| 16 PermissionPromptAndroid::PermissionPromptAndroid( | |
| 17 content::WebContents* web_contents) | |
| 18 : web_contents_(web_contents), | |
| 19 delegate_(nullptr), | |
| 20 infobar_delegate_(nullptr), | |
| 21 infobar_service_(nullptr) { | |
| 22 DCHECK(web_contents); | |
| 23 } | |
| 24 | |
| 25 PermissionPromptAndroid::~PermissionPromptAndroid() {} | |
| 26 | |
| 27 void PermissionPromptAndroid::SetDelegate(Delegate* delegate) { | |
| 28 delegate_ = delegate; | |
| 29 } | |
| 30 | |
| 31 void PermissionPromptAndroid::Show( | |
| 32 const std::vector<PermissionRequest*>& requests, | |
| 33 const std::vector<bool>& values) { | |
| 34 infobar_service_ = InfoBarService::FromWebContents(web_contents_); | |
| 35 | |
| 36 if (!infobar_service_) | |
| 37 return; | |
| 38 | |
| 39 infobar_ = GroupedPermissionInfoBarDelegate::Create( | |
| 40 infobar_service_, requests[0]->GetOrigin(), requests); | |
| 41 | |
| 42 infobar_delegate_ = | |
| 43 infobar_->delegate()->AsGroupedPermissionInfoBarDelegate(); | |
| 44 } | |
| 45 | |
| 46 bool PermissionPromptAndroid::CanAcceptRequestUpdate() { | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 void PermissionPromptAndroid::Hide() { | |
| 51 if (infobar_delegate_ && infobar_service_) { | |
|
raymes
2016/10/24 00:50:15
Do we actually need to check infobar_delegate_ her
| |
| 52 infobar_service_->RemoveInfoBar(infobar_); | |
| 53 infobar_delegate_ = nullptr; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 bool PermissionPromptAndroid::IsVisible() { | |
| 58 return infobar_delegate_ != nullptr; | |
| 59 } | |
| 60 | |
| 61 void PermissionPromptAndroid::UpdateAnchorPosition() { | |
| 62 NOTREACHED() << "UpdateAnchorPosition is not implemented"; | |
| 63 } | |
| 64 | |
| 65 gfx::NativeWindow PermissionPromptAndroid::GetNativeWindow() { | |
| 66 NOTREACHED() << "GetNativeWindow is not implemented"; | |
| 67 return nullptr; | |
| 68 } | |
| 69 | |
| 70 void PermissionPromptAndroid::Closing() { | |
| 71 if (infobar_delegate_) | |
| 72 infobar_delegate_ = nullptr; | |
| 73 if (delegate_) | |
| 74 delegate_->Closing(); | |
| 75 } | |
| 76 | |
| 77 void PermissionPromptAndroid::ToggleAccept(int index, bool value) { | |
| 78 if (infobar_delegate_) | |
| 79 infobar_delegate_->ToggleAccept(index, value); | |
| 80 } | |
| 81 | |
| 82 void PermissionPromptAndroid::Accept() { | |
| 83 if (infobar_delegate_) | |
| 84 infobar_delegate_->Accept(); | |
| 85 } | |
| 86 | |
| 87 void PermissionPromptAndroid::Deny() { | |
| 88 if (infobar_delegate_) | |
| 89 infobar_delegate_->Cancel(); | |
| 90 } | |
| 91 | |
| 92 // static | |
| 93 std::unique_ptr<PermissionPrompt> PermissionPrompt::Create( | |
| 94 content::WebContents* web_contents) { | |
| 95 return base::WrapUnique(new PermissionPromptAndroid(web_contents)); | |
| 96 } | |
| OLD | NEW |