[M108 Migration] Move codes that handle EWK IPC messages from render frame
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / web_contents_observer_efl.h
1 // Copyright 2022 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef WEB_CONTENTS_OBSERVER_EFL_H_
6 #define WEB_CONTENTS_OBSERVER_EFL_H_
7
8 #include <string>
9
10 #include "base/memory/weak_ptr.h"
11 #include "content/public/browser/web_contents_observer.h"
12 #include "eweb_view.h"
13
14 class DidPrintPagesParams;
15 class Ewk_Wrt_Message_Data;
16 class FaviconDownloader;
17 class GURL;
18 class SkBitmap;
19
20 namespace gfx {
21 class Rect;
22 }
23
24 namespace content {
25
26 class WebContentsDelegateEfl;
27
28 class WebContentsObserverEfl : public WebContentsObserver, public IPC::Sender {
29  public:
30   explicit WebContentsObserverEfl(EWebView* view,
31                                   WebContentsDelegateEfl* delegate);
32   WebContentsObserverEfl(const WebContentsObserverEfl&) = delete;
33   WebContentsObserverEfl& operator=(const WebContentsObserverEfl&) = delete;
34   ~WebContentsObserverEfl() override;
35
36   void SetContentSecurityPolicy(const std::string& policy,
37                                 Ewk_CSP_Header_Type header_type);
38
39   // IPC::Sender-----------------------------------------------------------
40   bool Send(IPC::Message* message) override;
41
42  private:
43   // WebContentsObserver overrides:
44   void DidStartNavigation(NavigationHandle* navigation_handle) override;
45   void DidRedirectNavigation(NavigationHandle* navigation_handle) override;
46   void DidFinishNavigation(NavigationHandle* navigation_handle) override;
47   void LoadProgressChanged(double progress) override;
48   void DidFinishLoad(RenderFrameHost* render_frame_host,
49                      const GURL& validated_url) override;
50   void DidFailLoad(RenderFrameHost* render_frame_host,
51                    const GURL& validated_url,
52                    int error_code) override;
53   void TitleWasSet(NavigationEntry* entry) override;
54   void OnPageScaleFactorChanged(float page_scale_factor) override;
55   void DidFirstVisuallyNonEmptyPaint() override;
56   void DidStartLoading() override;
57   void NavigationEntryCommitted(
58       const LoadCommittedDetails& load_details) override;
59   void PrimaryMainFrameRenderProcessGone(
60       base::TerminationStatus status) override;
61   void RenderViewCreated(RenderViewHost* render_view_host);
62   void DidUpdateFaviconURL(
63       RenderFrameHost* render_frame_host,
64       const std::vector<blink::mojom::FaviconURLPtr>& candidates) override;
65   bool OnMessageReceived(const IPC::Message& message,
66                          RenderFrameHost* render_frame_host) override;
67
68   // IPC message handlers:
69   void OnDidCreateDocumentElement();
70   void OnPrintedMetafileReceived(const DidPrintPagesParams& params);
71   void OnRequestSelectCollectionInformationUpdateACK(int form_element_count,
72                                                      int current_node_index,
73                                                      bool prev_state,
74                                                      bool nest_state);
75   void OnDidChangeMaxScrollOffset(int max_scroll_x, int max_scroll_y);
76   void OnDidChangeScrollOffset(int scroll_x, int scroll_y);
77   void OnFormSubmit(const GURL& url);
78   void OnDidNotAllowScript();
79   void OnWrtPluginMessage(const Ewk_Wrt_Message_Data& data);
80   void OnWrtPluginSyncMessage(const Ewk_Wrt_Message_Data& data,
81                               IPC::Message* reply);
82   void OnDidChangeContentsSize(int width, int height);
83   void OnDidChangeFocusedNodeBounds(const gfx::RectF& focused_node_bounds);
84
85   void DidDownloadFavicon(bool success,
86                           const GURL& icon_url,
87                           const SkBitmap& bitmap);
88
89   struct ContentSecurityPolicy {
90     ContentSecurityPolicy(const std::string& p, Ewk_CSP_Header_Type type)
91         : policy(p), header_type(type) {}
92     std::string policy;
93     Ewk_CSP_Header_Type header_type;
94   };
95
96   bool document_created_ = false;
97   EWebView* web_view_;
98   WebContents& web_contents_;
99   std::unique_ptr<ContentSecurityPolicy> pending_content_security_policy_;
100   std::unique_ptr<FaviconDownloader> favicon_downloader_;
101   WebContentsDelegateEfl* web_contents_delegate_ = nullptr;
102   base::WeakPtrFactory<WebContentsObserverEfl> weak_ptr_factory_;
103 };
104
105 }  // namespace content
106
107 #endif  // WEB_CONTENTS_OBSERVER_EFL_H_