• 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 FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H
18 
19 namespace OHOS::Ace {
20 
21 class WebConsoleLog : public AceType {
22     DECLARE_ACE_TYPE(WebConsoleLog, AceType)
23 public:
24    WebConsoleLog() = default;
25     ~WebConsoleLog() = default;
26 
27     virtual int GetLineNumber() = 0;
28     virtual std::string GetLog() = 0;
29     virtual int GetLogLevel() = 0;
30     virtual std::string GetSourceId() = 0;
31 };
32 
33 class WebFileSelectorParam : public AceType {
34     DECLARE_ACE_TYPE(WebFileSelectorParam, AceType)
35 public:
36     WebFileSelectorParam() = default;
37     ~WebFileSelectorParam() = default;
38 
39     virtual std::string GetTitle() = 0;
40     virtual int GetMode() = 0;
41     virtual std::string GetDefaultFileName() = 0;
42     virtual std::vector<std::string> GetAcceptType() = 0;
43     virtual bool IsCapture() = 0;
44 };
45 
46 class ACE_EXPORT WebError : public AceType {
DECLARE_ACE_TYPE(WebError,AceType)47     DECLARE_ACE_TYPE(WebError, AceType)
48 
49 public:
50     WebError(const std::string& info, int32_t code) : info_(info), code_(code) {}
51     ~WebError() = default;
52 
GetInfo()53     const std::string& GetInfo() const
54     {
55         return info_;
56     }
57 
GetCode()58     int32_t GetCode() const
59     {
60         return code_;
61     }
62 
63 private:
64     std::string info_;
65     int32_t code_;
66 };
67 
68 class ACE_EXPORT WebResponse : public AceType {
DECLARE_ACE_TYPE(WebResponse,AceType)69     DECLARE_ACE_TYPE(WebResponse, AceType)
70 
71 public:
72     WebResponse(const std::map<std::string, std::string>& headers, const std::string& data, const std::string& encoding,
73         const std::string& mimeType, const std::string& reason, int32_t statusCode)
74         : headers_(headers), data_(data), encoding_(encoding), mimeType_(mimeType), reason_(reason),
75           statusCode_(statusCode)
76     {}
77     ~WebResponse() = default;
78 
GetHeaders()79     const std::map<std::string, std::string>& GetHeaders() const
80     {
81         return headers_;
82     }
83 
GetData()84     const std::string& GetData() const
85     {
86         return data_;
87     }
88 
GetEncoding()89     const std::string& GetEncoding() const
90     {
91         return encoding_;
92     }
93 
GetMimeType()94     const std::string& GetMimeType() const
95     {
96         return mimeType_;
97     }
98 
GetReason()99     const std::string& GetReason() const
100     {
101         return reason_;
102     }
103 
GetStatusCode()104     int32_t GetStatusCode() const
105     {
106         return statusCode_;
107     }
108 
109 private:
110     std::map<std::string, std::string> headers_;
111     std::string data_;
112     std::string encoding_;
113     std::string mimeType_;
114     std::string reason_;
115     int32_t statusCode_;
116 };
117 
118 class ACE_EXPORT WebRequest : public AceType {
DECLARE_ACE_TYPE(WebRequest,AceType)119     DECLARE_ACE_TYPE(WebRequest, AceType)
120 
121 public:
122     WebRequest(const std::map<std::string, std::string>& headers, const std::string& method, const std::string& url,
123         bool hasGesture, bool isMainFrame, bool isRedirect)
124         : headers_(headers), method_(method), url_(url), hasGesture_(hasGesture), isMainFrame_(isMainFrame),
125           isRedirect_(isRedirect)
126     {}
127     ~WebRequest() = default;
128 
GetHeaders()129     const std::map<std::string, std::string>& GetHeaders() const
130     {
131         return headers_;
132     }
133 
GetMethod()134     const std::string& GetMethod() const
135     {
136         return method_;
137     }
138 
GetUrl()139     const std::string& GetUrl() const
140     {
141         return url_;
142     }
143 
HasGesture()144     bool HasGesture() const
145     {
146         return hasGesture_;
147     }
148 
IsMainFrame()149     bool IsMainFrame() const
150     {
151         return isMainFrame_;
152     }
153 
IsRedirect()154     bool IsRedirect() const
155     {
156         return isRedirect_;
157     }
158 
159 private:
160     std::map<std::string, std::string> headers_;
161     std::string method_;
162     std::string url_;
163     bool hasGesture_;
164     bool isMainFrame_;
165     bool isRedirect_;
166 };
167 
168 class ACE_EXPORT Result : public AceType {
169     DECLARE_ACE_TYPE(Result, AceType)
170 
171 public:
172     Result() = default;
173     ~Result() = default;
174 
175     virtual void Confirm() = 0;
176     virtual void Confirm(const std::string& message) = 0;
177     virtual void Cancel() = 0;
178 };
179 
180 class ACE_EXPORT FileSelectorResult : public AceType {
181     DECLARE_ACE_TYPE(FileSelectorResult, AceType)
182 
183 public:
184     FileSelectorResult() = default;
185     ~FileSelectorResult() = default;
186 
187     virtual void HandleFileList(std::vector<std::string>& fileList) = 0;
188 };
189 
190 class ACE_EXPORT WebDialogEvent : public BaseEventInfo {
191     DECLARE_RELATIONSHIP_OF_CLASSES(WebDialogEvent, BaseEventInfo);
192 
193 public:
WebDialogEvent(const std::string & url,const std::string & message,const RefPtr<Result> & result)194     WebDialogEvent(const std::string& url, const std::string& message, const RefPtr<Result>& result)
195         : BaseEventInfo("WebDialogEvent"), url_(url), message_(message), result_(result) {}
196     ~WebDialogEvent() = default;
197 
GetUrl()198     const std::string& GetUrl() const
199     {
200         return url_;
201     }
202 
GetMessage()203     const std::string& GetMessage() const
204     {
205         return message_;
206     }
207 
GetResult()208     const RefPtr<Result>& GetResult() const
209     {
210         return result_;
211     }
212 
213 private:
214     std::string url_;
215     std::string message_;
216     RefPtr<Result> result_;
217 };
218 
219 class ACE_EXPORT WebGeolocation : public AceType {
220     DECLARE_ACE_TYPE(WebGeolocation, AceType)
221 
222 public:
223     WebGeolocation() = default;
224     ~WebGeolocation() = default;
225 
226     virtual void Invoke(const std::string& origin, const bool& allow, const bool& retain) = 0;
227 };
228 
229 class ACE_EXPORT LoadWebPageStartEvent : public BaseEventInfo {
230     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebPageStartEvent, BaseEventInfo);
231 
232 public:
LoadWebPageStartEvent(const std::string & url)233     explicit LoadWebPageStartEvent(const std::string& url) : BaseEventInfo
234         ("LoadWebPageStartEvent"), loadedUrl_(url) {}
235     ~LoadWebPageStartEvent() = default;
236 
GetLoadedUrl()237     const std::string& GetLoadedUrl() const
238     {
239         return loadedUrl_;
240     }
241 
242 private:
243     std::string loadedUrl_;
244 };
245 
246 class ACE_EXPORT LoadWebPageFinishEvent : public BaseEventInfo {
247     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebPageFinishEvent, BaseEventInfo);
248 
249 public:
LoadWebPageFinishEvent(const std::string & url)250     explicit LoadWebPageFinishEvent(const std::string& url) : BaseEventInfo
251         ("LoadWebPageFinishEvent"), loadedUrl_(url) {}
252     ~LoadWebPageFinishEvent() = default;
253 
GetLoadedUrl()254     const std::string& GetLoadedUrl() const
255     {
256         return loadedUrl_;
257     }
258 
259 private:
260     std::string loadedUrl_;
261 };
262 
263 class ACE_EXPORT LoadWebProgressChangeEvent : public BaseEventInfo {
264     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebProgressChangeEvent, BaseEventInfo);
265 
266 public:
LoadWebProgressChangeEvent(const int & newProgress)267     explicit LoadWebProgressChangeEvent(const int& newProgress)
268         : BaseEventInfo("LoadWebProgressChangeEvent"), newProgress_(newProgress) {}
269     ~LoadWebProgressChangeEvent() = default;
270 
GetNewProgress()271     const int& GetNewProgress() const
272     {
273         return newProgress_;
274     }
275 
276 private:
277     int newProgress_;
278 };
279 
280 class ACE_EXPORT LoadWebTitleReceiveEvent : public BaseEventInfo {
281     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebTitleReceiveEvent, BaseEventInfo);
282 
283 public:
LoadWebTitleReceiveEvent(const std::string & title)284     explicit LoadWebTitleReceiveEvent(const std::string& title) : BaseEventInfo
285         ("LoadWebTitleReceiveEvent"), title_(title) {}
286     ~LoadWebTitleReceiveEvent() = default;
287 
GetTitle()288     const std::string& GetTitle() const
289     {
290         return title_;
291     }
292 
293 private:
294     std::string title_;
295 };
296 
297 class ACE_EXPORT UrlLoadInterceptEvent : public BaseEventInfo {
298     DECLARE_RELATIONSHIP_OF_CLASSES(UrlLoadInterceptEvent, BaseEventInfo);
299 
300 public:
UrlLoadInterceptEvent(const std::string & data)301     explicit UrlLoadInterceptEvent(const std::string& data) : BaseEventInfo
302         ("UrlLoadInterceptEvent"), data_(data) {}
303     ~UrlLoadInterceptEvent() = default;
304 
GetData()305     const std::string& GetData() const
306     {
307         return data_;
308     }
309 
310 private:
311     std::string data_;
312 };
313 
314 class ACE_EXPORT LoadWebGeolocationHideEvent : public BaseEventInfo {
315     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebGeolocationHideEvent, BaseEventInfo);
316 
317 public:
LoadWebGeolocationHideEvent(const std::string & origin)318     explicit LoadWebGeolocationHideEvent(const std::string& origin)
319         : BaseEventInfo("LoadWebGeolocationHideEvent"), origin_(origin) {}
320     ~LoadWebGeolocationHideEvent() = default;
321 
GetOrigin()322     const std::string& GetOrigin() const
323     {
324         return origin_;
325     }
326 
327 private:
328     std::string origin_;
329 };
330 
331 class ACE_EXPORT LoadWebGeolocationShowEvent : public BaseEventInfo {
332     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebGeolocationShowEvent, BaseEventInfo);
333 
334 public:
LoadWebGeolocationShowEvent(const std::string & origin,const RefPtr<WebGeolocation> & webGeolocation)335     LoadWebGeolocationShowEvent(const std::string& origin, const RefPtr<WebGeolocation>& webGeolocation)
336         : BaseEventInfo("LoadWebGeolocationShowEvent"), origin_(origin), webGeolocation_(webGeolocation) {}
337     ~LoadWebGeolocationShowEvent() = default;
338 
GetOrigin()339     const std::string& GetOrigin() const
340     {
341         return origin_;
342     }
343 
GetWebGeolocation()344     const RefPtr<WebGeolocation>& GetWebGeolocation() const
345     {
346         return webGeolocation_;
347     }
348 
349 private:
350     std::string origin_;
351     RefPtr<WebGeolocation> webGeolocation_;
352 };
353 
354 class ACE_EXPORT DownloadStartEvent : public BaseEventInfo {
355     DECLARE_RELATIONSHIP_OF_CLASSES(DownloadStartEvent, BaseEventInfo);
356 
357 public:
DownloadStartEvent(const std::string & url,const std::string & userAgent,const std::string & contentDisposition,const std::string & mimetype,long contentLength)358     DownloadStartEvent(const std::string& url, const std::string& userAgent, const std::string& contentDisposition,
359         const std::string& mimetype, long contentLength) : BaseEventInfo("DownloadStartEvent"), url_(url),
360         userAgent_(userAgent), contentDisposition_(contentDisposition), mimetype_(mimetype),
361         contentLength_(contentLength) {}
362     ~DownloadStartEvent() = default;
363 
GetUrl()364     const std::string& GetUrl() const
365     {
366         return url_;
367     }
368 
GetUserAgent()369     const std::string& GetUserAgent() const
370     {
371         return userAgent_;
372     }
373 
GetContentDisposition()374     const std::string& GetContentDisposition() const
375     {
376         return contentDisposition_;
377     }
378 
GetMimetype()379     const std::string& GetMimetype() const
380     {
381         return mimetype_;
382     }
383 
GetContentLength()384     long GetContentLength() const
385     {
386         return contentLength_;
387     }
388 
389 private:
390     std::string url_;
391     std::string userAgent_;
392     std::string contentDisposition_;
393     std::string mimetype_;
394     long contentLength_;
395 };
396 
397 class ACE_EXPORT ReceivedErrorEvent : public BaseEventInfo {
398     DECLARE_RELATIONSHIP_OF_CLASSES(ReceivedErrorEvent, BaseEventInfo);
399 
400 public:
ReceivedErrorEvent(const RefPtr<WebRequest> & request,const RefPtr<WebError> & error)401     ReceivedErrorEvent(const RefPtr<WebRequest>& request, const RefPtr<WebError>& error)
402         : BaseEventInfo("ReceivedErrorEvent"), request_(request), error_(error)
403     {
404         LOGI("ReceivedErrorEvent constructor");
405     }
406     ~ReceivedErrorEvent() = default;
407 
GetRequest()408     const RefPtr<WebRequest>& GetRequest() const
409     {
410         return request_;
411     }
412 
GetError()413     const RefPtr<WebError>& GetError() const
414     {
415         return error_;
416     }
417 
418 private:
419     RefPtr<WebRequest> request_;
420     RefPtr<WebError> error_;
421 };
422 
423 class ACE_EXPORT ReceivedHttpErrorEvent : public BaseEventInfo {
424     DECLARE_RELATIONSHIP_OF_CLASSES(ReceivedHttpErrorEvent, BaseEventInfo);
425 
426 public:
ReceivedHttpErrorEvent(const RefPtr<WebRequest> & request,const RefPtr<WebResponse> & response)427     ReceivedHttpErrorEvent(const RefPtr<WebRequest>& request, const RefPtr<WebResponse>& response)
428         : BaseEventInfo("ReceivedHttpErrorEvent"), request_(request), response_(response)
429     {
430         LOGI("ReceivedHttpErrorEvent constructor");
431     }
432     ~ReceivedHttpErrorEvent() = default;
433 
GetRequest()434     const RefPtr<WebRequest>& GetRequest() const
435     {
436         return request_;
437     }
438 
GetResponse()439     const RefPtr<WebResponse>& GetResponse() const
440     {
441         return response_;
442     }
443 
444 private:
445     RefPtr<WebRequest> request_;
446     RefPtr<WebResponse> response_;
447 };
448 
449 class ACE_EXPORT LoadWebRequestFocusEvent : public BaseEventInfo {
450     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebRequestFocusEvent, BaseEventInfo);
451 
452 public:
LoadWebRequestFocusEvent(const std::string & url)453     explicit LoadWebRequestFocusEvent(const std::string& url) : BaseEventInfo
454         ("LoadWebRequestFocusEvent"), focusUrl_(url) {}
455     ~LoadWebRequestFocusEvent() = default;
456 
GetRequestFocus()457     const std::string& GetRequestFocus() const
458     {
459         return focusUrl_;
460     }
461 private:
462     std::string focusUrl_;
463 };
464 
465 class ACE_EXPORT LoadWebOnFocusEvent : public BaseEventInfo {
466     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebOnFocusEvent, BaseEventInfo);
467 
468 public:
LoadWebOnFocusEvent(const std::string & url)469     explicit LoadWebOnFocusEvent(const std::string& url) : BaseEventInfo
470         ("LoadWebOnFocusEvent"), focusUrl_(url) {}
471     ~LoadWebOnFocusEvent() = default;
472 
GetOnFocus()473     const std::string& GetOnFocus() const
474     {
475         return focusUrl_;
476     }
477 private:
478     std::string focusUrl_;
479 };
480 
481 class ACE_EXPORT LoadWebConsoleLogEvent : public BaseEventInfo {
482     DECLARE_RELATIONSHIP_OF_CLASSES(LoadWebConsoleLogEvent, BaseEventInfo);
483 
484 public:
LoadWebConsoleLogEvent(RefPtr<WebConsoleLog> message)485     LoadWebConsoleLogEvent(RefPtr<WebConsoleLog> message) : BaseEventInfo("LoadWebConsoleLogEvent"),
486                                                             message_(message) {}
487     ~LoadWebConsoleLogEvent() = default;
488 
GetMessage()489     const RefPtr<WebConsoleLog> GetMessage() const
490     {
491         return message_;
492     }
493 
494 private:
495     RefPtr<WebConsoleLog> message_;
496 };
497 
498 class ACE_EXPORT RenderExitedEvent : public BaseEventInfo {
499     DECLARE_RELATIONSHIP_OF_CLASSES(RenderExitedEvent, BaseEventInfo);
500 
501 public:
RenderExitedEvent(int32_t exitedReason)502     explicit RenderExitedEvent(int32_t exitedReason) : BaseEventInfo("RenderExitedEvent"), exitedReason_(exitedReason) {}
503     ~RenderExitedEvent() = default;
504 
GetExitedReason()505     int32_t GetExitedReason() const
506     {
507         return exitedReason_;
508     }
509 
510 private:
511     int32_t exitedReason_;
512 };
513 
514 class ACE_EXPORT RefreshAccessedHistoryEvent : public BaseEventInfo {
515     DECLARE_RELATIONSHIP_OF_CLASSES(RefreshAccessedHistoryEvent, BaseEventInfo);
516 
517 public:
RefreshAccessedHistoryEvent(const std::string & url,bool isRefreshed)518     RefreshAccessedHistoryEvent(const std::string& url, bool isRefreshed) :
519                                 BaseEventInfo("RefreshAccessedHistoryEvent"),
520                                 url_(url),  isRefreshed_(isRefreshed) {}
521 
522     ~RefreshAccessedHistoryEvent() = default;
523 
GetVisitedUrl()524     const std::string& GetVisitedUrl() const
525     {
526         return url_;
527     }
528 
IsRefreshed()529     bool IsRefreshed() const
530     {
531         return isRefreshed_;
532     }
533 
534 private:
535     std::string url_;
536     bool isRefreshed_;
537 };
538 
539 class ACE_EXPORT FileSelectorEvent : public BaseEventInfo {
540     DECLARE_RELATIONSHIP_OF_CLASSES(FileSelectorEvent, BaseEventInfo);
541 
542 public:
FileSelectorEvent(const RefPtr<WebFileSelectorParam> & param,const RefPtr<FileSelectorResult> & result)543     FileSelectorEvent(const RefPtr<WebFileSelectorParam>& param,
544                       const RefPtr<FileSelectorResult>& result)
545         : BaseEventInfo("FileSelectorEvent"), param_(param), result_(result)
546     {
547         LOGI("FileSelectorEvent constructor");
548     }
549     ~FileSelectorEvent() = default;
550 
GetParam()551     const RefPtr<WebFileSelectorParam>& GetParam() const
552     {
553         return param_;
554     }
555 
GetFileSelectorResult()556     const RefPtr<FileSelectorResult>& GetFileSelectorResult() const
557     {
558         return result_;
559     }
560 
561 private:
562     RefPtr<WebFileSelectorParam> param_;
563     RefPtr<FileSelectorResult> result_;
564 };
565 } // namespace OHOS::Ace
566 
567 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_WEB_WEB_EVENT_H
568