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);
241 void InvokeLoadError(const ErrorParams &error);
242 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
243 void Find(const char* text, Ewk_Find_Options);
244 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
245 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
246 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
247 int selectedIndex, bool multiple);
248 Eina_Bool HidePopupMenu();
249 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
250 bool prevState, bool nextState);
251 void FormNavigate(bool direction);
252 bool IsSelectPickerShown() const;
253 void CloseSelectPicker();
254 bool FormIsNavigating() const { return formIsNavigating_; }
255 void SetFormIsNavigating(bool formIsNavigating);
256 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
257 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
258 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
259 Eina_Bool PopupMenuClose();
260 void HandleLongPressGesture(const content::ContextMenuParams&);
261 void ShowContextMenu(const content::ContextMenuParams&);
262 void CancelContextMenu(int request_id);
263 void SetScale(double scale_factor, int x, int y);
264 bool GetScrollPosition(int* x, int* y) const;
265 void SetScroll(int x, int y);
266 void UrlRequestSet(const char* url,
267 content::NavigationController::LoadURLType loadtype,
271 content::SelectionControllerEfl* GetSelectionController() const;
272 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
273 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
274 void MoveCaret(const gfx::Point& point);
275 void QuerySelectionStyle();
276 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
277 void SelectLinkText(const gfx::Point& touch_point);
278 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
279 Eina_Bool ClearSelection();
281 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
282 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
284 void RenderViewCreated(content::RenderViewHost* render_view_host);
287 * Creates a snapshot of given rectangle from EWebView
289 * @param rect rectangle of EWebView which will be taken into snapshot
291 * @return created snapshot or NULL if error occured.
292 * @note ownership of snapshot is passed to caller
294 Evas_Object* GetSnapshot(Eina_Rectangle rect);
296 bool GetSnapshotAsync(Eina_Rectangle rect, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
297 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
298 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
299 NavigationPolicyParams params, bool* handled);
300 void UseSettingsFont();
302 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
303 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
304 Ewk_Hit_Test_Mode mode,
305 Ewk_View_Hit_Test_Request_Callback,
307 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
308 Ewk_Hit_Test_Mode mode);
309 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
310 Ewk_Hit_Test_Mode mode,
311 Ewk_View_Hit_Test_Request_Callback,
313 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
314 void UpdateHitTestData(const Hit_Test_Params& params);
316 int current_find_request_id() const { return current_find_request_id_; }
317 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
318 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
319 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
320 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
321 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
322 void SetViewUserMediaPermissionCallback(
323 Ewk_View_User_Media_Permission_Callback callback,
325 bool InvokeViewUserMediaPermissionCallback(
326 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
328 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
329 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
330 void DidChangeContentsSize(int width, int height);
331 const Eina_Rectangle GetContentsSize() const;
332 void GetScrollSize(int* w, int* h);
334 void SetProgressValue(double progress);
335 double GetProgressValue();
336 const char* GetTitle();
337 bool SaveAsPdf(int width, int height, const std::string& file_name);
338 void BackForwardListClear();
339 _Ewk_Back_Forward_List* GetBackForwardList() const;
340 void InvokeBackForwardListChangedCallback();
341 _Ewk_History* GetBackForwardHistory() const;
342 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
343 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
344 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
345 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
346 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
347 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
348 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
349 bool IsNotificationPermissionCallbackSet() const;
350 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
352 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
353 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
355 void ExitFullscreen();
357 void DidChangePageScaleFactor(double scale_factor);
358 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
359 void JavaScriptAlertReply();
360 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
361 void JavaScriptConfirmReply(bool result);
362 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
363 void JavaScriptPromptReply(const char* result);
364 void set_renderer_crashed();
365 void GetPageScaleRange(double *min_scale, double *max_scale);
366 void SetDrawsTransparentBackground(bool enabled);
367 void GetSessionData(const char **data, unsigned *length) const;
368 bool RestoreFromSessionData(const char *data, unsigned length);
369 void ShowFileChooser(const content::FileChooserParams&);
370 void SetBrowserFont();
371 void SetCertificatePem(const std::string& certificate);
372 bool IsDragging() const;
374 void RequestColorPicker(int r, int g, int b, int a);
375 void DismissColorPicker();
376 bool SetColorPickerColor(int r, int g, int b, int a);
377 void InputPickerShow(ui::TextInputType input_type, double input_value);
379 void ShowContentsDetectedPopup(const char*);
381 // Returns TCP port number with Inspector, or 0 if error.
382 int StartInspectorServer(int port = 0);
383 bool StopInspectorServer();
385 void LoadNotFoundErrorPage(const std::string& invalidUrl);
386 static std::string GetPlatformLocale();
387 bool GetLinkMagnifierEnabled() const;
388 void SetLinkMagnifierEnabled(bool enabled);
390 void SetOverrideEncoding(const std::string& encoding);
391 void SetQuotaPermissionRequestCallback(Ewk_Quota_Permission_Request_Callback callback,
393 void InvokeQuotaPermissionRequest(_Ewk_Quota_Permission_Request* request,
394 const content::QuotaPermissionContext::PermissionCallback& cb);
395 void QuotaRequestReply(const _Ewk_Quota_Permission_Request *request,
397 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request *request);
399 void SetViewMode(blink::WebViewMode view_mode);
401 gfx::Point GetContextMenuPosition() const;
403 content::ContextMenuControllerEfl* GetContextMenuController() {
404 return context_menu_.get();
406 void ResetContextMenuController();
408 /// ---- Event handling
411 bool HandleMove(int x, int y);
412 bool HandleResize(int width, int height);
413 bool HandleTextSelectionDown(int x, int y);
414 bool HandleTextSelectionUp(int x, int y);
416 void HandleRendererProcessCrash();
417 void InvokeWebProcessCrashedCallback();
419 void HandleTapGestureForSelection(bool is_content_editable);
420 void HandleZoomGesture(blink::WebGestureEvent& event);
423 void InitializeContent();
424 void SendDelayedMessages(content::RenderViewHost* render_view_host);
426 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
427 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
428 Ewk_Hit_Test_Mode mode,
429 WebViewAsyncRequestHitTestDataCallback* cb);
431 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
433 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
434 static void cameraResultCb(service_h request, service_h reply,
435 service_result_e result, void* data);
438 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
439 bool LaunchCamera(base::string16 mimetype);
441 content::RenderWidgetHostViewEfl* rwhv() const;
442 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
444 void ReleasePopupMenuList();
446 void ShowContextMenuInternal(const content::ContextMenuParams&);
448 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
450 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
451 scoped_refptr<Ewk_Context> context_;
452 scoped_refptr<Ewk_Context> old_context_;
453 scoped_ptr<content::WebContents> web_contents_;
454 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
455 std::string pending_url_request_;
456 scoped_ptr<Ewk_Settings> settings_;
457 scoped_ptr<_Ewk_Frame> frame_;
458 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
459 Evas_Object* evas_object_;
460 Evas_Object* native_view_;
461 bool touch_events_enabled_;
462 bool mouse_events_enabled_;
463 double text_zoom_factor_;
464 mutable std::string user_agent_;
465 mutable std::string user_agent_app_name_;
466 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
468 Eina_List* popupMenuItems_;
469 Popup_Picker* popupPicker_;
470 bool formIsNavigating_;
477 formNavigation formNavigation_;
478 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
479 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
480 scoped_ptr<content::PopupControllerEfl> popup_controller_;
481 base::string16 previous_text_;
482 int current_find_request_id_;
483 static int find_request_id_counter_;
485 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*> EwkViewPlainTextGetCallback;
486 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
488 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*> MHTMLCallbackDetails;
489 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
491 gfx::Size contents_size_;
493 mutable std::string title_;
494 mutable std::string pem_certificate_;
495 Hit_Test_Params hit_test_params_;
496 base::WaitableEvent hit_test_completion_;
497 double page_scale_factor_;
498 double min_page_scale_factor_;
499 double max_page_scale_factor_;
501 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
502 _Ewk_Geolocation_Permission_Request*> geolocation_permission_cb_;
503 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
504 _Ewk_User_Media_Permission_Request*> user_media_permission_cb_;
505 WebViewCallback<Ewk_View_Unfocus_Allow_Callback,
506 Ewk_Unfocus_Direction> unfocus_allow_cb_;
507 WebViewCallback<Ewk_View_Notification_Permission_Callback,
508 Ewk_Notification_Permission_Request*> notification_permission_callback_;
509 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
510 const _Ewk_Quota_Permission_Request*> quota_request_callback_;
512 scoped_ptr<content::InputPicker> inputPicker_;
513 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
514 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
515 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
516 scoped_ptr<PermissionPopupManager> permission_popup_manager_;
517 scoped_ptr<ScrollDetector> scroll_detector_;
519 #if defined(OS_TIZEN_MOBILE)
520 content::FileChooserParams::Mode filechooser_mode_;
522 std::map<const _Ewk_Quota_Permission_Request*, content::QuotaPermissionContext::PermissionCallback> quota_permission_request_map_;
524 bool is_initialized_;
526 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
528 static content::WebContentsEflDelegate::WebContentsCreateCallback
529 create_new_window_web_contents_cb_;
532 gfx::Vector2d previous_scroll_position_;
534 gfx::Point context_menu_position_;
536 std::vector<IPC::Message*> delayed_messages_;
538 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
541 const unsigned int g_default_tilt_motion_sensitivity = 3;