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.
8 #if defined(OS_TIZEN_MOBILE)
9 #if !defined(EWK_BRINGUP)
10 // FIXME: appfw/app_service.h is no more in Tizen 2.3, figure out what to include instead.
11 #include <appcore-agent/service_app.h>
21 #include "base/callback.h"
22 #include "base/memory/scoped_ptr.h"
23 #include "base/synchronization/waitable_event.h"
24 #include "content/public/common/context_menu_params.h"
25 #include "content/public/common/file_chooser_params.h"
26 #include "content/browser/renderer_host/event_with_latency_info.h"
27 #include "content/common/input/input_event_ack_state.h"
28 #include "content/public/browser/navigation_controller.h"
29 #include "content/public/browser/quota_permission_context.h"
30 #include "content/public/browser/web_contents_delegate.h"
31 #include "content/public/browser/web_contents_efl_delegate.h"
32 #include "content/public/common/menu_item.h"
33 #include "base/id_map.h"
34 #include "context_menu_controller_efl.h"
35 #include "eweb_context.h"
36 #include "ewk_touch.h"
37 #include "private/ewk_history_private.h"
38 #include "private/ewk_hit_test_private.h"
39 #include "private/ewk_auth_challenge_private.h"
40 #include "private/ewk_back_forward_list_private.h"
41 #include "private/ewk_settings_private.h"
42 #include "private/ewk_web_application_icon_data_private.h"
43 #include "public/ewk_hit_test.h"
44 #include "public/ewk_view.h"
45 #include "eweb_view_callbacks.h"
46 #include "scroll_detector.h"
47 #include "selection_controller_efl.h"
48 #include "web_contents_delegate_efl.h"
49 #include "context_menu_controller_efl.h"
50 #include "file_chooser_controller_efl.h"
51 #include "ui/gfx/geometry/point.h"
52 #include "ui/gfx/geometry/size.h"
53 #include "browser/inputpicker/InputPicker.h"
54 #include "popup_controller_efl.h"
56 #include "browser/selectpicker/popup_picker.h"
60 class RenderWidgetHostViewEfl;
61 class WebContentsDelegateEfl;
62 class ContextMenuControllerEfl;
63 class DevToolsDelegateEfl;
64 class WebContentsViewEfl;
65 class PopupControllerEfl;
69 class _Ewk_Policy_Decision;
72 class WebViewEvasEventHandler;
73 class _Ewk_Quota_Permission_Request;
75 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
77 WebAppScreenshotCapturedCallback(Ewk_Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
78 : func_(func), user_data_(user_data), canvas_(canvas) {}
79 void Run(Evas_Object* image) {
81 (func_)(image, user_data_);
85 Ewk_Web_App_Screenshot_Captured_Callback func_;
90 class EwkViewPlainTextGetCallback {
92 EwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
94 : callback_(callback), user_data_(user_data)
96 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
99 Ewk_View_Plain_Text_Get_Callback callback_;
103 class OrientationLockCallback {
105 OrientationLockCallback(Ewk_Orientation_Lock_Cb lock,
108 user_data_(user_data)
111 Ewk_Orientation_Lock_Cb lock_;
115 class MHTMLCallbackDetails {
117 MHTMLCallbackDetails(Ewk_View_MHTML_Data_Get_Callback callback_func, void *user_data)
118 : callback_func_(callback_func),
119 user_data_(user_data)
121 void Run(Evas_Object* obj, const std::string& mhtml_content);
123 Ewk_View_MHTML_Data_Get_Callback callback_func_;
127 class WebApplicationIconUrlGetCallback {
129 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func, void *user_data)
130 : func_(func), user_data_(user_data)
132 void Run(const std::string &url) {
134 (func_)(url.c_str(), user_data_);
139 Ewk_Web_App_Icon_URL_Get_Callback func_;
143 class WebApplicationIconUrlsGetCallback {
145 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func, void *user_data)
146 : func_(func), user_data_(user_data)
148 void Run(const std::map<std::string, std::string> &urls) {
150 Eina_List *list = NULL;
151 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
152 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
153 list = eina_list_append(list, data);
155 (func_)(list, user_data_);
160 Ewk_Web_App_Icon_URLs_Get_Callback func_;
164 class WebApplicationCapableGetCallback {
166 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func, void *user_data)
167 : func_(func), user_data_(user_data)
169 void Run(bool capable) {
171 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
176 Ewk_Web_App_Capable_Get_Callback func_;
180 class AsyncHitTestRequest;
181 class NotificationPermissionCallback {
183 NotificationPermissionCallback(
185 Ewk_View_Notification_Permission_Callback func,
187 : obj_(obj), func_(func), user_data_(user_data) {}
188 bool Run(Ewk_Notification_Permission_Request* request) {
190 return (func_)(obj_, request, user_data_) == EINA_TRUE;
197 Ewk_View_Notification_Permission_Callback func_;
201 class QuotaPermissionRequestCallback {
203 QuotaPermissionRequestCallback(Ewk_Quota_Permission_Request_Callback func, void* user_data)
204 : func_(func), user_data_(user_data)
206 void Run(Evas_Object* obj, const _Ewk_Quota_Permission_Request* req) {
208 (func_)(obj, req, user_data_);
212 Ewk_Quota_Permission_Request_Callback func_;
216 class WebViewAsyncRequestHitTestDataCallback;
217 class JavaScriptDialogManagerEfl;
218 class WebViewGeolocationPermissionCallback;
219 class WebViewUnfocusAllowCallback;
223 static EWebView* FromEvasObject(Evas_Object* eo);
224 static int GetOrientation();
226 EWebView(Ewk_Context*, Evas_Object* smart_object);
229 // initialize data members and activate event handlers.
230 // call this once after created and before use
233 void CreateNewWindow(content::WebContentsEflDelegate::WebContentsCreateCallback);
234 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
236 Ewk_Context* context() const { return context_.get(); }
237 Evas_Object* evas_object() const { return evas_object_; }
238 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
240 content::WebContents& web_contents() const
242 return *web_contents_.get();
245 template<EWebViewCallbacks::CallbackType callbackType>
246 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
248 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
251 void set_magnifier(bool status);
254 void SetURL(const char* url_string);
255 const char* GetURL() const;
257 void ReloadIgnoringCache();
258 Eina_Bool CanGoBack();
259 Eina_Bool CanGoForward();
260 Eina_Bool HasFocus() const;
261 void SetFocus(Eina_Bool focus);
263 Eina_Bool GoForward();
267 double GetTextZoomFactor() const;
268 void SetTextZoomFactor(double text_zoom_factor);
269 void ExecuteEditCommand(const char* command, const char* value);
270 void SetOrientation(int orientation);
271 void SetOrientationLockCallback(Ewk_Orientation_Lock_Cb func, void* data);
272 bool TouchEventsEnabled() const;
273 void SetTouchEventsEnabled(bool enabled);
274 bool MouseEventsEnabled() const;
275 void SetMouseEventsEnabled(bool enabled);
276 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
279 bool ExecuteJavaScript(const char* script, Ewk_View_Script_Execute_Callback callback, void* userdata);
280 bool SetUserAgent(const char* userAgent);
281 bool SetUserAgentAppName(const char* application_name);
282 bool SetPrivateBrowsing(bool incognito);
283 bool GetPrivateBrowsing() const;
284 const char* GetUserAgent() const;
285 const char* GetUserAgentAppName() const;
286 const char* GetSelectedText() const;
287 Ewk_Settings* GetSettings();
288 _Ewk_Frame* GetMainFrame();
289 void UpdateWebKitPreferences();
290 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
291 void LoadPlainTextString(const char* plain_text);
292 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
293 void InvokeLoadError(const ErrorParams &error);
294 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
295 void Find(const char* text, Ewk_Find_Options);
296 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
297 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
298 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
299 int selectedIndex, bool multiple);
300 Eina_Bool HidePopupMenu();
301 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
302 bool prevState, bool nextState);
303 void FormNavigate(bool direction);
304 bool IsSelectPickerShown() const;
305 void CloseSelectPicker();
306 bool FormIsNavigating() const { return formIsNavigating_; }
307 void SetFormIsNavigating(bool formIsNavigating);
308 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
309 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
310 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
311 Eina_Bool PopupMenuClose();
312 void ShowContextMenu(
313 const content::ContextMenuParams& params,
314 content::ContextMenuType type = content::MENU_TYPE_LINK,
315 bool show_selection = true);
316 void CancelContextMenu(int request_id);
317 void SetScale(double scale_factor, int x, int y);
318 bool GetScrollPosition(int* x, int* y) const;
319 void SetScroll(int x, int y);
320 void UrlRequestSet(const char* url,
321 content::NavigationController::LoadURLType loadtype,
325 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
326 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
327 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
328 void MoveCaret(const gfx::Point& point);
329 void QuerySelectionStyle();
330 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
331 void SelectClosestWord(const gfx::Point& touch_point);
332 void SelectLinkText(const gfx::Point& touch_point);
333 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
334 void GetSnapShotForRect(gfx::Rect& rect);
336 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
337 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
339 void RenderViewCreated(content::RenderViewHost* render_view_host);
342 * Creates a snapshot of given rectangle from EWebView
344 * @param rect rectangle of EWebView which will be taken into snapshot
346 * @return created snapshot or NULL if error occured.
347 * @note ownership of snapshot is passed to caller
349 Evas_Object* GetSnapshot(Eina_Rectangle rect);
351 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
352 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
353 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
354 NavigationPolicyParams params, bool* handled);
355 void UseSettingsFont();
357 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
358 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
359 Ewk_Hit_Test_Mode mode,
360 Ewk_View_Hit_Test_Request_Callback,
362 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
363 Ewk_Hit_Test_Mode mode);
364 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
365 Ewk_Hit_Test_Mode mode,
366 Ewk_View_Hit_Test_Request_Callback,
368 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
369 void UpdateHitTestData(const Hit_Test_Params& params);
371 int current_find_request_id() const { return current_find_request_id_; }
372 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
373 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
374 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
375 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
376 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
377 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
378 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
379 void DidChangeContentsSize(int width, int height);
380 const Eina_Rectangle GetContentsSize() const;
381 void GetScrollSize(int* w, int* h);
383 void SetProgressValue(double progress);
384 double GetProgressValue();
385 const char* GetTitle();
386 bool SaveAsPdf(int width, int height, const std::string& file_name);
387 void BackForwardListClear();
388 _Ewk_Back_Forward_List* GetBackForwardList() const;
389 void InvokeBackForwardListChangedCallback();
390 _Ewk_History* GetBackForwardHistory() const;
391 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
392 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
393 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
394 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
395 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
396 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
397 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
398 bool IsNotificationPermissionCallbackSet() const;
399 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
401 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
402 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
404 void ExitFullscreen();
406 void DidChangePageScaleFactor(double scale_factor);
407 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
408 void JavaScriptAlertReply();
409 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
410 void JavaScriptConfirmReply(bool result);
411 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
412 void JavaScriptPromptReply(const char* result);
413 void set_renderer_crashed();
414 void GetPageScaleRange(double *min_scale, double *max_scale);
415 void DidChangePageScaleRange(double min_scale, double max_scale);
416 void SetDrawsTransparentBackground(bool enabled);
417 void GetSessionData(const char **data, unsigned *length) const;
418 bool RestoreFromSessionData(const char *data, unsigned length);
419 void ShowFileChooser(const content::FileChooserParams&);
420 void DidChangeContentsArea(int width, int height);
421 void SetBrowserFont();
422 void SetCertificatePem(const std::string& certificate);
423 bool IsDragging() const;
425 void RequestColorPicker(int r, int g, int b, int a);
426 void DismissColorPicker();
427 bool SetColorPickerColor(int r, int g, int b, int a);
428 void InputPickerShow(ui::TextInputType input_type, double input_value);
429 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
431 void ShowContentsDetectedPopup(const char*);
433 // Returns TCP port number with Inspector, or 0 if error.
434 int StartInspectorServer(int port = 0);
435 bool StopInspectorServer();
437 void LoadNotFoundErrorPage(const std::string& invalidUrl);
438 static std::string GetPlatformLocale();
439 bool GetLinkMagnifierEnabled() const;
440 void SetLinkMagnifierEnabled(bool enabled);
442 void SetOverrideEncoding(const std::string& encoding);
443 void SetQuotaPermissionRequestCallback(Ewk_Quota_Permission_Request_Callback callback,
445 void InvokeQuotaPermissionRequest(_Ewk_Quota_Permission_Request* request,
446 const content::QuotaPermissionContext::PermissionCallback& cb);
447 void QuotaRequestReply(const _Ewk_Quota_Permission_Request *request,
449 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request *request);
451 void SetViewMode(blink::WebViewMode view_mode);
453 gfx::Point GetContextMenuPosition() const;
455 content::ContextMenuControllerEfl* GetContextMenuController() {
456 return context_menu_.get();
458 void ResetContextMenuController();
460 /// ---- Event handling
463 bool HandleMove(int x, int y);
464 bool HandleResize(int width, int height);
465 bool HandleTextSelectionDown(int x, int y);
466 bool HandleTextSelectionUp(int x, int y);
468 void HandleRendererProcessCrash();
469 void InvokeWebProcessCrashedCallback();
470 void HandlePostponedGesture(int x, int y, ui::EventType type);
472 void InitializeContent();
473 void SendDelayedMessages(content::RenderViewHost* render_view_host);
475 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
476 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
477 Ewk_Hit_Test_Mode mode,
478 WebViewAsyncRequestHitTestDataCallback* cb);
479 void HandleLongPressGesture(int x, int y, Ewk_Hit_Test_Mode mode,
481 void HandleTapGesture(int x, int y, Ewk_Hit_Test_Mode mode,
483 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
485 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
486 static void cameraResultCb(service_h request, service_h reply,
487 service_result_e result, void* data);
490 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
491 bool LaunchCamera(base::string16 mimetype);
493 content::RenderWidgetHostViewEfl* rwhv() const;
494 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
496 void ReleasePopupMenuList();
498 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
499 scoped_refptr<Ewk_Context> context_;
500 scoped_refptr<Ewk_Context> old_context_;
501 scoped_ptr<content::WebContents> web_contents_;
502 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
503 std::string pending_url_request_;
504 scoped_ptr<Ewk_Settings> settings_;
505 scoped_ptr<_Ewk_Frame> frame_;
506 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
507 Evas_Object* evas_object_;
508 Evas_Object* native_view_;
509 bool touch_events_enabled_;
510 bool mouse_events_enabled_;
511 double text_zoom_factor_;
512 mutable std::string selected_text_;
513 mutable std::string user_agent_;
514 mutable std::string user_agent_app_name_;
515 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
517 Eina_List* popupMenuItems_;
518 Popup_Picker* popupPicker_;
519 bool formIsNavigating_;
526 formNavigation formNavigation_;
527 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
528 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
529 scoped_ptr<content::PopupControllerEfl> popup_controller_;
530 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
531 base::string16 previous_text_;
532 int current_find_request_id_;
533 static int find_request_id_counter_;
534 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
535 gfx::Size contents_size_;
537 mutable std::string title_;
538 mutable std::string pem_certificate_;
539 Hit_Test_Params hit_test_params_;
540 base::WaitableEvent hit_test_completion_;
541 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
542 double page_scale_factor_;
543 double min_page_scale_factor_;
544 double max_page_scale_factor_;
545 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
546 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
547 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
548 scoped_ptr<content::InputPicker> inputPicker_;
549 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
550 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
551 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
552 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
553 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
554 content::DevToolsDelegateEfl* inspector_server_;
555 scoped_ptr<ScrollDetector> scroll_detector_;
556 #if defined(OS_TIZEN_MOBILE)
557 content::FileChooserParams::Mode filechooser_mode_;
559 std::map<const _Ewk_Quota_Permission_Request*, content::QuotaPermissionContext::PermissionCallback> quota_permission_request_map_;
560 scoped_ptr<QuotaPermissionRequestCallback> quota_request_callback_;
561 bool is_initialized_;
563 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
565 static content::WebContentsEflDelegate::WebContentsCreateCallback
566 create_new_window_web_contents_cb_;
569 Eina_Bool AsyncRequestHitTestPrivate(
570 int x, int y, Ewk_Hit_Test_Mode mode,
571 AsyncHitTestRequest* asyncHitTestRequest);
573 gfx::Vector2d previous_scroll_position_;
575 gfx::Point context_menu_position_;
577 std::set<IPC::Message*> delayed_messages_;
579 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
582 const unsigned int g_default_tilt_motion_sensitivity = 3;