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 CLIPBOARD_READ_WRITE = 1 << 5, 37 }; 38 39 /** 40 * Get the origin of the web page which is trying to access the resource. 41 * 42 * @return the origin of the web page which is trying to access the resource. 43 */ 44 virtual std::string Origin() = 0; 45 46 /** 47 * Get the resource id the web page is trying to access. 48 * 49 * @return the resource id the web page is trying to access. 50 */ 51 virtual int ResourceAcessId() = 0; 52 53 /** 54 * Agree the origin to access the given resources. 55 * The granted access is only valid for this WebView. 56 * 57 * @param resourceId id of the resource agreed to be accessed by origin. It 58 * must be equal to requested resource id returned by {@link 59 * #GetResourceAcessId()}. 60 */ 61 virtual void Agree(int resourceId) = 0; 62 63 /** 64 * Refuse the request. 65 */ 66 virtual void Refuse() = 0; 67 }; 68 69 struct NWebScreenCaptureConfig { 70 int32_t mode = 0; 71 int32_t sourceId = -1; 72 }; 73 74 class OHOS_NWEB_EXPORT NWebScreenCaptureAccessRequest { 75 public: 76 NWebScreenCaptureAccessRequest() = default; 77 78 virtual ~NWebScreenCaptureAccessRequest() = default; 79 80 /** 81 * Get the origin of the web page which is trying to access the screen capture resource. 82 * 83 * @return the origin of the web page which is trying to access the screen capture resource. 84 */ 85 virtual std::string Origin() = 0; 86 87 /** 88 * Agree the origin to access the given resources. 89 * The granted access is only valid for this WebView. 90 * 91 * @param config screen capture config. 92 */ 93 virtual void Agree(const NWebScreenCaptureConfig& config) = 0; 94 95 /** 96 * Refuse the screen capture request. 97 */ 98 virtual void Refuse() = 0; 99 }; 100 } // namespace OHOS::NWeb 101 102 #endif // NWEB_ACCESS_REQUEST_H