6fec004af5d20c28296e70f59868241a64ca326e
[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 "base/memory/scoped_ptr.h"
11 #include "content/public/browser/browser_context.h"
12 #include "browser/javascript_dialog_manager_efl.h"
13 #include "browser_context_efl.h"
14 #include "eweb_view.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_contents_delegate.h"
17 #include "content/public/common/frame_navigate_params.h"
18 #include "content/public/browser/render_view_host.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "content/browser/web_contents/web_contents_impl.h"
21 #include "url/gurl.h"
22 #include "browser/favicon/favicon_downloader.h"
23 #include "third_party/WebKit/Source/platform/text/TextDirection.h"
24 #include "ui/base/ime/text_input_type.h"
25
26 #include "tizen_webview/public/tw_content_security_policy.h"
27
28 class DidPrintPagesParams;
29 class JavaScriptDialogManagerEfl;
30
31 namespace tizen_webview {
32 class WrtIpcMessageData;
33 }
34
35 namespace content {
36 struct DateTimeSuggestion;
37
38 class WebContentsDelegateEfl
39     : public WebContentsDelegate,
40       public WebContentsObserver {
41  public:
42   WebContentsDelegateEfl(EWebView*);
43   ~WebContentsDelegateEfl();
44
45   virtual WebContents* OpenURLFromTab(WebContents* source,
46       const content::OpenURLParams& params) override;
47   virtual void NavigationStateChanged(const WebContents* source,
48                                       InvalidateTypes changed_flags) override;
49
50   virtual void LoadProgressChanged(WebContents* source, double progress) override;
51   virtual void LoadingStateChanged(WebContents* source,
52                                    bool to_different_document) override;
53
54   virtual bool ShouldCreateWebContents(
55       WebContents*,
56       int route_id,
57       WindowContainerType,
58       const base::string16& frame_name,
59       const GURL& target_url,
60       const std::string& partition_id,
61       SessionStorageNamespace* session_storage_namespace) override;
62
63   bool ShouldCreateWebContentsAsync(NewWindowDecideCallback, const GURL&) override;
64
65   bool WebContentsCreateAsync(WebContentsCreateCallback) override;
66
67   virtual void CloseContents(WebContents* source) override;
68
69   virtual void ToggleFullscreenModeForTab(WebContents* web_contents,
70                                           bool enter_fullscreen) override;
71   virtual bool IsFullscreenForTabOrPending(
72       const WebContents* web_contents) const override;
73 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
74   virtual bool CheckMediaAccessPermission(WebContents* web_contents,
75                                           const GURL& security_origin,
76                                           MediaStreamType type) override;
77
78   virtual void RequestMediaAccessPermission(
79       WebContents* web_contents,
80       const MediaStreamRequest& request,
81       const MediaResponseCallback& callback) override;
82
83   void OnAccessRequestResponse(bool allowed);
84 #endif
85   void RegisterProtocolHandler(WebContents* web_contents,
86                                const std::string& protocol,
87                                const GURL& url,
88                                bool user_gesture) override;
89
90   void FindReply(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 RequestCertificateConfirm(WebContents* web_contents, int cert_error,
98       const net::SSLInfo& ssl_info, const GURL& url, ResourceType resource_type,
99       bool overridable,
100       bool strict_enforcement,
101       const base::Callback<void(bool)>& callback,
102       CertificateRequestResultType* result);
103
104   EWebView* web_view() const { return web_view_; }
105   WebContents& web_contents() const { return web_contents_; }
106
107   virtual void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
108                                                const GURL& validated_url,
109                                                bool is_error_page,
110                                                bool is_iframe_srcdoc) override;
111
112   virtual void DidCommitProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
113                                                 const GURL& url,
114                                                 ui::PageTransition transition_type) override;
115
116   virtual void DidNavigateMainFrame(const LoadCommittedDetails& details,
117                                     const FrameNavigateParams& params) override;
118   virtual void DocumentOnLoadCompletedInMainFrame() override;
119
120   virtual void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
121                                    const LoadCommittedDetails& details,
122                                    const FrameNavigateParams& params) override;
123
124   void OnAuthRequired(net::URLRequest* request,
125                       const std::string& realm,
126                       LoginDelegateEfl* login_delegate);
127
128   virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
129                              const GURL& validated_url) override;
130
131   virtual void DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) override;
132   virtual void DidDownloadFavicon(bool success, const GURL& icon_url, const SkBitmap& bitmap);
133
134   void OnFormSubmit(const GURL&);
135   void OnUpdateSettings(const Ewk_Settings *settings);
136   void SetContentSecurityPolicy(const std::string& policy, tizen_webview::ContentSecurityPolicyType header_type);
137   void ShowPopupMenu(RenderFrameHost* render_frame_host,
138                      const gfx::Rect& rect,
139                      blink::TextDirection textDirection,
140                      double pageScaleFactor,
141                      const std::vector<MenuItem>& items,
142                      int data,
143                      int selectedIndex,
144                      bool multiple);
145   void HidePopupMenu();
146   void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
147       bool prevState, bool nextState);
148
149   JavaScriptDialogManager* GetJavaScriptDialogManager() override;
150
151   void DidFirstVisuallyNonEmptyPaint() override;
152
153   bool OnMessageReceived(const IPC::Message& message) override;
154   void OnPrintedMetafileReceived(const DidPrintPagesParams& params);
155   void NavigationEntryCommitted(const LoadCommittedDetails& load_details) override;
156   void RenderProcessGone(base::TerminationStatus status) override;
157   bool AddMessageToConsole(WebContents* source,
158                            int32 level,
159                            const base::string16& message,
160                            int32 line_no,
161                            const base::string16& source_id) override;
162   void RunFileChooser(WebContents* web_contents,
163                       const FileChooserParams& params) override;
164   ColorChooser* OpenColorChooser(WebContents* web_contents, SkColor color,
165       const std::vector<ColorSuggestion>& suggestions) override;
166   void OpenDateTimeDialog(ui::TextInputType dialog_type,
167       double dialog_value,
168       double min,
169       double max,
170       double step,
171       const std::vector<DateTimeSuggestion>& suggestions) override;
172
173  private:
174   void OnGetContentSecurityPolicy(IPC::Message* reply_msg);
175   void OnWrtPluginMessage(const tizen_webview::WrtIpcMessageData& data);
176   void OnWrtPluginSyncMessage(const tizen_webview::WrtIpcMessageData& data,
177                               IPC::Message* reply);
178
179   EWebView* web_view_;
180   bool is_fullscreen_;
181   WebContents& web_contents_;
182
183   struct ContentSecurityPolicy {
184     ContentSecurityPolicy(const std::string& p, tizen_webview::ContentSecurityPolicyType type)
185         : policy(p),
186           header_type(type) {
187     }
188     std::string policy;
189     tizen_webview::ContentSecurityPolicyType header_type;
190   };
191
192 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
193   // Structure to hold media request and its callback.
194   struct PendingAccessRequest {
195     PendingAccessRequest(const content::MediaStreamRequest& request,
196                          const content::MediaResponseCallback& callback);
197     ~PendingAccessRequest();
198     content::MediaStreamRequest request;
199     content::MediaResponseCallback callback;
200   };
201
202   //Queue to hold all pending request for requesting user permissions.
203   std::deque<PendingAccessRequest> requests_queue_;
204 #endif
205
206   scoped_ptr<ContentSecurityPolicy> pending_content_security_policy_;
207   bool document_created_;
208   JavaScriptDialogManagerEfl* dialog_manager_;
209   scoped_ptr<FaviconDownloader> favicon_downloader_;
210   base::WeakPtrFactory<WebContentsDelegateEfl> weak_ptr_factory_;
211   scoped_ptr<_Ewk_Certificate_Policy_Decision> certificate_policy_decision_;
212
213   DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateEfl);
214 };
215
216 }
217
218 #endif