1aa643e2d812eecb0fc2c2027f18d1c0fac593e4
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / web_contents_delegate_efl.h
1 // Copyright 2014 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_DELEGATE_EFL
6 #define WEB_CONTENTS_DELEGATE_EFL
7
8 #include <deque>
9
10 #include "content/public/browser/browser_context.h"
11 #include "browser/javascript_dialog_manager_efl.h"
12 #include "browser_context_efl.h"
13 #include "eweb_view.h"
14 #include "content/public/browser/web_contents.h"
15 #include "content/public/browser/web_contents_delegate.h"
16 #include "content/public/common/frame_navigate_params.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/web_contents_observer.h"
19 #include "content/browser/web_contents/web_contents_impl.h"
20 #include "url/gurl.h"
21 #include "browser/favicon/favicon_downloader.h"
22 #include "public/ewk_view.h"
23 #include "ui/base/ime/text_input_type.h"
24
25 class DidPrintPagesParams;
26 class Ewk_Wrt_Message_Data;
27 class JavaScriptDialogManagerEfl;
28
29 namespace content {
30 struct DateTimeSuggestion;
31
32 class WebContentsDelegateEfl : public WebContentsDelegate,
33                                public WebContentsObserver {
34  public:
35   WebContentsDelegateEfl(EWebView*);
36   ~WebContentsDelegateEfl();
37
38   // Overridden from content::WebContentsDelegate:
39   content::WebContents* OpenURLFromTab(
40       content::WebContents* source,
41       const content::OpenURLParams& params) override;
42   void NavigationStateChanged(content::WebContents* source,
43                               content::InvalidateTypes changed_flags) override;
44   void LoadingStateChanged(content::WebContents* source,
45                            bool to_different_document) override;
46   bool ShouldCreateWebContents(
47       content::WebContents* web_contents,
48       content::RenderFrameHost* opener,
49       content::SiteInstance* source_site_instance,
50       int32_t route_id,
51       int32_t main_frame_route_id,
52       int32_t main_frame_widget_route_id,
53       content::mojom::WindowContainerType window_container_type,
54       const GURL& opener_url,
55       const std::string& frame_name,
56       const GURL& target_url,
57       const std::string& partition_id,
58       content::SessionStorageNamespace* session_storage_namespace) override;
59   void CloseContents(content::WebContents* source) override;
60   void EnterFullscreenModeForTab(content::WebContents* web_contents,
61                                  const GURL& origin) override;
62   void ExitFullscreenModeForTab(content::WebContents* web_contents) override;
63   bool IsFullscreenForTabOrPending(
64       const content::WebContents* web_contents) const override;
65
66 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
67   virtual bool CheckMediaAccessPermission(WebContents* web_contents,
68                                           const GURL& security_origin,
69                                           MediaStreamType type) override;
70
71   virtual void RequestMediaAccessPermission(
72       WebContents* web_contents,
73       const MediaStreamRequest& request,
74       const MediaResponseCallback& callback) override;
75
76   void RequestMediaAccessAllow(const MediaStreamRequest& request,
77                                const MediaResponseCallback& callback);
78
79   void RequestMediaAccessDeny(const MediaStreamRequest& request,
80                               const MediaResponseCallback& callback);
81 #endif
82   void RegisterProtocolHandler(content::WebContents* web_contents,
83                                const std::string& protocol,
84                                const GURL& url,
85                                bool user_gesture) override;
86   void UnregisterProtocolHandler(content::WebContents* web_contents,
87                                  const std::string& protocol,
88                                  const GURL& url,
89                                  bool user_gesture) override;
90   void FindReply(content::WebContents* web_contents,
91                  int request_id,
92                  int number_of_matches,
93                  const gfx::Rect& selection_rect,
94                  int active_match_ordinal,
95                  bool final_update) override;
96
97   void DidRenderFrame() override;
98
99   void RequestCertificateConfirm(
100       WebContents* web_contents,
101       int cert_error,
102       const net::SSLInfo& ssl_info,
103       const GURL& url,
104       ResourceType resource_type,
105       bool overridable,
106       bool strict_enforcement,
107       base::Callback<void(CertificateRequestResultType)>& callback);
108
109   JavaScriptDialogManager* GetJavaScriptDialogManager(
110       WebContents* source) override;
111
112   void OnUpdateSettings(const Ewk_Settings* settings);
113   void SetContentSecurityPolicy(const std::string& policy,
114                                 Ewk_CSP_Header_Type header_type);
115
116   void DidFirstVisuallyNonEmptyPaint() override;
117   void DidStartLoading() override;
118
119   bool OnMessageReceived(const IPC::Message& message) override;
120   void OnPrintedMetafileReceived(const DidPrintPagesParams& params);
121   void NavigationEntryCommitted(
122       const LoadCommittedDetails& load_details) override;
123   void RenderViewCreated(RenderViewHost* render_view_host) override;
124   void RenderProcessGone(base::TerminationStatus status) override;
125   bool DidAddMessageToConsole(WebContents* source,
126                               int32_t level,
127                               const base::string16& message,
128                               int32_t line_no,
129                               const base::string16& source_id) override;
130   void RunFileChooser(content::RenderFrameHost* render_frame_host,
131                       const FileChooserParams& params) override;
132   ColorChooser* OpenColorChooser(
133       WebContents* web_contents,
134       SkColor color,
135       const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions)
136       override;
137   void OpenDateTimeDialog(ui::TextInputType dialog_type,
138                           double dialog_value,
139                           double min,
140                           double max,
141                           double step,
142                           const std::vector<DateTimeSuggestion>& suggestions);
143   bool PreHandleGestureEvent(WebContents* source,
144                              const blink::WebGestureEvent& event) override;
145
146   // WebContentsObserver---------------------------------------------------
147   void DidFailLoad(RenderFrameHost* render_frame_host,
148                    const GURL& validated_url,
149                    int error_code,
150                    const base::string16& error_description) override;
151
152   // EWK_BRINGUP: These APIs are removed in upstream.
153   void TitleWasSet(content::NavigationEntry* entry, bool explicit_set);
154
155   void LoadProgressChanged(WebContents* source, double progress);
156   void DidFinishLoad(RenderFrameHost* render_frame_host,
157                      const GURL& validated_url);
158
159   void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
160                                        const GURL& validated_url,
161                                        bool is_error_page,
162                                        bool is_iframe_srcdoc);
163
164   void DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates);
165
166   void DidCommitProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
167                                         const GURL& url,
168                                         ui::PageTransition transition_type);
169
170   void DidNavigateMainFrame(const LoadCommittedDetails& details,
171                             const FrameNavigateParams& params);
172   void DocumentOnLoadCompletedInMainFrame();
173
174   void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
175                            const LoadCommittedDetails& details,
176                            const FrameNavigateParams& params);
177
178   void DidFailProvisionalLoad(RenderFrameHost* render_frame_host,
179                               const GURL& validated_url,
180                               int error_code,
181                               const base::string16& error_description,
182                               bool was_ignored_by_handler);
183   // EWK_BRINGUP end.
184
185   void OnAuthRequired(net::URLRequest* request,
186                       const std::string& realm,
187                       LoginDelegateEfl* login_delegate);
188
189   void DidDownloadFavicon(bool success,
190                           const GURL& icon_url,
191                           const SkBitmap& bitmap);
192
193   EWebView* web_view() const { return web_view_; }
194   WebContents& web_contents() const { return web_contents_; }
195
196  private:
197   void OnGetContentSecurityPolicy(IPC::Message* reply_msg);
198   void OnWrtPluginMessage(const Ewk_Wrt_Message_Data& data);
199   void OnWrtPluginSyncMessage(const Ewk_Wrt_Message_Data& data,
200                               IPC::Message* reply);
201
202   EWebView* web_view_;
203   bool is_fullscreen_;
204   WebContents& web_contents_;
205
206   bool did_render_frame_;
207   bool did_first_visually_non_empty_paint_;
208
209   struct ContentSecurityPolicy {
210     ContentSecurityPolicy(const std::string& p, Ewk_CSP_Header_Type type)
211         : policy(p), header_type(type) {}
212     std::string policy;
213     Ewk_CSP_Header_Type header_type;
214   };
215
216   std::unique_ptr<ContentSecurityPolicy> pending_content_security_policy_;
217   bool document_created_;
218   JavaScriptDialogManagerEfl* dialog_manager_;
219   std::unique_ptr<FaviconDownloader> favicon_downloader_;
220   base::WeakPtrFactory<WebContentsDelegateEfl> weak_ptr_factory_;
221   std::unique_ptr<_Ewk_Certificate_Policy_Decision>
222       certificate_policy_decision_;
223
224   DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateEfl);
225 };
226 }
227
228 #endif