0fca8dadfd7cea8e20996f164118d84a4199097e
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / web_contents_delegate_efl.cc
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 #include "web_contents_delegate_efl.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "browser/favicon/favicon_service.h"
9 #include "browser/inputpicker/color_chooser_efl.h"
10 #include "browser/javascript_dialog_manager_efl.h"
11 #include "browser/policy_response_delegate_efl.h"
12 #include "common/render_messages_ewk.h"
13 #include "content/browser/renderer_host/render_widget_host_view_efl.h"
14 #include "content/common/content_switches_internal.h"
15 #include "content/common/date_time_suggestion.h"
16 #include "content/common/render_messages_efl.h"
17 #include "content/common/view_messages.h"
18 #include "content/public/browser/browser_thread.h"
19 #include "content/public/browser/favicon_status.h"
20 #include "content/public/browser/invalidate_type.h"
21 #include "content/public/browser/navigation_entry.h"
22 #include "content/public/common/favicon_url.h"
23 #include "eweb_view.h"
24 #include "eweb_view_callbacks.h"
25 #include "net/base/load_states.h"
26 #include "net/http/http_response_headers.h"
27 #include "printing/pdf_metafile_skia.h"
28 #include "private/ewk_certificate_private.h"
29 #include "private/ewk_console_message_private.h"
30 #include "private/ewk_custom_handlers_private.h"
31 #include "private/ewk_error_private.h"
32 #include "private/ewk_policy_decision_private.h"
33 #include "private/ewk_user_media_private.h"
34 #include "private/webview_delegate_ewk.h"
35 #include "public/web/WebInputEvent.h"
36 #include "url/gurl.h"
37
38 #if defined(OS_TIZEN)
39 #include "content/public/browser/media_capture_devices.h"
40 #include "media/video/capture/tizen/video_capture_device_tizen.h"
41 #endif
42
43 #if defined(TIZEN_AUTOFILL_SUPPORT)
44 #include "browser/autofill/autofill_manager_delegate_efl.h"
45 #include "components/autofill/content/browser/content_autofill_driver_factory.h"
46 #include "browser/password_manager/password_manager_client_efl.h"
47 #include "components/autofill/core/browser/autofill_client.h"
48 #include "components/autofill/core/browser/autofill_manager.h"
49 #include "components/web_modal/web_contents_modal_dialog_manager.h"
50
51 using autofill::AutofillManager;
52 using autofill::AutofillManagerDelegateEfl;
53 using autofill::ContentAutofillDriverFactory;
54 using password_manager::PasswordManagerClientEfl;
55 #endif
56 using base::string16;
57 using namespace ui;
58
59 namespace content {
60
61 void WritePdfDataToFile(printing::PdfMetafileSkia* metafile, const base::FilePath& filename) {
62   DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
63   DCHECK(metafile);
64   base::File file(filename, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
65   metafile->SaveTo(&file);
66   file.Close();
67   delete metafile;
68 }
69
70 #if defined(OS_TIZEN)
71 static const content::MediaStreamDevice*
72   GetRequestedVideoDevice(const std::string& device_id) {
73   const content::MediaStreamDevices& video_devices =
74       MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
75   if (video_devices.empty())
76     return NULL;
77   if (device_id.length() == 0)
78     return &(*video_devices.begin());
79   return video_devices.FindById(device_id);
80 }
81 #endif
82
83 WebContentsDelegateEfl::WebContentsDelegateEfl(EWebView* view)
84     : WebContentsObserver(&view->web_contents())
85     , web_view_(view)
86     , is_fullscreen_(false)
87     , web_contents_(view->web_contents())
88     , document_created_(false)
89     , dialog_manager_(NULL)
90     , weak_ptr_factory_(this) {
91 #if defined(TIZEN_AUTOFILL_SUPPORT)
92   AutofillManagerDelegateEfl::CreateForWebContents(&web_contents_);
93   AutofillManagerDelegateEfl* autofill_manager =
94       AutofillManagerDelegateEfl::FromWebContents(&web_contents_);
95   autofill_manager->SetEWebView(view);
96   PasswordManagerClientEfl::CreateForWebContents(&web_contents_);
97   ContentAutofillDriverFactory::CreateForWebContentsAndDelegate(&web_contents_,
98     autofill_manager,
99     EWebView::GetPlatformLocale(),
100     AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER);
101 #endif
102 }
103
104 WebContentsDelegateEfl::~WebContentsDelegateEfl() {
105   // It's important to delete web_contents_ before dialog_manager_
106   // destructor of web contents uses dialog_manager_
107
108   delete dialog_manager_;
109 }
110
111 WebContents* WebContentsDelegateEfl::OpenURLFromTab(
112   WebContents* source,
113   const content::OpenURLParams& params) {
114
115   const GURL& url = params.url;
116   WindowOpenDisposition disposition = params.disposition;
117
118   if (!source || (disposition != CURRENT_TAB &&
119                   disposition != NEW_FOREGROUND_TAB &&
120                   disposition != NEW_BACKGROUND_TAB &&
121                   disposition != OFF_THE_RECORD)) {
122     NOTIMPLEMENTED();
123     return NULL;
124   }
125
126   if (disposition == NEW_FOREGROUND_TAB ||
127       disposition == NEW_BACKGROUND_TAB ||
128       disposition == OFF_THE_RECORD) {
129     Evas_Object* new_object = NULL;
130     web_view_->SmartCallback<EWebViewCallbacks::CreateNewWindow>().call(&new_object);
131
132     if (!new_object)
133       return NULL;
134
135     EWebView* wv = WebViewDelegateEwk::GetInstance().
136       GetWebViewFromEvasObject(new_object);
137     DCHECK(wv);
138     wv->SetURL(url.spec().c_str());
139     return NULL;
140   }
141
142   ui::PageTransition transition(ui::PageTransitionFromInt(params.transition));
143   source->GetController().LoadURL(url, params.referrer, transition,
144                                   std::string());
145   return source;
146 }
147
148 void WebContentsDelegateEfl::NavigationStateChanged(
149     WebContents* source, InvalidateTypes changed_flags) {
150   if (changed_flags & content::INVALIDATE_TYPE_URL) {
151     const char* url = source->GetVisibleURL().spec().c_str();
152     web_view_->SmartCallback<EWebViewCallbacks::URLChanged>().call(url);
153     web_view_->SmartCallback<EWebViewCallbacks::URIChanged>().call(url);
154   }
155 }
156
157 void WebContentsDelegateEfl::LoadingStateChanged(WebContents* source,
158                                                  bool to_different_document) {
159   if (source->IsLoading())
160     web_view_->SmartCallback<EWebViewCallbacks::LoadProgressStarted>().call();
161   else
162     web_view_->SmartCallback<EWebViewCallbacks::LoadProgressFinished>().call();
163 }
164
165 void WebContentsDelegateEfl::LoadProgressChanged(WebContents* source, double progress) {
166   web_view_->SetProgressValue(progress);
167   web_view_->SmartCallback<EWebViewCallbacks::LoadProgress>().call(&progress);
168 }
169
170 bool WebContentsDelegateEfl::ShouldCreateWebContents(
171     WebContents* web_contents,
172     int route_id,
173     int main_frame_route_id,
174     WindowContainerType window_container_type,
175     const string16& /*frame_name*/,
176     const GURL& target_url,
177     const std::string& partition_id,
178     SessionStorageNamespace* session_storage_namespace) {
179   // We implement the asynchronous version of the function, this
180   // one should never be invoked.
181   NOTREACHED();
182   return false;
183 }
184
185 void WebContentsDelegateEfl::CloseContents(WebContents* source) {
186   web_view_->SmartCallback<EWebViewCallbacks::WindowClosed>().call();
187 }
188
189 void WebContentsDelegateEfl::EnterFullscreenModeForTab(content::WebContents* web_contents,
190       const GURL& origin, int display_id) {
191    is_fullscreen_ = true;
192    web_view_->SmartCallback<EWebViewCallbacks::EnterFullscreen>().call();
193 }
194
195 void WebContentsDelegateEfl::ExitFullscreenModeForTab(content::WebContents* web_contents) {
196    is_fullscreen_ = false;
197    web_view_->SmartCallback<EWebViewCallbacks::ExitFullscreen>().call();
198 }
199
200 bool WebContentsDelegateEfl::IsFullscreenForTabOrPending(
201       const WebContents* web_contents) const {
202   return is_fullscreen_;
203 }
204
205 void WebContentsDelegateEfl::RegisterProtocolHandler(WebContents* web_contents,
206         const std::string& protocol, const GURL& url, bool user_gesture) {
207   Ewk_Custom_Handlers_Data protocol_data(protocol.c_str(),
208           url.host().c_str(), url.spec().c_str());
209   web_view_->SmartCallback<EWebViewCallbacks::RegisterProtocolHandler>().call(&protocol_data);
210 }
211
212 void WebContentsDelegateEfl::UnregisterProtocolHandler(WebContents* web_contents,
213                                                        const std::string& protocol,
214                                                        const GURL& url,
215                                                        bool user_gesture) {
216   Ewk_Custom_Handlers_Data protocol_data(protocol.c_str(),
217           url.host().c_str(), url.spec().c_str());
218   web_view_->SmartCallback<EWebViewCallbacks::UnregisterProtocolHandler>()
219       .call(&protocol_data);
220 }
221
222 #if defined(TIZEN_MULTIMEDIA_SUPPORT)
223 void WebContentsDelegateEfl::RequestMediaAccessAllow(
224     const MediaStreamRequest& request,
225     const MediaResponseCallback& callback) {
226
227   MediaStreamDevices devices;
228
229   if (request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
230     devices.push_back(MediaStreamDevice(request.audio_type,
231         "default", "Default"));
232   }
233
234   if (request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
235 #if defined(OS_TIZEN)
236     const content::MediaStreamDevice* video_device =
237         GetRequestedVideoDevice(request.requested_video_device_id);
238     if (video_device) {
239       devices.push_back(*video_device);
240     }
241     else {
242       callback.Run(MediaStreamDevices(), MEDIA_DEVICE_NOT_SUPPORTED,
243           scoped_ptr<MediaStreamUI>());
244     }
245 #else
246     devices.push_back(MediaStreamDevice(request.video_type, "/dev/video0", "1"));
247 #endif
248   }
249
250   callback.Run(devices, MEDIA_DEVICE_OK,scoped_ptr<MediaStreamUI>());
251 }
252
253 void WebContentsDelegateEfl::RequestMediaAccessDeny(
254     const MediaStreamRequest& request,
255     const MediaResponseCallback& callback) {
256   LOG(ERROR) << __FUNCTION__ << " Decline request with empty list";
257   callback.Run(MediaStreamDevices(), MEDIA_DEVICE_NOT_SUPPORTED,
258       scoped_ptr<MediaStreamUI>());
259 }
260
261 bool WebContentsDelegateEfl::CheckMediaAccessPermission(
262     WebContents* web_contents,
263     const GURL& security_origin,
264     MediaStreamType type) {
265   return true;
266 }
267
268 void WebContentsDelegateEfl::RequestMediaAccessPermission(
269         WebContents* web_contents,
270         const MediaStreamRequest& request,
271         const MediaResponseCallback& callback) {
272   scoped_ptr<_Ewk_User_Media_Permission_Request> media_permission_request(
273       new _Ewk_User_Media_Permission_Request(this, request, callback));
274
275   Eina_Bool callback_result = EINA_FALSE;
276   if (!web_view_->InvokeViewUserMediaPermissionCallback(
277         media_permission_request.get(), &callback_result)) {
278       web_view_->SmartCallback<EWebViewCallbacks::UserMediaPermission>()
279         .call(media_permission_request.get());
280   }
281
282   if (media_permission_request->IsSuspended())
283     media_permission_request.release();
284   else if (!media_permission_request->IsDecided()) {
285     callback.Run(MediaStreamDevices(), MEDIA_DEVICE_NOT_SUPPORTED,
286         scoped_ptr<MediaStreamUI>());
287   }
288 }
289 #endif
290
291 void WebContentsDelegateEfl::OnAuthRequired(net::URLRequest* request,
292                                             const std::string& realm,
293                                             LoginDelegateEfl* login_delegate) {
294   web_view_->InvokeAuthCallback(login_delegate, request->url(), realm);
295 }
296
297 void WebContentsDelegateEfl::DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
298                                                              const GURL& validated_url,
299                                                              bool is_error_page,
300                                                              bool is_iframe_srcdoc) {
301   web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadStarted>().call();
302 }
303
304 void WebContentsDelegateEfl::DidCommitProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
305                                                               const GURL& url,
306                                                               ui::PageTransition transition_type) {
307   web_view_->SmartCallback<EWebViewCallbacks::LoadCommitted>().call();
308 }
309
310
311 void WebContentsDelegateEfl::DidNavigateMainFrame(const LoadCommittedDetails& details,
312                                                   const FrameNavigateParams& params) {
313   // The condition checks whether the main frame navigated to a different page,
314   // not scrolled to a fragment inside the current page.
315   if (details.is_navigation_to_different_page())
316     web_view_->SmartCallback<EWebViewCallbacks::LoadStarted>().call();
317 }
318
319 void WebContentsDelegateEfl::DocumentOnLoadCompletedInMainFrame() {
320   web_view_->SmartCallback<EWebViewCallbacks::LoadFinished>().call();
321 }
322
323 void WebContentsDelegateEfl::DidNavigateAnyFrame(RenderFrameHost* render_frame_host, const LoadCommittedDetails& details, const FrameNavigateParams& params) {
324   web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadRedirect>().call();
325   static_cast<BrowserContextEfl*>(web_contents_.GetBrowserContext())->AddVisitedURLs(params.redirects);
326 }
327
328 void WebContentsDelegateEfl::DidFinishLoad(RenderFrameHost* render_frame_host,
329                                            const GURL& validated_url) {
330   if (render_frame_host->GetParent())
331     return;
332
333   NavigationEntry *entry = web_contents().GetController().GetVisibleEntry();
334   if (!entry)
335     return;
336
337   FaviconStatus &favicon = entry->GetFavicon();
338
339   if (favicon.valid) {
340     // check/update the url and favicon url in favicon database
341     FaviconService fs;
342     fs.SetFaviconURLForPageURL(favicon.url, validated_url);
343
344     // download favicon if there is no such in database
345     if (!fs.ExistsForFaviconURL(favicon.url)) {
346       LOG(ERROR) << "[DidFinishLoad] :: no favicon in database for URL: "
347                  << favicon.url.spec();
348       favicon_downloader_.reset(
349         new FaviconDownloader(&web_contents_,
350                               favicon.url,
351                               base::Bind(
352                                 &WebContentsDelegateEfl::DidDownloadFavicon,
353                                 weak_ptr_factory_.GetWeakPtr())));
354       favicon_downloader_->Start();
355     } else {
356       web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
357     }
358   }
359
360   web_contents_.Focus();
361 }
362
363
364 void WebContentsDelegateEfl::DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) {
365   // select and set proper favicon
366   for (unsigned int i = 0; i < candidates.size(); ++i) {
367     FaviconURL favicon = candidates[i];
368     if (favicon.icon_type == FaviconURL::FAVICON && !favicon.icon_url.is_empty()) {
369       NavigationEntry *entry = web_contents_.GetController().GetVisibleEntry();
370       if (!entry)
371         return;
372       entry->GetFavicon().url = favicon.icon_url;
373       entry->GetFavicon().valid = true;
374       return;
375     }
376   }
377   return;
378 }
379
380 void WebContentsDelegateEfl::DidDownloadFavicon(bool success, const GURL& icon_url, const SkBitmap& bitmap) {
381   favicon_downloader_.reset();
382   if (success) {
383     FaviconService fs;
384     fs.SetBitmapForFaviconURL(bitmap, icon_url);
385     // emit "icon,received"
386     web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
387   }
388 }
389
390 void WebContentsDelegateEfl::RequestCertificateConfirm(WebContents* /*web_contents*/,
391                                                       int cert_error,
392                                                       const net::SSLInfo& ssl_info,
393                                                       const GURL& url,
394                                                       ResourceType /*resource_type*/,
395                                                       bool /*overridable*/,
396                                                       bool /*strict_enforcement*/,
397                                                       const base::Callback<void(bool)>& callback,
398                                                       CertificateRequestResultType* result) {
399   DCHECK(result);
400   std::string pem_certificate;
401   if (!net::X509Certificate::GetPEMEncoded(ssl_info.cert->os_cert_handle(), &pem_certificate)) {
402     *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
403     return;
404   }
405   certificate_policy_decision_.reset(new _Ewk_Certificate_Policy_Decision(url,
406                                                                         pem_certificate,
407                                                                         cert_error,
408                                                                         callback));
409   web_view_->SmartCallback<EWebViewCallbacks::RequestCertificateConfirm>().call(
410       certificate_policy_decision_.get());
411
412   // if policy is suspended, the API takes over the policy object lifetime
413   // and policy will be deleted after decision is made
414   if (certificate_policy_decision_->isSuspended()) {
415     certificate_policy_decision_.release();
416   } else {
417     certificate_policy_decision_->setDecision(true);
418   }
419 }
420
421 void WebContentsDelegateEfl::SetContentSecurityPolicy(const std::string& policy, Ewk_CSP_Header_Type header_type) {
422   if (document_created_) {
423     RenderViewHost* rvh = web_contents_.GetRenderViewHost();
424     rvh->Send(new EwkViewMsg_SetCSP(rvh->GetRoutingID(), policy, header_type));
425   } else {
426     DCHECK(!pending_content_security_policy_.get());
427     pending_content_security_policy_.reset(new ContentSecurityPolicy(policy, header_type));
428   }
429 }
430
431 void WebContentsDelegateEfl::FindReply(WebContents* web_contents,
432                                        int request_id,
433                                        int number_of_matches,
434                                        const gfx::Rect& selection_rect,
435                                        int active_match_ordinal,
436                                        bool final_update) {
437   if (final_update && request_id == web_view_->current_find_request_id()) {
438     unsigned int uint_number_of_matches = static_cast<unsigned int>(number_of_matches);
439     web_view_->SmartCallback<EWebViewCallbacks::TextFound>().call(&uint_number_of_matches);
440   }
441 }
442
443 JavaScriptDialogManager* WebContentsDelegateEfl::GetJavaScriptDialogManager(
444       WebContents* source) {
445   if (!dialog_manager_)
446     dialog_manager_ = new JavaScriptDialogManagerEfl();
447   return dialog_manager_;
448 }
449
450 void WebContentsDelegateEfl::OnUpdateSettings(const Ewk_Settings *settings) {
451 #if defined(TIZEN_AUTOFILL_SUPPORT)
452   PasswordManagerClientEfl *client =
453       PasswordManagerClientEfl::FromWebContents(&web_contents_);
454   if(client) {
455     client->SetPasswordManagerSavingEnabled(settings->autofillPasswordForm());
456     client->SetPasswordManagerFillingEnabled(settings->autofillPasswordForm());
457   }
458 #endif
459 }
460
461 bool WebContentsDelegateEfl::OnMessageReceived(const IPC::Message& message) {
462   bool handled = true;
463   IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateEfl, message)
464     IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_GetContentSecurityPolicy, OnGetContentSecurityPolicy)
465     IPC_MESSAGE_HANDLER(EwkHostMsg_DidPrintPagesToPdf, OnPrintedMetafileReceived)
466     IPC_MESSAGE_HANDLER(EwkHostMsg_WrtMessage, OnWrtPluginMessage)
467     IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_WrtSyncMessage, OnWrtPluginSyncMessage)
468     IPC_MESSAGE_UNHANDLED(handled = false)
469   IPC_END_MESSAGE_MAP()
470
471   return handled;
472 }
473
474 void WebContentsDelegateEfl::OnWrtPluginMessage(const Ewk_Wrt_Message_Data& data) {
475   scoped_ptr<Ewk_Wrt_Message_Data> p(new Ewk_Wrt_Message_Data);
476   p->type = data.type;
477   p->value = data.value;
478   p->id = data.id;
479   p->reference_id = data.reference_id;
480
481   web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(p.get());
482 }
483
484 void WebContentsDelegateEfl::OnWrtPluginSyncMessage(const Ewk_Wrt_Message_Data& data,
485                                                     IPC::Message* reply) {
486   Ewk_Wrt_Message_Data tmp = data;
487   web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(&tmp);
488   EwkHostMsg_WrtSyncMessage::WriteReplyParams(reply, tmp.value);
489   Send(reply);
490 }
491
492 void WebContentsDelegateEfl::DidFirstVisuallyNonEmptyPaint() {
493   web_view_->SmartCallback<EWebViewCallbacks::LoadNonEmptyLayoutFinished>().call();
494   web_view_->SmartCallback<EWebViewCallbacks::FrameRendered>().call(0);
495 }
496
497 void WebContentsDelegateEfl::OnGetContentSecurityPolicy(IPC::Message* reply_msg) {
498   document_created_ = true;
499   if (!pending_content_security_policy_.get()) {
500     EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(reply_msg, std::string(), EWK_DEFAULT_POLICY);
501   } else {
502     EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(reply_msg,
503         pending_content_security_policy_->policy, pending_content_security_policy_->header_type);
504     pending_content_security_policy_.reset();
505   }
506   Send(reply_msg);
507 }
508
509 void WebContentsDelegateEfl::OnPrintedMetafileReceived(const DidPrintPagesParams& params) {
510   base::SharedMemory shared_buf(params.metafile_data_handle, true);
511   if (!shared_buf.Map(params.data_size)) {
512      NOTREACHED() << "couldn't map";
513      return;
514   }
515   scoped_ptr<printing::PdfMetafileSkia> metafile(new printing::PdfMetafileSkia);
516   if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) {
517     NOTREACHED() << "Invalid metafile header";
518     return;
519   }
520   BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
521         base::Bind(&WritePdfDataToFile, metafile.release(), params.filename));
522 }
523
524 void WebContentsDelegateEfl::NavigationEntryCommitted(const LoadCommittedDetails& load_details) {
525   web_view_->InvokeBackForwardListChangedCallback();
526 }
527
528 void WebContentsDelegateEfl::RenderViewCreated(RenderViewHost* render_view_host) {
529   web_view_->RenderViewCreated(render_view_host);
530 }
531
532 void WebContentsDelegateEfl::RenderProcessGone(base::TerminationStatus status) {
533   // See RenderWidgetHostViewEfl::RenderProcessGone.
534   if (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION
535       || status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED
536       || status == base::TERMINATION_STATUS_PROCESS_CRASHED) {
537     web_view_->HandleRendererProcessCrash();
538   }
539 }
540
541 bool WebContentsDelegateEfl::AddMessageToConsole(WebContents* source,
542                                               int32 level,
543                                               const string16& message,
544                                               int32 line_no,
545                                               const string16& source_id) {
546   scoped_ptr<_Ewk_Console_Message> console_message(new _Ewk_Console_Message(level,
547                                                                           UTF16ToUTF8(message).c_str(),
548                                                                           line_no,
549                                                                           source->GetVisibleURL().spec().c_str()));
550   web_view_->SmartCallback<EWebViewCallbacks::ConsoleMessage>().call(console_message.get());
551   return true;
552 }
553
554 void WebContentsDelegateEfl::RunFileChooser(WebContents* web_contents, const FileChooserParams& params) {
555   web_view_->ShowFileChooser(params);
556 }
557
558 content::ColorChooser* WebContentsDelegateEfl::OpenColorChooser(
559     WebContents* web_contents,
560     SkColor color,
561     const std::vector<ColorSuggestion>& suggestions) {
562   ColorChooserEfl* color_chooser_efl = new ColorChooserEfl(*web_contents);
563   web_view_->RequestColorPicker(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color), SkColorGetA(color));
564
565   return color_chooser_efl;
566 }
567
568 void WebContentsDelegateEfl::OpenDateTimeDialog(
569     ui::TextInputType dialog_type,
570     double dialog_value,
571     double min,
572     double max,
573     double step,
574     const std::vector<DateTimeSuggestion>& suggestions) {
575   web_view_->InputPickerShow(dialog_type, dialog_value);
576 }
577
578 bool WebContentsDelegateEfl::PreHandleGestureEvent(
579     WebContents* source,
580     const blink::WebGestureEvent& event) {
581   switch (event.type) {
582     case blink::WebInputEvent::GestureDoubleTap:
583       if (is_fullscreen_)
584         return true;
585       break;
586     case blink::WebInputEvent::GesturePinchBegin:
587     case blink::WebInputEvent::GesturePinchUpdate:
588     case blink::WebInputEvent::GesturePinchEnd:
589       if (!IsPinchToZoomEnabled() ||
590           IsFullscreenForTabOrPending(&web_contents()))
591         return true;
592       break;
593     default:
594       break;
595   }
596   return false;
597 }
598
599 } //namespace content