58dfde6735339d508fbf38fc8519baf2e110a123
[platform/framework/web/chromium-efl.git] / tizen_src / impl / web_contents_delegate_efl.h
1 #ifndef WEB_CONTENTS_DELEGATE_EFL
2 #define WEB_CONTENTS_DELEGATE_EFL
3
4 #include <deque>
5
6 #include "base/memory/scoped_ptr.h"
7 #include "base/memory/weak_ptr.h"
8 #include "content/public/browser/browser_context.h"
9 #include "browser/javascript_dialog_manager_efl.h"
10 #include "browser_context_efl.h"
11 #include "eweb_view.h"
12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_delegate.h"
14 #include "content/public/common/frame_navigate_params.h"
15 #include "content/public/browser/render_view_host.h"
16 #include "content/public/browser/web_contents_observer.h"
17 #include "content/browser/web_contents/web_contents_impl.h"
18 #include "url/gurl.h"
19 #include "browser/favicon/favicon_downloader.h"
20 #include "third_party/WebKit/Source/platform/text/TextDirection.h"
21 #include "ui/base/ime/text_input_type.h"
22
23 #include "tizen_webview/public/tw_content_security_policy.h"
24
25 class DidPrintPagesParams;
26
27 namespace tizen_webview {
28 class WrtIpcMessageData;
29 }
30
31 namespace content {
32 struct DateTimeSuggestion;
33
34 class WebContentsDelegateEfl
35     : public WebContentsDelegate,
36       public WebContentsObserver {
37  public:
38   WebContentsDelegateEfl(EWebView*);
39   ~WebContentsDelegateEfl();
40
41   // Reusing the given WebContents instead of creating a new one.
42   WebContentsDelegateEfl(EWebView*, WebContents*);
43
44   virtual void NavigationStateChanged(const WebContents* source,
45                                       unsigned changed_flags) OVERRIDE;
46
47   virtual void LoadProgressChanged(WebContents* source, double progress) OVERRIDE;
48   virtual void LoadingStateChanged(WebContents* source,
49                                    bool to_different_document) OVERRIDE;
50
51   virtual bool ShouldCreateWebContents(
52       WebContents*,
53       int route_id,
54       WindowContainerType,
55       const base::string16& frame_name,
56       const GURL& target_url,
57       const std::string& partition_id,
58       SessionStorageNamespace* session_storage_namespace) OVERRIDE;
59
60   virtual void WebContentsCreated(
61       WebContents* source_contents,
62       int opener_render_frame_id,
63       const base::string16& frame_name,
64       const GURL& target_url,
65       WebContents* new_contents) 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   virtual void RequestMediaAccessPermission(
74       WebContents* web_contents,
75       const MediaStreamRequest& request,
76       const MediaResponseCallback& callback) OVERRIDE;
77   void RegisterProtocolHandler(WebContents* web_contents,
78                                const std::string& protocol,
79                                const GURL& url,
80                                bool user_gesture) OVERRIDE;
81
82   void FindReply(WebContents* web_contents,
83                  int request_id,
84                  int number_of_matches,
85                  const gfx::Rect& selection_rect,
86                  int active_match_ordinal,
87                  bool final_update) OVERRIDE;
88
89   void RequestCertificateConfirm(WebContents* web_contents, int cert_error,
90       const net::SSLInfo& ssl_info, const GURL& url, ResourceType::Type resource_type,
91       bool overridable,
92       bool strict_enforcement,
93       const base::Callback<void(bool)>& callback,
94       CertificateRequestResultType* result);
95
96   EWebView* web_view() const { return web_view_; }
97   WebContents* web_contents() const { return web_contents_; }
98
99   virtual void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
100                                                const GURL& validated_url,
101                                                bool is_error_page,
102                                                bool is_iframe_srcdoc) OVERRIDE;
103
104   virtual void DidCommitProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
105                                                 const GURL& url,
106                                                 PageTransition transition_type) OVERRIDE;
107
108   virtual void DidNavigateAnyFrame(const LoadCommittedDetails& details, const FrameNavigateParams& params) OVERRIDE;
109   void OnAuthRequired(net::URLRequest* request,
110                       const std::string& realm,
111                       LoginDelegateEfl* login_delegate);
112   virtual void DidFailProvisionalLoad(RenderFrameHost* render_frame_host,
113                                       const GURL& validated_url,
114                                       int error_code,
115                                       const base::string16& error_description) OVERRIDE;
116   virtual void DidFailLoad(RenderFrameHost* render_frame_host,
117                            const GURL& validated_url,
118                            int error_code,
119                            const base::string16& error_description) OVERRIDE;
120
121   virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
122                              const GURL& validated_url) OVERRIDE;
123
124   virtual void DidStartLoading(RenderViewHost* render_view_host) OVERRIDE;
125   virtual void DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) OVERRIDE;
126   virtual void DidDownloadFavicon(bool success, const GURL& icon_url, const SkBitmap& bitmap);
127
128   void OnFormSubmit(const GURL&);
129   void SetContentSecurityPolicy(const std::string& policy, tizen_webview::ContentSecurityPolicyType header_type);
130   void ShowPopupMenu(const gfx::Rect& rect, blink::TextDirection textDirection, double pageScaleFactor, const std::vector<MenuItem>& items, int data, int selectedIndex, bool multiple);
131   void HidePopupMenu();
132
133   void set_new_window_policy(bool policy) { should_open_new_window_ = policy; }
134   bool get_new_window_policy() const { return should_open_new_window_; }
135   JavaScriptDialogManager* GetJavaScriptDialogManager() OVERRIDE;
136
137   void DidFirstVisuallyNonEmptyPaint() OVERRIDE;
138
139   bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
140   void OnPrintedMetafileReceived(const DidPrintPagesParams& params);
141   virtual void NavigationEntryCommitted(const LoadCommittedDetails& load_details) OVERRIDE;
142   virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
143   virtual bool AddMessageToConsole(WebContents* source,
144                                    int32 level,
145                                    const base::string16& message,
146                                    int32 line_no,
147                                    const base::string16& source_id) OVERRIDE;
148   void RunFileChooser(WebContents* web_contents, const FileChooserParams& params);
149   ColorChooser* OpenColorChooser(WebContents* web_contents, SkColor color, const std::vector<ColorSuggestion>& suggestions);
150   void OnAccessRequestResponse(Eina_Bool allowed);
151   void OpenDateTimeDialog(ui::TextInputType dialog_type,
152                           double dialog_value,
153                           double min,
154                           double max,
155                           double step,
156                           const std::vector<DateTimeSuggestion>& suggestions);
157
158  private:
159   void OnGetContentSecurityPolicy(IPC::Message* reply_msg);
160   void OnWrtPluginMessage(const tizen_webview::WrtIpcMessageData& data);
161   void OnWrtPluginSyncMessage(const tizen_webview::WrtIpcMessageData& data,
162                               IPC::Message* reply);
163
164   EWebView* web_view_;
165   bool is_fullscreen_;
166   WebContents* web_contents_;
167
168   struct ContentSecurityPolicy {
169     ContentSecurityPolicy(const std::string& p, tizen_webview::ContentSecurityPolicyType type)
170         : policy(p),
171           header_type(type) {
172     }
173     std::string policy;
174     tizen_webview::ContentSecurityPolicyType header_type;
175   };
176
177   // Structure to hold media request and its callback.
178   struct PendingAccessRequest {
179     PendingAccessRequest(const content::MediaStreamRequest& request,
180                          const content::MediaResponseCallback& callback);
181     ~PendingAccessRequest();
182     content::MediaStreamRequest request;
183     content::MediaResponseCallback callback;
184   };
185
186   //Queue to hold all pending request for requesting user permissions.
187   std::deque<PendingAccessRequest> requests_Queue_;
188   scoped_ptr<ContentSecurityPolicy> pending_content_security_policy_;
189   bool document_created_;
190   bool should_open_new_window_;
191   JavaScriptDialogManagerEfl* dialog_manager_;
192   int forward_backward_list_count_;
193   scoped_ptr<FaviconDownloader> favicon_downloader_;
194   base::WeakPtrFactory<WebContentsDelegateEfl> weak_ptr_factory_;
195
196   DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateEfl);
197 };
198
199 }
200
201 #endif