2 Copyright (C) 2014 Samsung Electronics
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #include "content_browser_client_efl.h"
22 #include "command_line_efl.h"
23 #include "browser_main_parts_efl.h"
24 #include "browser_context_efl.h"
25 #include "web_contents_delegate_efl.h"
26 #include "browser/web_contents/web_contents_view_efl.h"
27 #include "browser/geolocation/access_token_store_efl.h"
28 #include "browser/renderer_host/render_message_filter_efl.h"
29 #include "browser/resource_dispatcher_host_delegate_efl.h"
30 #include "browser/vibration/vibration_message_filter.h"
31 #include "content/public/browser/resource_dispatcher_host.h"
32 #include "content/public/browser/web_contents.h"
33 #include "content/public/common/show_desktop_notification_params.h"
34 #include "common/web_contents_utils.h"
35 #include "components/editing/content/browser/editor_client_observer.h"
38 #include "browser/geolocation/location_provider_efl.h"
41 #include "tizen_webview/public/tw_notification.h"
42 #include "tizen_webview/public/tw_security_origin.h"
43 #include "tizen_webview/public/tw_url.h"
44 #include "tizen_webview/tw_misc_utility.h"
46 using web_contents_utils::WebContentsFromFrameID;
47 using web_contents_utils::WebContentsFromViewID;
48 using tizen_webview::NotificationPermissionRequest;
49 using tizen_webview::URL;
50 using tizen_webview::Security_Origin;
52 #warning "[M38] tempoary disable notification. remove below line"
53 #undef ENABLE_NOTIFICATIONS
57 ContentBrowserClientEfl::ContentBrowserClientEfl()
58 : web_context_(NULL), browser_main_parts_efl_(NULL) {
61 BrowserMainParts* ContentBrowserClientEfl::CreateBrowserMainParts(
62 const MainFunctionParams& parameters) {
63 browser_main_parts_efl_ = new BrowserMainPartsEfl();
64 return browser_main_parts_efl_;
67 net::URLRequestContextGetter* ContentBrowserClientEfl::CreateRequestContext(
68 BrowserContext* browser_context,
69 ProtocolHandlerMap* protocol_handlers,
70 URLRequestInterceptorScopedVector request_interceptors) {
71 if (browser_context->IsOffTheRecord()) {
72 LOG(ERROR) << "off the record browser context not implemented";
76 return static_cast<BrowserContextEfl*>(browser_context)->
77 CreateRequestContext(protocol_handlers, request_interceptors.Pass());
80 AccessTokenStore* ContentBrowserClientEfl::CreateAccessTokenStore() {
81 return new AccessTokenStoreEfl();
85 LocationProvider* ContentBrowserClientEfl::OverrideSystemLocationProvider() {
86 return LocationProviderEfl::Create();
90 void ContentBrowserClientEfl::AppendExtraCommandLineSwitches(CommandLine* command_line,
91 int child_process_id) {
92 CommandLineEfl::AppendProcessSpecificArgs(*command_line);
95 void ContentBrowserClientEfl::ResourceDispatcherHostCreated() {
96 ResourceDispatcherHost* host = ResourceDispatcherHost::Get();
97 resource_disp_host_del_efl_.reset(new ResourceDispatcherHostDelegateEfl());
98 host->SetDelegate(resource_disp_host_del_efl_.get());
101 void ContentBrowserClientEfl::AllowCertificateError(
102 int render_process_id, int render_frame_id, int cert_error,
103 const net::SSLInfo& ssl_info, const GURL& request_url,
104 ResourceType::Type resource_type, bool overridable,
105 bool strict_enforcement, const base::Callback<void(bool)>& callback,
106 CertificateRequestResultType* result) {
108 WebContents* web_contents = WebContentsFromFrameID(render_process_id, render_frame_id);
113 WebContentsDelegate * delegate = web_contents->GetDelegate();
118 static_cast<content::WebContentsDelegateEfl*>(delegate)->
119 RequestCertificateConfirm(web_contents, cert_error, ssl_info, request_url,
120 resource_type, overridable, strict_enforcement, callback, result);
123 void ContentBrowserClientEfl::RequestDesktopNotificationPermission(
124 const GURL& source_origin,
125 content::RenderFrameHost* render_frame_host,
126 const base::Closure& callback) {
127 #if defined(ENABLE_NOTIFICATIONS) && !defined(EWK_BRINGUP)
128 WebContents* web_contents = WebContentsFromViewID(render_process_id,
133 WebContentsDelegateEfl* delegate =
134 static_cast<WebContentsDelegateEfl*>(web_contents->GetDelegate());
138 BrowserContextEfl* browser_context =
139 static_cast<BrowserContextEfl*>(web_contents->GetBrowserContext());
140 NotificationPermissionRequest* notification_permission
141 = new NotificationPermissionRequest(delegate->web_view()->evas_object(),
143 tizen_webview::GetURL(source_origin));
145 delegate->web_view()->
146 SmartCallback<EWebViewCallbacks::NotificationPermissionRequest>()
147 .call(notification_permission);
148 // A smart callback cannot have ownership for data because the callback may
149 // not ever exist. Therefore new resource should be deleted in the call site.
150 // [sns.park] TODO: uncomment below if no side effect.
151 //delete notification_permission;
157 void ContentBrowserClientEfl::ShowDesktopNotification(
158 const content::ShowDesktopNotificationHostMsgParams& params,
159 content::RenderFrameHost* render_frame_host,
160 content::DesktopNotificationDelegate* delegate,
161 base::Closure* cancel_callback) {
162 #if defined(ENABLE_NOTIFICATIONS) && !defined(EWK_BRINGUP)
163 WebContents* web_contents = WebContentsFromViewID(render_process_id, render_view_id);
167 WebContentsDelegateEfl* delegate =
168 static_cast<WebContentsDelegateEfl*>(web_contents->GetDelegate());
172 BrowserContextEfl* browser_context =
173 static_cast<BrowserContextEfl*>(web_contents->GetBrowserContext());
174 uint64_t old_notification_id = 0;
176 if (!params.replace_id.empty() && browser_context->GetNotificationController()->
177 IsNotificationPresent(params.replace_id, old_notification_id))
178 CancelDesktopNotification(render_process_id, render_view_id, old_notification_id);
180 browser_context->GetNotificationController()->
181 AddNotification(params.notification_id, render_process_id,
182 render_view_id, params.replace_id);
183 tizen_webview::Notification* notification =
184 new tizen_webview::Notification(base::UTF16ToUTF8(params.body),
185 params.icon_url.spec(),
186 base::UTF16ToUTF8(params.replace_id),
187 base::UTF16ToUTF8(params.title),
188 params.notification_id,
189 URL(params.origin.host(),
190 params.origin.scheme(),
191 atoi(params.origin.port().c_str())));
193 delegate->web_view()->
194 SmartCallback<EWebViewCallbacks::NotificationShow>().call(notification);
195 // A smart callback cannot have ownership for data because the callback may
196 // not ever exist. Therefore new resource should be deleted in the call site.
197 // [sns.park] TODO: uncomment below if no side effect.
198 //delete notification;
204 bool ContentBrowserClientEfl::AllowGetCookie(const GURL& url,
205 const GURL& first_party,
206 const net::CookieList& cookie_list,
207 content::ResourceContext* context,
208 int render_process_id,
209 int render_frame_id) {
213 CookieManager* cookie_manager = web_context_->cookieManager();
217 return cookie_manager->AllowGetCookie(url,
225 bool ContentBrowserClientEfl::AllowSetCookie(const GURL& url,
226 const GURL& first_party,
227 const std::string& cookie_line,
228 content::ResourceContext* context,
229 int render_process_id,
231 net::CookieOptions* options) {
235 CookieManager* cookie_manager = web_context_->cookieManager();
239 return cookie_manager->AllowSetCookie(url,
248 void ContentBrowserClientEfl::RenderProcessWillLaunch(
249 content::RenderProcessHost* host) {
251 BrowserContextEfl* browser_context = static_cast<BrowserContextEfl*>(
252 host->GetBrowserContext());
254 // TODO: is this situation possible? Should it ever happen?
255 DCHECK(browser_context);
258 web_context_ = browser_context->WebContext();
260 host->AddFilter(new RenderMessageFilterEfl(host->GetID()));
261 host->AddFilter(new VibrationMessageFilter());
262 host->AddFilter(new editing::EditorClientObserver(host->GetID()));