[M108 Migration] Set ContentSecurityPolicy rules to blink
[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 OnWrtPluginMessage(const Ewk_Wrt_Message_Data& data);
72   void OnWrtPluginSyncMessage(const Ewk_Wrt_Message_Data& data,
73                               IPC::Message* reply);
74   void OnDidChangeContentsSize(int width, int height);
75   void OnDidChangeFocusedNodeBounds(const gfx::RectF& focused_node_bounds);
76
77   void DidDownloadFavicon(bool success,
78                           const GURL& icon_url,
79                           const SkBitmap& bitmap);
80
81   struct ContentSecurityPolicy {
82     ContentSecurityPolicy(const std::string& p, Ewk_CSP_Header_Type type)
83         : policy(p), header_type(type) {}
84     std::string policy;
85     Ewk_CSP_Header_Type header_type;
86   };
87
88   bool document_created_ = false;
89   EWebView* web_view_;
90   WebContents& web_contents_;
91   std::unique_ptr<ContentSecurityPolicy> pending_content_security_policy_;
92   std::unique_ptr<FaviconDownloader> favicon_downloader_;
93   WebContentsDelegateEfl* web_contents_delegate_ = nullptr;
94   base::WeakPtrFactory<WebContentsObserverEfl> weak_ptr_factory_;
95 };
96
97 }  // namespace content
98
99 #endif  // WEB_CONTENTS_OBSERVER_EFL_H_