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/id_map.h"
23 #include "base/memory/scoped_ptr.h"
24 #include "base/synchronization/waitable_event.h"
25 #include "browser/inputpicker/InputPicker.h"
26 #include "browser/selectpicker/popup_picker.h"
27 #include "content/public/common/context_menu_params.h"
28 #include "content/public/common/file_chooser_params.h"
29 #include "content/browser/renderer_host/event_with_latency_info.h"
30 #include "content/browser/selection/selection_controller_efl.h"
31 #include "content/common/input/input_event_ack_state.h"
32 #include "content/public/browser/navigation_controller.h"
33 #include "content/public/browser/quota_permission_context.h"
34 #include "content/public/browser/web_contents_delegate.h"
35 #include "content/public/browser/web_contents_efl_delegate.h"
36 #include "content/public/common/menu_item.h"
37 #include "context_menu_controller_efl.h"
38 #include "eweb_context.h"
39 #include "eweb_view_callbacks.h"
40 #include "ewk_touch.h"
41 #include "file_chooser_controller_efl.h"
42 #include "permission_popup_manager.h"
43 #include "popup_controller_efl.h"
44 #include "private/ewk_history_private.h"
45 #include "private/ewk_hit_test_private.h"
46 #include "private/ewk_auth_challenge_private.h"
47 #include "private/ewk_back_forward_list_private.h"
48 #include "private/ewk_settings_private.h"
49 #include "private/ewk_web_application_icon_data_private.h"
50 #include "public/ewk_hit_test.h"
51 #include "public/ewk_view.h"
52 #include "scroll_detector.h"
53 #include "ui/gfx/geometry/point.h"
54 #include "ui/gfx/geometry/size.h"
55 #include "web_contents_delegate_efl.h"
59 class RenderWidgetHostViewEfl;
60 class WebContentsDelegateEfl;
61 class ContextMenuControllerEfl;
62 class DevToolsDelegateEfl;
63 class WebContentsViewEfl;
64 class PopupControllerEfl;
68 class _Ewk_Policy_Decision;
71 class WebViewEvasEventHandler;
72 class _Ewk_Quota_Permission_Request;
74 class EwkViewPlainTextGetCallback {
76 EwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
78 : callback_(callback), user_data_(user_data)
80 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
83 Ewk_View_Plain_Text_Get_Callback callback_;
87 class OrientationLockCallback {
89 OrientationLockCallback(Ewk_Orientation_Lock_Cb lock,
95 Ewk_Orientation_Lock_Cb lock_;
99 class MHTMLCallbackDetails {
101 MHTMLCallbackDetails(Ewk_View_MHTML_Data_Get_Callback callback_func, void *user_data)
102 : callback_func_(callback_func),
103 user_data_(user_data)
105 void Run(Evas_Object* obj, const std::string& mhtml_content);
107 Ewk_View_MHTML_Data_Get_Callback callback_func_;
111 class WebApplicationIconUrlGetCallback {
113 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func, void *user_data)
114 : func_(func), user_data_(user_data)
116 void Run(const std::string &url) {
118 (func_)(url.c_str(), user_data_);
123 Ewk_Web_App_Icon_URL_Get_Callback func_;
127 class WebApplicationIconUrlsGetCallback {
129 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func, void *user_data)
130 : func_(func), user_data_(user_data)
132 void Run(const std::map<std::string, std::string> &urls) {
134 Eina_List *list = NULL;
135 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
136 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
137 list = eina_list_append(list, data);
139 (func_)(list, user_data_);
144 Ewk_Web_App_Icon_URLs_Get_Callback func_;
148 class WebApplicationCapableGetCallback {
150 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func, void *user_data)
151 : func_(func), user_data_(user_data)
153 void Run(bool capable) {
155 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
160 Ewk_Web_App_Capable_Get_Callback func_;
164 class AsyncHitTestRequest;
165 class NotificationPermissionCallback {
167 NotificationPermissionCallback(
169 Ewk_View_Notification_Permission_Callback func,
171 : obj_(obj), func_(func), user_data_(user_data) {}
172 bool Run(Ewk_Notification_Permission_Request* request) {
174 return (func_)(obj_, request, user_data_) == EINA_TRUE;
181 Ewk_View_Notification_Permission_Callback func_;
185 class QuotaPermissionRequestCallback {
187 QuotaPermissionRequestCallback(Ewk_Quota_Permission_Request_Callback func, void* user_data)
188 : func_(func), user_data_(user_data)
190 void Run(Evas_Object* obj, const _Ewk_Quota_Permission_Request* req) {
192 (func_)(obj, req, user_data_);
196 Ewk_Quota_Permission_Request_Callback func_;
200 class WebViewAsyncRequestHitTestDataCallback;
201 class JavaScriptDialogManagerEfl;
202 class WebViewGeolocationPermissionCallback;
203 class WebViewUserMediaPermissionCallback;
204 class WebViewUnfocusAllowCallback;
205 class PermissionPopupManager;
209 static EWebView* FromEvasObject(Evas_Object* eo);
210 static int GetOrientation();
212 EWebView(Ewk_Context*, Evas_Object* smart_object);
215 // initialize data members and activate event handlers.
216 // call this once after created and before use
219 void CreateNewWindow(content::WebContentsEflDelegate::WebContentsCreateCallback);
220 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
222 Ewk_Context* context() const { return context_.get(); }
223 Evas_Object* evas_object() const { return evas_object_; }
224 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
225 PermissionPopupManager* GetPermissionPopupManager() const
227 return permission_popup_manager_.get();
230 content::WebContents& web_contents() const
232 return *web_contents_.get();
235 template<EWebViewCallbacks::CallbackType callbackType>
236 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
238 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
241 void set_magnifier(bool status);
244 void SetURL(const char* url_string);
245 const char* GetURL() const;
247 void ReloadIgnoringCache();
248 Eina_Bool CanGoBack();
249 Eina_Bool CanGoForward();
250 Eina_Bool HasFocus() const;
251 void SetFocus(Eina_Bool focus);
253 Eina_Bool GoForward();
257 double GetTextZoomFactor() const;
258 void SetTextZoomFactor(double text_zoom_factor);
259 void ExecuteEditCommand(const char* command, const char* value);
260 void SetOrientation(int orientation);
261 void SetOrientationLockCallback(Ewk_Orientation_Lock_Cb func, void* data);
262 bool TouchEventsEnabled() const;
263 void SetTouchEventsEnabled(bool enabled);
264 bool MouseEventsEnabled() const;
265 void SetMouseEventsEnabled(bool enabled);
266 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
269 bool ExecuteJavaScript(const char* script, Ewk_View_Script_Execute_Callback callback, void* userdata);
270 bool SetUserAgent(const char* userAgent);
271 bool SetUserAgentAppName(const char* application_name);
272 bool SetPrivateBrowsing(bool incognito);
273 bool GetPrivateBrowsing() const;
274 const char* GetUserAgent() const;
275 const char* GetUserAgentAppName() const;
276 const char* GetSelectedText() const;
277 Ewk_Settings* GetSettings();
278 _Ewk_Frame* GetMainFrame();
279 void UpdateWebKitPreferences();
280 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
281 void LoadPlainTextString(const char* plain_text);
282 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
283 void InvokeLoadError(const ErrorParams &error);
284 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
285 void Find(const char* text, Ewk_Find_Options);
286 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
287 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
288 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
289 int selectedIndex, bool multiple);
290 Eina_Bool HidePopupMenu();
291 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
292 bool prevState, bool nextState);
293 void FormNavigate(bool direction);
294 bool IsSelectPickerShown() const;
295 void CloseSelectPicker();
296 bool FormIsNavigating() const { return formIsNavigating_; }
297 void SetFormIsNavigating(bool formIsNavigating);
298 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
299 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
300 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
301 Eina_Bool PopupMenuClose();
302 void ShowContextMenu(
303 const content::ContextMenuParams& params,
304 content::ContextMenuType type = content::MENU_TYPE_LINK);
305 void CancelContextMenu(int request_id);
306 void SetScale(double scale_factor, int x, int y);
307 bool GetScrollPosition(int* x, int* y) const;
308 void SetScroll(int x, int y);
309 void UrlRequestSet(const char* url,
310 content::NavigationController::LoadURLType loadtype,
314 content::SelectionControllerEfl* GetSelectionController() const;
315 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
316 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
317 void MoveCaret(const gfx::Point& point);
318 void QuerySelectionStyle();
319 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
320 void SelectClosestWord(const gfx::Point& touch_point);
321 void SelectLinkText(const gfx::Point& touch_point);
322 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
324 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
325 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
327 void RenderViewCreated(content::RenderViewHost* render_view_host);
330 * Creates a snapshot of given rectangle from EWebView
332 * @param rect rectangle of EWebView which will be taken into snapshot
334 * @return created snapshot or NULL if error occured.
335 * @note ownership of snapshot is passed to caller
337 Evas_Object* GetSnapshot(Eina_Rectangle rect);
339 bool GetSnapshotAsync(Eina_Rectangle rect, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
340 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
341 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
342 NavigationPolicyParams params, bool* handled);
343 void UseSettingsFont();
345 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
346 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
347 Ewk_Hit_Test_Mode mode,
348 Ewk_View_Hit_Test_Request_Callback,
350 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
351 Ewk_Hit_Test_Mode mode);
352 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
353 Ewk_Hit_Test_Mode mode,
354 Ewk_View_Hit_Test_Request_Callback,
356 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
357 void UpdateHitTestData(const Hit_Test_Params& params);
359 int current_find_request_id() const { return current_find_request_id_; }
360 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
361 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
362 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
363 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
364 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
365 void SetViewUserMediaPermissionCallback(
366 Ewk_View_User_Media_Permission_Callback callback,
368 bool InvokeViewUserMediaPermissionCallback(
369 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
371 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
372 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
373 void DidChangeContentsSize(int width, int height);
374 const Eina_Rectangle GetContentsSize() const;
375 void GetScrollSize(int* w, int* h);
377 void SetProgressValue(double progress);
378 double GetProgressValue();
379 const char* GetTitle();
380 bool SaveAsPdf(int width, int height, const std::string& file_name);
381 void BackForwardListClear();
382 _Ewk_Back_Forward_List* GetBackForwardList() const;
383 void InvokeBackForwardListChangedCallback();
384 _Ewk_History* GetBackForwardHistory() const;
385 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
386 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
387 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
388 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
389 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
390 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
391 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
392 bool IsNotificationPermissionCallbackSet() const;
393 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
395 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
396 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
398 void ExitFullscreen();
400 void DidChangePageScaleFactor(double scale_factor);
401 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
402 void JavaScriptAlertReply();
403 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
404 void JavaScriptConfirmReply(bool result);
405 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
406 void JavaScriptPromptReply(const char* result);
407 void set_renderer_crashed();
408 void GetPageScaleRange(double *min_scale, double *max_scale);
409 void DidChangePageScaleRange(double min_scale, double max_scale);
410 void SetDrawsTransparentBackground(bool enabled);
411 void GetSessionData(const char **data, unsigned *length) const;
412 bool RestoreFromSessionData(const char *data, unsigned length);
413 void ShowFileChooser(const content::FileChooserParams&);
414 void SetBrowserFont();
415 void SetCertificatePem(const std::string& certificate);
416 bool IsDragging() const;
418 void RequestColorPicker(int r, int g, int b, int a);
419 void DismissColorPicker();
420 bool SetColorPickerColor(int r, int g, int b, int a);
421 void InputPickerShow(ui::TextInputType input_type, double input_value);
423 void ShowContentsDetectedPopup(const char*);
425 // Returns TCP port number with Inspector, or 0 if error.
426 int StartInspectorServer(int port = 0);
427 bool StopInspectorServer();
429 void LoadNotFoundErrorPage(const std::string& invalidUrl);
430 static std::string GetPlatformLocale();
431 bool GetLinkMagnifierEnabled() const;
432 void SetLinkMagnifierEnabled(bool enabled);
434 void SetOverrideEncoding(const std::string& encoding);
435 void SetQuotaPermissionRequestCallback(Ewk_Quota_Permission_Request_Callback callback,
437 void InvokeQuotaPermissionRequest(_Ewk_Quota_Permission_Request* request,
438 const content::QuotaPermissionContext::PermissionCallback& cb);
439 void QuotaRequestReply(const _Ewk_Quota_Permission_Request *request,
441 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request *request);
443 void SetViewMode(blink::WebViewMode view_mode);
445 gfx::Point GetContextMenuPosition() const;
447 content::ContextMenuControllerEfl* GetContextMenuController() {
448 return context_menu_.get();
450 void ResetContextMenuController();
452 /// ---- Event handling
455 bool HandleMove(int x, int y);
456 bool HandleResize(int width, int height);
457 bool HandleTextSelectionDown(int x, int y);
458 bool HandleTextSelectionUp(int x, int y);
460 void HandleRendererProcessCrash();
461 void InvokeWebProcessCrashedCallback();
463 void HandleZoomGesture(blink::WebGestureEvent& event);
466 void InitializeContent();
467 void SendDelayedMessages(content::RenderViewHost* render_view_host);
469 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
470 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
471 Ewk_Hit_Test_Mode mode,
472 WebViewAsyncRequestHitTestDataCallback* cb);
474 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
476 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
477 static void cameraResultCb(service_h request, service_h reply,
478 service_result_e result, void* data);
481 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
482 bool LaunchCamera(base::string16 mimetype);
484 content::RenderWidgetHostViewEfl* rwhv() const;
485 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
487 void ReleasePopupMenuList();
489 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
490 scoped_refptr<Ewk_Context> context_;
491 scoped_refptr<Ewk_Context> old_context_;
492 scoped_ptr<content::WebContents> web_contents_;
493 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
494 std::string pending_url_request_;
495 scoped_ptr<Ewk_Settings> settings_;
496 scoped_ptr<_Ewk_Frame> frame_;
497 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
498 Evas_Object* evas_object_;
499 Evas_Object* native_view_;
500 bool touch_events_enabled_;
501 bool mouse_events_enabled_;
502 double text_zoom_factor_;
503 mutable std::string selected_text_;
504 mutable std::string user_agent_;
505 mutable std::string user_agent_app_name_;
506 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
508 Eina_List* popupMenuItems_;
509 Popup_Picker* popupPicker_;
510 bool formIsNavigating_;
517 formNavigation formNavigation_;
518 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
519 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
520 scoped_ptr<content::PopupControllerEfl> popup_controller_;
521 base::string16 previous_text_;
522 int current_find_request_id_;
523 static int find_request_id_counter_;
524 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
525 gfx::Size contents_size_;
527 mutable std::string title_;
528 mutable std::string pem_certificate_;
529 Hit_Test_Params hit_test_params_;
530 base::WaitableEvent hit_test_completion_;
531 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
532 double page_scale_factor_;
533 double min_page_scale_factor_;
534 double max_page_scale_factor_;
535 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
536 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
537 scoped_ptr<WebViewUserMediaPermissionCallback> user_media_permission_cb_;
538 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
539 scoped_ptr<content::InputPicker> inputPicker_;
540 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
541 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
542 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
543 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
544 scoped_ptr<PermissionPopupManager> permission_popup_manager_;
545 content::DevToolsDelegateEfl* inspector_server_;
546 scoped_ptr<ScrollDetector> scroll_detector_;
547 #if defined(OS_TIZEN_MOBILE)
548 content::FileChooserParams::Mode filechooser_mode_;
550 std::map<const _Ewk_Quota_Permission_Request*, content::QuotaPermissionContext::PermissionCallback> quota_permission_request_map_;
551 scoped_ptr<QuotaPermissionRequestCallback> quota_request_callback_;
552 bool is_initialized_;
554 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
556 static content::WebContentsEflDelegate::WebContentsCreateCallback
557 create_new_window_web_contents_cb_;
560 Eina_Bool AsyncRequestHitTestPrivate(
561 int x, int y, Ewk_Hit_Test_Mode mode,
562 AsyncHitTestRequest* asyncHitTestRequest);
564 gfx::Vector2d previous_scroll_position_;
566 gfx::Point context_menu_position_;
568 std::set<IPC::Message*> delayed_messages_;
570 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
573 const unsigned int g_default_tilt_motion_sensitivity = 3;