1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef NWEB_ACCESS_REQUEST_H 17 #define NWEB_ACCESS_REQUEST_H 18 19 #include <string> 20 21 #include "nweb_export.h" 22 23 namespace OHOS::NWeb { 24 class OHOS_NWEB_EXPORT NWebAccessRequest { 25 public: 26 NWebAccessRequest() = default; 27 28 virtual ~NWebAccessRequest() = default; 29 30 enum Resources { 31 GEOLOCATION = 1 << 0, 32 VIDEO_CAPTURE = 1 << 1, 33 AUDIO_CAPTURE = 1 << 2, 34 PROTECTED_MEDIA_ID = 1 << 3, 35 MIDI_SYSEX = 1 << 4, 36 }; 37 38 /** 39 * Get the origin of the web page which is trying to access the resource. 40 * 41 * @return the origin of the web page which is trying to access the resource. 42 */ 43 virtual std::string Origin() = 0; 44 45 /** 46 * Get the resource id the web page is trying to access. 47 * 48 * @return the resource id the web page is trying to access. 49 */ 50 virtual int ResourceAcessId() = 0; 51 52 /** 53 * Agree the origin to access the given resources. 54 * The granted access is only valid for this WebView. 55 * 56 * @param resourceId id of the resource agreed to be accessed by origin. It 57 * must be equal to requested resource id returned by {@link 58 * #GetResourceAcessId()}. 59 */ 60 virtual void Agree(int resourceId) = 0; 61 62 /** 63 * Refuse the request. 64 */ 65 virtual void Refuse() = 0; 66 }; 67 68 struct NWebScreenCaptureConfig { 69 int32_t mode = 0; 70 int32_t sourceId = -1; 71 }; 72 73 class OHOS_NWEB_EXPORT NWebScreenCaptureAccessRequest { 74 public: 75 NWebScreenCaptureAccessRequest() = default; 76 77 virtual ~NWebScreenCaptureAccessRequest() = default; 78 79 /** 80 * Get the origin of the web page which is trying to access the screen capture resource. 81 * 82 * @return the origin of the web page which is trying to access the screen capture resource. 83 */ 84 virtual std::string Origin() = 0; 85 86 /** 87 * Agree the origin to access the given resources. 88 * The granted access is only valid for this WebView. 89 * 90 * @param config screen capture config. 91 */ 92 virtual void Agree(const NWebScreenCaptureConfig& config) = 0; 93 94 /** 95 * Refuse the screen capture request. 96 */ 97 virtual void Refuse() = 0; 98 }; 99 } // namespace OHOS::NWeb 100 101 #endif // NWEB_ACCESS_REQUEST_H