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.
5 #ifndef WEB_CONTENTS_DELEGATE_EFL
6 #define WEB_CONTENTS_DELEGATE_EFL
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"
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"
26 #include "tizen_webview/public/tw_content_security_policy.h"
28 class DidPrintPagesParams;
29 class JavaScriptDialogManagerEfl;
31 namespace tizen_webview {
32 class WrtIpcMessageData;
36 struct DateTimeSuggestion;
38 class WebContentsDelegateEfl
39 : public WebContentsDelegate,
40 public WebContentsObserver {
42 WebContentsDelegateEfl(EWebView*);
43 ~WebContentsDelegateEfl();
45 virtual WebContents* OpenURLFromTab(WebContents* source,
46 const content::OpenURLParams& params) override;
47 virtual void NavigationStateChanged(const WebContents* source,
48 InvalidateTypes changed_flags) override;
50 virtual void LoadProgressChanged(WebContents* source, double progress) override;
51 virtual void LoadingStateChanged(WebContents* source,
52 bool to_different_document) override;
54 virtual bool ShouldCreateWebContents(
58 const base::string16& frame_name,
59 const GURL& target_url,
60 const std::string& partition_id,
61 SessionStorageNamespace* session_storage_namespace) override;
63 bool ShouldCreateWebContentsAsync(NewWindowDecideCallback, const GURL&) override;
65 bool WebContentsCreateAsync(WebContentsCreateCallback) override;
67 virtual void CloseContents(WebContents* source) override;
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;
78 virtual void RequestMediaAccessPermission(
79 WebContents* web_contents,
80 const MediaStreamRequest& request,
81 const MediaResponseCallback& callback) override;
83 void OnAccessRequestResponse(bool allowed);
85 void RegisterProtocolHandler(WebContents* web_contents,
86 const std::string& protocol,
88 bool user_gesture) override;
90 void FindReply(WebContents* web_contents,
92 int number_of_matches,
93 const gfx::Rect& selection_rect,
94 int active_match_ordinal,
95 bool final_update) override;
97 void RequestCertificateConfirm(WebContents* web_contents, int cert_error,
98 const net::SSLInfo& ssl_info, const GURL& url, ResourceType resource_type,
100 bool strict_enforcement,
101 const base::Callback<void(bool)>& callback,
102 CertificateRequestResultType* result);
104 EWebView* web_view() const { return web_view_; }
105 WebContents& web_contents() const { return web_contents_; }
107 virtual void DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
108 const GURL& validated_url,
110 bool is_iframe_srcdoc) override;
112 virtual void DidCommitProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
114 ui::PageTransition transition_type) override;
116 virtual void DidNavigateMainFrame(const LoadCommittedDetails& details,
117 const FrameNavigateParams& params) override;
118 virtual void DocumentOnLoadCompletedInMainFrame() override;
120 virtual void DidNavigateAnyFrame(RenderFrameHost* render_frame_host,
121 const LoadCommittedDetails& details,
122 const FrameNavigateParams& params) override;
124 void OnAuthRequired(net::URLRequest* request,
125 const std::string& realm,
126 LoginDelegateEfl* login_delegate);
128 virtual void DidFinishLoad(RenderFrameHost* render_frame_host,
129 const GURL& validated_url) override;
131 virtual void DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) override;
132 virtual void DidDownloadFavicon(bool success, const GURL& icon_url, const SkBitmap& bitmap);
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,
145 void HidePopupMenu();
146 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
147 bool prevState, bool nextState);
149 JavaScriptDialogManager* GetJavaScriptDialogManager() override;
151 void DidFirstVisuallyNonEmptyPaint() override;
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,
159 const base::string16& message,
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,
171 const std::vector<DateTimeSuggestion>& suggestions) override;
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);
181 WebContents& web_contents_;
183 struct ContentSecurityPolicy {
184 ContentSecurityPolicy(const std::string& p, tizen_webview::ContentSecurityPolicyType type)
189 tizen_webview::ContentSecurityPolicyType header_type;
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;
202 //Queue to hold all pending request for requesting user permissions.
203 std::deque<PendingAccessRequest> requests_queue_;
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_;
213 DISALLOW_COPY_AND_ASSIGN(WebContentsDelegateEfl);