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