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 WebContentsViewEfl;
63 class PopupControllerEfl;
67 class _Ewk_Policy_Decision;
70 class WebViewEvasEventHandler;
71 class _Ewk_Quota_Permission_Request;
73 template <typename CallbackPtr, typename CallbackParameter>
74 class WebViewCallback {
76 WebViewCallback() { Set(nullptr, nullptr); }
78 void Set(CallbackPtr cb, void* data) {
83 bool IsCallbackSet() const {
87 Eina_Bool Run(Evas_Object* webview, CallbackParameter param, Eina_Bool* callback_result) {
88 CHECK(callback_result);
89 if (IsCallbackSet()) {
90 *callback_result = callback_(webview, param, user_data_);
96 void Run(Evas_Object* webview, CallbackParameter param) {
98 callback_(webview, param, user_data_);
102 CallbackPtr callback_;
106 class WebApplicationIconUrlGetCallback {
108 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func, void *user_data)
109 : func_(func), user_data_(user_data)
111 void Run(const std::string &url) {
113 (func_)(url.c_str(), user_data_);
118 Ewk_Web_App_Icon_URL_Get_Callback func_;
122 class WebApplicationIconUrlsGetCallback {
124 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func, void *user_data)
125 : func_(func), user_data_(user_data)
127 void Run(const std::map<std::string, std::string> &urls) {
129 Eina_List *list = NULL;
130 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
131 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
132 list = eina_list_append(list, data);
134 (func_)(list, user_data_);
139 Ewk_Web_App_Icon_URLs_Get_Callback func_;
143 class WebApplicationCapableGetCallback {
145 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func, void *user_data)
146 : func_(func), user_data_(user_data)
148 void Run(bool capable) {
150 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
155 Ewk_Web_App_Capable_Get_Callback func_;
159 class WebViewAsyncRequestHitTestDataCallback;
160 class JavaScriptDialogManagerEfl;
161 class PermissionPopupManager;
165 static EWebView* FromEvasObject(Evas_Object* eo);
166 static int GetOrientation();
168 EWebView(Ewk_Context*, Evas_Object* smart_object);
171 // initialize data members and activate event handlers.
172 // call this once after created and before use
175 void CreateNewWindow(content::WebContentsEflDelegate::WebContentsCreateCallback);
176 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
178 Ewk_Context* context() const { return context_.get(); }
179 Evas_Object* evas_object() const { return evas_object_; }
180 Evas_Object* native_view() const { return native_view_; }
181 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
182 PermissionPopupManager* GetPermissionPopupManager() const
184 return permission_popup_manager_.get();
187 content::WebContents& web_contents() const
189 return *web_contents_.get();
192 template<EWebViewCallbacks::CallbackType callbackType>
193 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
195 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
198 void set_magnifier(bool status);
201 void SetURL(const GURL& url);
202 const GURL& GetURL() const;
204 void ReloadIgnoringCache();
205 Eina_Bool CanGoBack();
206 Eina_Bool CanGoForward();
207 Eina_Bool HasFocus() const;
208 void SetFocus(Eina_Bool focus);
210 Eina_Bool GoForward();
214 double GetTextZoomFactor() const;
215 void SetTextZoomFactor(double text_zoom_factor);
216 double GetPageZoomFactor() const;
217 void SetPageZoomFactor(double page_zoom_factor);
218 void ExecuteEditCommand(const char* command, const char* value);
219 void SetOrientation(int orientation);
220 bool TouchEventsEnabled() const;
221 void SetTouchEventsEnabled(bool enabled);
222 bool MouseEventsEnabled() const;
223 void SetMouseEventsEnabled(bool enabled);
224 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
227 bool ExecuteJavaScript(const char* script, Ewk_View_Script_Execute_Callback callback, void* userdata);
228 bool SetUserAgent(const char* userAgent);
229 bool SetUserAgentAppName(const char* application_name);
230 bool SetPrivateBrowsing(bool incognito);
231 bool GetPrivateBrowsing() const;
232 const char* GetUserAgent() const;
233 const char* GetUserAgentAppName() const;
234 const char* GetSelectedText() const;
235 Ewk_Settings* GetSettings() { return settings_.get(); }
236 _Ewk_Frame* GetMainFrame();
237 void UpdateWebKitPreferences();
238 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
239 void LoadPlainTextString(const char* plain_text);
240 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
242 void InvokeLoadError(const GURL& url, int error_code,
243 const std::string& error_description, bool is_main_frame);
244 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
245 void Find(const char* text, Ewk_Find_Options);
246 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
247 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
248 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
249 int selectedIndex, bool multiple);
250 Eina_Bool HidePopupMenu();
251 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
252 bool prevState, bool nextState);
253 void FormNavigate(bool direction);
254 bool IsSelectPickerShown() const;
255 void CloseSelectPicker();
256 bool FormIsNavigating() const { return formIsNavigating_; }
257 void SetFormIsNavigating(bool formIsNavigating);
258 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
259 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
260 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
261 Eina_Bool PopupMenuClose();
262 void HandleLongPressGesture(const content::ContextMenuParams&);
263 void ShowContextMenu(const content::ContextMenuParams&);
264 void CancelContextMenu(int request_id);
265 void SetScale(double scale_factor, int x, int y);
266 bool GetScrollPosition(int* x, int* y) const;
267 void SetScroll(int x, int y);
268 void UrlRequestSet(const char* url,
269 content::NavigationController::LoadURLType loadtype,
273 content::SelectionControllerEfl* GetSelectionController() const;
274 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
275 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
276 void MoveCaret(const gfx::Point& point);
277 void QuerySelectionStyle();
278 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
279 void SelectLinkText(const gfx::Point& touch_point);
280 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
281 Eina_Bool ClearSelection();
283 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
284 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
286 void RenderViewCreated(content::RenderViewHost* render_view_host);
289 * Creates a snapshot of given rectangle from EWebView
291 * @param rect rectangle of EWebView which will be taken into snapshot
293 * @return created snapshot or NULL if error occured.
294 * @note ownership of snapshot is passed to caller
296 Evas_Object* GetSnapshot(Eina_Rectangle rect);
298 bool GetSnapshotAsync(Eina_Rectangle rect, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
299 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
300 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
301 NavigationPolicyParams params, bool* handled);
302 void UseSettingsFont();
304 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
305 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
306 Ewk_Hit_Test_Mode mode,
307 Ewk_View_Hit_Test_Request_Callback,
309 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
310 Ewk_Hit_Test_Mode mode);
311 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
312 Ewk_Hit_Test_Mode mode,
313 Ewk_View_Hit_Test_Request_Callback,
315 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
316 void UpdateHitTestData(const Hit_Test_Params& params);
318 int current_find_request_id() const { return current_find_request_id_; }
319 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
320 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
321 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
322 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
323 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
324 void SetViewUserMediaPermissionCallback(
325 Ewk_View_User_Media_Permission_Callback callback,
327 bool InvokeViewUserMediaPermissionCallback(
328 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
330 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
331 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
332 void DidChangeContentsSize(int width, int height);
333 const Eina_Rectangle GetContentsSize() const;
334 void GetScrollSize(int* w, int* h);
336 void SetProgressValue(double progress);
337 double GetProgressValue();
338 const char* GetTitle();
339 bool SaveAsPdf(int width, int height, const std::string& file_name);
340 void BackForwardListClear();
341 _Ewk_Back_Forward_List* GetBackForwardList() const;
342 void InvokeBackForwardListChangedCallback();
343 _Ewk_History* GetBackForwardHistory() const;
344 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
345 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
346 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
347 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
348 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
349 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
350 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
351 bool IsNotificationPermissionCallbackSet() const;
352 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
354 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
355 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
357 void ExitFullscreen();
359 void DidChangePageScaleFactor(double scale_factor);
360 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
361 void JavaScriptAlertReply();
362 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
363 void JavaScriptConfirmReply(bool result);
364 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
365 void JavaScriptPromptReply(const char* result);
366 void set_renderer_crashed();
367 void GetPageScaleRange(double *min_scale, double *max_scale);
368 void SetDrawsTransparentBackground(bool enabled);
369 void GetSessionData(const char **data, unsigned *length) const;
370 bool RestoreFromSessionData(const char *data, unsigned length);
371 void ShowFileChooser(const content::FileChooserParams&);
372 void SetBrowserFont();
373 void SetCertificatePem(const std::string& certificate);
374 bool IsDragging() const;
376 void RequestColorPicker(int r, int g, int b, int a);
377 void DismissColorPicker();
378 bool SetColorPickerColor(int r, int g, int b, int a);
379 void InputPickerShow(ui::TextInputType input_type, double input_value);
381 void ShowContentsDetectedPopup(const char*);
383 // Returns TCP port number with Inspector, or 0 if error.
384 int StartInspectorServer(int port = 0);
385 bool StopInspectorServer();
387 void LoadNotFoundErrorPage(const std::string& invalidUrl);
388 static std::string GetPlatformLocale();
389 bool GetLinkMagnifierEnabled() const;
390 void SetLinkMagnifierEnabled(bool enabled);
392 void SetOverrideEncoding(const std::string& encoding);
393 void SetQuotaPermissionRequestCallback(Ewk_Quota_Permission_Request_Callback callback,
395 void InvokeQuotaPermissionRequest(_Ewk_Quota_Permission_Request* request,
396 const content::QuotaPermissionContext::PermissionCallback& cb);
397 void QuotaRequestReply(const _Ewk_Quota_Permission_Request *request,
399 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request *request);
401 void SetViewMode(blink::WebViewMode view_mode);
403 gfx::Point GetContextMenuPosition() const;
405 content::ContextMenuControllerEfl* GetContextMenuController() {
406 return context_menu_.get();
408 void ResetContextMenuController();
410 /// ---- Event handling
413 bool HandleMove(int x, int y);
414 bool HandleResize(int width, int height);
415 bool HandleTextSelectionDown(int x, int y);
416 bool HandleTextSelectionUp(int x, int y);
418 void HandleRendererProcessCrash();
419 void InvokeWebProcessCrashedCallback();
421 void HandleTapGestureForSelection(bool is_content_editable);
422 void HandleZoomGesture(blink::WebGestureEvent& event);
425 void InitializeContent();
426 void SendDelayedMessages(content::RenderViewHost* render_view_host);
428 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
429 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
430 Ewk_Hit_Test_Mode mode,
431 WebViewAsyncRequestHitTestDataCallback* cb);
433 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
435 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
436 static void cameraResultCb(service_h request, service_h reply,
437 service_result_e result, void* data);
440 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
441 bool LaunchCamera(base::string16 mimetype);
443 content::RenderWidgetHostViewEfl* rwhv() const;
444 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
446 void ReleasePopupMenuList();
448 void ShowContextMenuInternal(const content::ContextMenuParams&);
450 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
452 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
453 scoped_refptr<Ewk_Context> context_;
454 scoped_refptr<Ewk_Context> old_context_;
455 scoped_ptr<content::WebContents> web_contents_;
456 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
457 std::string pending_url_request_;
458 scoped_ptr<Ewk_Settings> settings_;
459 scoped_ptr<_Ewk_Frame> frame_;
460 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
461 Evas_Object* evas_object_;
462 Evas_Object* native_view_;
463 bool touch_events_enabled_;
464 bool mouse_events_enabled_;
465 double text_zoom_factor_;
466 mutable std::string user_agent_;
467 mutable std::string user_agent_app_name_;
468 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
470 Eina_List* popupMenuItems_;
471 Popup_Picker* popupPicker_;
472 bool formIsNavigating_;
479 formNavigation formNavigation_;
480 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
481 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
482 scoped_ptr<content::PopupControllerEfl> popup_controller_;
483 base::string16 previous_text_;
484 int current_find_request_id_;
485 static int find_request_id_counter_;
487 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*> EwkViewPlainTextGetCallback;
488 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
490 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*> MHTMLCallbackDetails;
491 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
493 gfx::Size contents_size_;
495 mutable std::string title_;
496 mutable std::string pem_certificate_;
497 Hit_Test_Params hit_test_params_;
498 base::WaitableEvent hit_test_completion_;
499 double page_scale_factor_;
500 double min_page_scale_factor_;
501 double max_page_scale_factor_;
503 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
504 _Ewk_Geolocation_Permission_Request*> geolocation_permission_cb_;
505 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
506 _Ewk_User_Media_Permission_Request*> user_media_permission_cb_;
507 WebViewCallback<Ewk_View_Unfocus_Allow_Callback,
508 Ewk_Unfocus_Direction> unfocus_allow_cb_;
509 WebViewCallback<Ewk_View_Notification_Permission_Callback,
510 Ewk_Notification_Permission_Request*> notification_permission_callback_;
511 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
512 const _Ewk_Quota_Permission_Request*> quota_request_callback_;
514 scoped_ptr<content::InputPicker> inputPicker_;
515 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
516 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
517 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
518 scoped_ptr<PermissionPopupManager> permission_popup_manager_;
519 scoped_ptr<ScrollDetector> scroll_detector_;
521 #if defined(OS_TIZEN_MOBILE)
522 content::FileChooserParams::Mode filechooser_mode_;
524 std::map<const _Ewk_Quota_Permission_Request*, content::QuotaPermissionContext::PermissionCallback> quota_permission_request_map_;
526 bool is_initialized_;
528 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
530 static content::WebContentsEflDelegate::WebContentsCreateCallback
531 create_new_window_web_contents_cb_;
534 gfx::Vector2d previous_scroll_position_;
536 gfx::Point context_menu_position_;
538 std::vector<IPC::Message*> delayed_messages_;
540 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
543 const unsigned int g_default_tilt_motion_sensitivity = 3;