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