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 "private/ewk_hit_test_private.h"
35 #include "private/ewk_auth_challenge_private.h"
36 #include "private/ewk_settings_private.h"
37 #include "private/ewk_web_application_icon_data_private.h"
38 #include "eweb_view_callbacks.h"
39 #include "selection_controller_efl.h"
40 #include "web_contents_delegate_efl.h"
41 #include "context_menu_controller_efl.h"
42 #include "file_chooser_controller_efl.h"
43 #include "ui/gfx/point.h"
44 #include "ui/gfx/size.h"
45 #include "browser/inputpicker/InputPicker.h"
46 #include "third_party/WebKit/Source/platform/text/TextDirection.h"
47 #include "tizen_webview/public/tw_hit_test.h"
49 #ifdef TIZEN_CONTENTS_DETECTION
50 #include "popup_controller_efl.h"
53 #ifdef TIZEN_EDGE_EFFECT
54 #include "EdgeEffect.h"
58 #include "browser/selectpicker/popup_picker.h"
61 #include "tizen_webview/public/tw_back_forward_history.h"
62 #include "tizen_webview/public/tw_back_forward_list_impl.h"
63 #include "tizen_webview/public/tw_hit_test.h"
64 #include "tizen_webview/public/tw_touch_event.h"
65 #include "tizen_webview/public/tw_callbacks.h"
66 #include "tizen_webview/public/tw_content_security_policy.h"
67 #include "tizen_webview/public/tw_frame.h"
68 #include "tizen_webview/public/tw_find_options.h"
69 #include "tizen_webview/public/tw_touch_event.h"
73 class RenderWidgetHostViewEfl;
74 class WebContentsDelegateEfl;
75 class ContextMenuControllerEfl;
76 class DevToolsDelegateEfl;
77 class WebContentsViewEfl;
78 #ifdef TIZEN_CONTENTS_DETECTION
79 class PopupControllerEfl;
84 class GestureRecognizer;
89 namespace tizen_webview {
93 class WebViewDelegate;
94 class WebViewEvasEventHandler;
99 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
101 WebAppScreenshotCapturedCallback(tizen_webview::Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
102 : func_(func), user_data_(user_data), canvas_(canvas) {}
103 void Run(Evas_Object* image) {
105 (func_)(image, user_data_);
109 tizen_webview::Web_App_Screenshot_Captured_Callback func_;
114 class EwkViewPlainTextGetCallback {
116 EwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback,
118 : callback_(callback), user_data_(user_data)
120 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
123 tizen_webview::View_Plain_Text_Get_Callback callback_;
127 class OrientationLockCallback {
129 OrientationLockCallback(tizen_webview::Orientation_Lock_Cb lock,
132 user_data_(user_data)
135 tizen_webview::Orientation_Lock_Cb lock_;
139 class MHTMLCallbackDetails {
141 MHTMLCallbackDetails(tizen_webview::View_MHTML_Data_Get_Callback callback_func, void *user_data)
142 : callback_func_(callback_func),
143 user_data_(user_data)
145 void Run(Evas_Object* obj, const std::string& mhtml_content);
147 tizen_webview::View_MHTML_Data_Get_Callback callback_func_;
151 class WebApplicationIconUrlGetCallback {
153 WebApplicationIconUrlGetCallback(tizen_webview::Web_App_Icon_URL_Get_Callback func, void *user_data)
154 : func_(func), user_data_(user_data)
156 void Run(const std::string &url) {
158 (func_)(url.c_str(), user_data_);
163 tizen_webview::Web_App_Icon_URL_Get_Callback func_;
167 class WebApplicationIconUrlsGetCallback {
169 WebApplicationIconUrlsGetCallback(tizen_webview::Web_App_Icon_URLs_Get_Callback func, void *user_data)
170 : func_(func), user_data_(user_data)
172 void Run(const std::map<std::string, std::string> &urls) {
174 Eina_List *list = NULL;
175 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
176 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
177 list = eina_list_append(list, data);
179 (func_)(list, user_data_);
184 tizen_webview::Web_App_Icon_URLs_Get_Callback func_;
188 class WebApplicationCapableGetCallback {
190 WebApplicationCapableGetCallback(tizen_webview::Web_App_Capable_Get_Callback func, void *user_data)
191 : func_(func), user_data_(user_data)
193 void Run(bool capable) {
195 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
200 tizen_webview::Web_App_Capable_Get_Callback func_;
204 class AsyncHitTestRequest;
205 class NotificationPermissionCallback {
207 NotificationPermissionCallback(
209 tizen_webview::View_Notification_Permission_Callback func,
211 : obj_(obj), func_(func), user_data_(user_data) {}
212 bool Run(Ewk_Notification_Permission_Request* request) {
214 return (func_)(obj_, request, user_data_) == EINA_TRUE;
221 tizen_webview::View_Notification_Permission_Callback func_;
225 class WebViewAsyncRequestHitTestDataCallback;
226 class JavaScriptDialogManagerEfl;
227 class WebViewGeolocationPermissionCallback;
228 class WebViewUnfocusAllowCallback;
232 static EWebView* FromEvasObject(Evas_Object* eo);
233 static int GetOrientation();
235 // initialize data members and activate event handlers.
236 // call this once after created and before use
239 void CreateNewWindow(content::WebContentsDelegate::WebContentsCreateCallback);
240 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
242 tizen_webview::WebView* GetPublicWebView();
243 tizen_webview::WebContext* context() const { return context_.get(); }
244 Evas_Object* evas_object() const { return evas_object_; }
245 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
246 Evas_Object* GetContentImageObject() const;
248 content::WebContents& web_contents() const
250 return *web_contents_.get();
253 template<EWebViewCallbacks::CallbackType callbackType>
254 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
256 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
259 void set_magnifier(bool status);
262 void SetURL(const char* url_string);
263 const char* GetURL() const;
265 void ReloadIgnoringCache();
266 Eina_Bool CanGoBack();
267 Eina_Bool CanGoForward();
268 Eina_Bool HasFocus() const;
269 void SetFocus(Eina_Bool focus);
271 Eina_Bool GoForward();
275 double GetTextZoomFactor() const;
276 void SetTextZoomFactor(double text_zoom_factor);
277 void ExecuteEditCommand(const char* command, const char* value);
278 void SetOrientation(int orientation);
279 void SetOrientationLockCallback(tizen_webview::Orientation_Lock_Cb func, void* data);
280 bool TouchEventsEnabled() const;
281 void SetTouchEventsEnabled(bool enabled);
282 bool MouseEventsEnabled() const;
283 void SetMouseEventsEnabled(bool enabled);
286 bool ExecuteJavaScript(const char* script, tizen_webview::View_Script_Execute_Callback callback, void* userdata);
287 bool SetUserAgent(const char* userAgent);
288 bool SetUserAgentAppName(const char* application_name);
289 bool SetPrivateBrowsing(bool incognito);
290 bool GetPrivateBrowsing() const;
291 const char* GetUserAgent() const;
292 const char* GetUserAgentAppName() const;
293 const char* GetSelectedText() const;
294 bool IsLastAvailableTextEmpty() const;
295 Ewk_Settings* GetSettings();
296 tizen_webview::Frame* GetMainFrame();
297 void UpdateWebKitPreferences();
298 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
299 void LoadPlainTextString(const char* plain_text);
300 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
301 void InvokeLoadError(const tizen_webview::Error &error);
302 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
303 void Find(const char* text, tizen_webview::Find_Options);
304 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
305 void SetContentSecurityPolicy(const char* policy, tizen_webview::ContentSecurityPolicyType type);
306 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
307 int selectedIndex, bool multiple);
308 Eina_Bool HidePopupMenu();
309 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
310 bool prevState, bool nextState);
311 void FormNavigate(bool direction);
312 bool IsSelectPickerShown() const;
313 void CloseSelectPicker();
314 bool FormIsNavigating() const { return formIsNavigating_; }
315 void SetFormIsNavigating(bool formIsNavigating);
316 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
317 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
318 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
319 Eina_Bool PopupMenuClose();
320 void ShowContextMenu(
321 const content::ContextMenuParams& params,
322 content::ContextMenuType type = content::MENU_TYPE_LINK,
323 bool show_selection = true);
324 void CancelContextMenu(int request_id);
325 void SetScale(double scale_factor, int x, int y);
326 bool GetScrollPosition(int* x, int* y) const;
327 void SetScroll(int x, int y);
328 void UrlRequestSet(const char* url,
329 content::NavigationController::LoadURLType loadtype,
333 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
334 #ifdef TIZEN_CONTENTS_DETECTION
335 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
337 void SelectRange(const gfx::Point& start, const gfx::Point& end);
338 void MoveCaret(const gfx::Point& point);
339 void QuerySelectionStyle();
340 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
341 void SelectClosestWord(const gfx::Point& touch_point);
342 void SelectLinkText(const gfx::Point& touch_point);
343 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
344 void GetSnapShotForRect(gfx::Rect& rect);
346 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
347 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
350 * Creates a snapshot of given rectangle from EWebView
352 * @param rect rectangle of EWebView which will be taken into snapshot
354 * @return created snapshot or NULL if error occured.
355 * @note ownership of snapshot is passed to caller
357 Evas_Object* GetSnapshot(Eina_Rectangle rect);
359 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, tizen_webview::Web_App_Screenshot_Captured_Callback callback, void* user_data);
360 void InvokePolicyResponseCallback(tizen_webview::PolicyDecision* policy_decision);
361 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
362 NavigationPolicyParams params, bool* handled);
363 void UseSettingsFont();
365 tizen_webview::Hit_Test* RequestHitTestDataAt(int x, int y,
366 tizen_webview::Hit_Test_Mode mode);
367 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
368 tizen_webview::Hit_Test_Mode mode,
369 tizen_webview::View_Hit_Test_Request_Callback,
371 tizen_webview::Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
372 tizen_webview::Hit_Test_Mode mode);
373 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
374 tizen_webview::Hit_Test_Mode mode,
375 tizen_webview::View_Hit_Test_Request_Callback,
377 void DispatchAsyncHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes, int64_t request_id);
378 void UpdateHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes);
380 int current_find_request_id() const { return current_find_request_id_; }
381 bool PlainTextGet(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
382 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
383 int SetEwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
384 void SetViewGeolocationPermissionCallback(tizen_webview::View_Geolocation_Permission_Callback callback, void* user_data);
385 bool InvokeViewGeolocationPermissionCallback(void* geolocation_permission_request_context, Eina_Bool* result);
386 void SetViewUnfocusAllowCallback(tizen_webview::View_Unfocus_Allow_Callback callback, void* user_data);
387 bool InvokeViewUnfocusAllowCallback(tizen_webview::Unfocus_Direction direction, Eina_Bool* result);
388 void DidChangeContentsSize(int width, int height);
389 const Eina_Rectangle GetContentsSize() const;
390 void GetScrollSize(int* w, int* h);
392 void SetProgressValue(double progress);
393 double GetProgressValue();
394 const char* GetTitle();
395 bool SaveAsPdf(int width, int height, const std::string& file_name);
396 void BackForwardListClear();
397 tizen_webview::BackForwardList* GetBackForwardList() const;
398 void InvokeBackForwardListChangedCallback();
399 tizen_webview::BackForwardHistory* GetBackForwardHistory() const;
400 bool WebAppCapableGet(tizen_webview::Web_App_Capable_Get_Callback callback, void *userData);
401 bool WebAppIconUrlGet(tizen_webview::Web_App_Icon_URL_Get_Callback callback, void *userData);
402 bool WebAppIconUrlsGet(tizen_webview::Web_App_Icon_URLs_Get_Callback callback, void *userData);
403 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
404 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
405 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
406 void SetNotificationPermissionCallback(tizen_webview::View_Notification_Permission_Callback callback, void* user_data);
407 bool IsNotificationPermissionCallbackSet() const;
408 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
410 bool GetMHTMLData(tizen_webview::View_MHTML_Data_Get_Callback callback, void* user_data);
411 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
413 void ExitFullscreen();
415 void DidChangePageScaleFactor(double scale_factor);
416 void SetJavaScriptAlertCallback(tizen_webview::View_JavaScript_Alert_Callback callback, void* user_data);
417 void JavaScriptAlertReply();
418 void SetJavaScriptConfirmCallback(tizen_webview::View_JavaScript_Confirm_Callback callback, void* user_data);
419 void JavaScriptConfirmReply(bool result);
420 void SetJavaScriptPromptCallback(tizen_webview::View_JavaScript_Prompt_Callback callback, void* user_data);
421 void JavaScriptPromptReply(const char* result);
422 void set_renderer_crashed();
423 void GetPageScaleRange(double *min_scale, double *max_scale);
424 void DidChangePageScaleRange(double min_scale, double max_scale);
425 void SetDrawsTransparentBackground(bool enabled);
426 void GetSessionData(const char **data, unsigned *length) const;
427 bool RestoreFromSessionData(const char *data, unsigned length);
428 void ShowFileChooser(const content::FileChooserParams&);
429 void DidChangeContentsArea(int width, int height);
430 void SetBrowserFont();
431 void SetCertificatePem(const std::string& certificate);
432 bool IsDragging() const;
434 void RequestColorPicker(int r, int g, int b, int a);
435 void DismissColorPicker();
436 bool SetColorPickerColor(int r, int g, int b, int a);
437 void InputPickerShow(
438 ui::TextInputType input_type, double input_value);
439 void FindAndRunSnapshotCallback(Evas_Object* image, int snapshotId);
441 #ifdef TIZEN_EDGE_EFFECT
442 scoped_refptr<EdgeEffect> edgeEffect() { return edge_effect_; }
444 #ifdef TIZEN_CONTENTS_DETECTION
445 void ShowContentsDetectedPopup(const char*);
449 gfx::Rect GetIMERect();
450 void ScrollFocusedEditableNode();
452 // Returns TCP port number with Inspector, or 0 if error.
453 int StartInspectorServer(int port = 0);
454 bool StopInspectorServer();
456 void LoadNotFoundErrorPage(const std::string& invalidUrl);
457 static std::string GetPlatformLocale();
458 bool GetLinkMagnifierEnabled() const;
459 void SetLinkMagnifierEnabled(bool enabled);
461 void SetOverrideEncoding(const std::string& encoding);
462 void SetViewMode(blink::WebViewMode view_mode);
464 gfx::Point GetContextMenuPosition() const;
466 /// ---- Event handling
469 bool HandleMove(int x, int y);
470 bool HandleResize(int width, int height);
471 bool HandleTextSelectionDown(int x, int y);
472 bool HandleTextSelectionUp(int x, int y);
474 void HandleRendererProcessCrash();
475 void HandlePostponedGesture(int x, int y, ui::EventType type);
477 void InitializeContent();
478 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
479 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
480 tizen_webview::Hit_Test_Mode mode,
481 WebViewAsyncRequestHitTestDataCallback* cb);
482 void HandleLongPressGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
483 tizen_webview::Hit_Test*);
484 void HandleTapGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
485 tizen_webview::Hit_Test*);
486 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
488 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
489 static void cameraResultCb(service_h request, service_h reply,
490 service_result_e result, void* data);
493 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
494 bool LaunchCamera(base::string16 mimetype);
496 content::RenderWidgetHostViewEfl* rwhv() const;
497 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
499 #if defined(OS_TIZEN)
500 void ReleasePopupMenuList();
503 tizen_webview::WebView* public_webview_;
504 scoped_refptr<tizen_webview::WebContext> context_;
505 scoped_refptr<tizen_webview::WebContext> old_context_;
506 scoped_ptr<content::WebContents> web_contents_;
507 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
508 std::string pending_url_request_;
509 scoped_ptr<Ewk_Settings> settings_;
510 scoped_ptr<tizen_webview::Frame> frame_;
511 scoped_ptr<tizen_webview::PolicyDecision> window_policy_;
512 Evas_Object* evas_object_;
513 Evas_Object* native_view_;
514 bool touch_events_enabled_;
515 bool mouse_events_enabled_;
516 double text_zoom_factor_;
517 mutable std::string selected_text_;
518 mutable std::string user_agent_;
519 mutable std::string user_agent_app_name_;
520 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
522 #if defined(OS_TIZEN)
523 Eina_List* popupMenuItems_;
524 Popup_Picker* popupPicker_;
526 bool formIsNavigating_;
533 formNavigation formNavigation_;
534 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
535 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
536 #ifdef TIZEN_CONTENTS_DETECTION
537 scoped_ptr<content::PopupControllerEfl> popup_controller_;
539 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
540 base::string16 previous_text_;
541 int current_find_request_id_;
542 static int find_request_id_counter_;
543 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
544 gfx::Size contents_size_;
546 mutable std::string title_;
547 mutable std::string pem_certificate_;
548 _Ewk_Hit_Test hit_test_data_;
549 base::WaitableEvent hit_test_completion_;
550 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
551 double page_scale_factor_;
552 double min_page_scale_factor_;
553 double max_page_scale_factor_;
554 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
555 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
556 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
557 scoped_ptr<content::InputPicker> inputPicker_;
558 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
559 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
560 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
561 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
562 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
563 content::DevToolsDelegateEfl* inspector_server_;
564 #ifdef TIZEN_EDGE_EFFECT
565 scoped_refptr<EdgeEffect> edge_effect_;
568 #if defined(OS_TIZEN_MOBILE)
569 content::FileChooserParams::Mode filechooser_mode_;
571 bool is_initialized_;
573 scoped_ptr<tizen_webview::BackForwardList> back_forward_list_;
575 static content::WebContentsDelegate::WebContentsCreateCallback
576 create_new_window_web_contents_cb_;
579 Eina_Bool AsyncRequestHitTestPrivate(
580 int x, int y, tizen_webview::Hit_Test_Mode mode,
581 AsyncHitTestRequest* asyncHitTestRequest);
583 gfx::Vector2d previous_scroll_position_;
585 gfx::Point context_menu_position_;
587 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
588 // only tizen_webview::WebView can create and delete this
589 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
591 friend class tizen_webview::WebView;
592 friend class tizen_webview::WebViewEvasEventHandler;
595 namespace tizen_webview {
596 typedef ::EWebView WebViewImpl;
599 const unsigned int g_default_tilt_motion_sensitivity = 3;