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 <memory> 20 #include <string> 21 22 #include "nweb_export.h" 23 24 namespace OHOS::NWeb { 25 26 class OHOS_NWEB_EXPORT NWebAccessRequest { 27 public: 28 NWebAccessRequest() = default; 29 30 virtual ~NWebAccessRequest() = default; 31 32 enum Resources { 33 GEOLOCATION = 1 << 0, 34 VIDEO_CAPTURE = 1 << 1, 35 AUDIO_CAPTURE = 1 << 2, 36 PROTECTED_MEDIA_ID = 1 << 3, 37 MIDI_SYSEX = 1 << 4, 38 CLIPBOARD_READ_WRITE = 1 << 5, 39 CLIPBOARD_SANITIZED_WRITE = 1 << 6, 40 SENSORS = 1 << 7, 41 NOTIFICATION = 1 << 8, 42 }; 43 44 /** 45 * Get the origin of the web page which is trying to access the resource. 46 * 47 * @return the origin of the web page which is trying to access the resource. 48 */ 49 virtual std::string Origin() = 0; 50 51 /** 52 * Get the resource id the web page is trying to access. 53 * 54 * @return the resource id the web page is trying to access. 55 */ 56 virtual int ResourceAcessId() = 0; 57 58 /** 59 * Agree the origin to access the given resources. 60 * The granted access is only valid for this WebView. 61 * 62 * @param resourceId id of the resource agreed to be accessed by origin. It 63 * must be equal to requested resource id returned by {@link 64 * #GetResourceAcessId()}. 65 */ 66 virtual void Agree(int resourceId) = 0; 67 68 /** 69 * Refuse the request. 70 */ 71 virtual void Refuse() = 0; 72 }; 73 74 class NWebScreenCaptureConfig { 75 public: 76 virtual ~NWebScreenCaptureConfig() = default; 77 78 virtual int32_t GetMode() = 0; 79 virtual int32_t GetSourceId() = 0; 80 }; 81 82 class OHOS_NWEB_EXPORT NWebScreenCaptureAccessRequest { 83 public: 84 NWebScreenCaptureAccessRequest() = default; 85 86 virtual ~NWebScreenCaptureAccessRequest() = default; 87 88 /** 89 * Get the origin of the web page which is trying to access the screen capture resource. 90 * 91 * @return the origin of the web page which is trying to access the resource. 92 */ 93 virtual std::string Origin() = 0; 94 95 /** 96 * Agree the origin to access the given resources. 97 * The granted access is only valid for this WebView. 98 * 99 * @param config screen capture config. 100 */ 101 virtual void Agree(std::shared_ptr<NWebScreenCaptureConfig> config) = 0; 102 103 /** 104 * Refuse the request. 105 */ 106 virtual void Refuse() = 0; 107 }; 108 109 } // namespace OHOS::NWeb 110 111 #endif // NWEB_ACCESS_REQUEST_H 112