| 1 | /* |
| 2 | * Copyright (C) 2014 Igalia S.L |
| 3 | * Copyright (C) 2016 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Lesser General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Lesser General Public |
| 16 | * License along with this library; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "config.h" |
| 21 | #include "WKUserMediaPermissionRequest.h" |
| 22 | |
| 23 | #include "UserMediaPermissionRequestProxy.h" |
| 24 | #include "WKAPICast.h" |
| 25 | #include "WKArray.h" |
| 26 | #include "WKMutableArray.h" |
| 27 | #include "WKString.h" |
| 28 | |
| 29 | using namespace WebKit; |
| 30 | |
| 31 | WKTypeID WKUserMediaPermissionRequestGetTypeID() |
| 32 | { |
| 33 | return toAPI(UserMediaPermissionRequestProxy::APIType); |
| 34 | } |
| 35 | |
| 36 | |
| 37 | void WKUserMediaPermissionRequestAllow(WKUserMediaPermissionRequestRef userMediaPermissionRequestRef, WKStringRef audioDeviceUID, WKStringRef videoDeviceUID) |
| 38 | { |
| 39 | toImpl(userMediaPermissionRequestRef)->allow(toWTFString(audioDeviceUID), toWTFString(videoDeviceUID)); |
| 40 | } |
| 41 | |
| 42 | static UserMediaPermissionRequestProxy::UserMediaAccessDenialReason toWK(UserMediaPermissionRequestDenialReason reason) |
| 43 | { |
| 44 | switch (reason) { |
| 45 | case kWKNoConstraints: |
| 46 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::NoConstraints; |
| 47 | break; |
| 48 | case kWKUserMediaDisabled: |
| 49 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::UserMediaDisabled; |
| 50 | break; |
| 51 | case kWKNoCaptureDevices: |
| 52 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::NoCaptureDevices; |
| 53 | break; |
| 54 | case kWKInvalidConstraint: |
| 55 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::InvalidConstraint; |
| 56 | break; |
| 57 | case kWKHardwareError: |
| 58 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::HardwareError; |
| 59 | break; |
| 60 | case kWKPermissionDenied: |
| 61 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::PermissionDenied; |
| 62 | break; |
| 63 | case kWKOtherFailure: |
| 64 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::OtherFailure; |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | ASSERT_NOT_REACHED(); |
| 69 | return UserMediaPermissionRequestProxy::UserMediaAccessDenialReason::OtherFailure; |
| 70 | |
| 71 | } |
| 72 | |
| 73 | void WKUserMediaPermissionRequestDeny(WKUserMediaPermissionRequestRef userMediaPermissionRequestRef, UserMediaPermissionRequestDenialReason reason) |
| 74 | { |
| 75 | toImpl(userMediaPermissionRequestRef)->deny(toWK(reason)); |
| 76 | } |
| 77 | |
| 78 | WKArrayRef WKUserMediaPermissionRequestVideoDeviceUIDs(WKUserMediaPermissionRequestRef userMediaPermissionRef) |
| 79 | { |
| 80 | WKMutableArrayRef array = WKMutableArrayCreate(); |
| 81 | #if ENABLE(MEDIA_STREAM) |
| 82 | for (auto& deviceUID : toImpl(userMediaPermissionRef)->videoDeviceUIDs()) |
| 83 | WKArrayAppendItem(array, toAPI(API::String::create(deviceUID).ptr())); |
| 84 | #endif |
| 85 | return array; |
| 86 | } |
| 87 | |
| 88 | WKArrayRef WKUserMediaPermissionRequestAudioDeviceUIDs(WKUserMediaPermissionRequestRef userMediaPermissionRef) |
| 89 | { |
| 90 | WKMutableArrayRef array = WKMutableArrayCreate(); |
| 91 | #if ENABLE(MEDIA_STREAM) |
| 92 | for (auto& deviceUID : toImpl(userMediaPermissionRef)->audioDeviceUIDs()) |
| 93 | WKArrayAppendItem(array, toAPI(API::String::create(deviceUID).ptr())); |
| 94 | #endif |
| 95 | return array; |
| 96 | } |
| 97 | |