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/web_contents_delegate.h"
30 #include "content/public/common/menu_item.h"
31 #include "base/id_map.h"
32 #include "context_menu_controller_efl.h"
33 #include "eweb_context.h"
34 #include "ewk_touch.h"
35 #include "private/ewk_history_private.h"
36 #include "private/ewk_hit_test_private.h"
37 #include "private/ewk_auth_challenge_private.h"
38 #include "private/ewk_back_forward_list_private.h"
39 #include "private/ewk_settings_private.h"
40 #include "private/ewk_web_application_icon_data_private.h"
41 #include "public/ewk_view.h"
42 #include "eweb_view_callbacks.h"
43 #include "scroll_detector.h"
44 #include "selection_controller_efl.h"
45 #include "web_contents_delegate_efl.h"
46 #include "context_menu_controller_efl.h"
47 #include "file_chooser_controller_efl.h"
48 #include "ui/gfx/geometry/point.h"
49 #include "ui/gfx/geometry/size.h"
50 #include "browser/inputpicker/InputPicker.h"
51 #include "tizen_webview/public/tw_hit_test.h"
52 #include "popup_controller_efl.h"
55 #include "browser/selectpicker/popup_picker.h"
58 #include "tizen_webview/public/tw_hit_test.h"
59 #include "tizen_webview/public/tw_callbacks.h"
63 class RenderWidgetHostViewEfl;
64 class WebContentsDelegateEfl;
65 class ContextMenuControllerEfl;
66 class DevToolsDelegateEfl;
67 class WebContentsViewEfl;
68 class PopupControllerEfl;
72 class GestureRecognizer;
77 namespace tizen_webview {
81 class WebViewDelegate;
82 class WebViewEvasEventHandler;
86 class _Ewk_Policy_Decision;
88 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
90 WebAppScreenshotCapturedCallback(tizen_webview::Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
91 : func_(func), user_data_(user_data), canvas_(canvas) {}
92 void Run(Evas_Object* image) {
94 (func_)(image, user_data_);
98 tizen_webview::Web_App_Screenshot_Captured_Callback func_;
103 class EwkViewPlainTextGetCallback {
105 EwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback,
107 : callback_(callback), user_data_(user_data)
109 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
112 tizen_webview::View_Plain_Text_Get_Callback callback_;
116 class OrientationLockCallback {
118 OrientationLockCallback(tizen_webview::Orientation_Lock_Cb lock,
121 user_data_(user_data)
124 tizen_webview::Orientation_Lock_Cb lock_;
128 class MHTMLCallbackDetails {
130 MHTMLCallbackDetails(tizen_webview::View_MHTML_Data_Get_Callback callback_func, void *user_data)
131 : callback_func_(callback_func),
132 user_data_(user_data)
134 void Run(Evas_Object* obj, const std::string& mhtml_content);
136 tizen_webview::View_MHTML_Data_Get_Callback callback_func_;
140 class WebApplicationIconUrlGetCallback {
142 WebApplicationIconUrlGetCallback(tizen_webview::Web_App_Icon_URL_Get_Callback func, void *user_data)
143 : func_(func), user_data_(user_data)
145 void Run(const std::string &url) {
147 (func_)(url.c_str(), user_data_);
152 tizen_webview::Web_App_Icon_URL_Get_Callback func_;
156 class WebApplicationIconUrlsGetCallback {
158 WebApplicationIconUrlsGetCallback(tizen_webview::Web_App_Icon_URLs_Get_Callback func, void *user_data)
159 : func_(func), user_data_(user_data)
161 void Run(const std::map<std::string, std::string> &urls) {
163 Eina_List *list = NULL;
164 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
165 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
166 list = eina_list_append(list, data);
168 (func_)(list, user_data_);
173 tizen_webview::Web_App_Icon_URLs_Get_Callback func_;
177 class WebApplicationCapableGetCallback {
179 WebApplicationCapableGetCallback(tizen_webview::Web_App_Capable_Get_Callback func, void *user_data)
180 : func_(func), user_data_(user_data)
182 void Run(bool capable) {
184 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
189 tizen_webview::Web_App_Capable_Get_Callback func_;
193 class AsyncHitTestRequest;
194 class NotificationPermissionCallback {
196 NotificationPermissionCallback(
198 tizen_webview::View_Notification_Permission_Callback func,
200 : obj_(obj), func_(func), user_data_(user_data) {}
201 bool Run(Ewk_Notification_Permission_Request* request) {
203 return (func_)(obj_, request, user_data_) == EINA_TRUE;
210 tizen_webview::View_Notification_Permission_Callback func_;
214 class WebViewAsyncRequestHitTestDataCallback;
215 class JavaScriptDialogManagerEfl;
216 class WebViewGeolocationPermissionCallback;
217 class WebViewUnfocusAllowCallback;
221 static EWebView* FromEvasObject(Evas_Object* eo);
222 static int GetOrientation();
224 // initialize data members and activate event handlers.
225 // call this once after created and before use
228 void CreateNewWindow(content::WebContentsDelegate::WebContentsCreateCallback);
229 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
231 tizen_webview::WebView* GetPublicWebView();
232 tizen_webview::WebContext* context() const { return context_.get(); }
233 Evas_Object* evas_object() const { return evas_object_; }
234 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
236 content::WebContents& web_contents() const
238 return *web_contents_.get();
241 template<EWebViewCallbacks::CallbackType callbackType>
242 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
244 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
247 void set_magnifier(bool status);
250 void SetURL(const char* url_string);
251 const char* GetURL() const;
253 void ReloadIgnoringCache();
254 Eina_Bool CanGoBack();
255 Eina_Bool CanGoForward();
256 Eina_Bool HasFocus() const;
257 void SetFocus(Eina_Bool focus);
259 Eina_Bool GoForward();
263 double GetTextZoomFactor() const;
264 void SetTextZoomFactor(double text_zoom_factor);
265 void ExecuteEditCommand(const char* command, const char* value);
266 void SetOrientation(int orientation);
267 void SetOrientationLockCallback(tizen_webview::Orientation_Lock_Cb func, void* data);
268 bool TouchEventsEnabled() const;
269 void SetTouchEventsEnabled(bool enabled);
270 bool MouseEventsEnabled() const;
271 void SetMouseEventsEnabled(bool enabled);
272 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
275 bool ExecuteJavaScript(const char* script, tizen_webview::View_Script_Execute_Callback callback, void* userdata);
276 bool SetUserAgent(const char* userAgent);
277 bool SetUserAgentAppName(const char* application_name);
278 bool SetPrivateBrowsing(bool incognito);
279 bool GetPrivateBrowsing() const;
280 const char* GetUserAgent() const;
281 const char* GetUserAgentAppName() const;
282 const char* GetSelectedText() const;
283 bool IsLastAvailableTextEmpty() const;
284 Ewk_Settings* GetSettings();
285 _Ewk_Frame* GetMainFrame();
286 void UpdateWebKitPreferences();
287 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
288 void LoadPlainTextString(const char* plain_text);
289 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
290 void InvokeLoadError(const ErrorParams &error);
291 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
292 void Find(const char* text, Ewk_Find_Options);
293 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
294 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
295 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
296 int selectedIndex, bool multiple);
297 Eina_Bool HidePopupMenu();
298 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
299 bool prevState, bool nextState);
300 void FormNavigate(bool direction);
301 bool IsSelectPickerShown() const;
302 void CloseSelectPicker();
303 bool FormIsNavigating() const { return formIsNavigating_; }
304 void SetFormIsNavigating(bool formIsNavigating);
305 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
306 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
307 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
308 Eina_Bool PopupMenuClose();
309 void ShowContextMenu(
310 const content::ContextMenuParams& params,
311 content::ContextMenuType type = content::MENU_TYPE_LINK,
312 bool show_selection = true);
313 void CancelContextMenu(int request_id);
314 void SetScale(double scale_factor, int x, int y);
315 bool GetScrollPosition(int* x, int* y) const;
316 void SetScroll(int x, int y);
317 void UrlRequestSet(const char* url,
318 content::NavigationController::LoadURLType loadtype,
322 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
323 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
324 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
325 void SelectRange(const gfx::Point& start, const gfx::Point& end);
326 void MoveCaret(const gfx::Point& point);
327 void QuerySelectionStyle();
328 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
329 void SelectClosestWord(const gfx::Point& touch_point);
330 void SelectLinkText(const gfx::Point& touch_point);
331 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
332 void GetSnapShotForRect(gfx::Rect& rect);
334 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
335 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
338 * Creates a snapshot of given rectangle from EWebView
340 * @param rect rectangle of EWebView which will be taken into snapshot
342 * @return created snapshot or NULL if error occured.
343 * @note ownership of snapshot is passed to caller
345 Evas_Object* GetSnapshot(Eina_Rectangle rect);
347 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, tizen_webview::Web_App_Screenshot_Captured_Callback callback, void* user_data);
348 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
349 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
350 NavigationPolicyParams params, bool* handled);
351 void UseSettingsFont();
353 tizen_webview::Hit_Test* RequestHitTestDataAt(int x, int y,
354 tizen_webview::Hit_Test_Mode mode);
355 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
356 tizen_webview::Hit_Test_Mode mode,
357 tizen_webview::View_Hit_Test_Request_Callback,
359 tizen_webview::Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
360 tizen_webview::Hit_Test_Mode mode);
361 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
362 tizen_webview::Hit_Test_Mode mode,
363 tizen_webview::View_Hit_Test_Request_Callback,
365 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
366 void UpdateHitTestData(const Hit_Test_Params& params);
368 int current_find_request_id() const { return current_find_request_id_; }
369 bool PlainTextGet(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
370 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
371 int SetEwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
372 void SetViewGeolocationPermissionCallback(tizen_webview::View_Geolocation_Permission_Callback callback, void* user_data);
373 bool InvokeViewGeolocationPermissionCallback(void* geolocation_permission_request_context, Eina_Bool* result);
374 void SetViewUnfocusAllowCallback(tizen_webview::View_Unfocus_Allow_Callback callback, void* user_data);
375 bool InvokeViewUnfocusAllowCallback(tizen_webview::Unfocus_Direction direction, Eina_Bool* result);
376 void DidChangeContentsSize(int width, int height);
377 const Eina_Rectangle GetContentsSize() const;
378 void GetScrollSize(int* w, int* h);
380 void SetProgressValue(double progress);
381 double GetProgressValue();
382 const char* GetTitle();
383 bool SaveAsPdf(int width, int height, const std::string& file_name);
384 void BackForwardListClear();
385 _Ewk_Back_Forward_List* GetBackForwardList() const;
386 void InvokeBackForwardListChangedCallback();
387 _Ewk_History* GetBackForwardHistory() const;
388 bool WebAppCapableGet(tizen_webview::Web_App_Capable_Get_Callback callback, void *userData);
389 bool WebAppIconUrlGet(tizen_webview::Web_App_Icon_URL_Get_Callback callback, void *userData);
390 bool WebAppIconUrlsGet(tizen_webview::Web_App_Icon_URLs_Get_Callback callback, void *userData);
391 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
392 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
393 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
394 void SetNotificationPermissionCallback(tizen_webview::View_Notification_Permission_Callback callback, void* user_data);
395 bool IsNotificationPermissionCallbackSet() const;
396 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
398 bool GetMHTMLData(tizen_webview::View_MHTML_Data_Get_Callback callback, void* user_data);
399 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
401 void ExitFullscreen();
403 void DidChangePageScaleFactor(double scale_factor);
404 void SetJavaScriptAlertCallback(tizen_webview::View_JavaScript_Alert_Callback callback, void* user_data);
405 void JavaScriptAlertReply();
406 void SetJavaScriptConfirmCallback(tizen_webview::View_JavaScript_Confirm_Callback callback, void* user_data);
407 void JavaScriptConfirmReply(bool result);
408 void SetJavaScriptPromptCallback(tizen_webview::View_JavaScript_Prompt_Callback callback, void* user_data);
409 void JavaScriptPromptReply(const char* result);
410 void set_renderer_crashed();
411 void GetPageScaleRange(double *min_scale, double *max_scale);
412 void DidChangePageScaleRange(double min_scale, double max_scale);
413 void SetDrawsTransparentBackground(bool enabled);
414 void GetSessionData(const char **data, unsigned *length) const;
415 bool RestoreFromSessionData(const char *data, unsigned length);
416 void ShowFileChooser(const content::FileChooserParams&);
417 void DidChangeContentsArea(int width, int height);
418 void SetBrowserFont();
419 void SetCertificatePem(const std::string& certificate);
420 bool IsDragging() const;
422 void RequestColorPicker(int r, int g, int b, int a);
423 void DismissColorPicker();
424 bool SetColorPickerColor(int r, int g, int b, int a);
425 void InputPickerShow(ui::TextInputType input_type, double input_value);
426 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
428 void ShowContentsDetectedPopup(const char*);
431 gfx::Rect GetIMERect();
432 void ScrollFocusedEditableNode();
434 // Returns TCP port number with Inspector, or 0 if error.
435 int StartInspectorServer(int port = 0);
436 bool StopInspectorServer();
438 void LoadNotFoundErrorPage(const std::string& invalidUrl);
439 static std::string GetPlatformLocale();
440 bool GetLinkMagnifierEnabled() const;
441 void SetLinkMagnifierEnabled(bool enabled);
443 void SetOverrideEncoding(const std::string& encoding);
444 void SetViewMode(blink::WebViewMode view_mode);
446 gfx::Point GetContextMenuPosition() const;
448 /// ---- Event handling
451 bool HandleMove(int x, int y);
452 bool HandleResize(int width, int height);
453 bool HandleTextSelectionDown(int x, int y);
454 bool HandleTextSelectionUp(int x, int y);
456 void HandleRendererProcessCrash();
457 void HandlePostponedGesture(int x, int y, ui::EventType type);
459 void InitializeContent();
460 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
461 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
462 tizen_webview::Hit_Test_Mode mode,
463 WebViewAsyncRequestHitTestDataCallback* cb);
464 void HandleLongPressGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
465 tizen_webview::Hit_Test*);
466 void HandleTapGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
467 tizen_webview::Hit_Test*);
468 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
470 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
471 static void cameraResultCb(service_h request, service_h reply,
472 service_result_e result, void* data);
475 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
476 bool LaunchCamera(base::string16 mimetype);
478 content::RenderWidgetHostViewEfl* rwhv() const;
479 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
481 #if defined(OS_TIZEN)
482 void ReleasePopupMenuList();
485 tizen_webview::WebView* public_webview_;
486 scoped_refptr<tizen_webview::WebContext> context_;
487 scoped_refptr<tizen_webview::WebContext> old_context_;
488 scoped_ptr<content::WebContents> web_contents_;
489 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
490 std::string pending_url_request_;
491 scoped_ptr<Ewk_Settings> settings_;
492 scoped_ptr<_Ewk_Frame> frame_;
493 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
494 Evas_Object* evas_object_;
495 Evas_Object* native_view_;
496 bool touch_events_enabled_;
497 bool mouse_events_enabled_;
498 double text_zoom_factor_;
499 mutable std::string selected_text_;
500 mutable std::string user_agent_;
501 mutable std::string user_agent_app_name_;
502 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
504 #if defined(OS_TIZEN)
505 Eina_List* popupMenuItems_;
506 Popup_Picker* popupPicker_;
508 bool formIsNavigating_;
515 formNavigation formNavigation_;
516 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
517 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
518 scoped_ptr<content::PopupControllerEfl> popup_controller_;
519 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
520 base::string16 previous_text_;
521 int current_find_request_id_;
522 static int find_request_id_counter_;
523 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
524 gfx::Size contents_size_;
526 mutable std::string title_;
527 mutable std::string pem_certificate_;
528 Hit_Test_Params hit_test_params_;
529 base::WaitableEvent hit_test_completion_;
530 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
531 double page_scale_factor_;
532 double min_page_scale_factor_;
533 double max_page_scale_factor_;
534 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
535 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
536 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
537 scoped_ptr<content::InputPicker> inputPicker_;
538 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
539 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
540 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
541 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
542 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
543 content::DevToolsDelegateEfl* inspector_server_;
544 scoped_ptr<ScrollDetector> scroll_detector_;
545 #if defined(OS_TIZEN_MOBILE)
546 content::FileChooserParams::Mode filechooser_mode_;
548 bool is_initialized_;
550 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
552 static content::WebContentsDelegate::WebContentsCreateCallback
553 create_new_window_web_contents_cb_;
556 Eina_Bool AsyncRequestHitTestPrivate(
557 int x, int y, tizen_webview::Hit_Test_Mode mode,
558 AsyncHitTestRequest* asyncHitTestRequest);
560 gfx::Vector2d previous_scroll_position_;
562 gfx::Point context_menu_position_;
564 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
565 // only tizen_webview::WebView can create and delete this
566 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
568 friend class tizen_webview::WebView;
569 friend class tizen_webview::WebViewEvasEventHandler;
572 namespace tizen_webview {
573 typedef ::EWebView WebViewImpl;
576 const unsigned int g_default_tilt_motion_sensitivity = 3;