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_hit_test_private.h"
36 #include "private/ewk_auth_challenge_private.h"
37 #include "private/ewk_settings_private.h"
38 #include "private/ewk_web_application_icon_data_private.h"
39 #include "eweb_view_callbacks.h"
40 #include "selection_controller_efl.h"
41 #include "web_contents_delegate_efl.h"
42 #include "context_menu_controller_efl.h"
43 #include "file_chooser_controller_efl.h"
44 #include "ui/gfx/point.h"
45 #include "ui/gfx/size.h"
46 #include "browser/inputpicker/InputPicker.h"
47 #include "third_party/WebKit/Source/platform/text/TextDirection.h"
48 #include "tizen_webview/public/tw_hit_test.h"
50 #ifdef TIZEN_CONTENTS_DETECTION
51 #include "popup_controller_efl.h"
54 #ifdef TIZEN_EDGE_EFFECT
55 #include "EdgeEffect.h"
59 #include "browser/selectpicker/popup_picker.h"
62 #include "tizen_webview/public/tw_back_forward_history.h"
63 #include "tizen_webview/public/tw_back_forward_list_impl.h"
64 #include "tizen_webview/public/tw_hit_test.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_find_options.h"
71 class RenderWidgetHostViewEfl;
72 class WebContentsDelegateEfl;
73 class ContextMenuControllerEfl;
74 class DevToolsDelegateEfl;
75 class WebContentsViewEfl;
76 #ifdef TIZEN_CONTENTS_DETECTION
77 class PopupControllerEfl;
82 class GestureRecognizer;
87 namespace tizen_webview {
91 class WebViewDelegate;
92 class WebViewEvasEventHandler;
97 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
99 WebAppScreenshotCapturedCallback(tizen_webview::Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
100 : func_(func), user_data_(user_data), canvas_(canvas) {}
101 void Run(Evas_Object* image) {
103 (func_)(image, user_data_);
107 tizen_webview::Web_App_Screenshot_Captured_Callback func_;
112 class EwkViewPlainTextGetCallback {
114 EwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback,
116 : callback_(callback), user_data_(user_data)
118 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
121 tizen_webview::View_Plain_Text_Get_Callback callback_;
125 class OrientationLockCallback {
127 OrientationLockCallback(tizen_webview::Orientation_Lock_Cb lock,
130 user_data_(user_data)
133 tizen_webview::Orientation_Lock_Cb lock_;
137 class MHTMLCallbackDetails {
139 MHTMLCallbackDetails(tizen_webview::View_MHTML_Data_Get_Callback callback_func, void *user_data)
140 : callback_func_(callback_func),
141 user_data_(user_data)
143 void Run(Evas_Object* obj, const std::string& mhtml_content);
145 tizen_webview::View_MHTML_Data_Get_Callback callback_func_;
149 class WebApplicationIconUrlGetCallback {
151 WebApplicationIconUrlGetCallback(tizen_webview::Web_App_Icon_URL_Get_Callback func, void *user_data)
152 : func_(func), user_data_(user_data)
154 void Run(const std::string &url) {
156 (func_)(url.c_str(), user_data_);
161 tizen_webview::Web_App_Icon_URL_Get_Callback func_;
165 class WebApplicationIconUrlsGetCallback {
167 WebApplicationIconUrlsGetCallback(tizen_webview::Web_App_Icon_URLs_Get_Callback func, void *user_data)
168 : func_(func), user_data_(user_data)
170 void Run(const std::map<std::string, std::string> &urls) {
172 Eina_List *list = NULL;
173 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
174 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
175 list = eina_list_append(list, data);
177 (func_)(list, user_data_);
182 tizen_webview::Web_App_Icon_URLs_Get_Callback func_;
186 class WebApplicationCapableGetCallback {
188 WebApplicationCapableGetCallback(tizen_webview::Web_App_Capable_Get_Callback func, void *user_data)
189 : func_(func), user_data_(user_data)
191 void Run(bool capable) {
193 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
198 tizen_webview::Web_App_Capable_Get_Callback func_;
202 class AsyncHitTestRequest;
203 class NotificationPermissionCallback {
205 NotificationPermissionCallback(
207 tizen_webview::View_Notification_Permission_Callback func,
209 : obj_(obj), func_(func), user_data_(user_data) {}
210 bool Run(Ewk_Notification_Permission_Request* request) {
212 return (func_)(obj_, request, user_data_) == EINA_TRUE;
219 tizen_webview::View_Notification_Permission_Callback func_;
223 class WebViewAsyncRequestHitTestDataCallback;
224 class JavaScriptDialogManagerEfl;
225 class WebViewGeolocationPermissionCallback;
226 class WebViewUnfocusAllowCallback;
230 static EWebView* FromEvasObject(Evas_Object* eo);
231 static int GetOrientation();
233 // initialize data members and activate event handlers.
234 // call this once after created and before use
237 void CreateNewWindow(content::WebContentsDelegate::WebContentsCreateCallback);
238 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
240 tizen_webview::WebView* GetPublicWebView();
241 tizen_webview::WebContext* context() const { return context_.get(); }
242 Evas_Object* evas_object() const { return evas_object_; }
243 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
245 content::WebContents& web_contents() const
247 return *web_contents_.get();
250 template<EWebViewCallbacks::CallbackType callbackType>
251 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
253 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
256 void set_magnifier(bool status);
259 void SetURL(const char* url_string);
260 const char* GetURL() const;
262 void ReloadIgnoringCache();
263 Eina_Bool CanGoBack();
264 Eina_Bool CanGoForward();
265 Eina_Bool HasFocus() const;
266 void SetFocus(Eina_Bool focus);
268 Eina_Bool GoForward();
272 double GetTextZoomFactor() const;
273 void SetTextZoomFactor(double text_zoom_factor);
274 void ExecuteEditCommand(const char* command, const char* value);
275 void SetOrientation(int orientation);
276 void SetOrientationLockCallback(tizen_webview::Orientation_Lock_Cb func, void* data);
277 bool TouchEventsEnabled() const;
278 void SetTouchEventsEnabled(bool enabled);
279 bool MouseEventsEnabled() const;
280 void SetMouseEventsEnabled(bool enabled);
281 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
284 bool ExecuteJavaScript(const char* script, tizen_webview::View_Script_Execute_Callback callback, void* userdata);
285 bool SetUserAgent(const char* userAgent);
286 bool SetUserAgentAppName(const char* application_name);
287 bool SetPrivateBrowsing(bool incognito);
288 bool GetPrivateBrowsing() const;
289 const char* GetUserAgent() const;
290 const char* GetUserAgentAppName() const;
291 const char* GetSelectedText() const;
292 bool IsLastAvailableTextEmpty() const;
293 Ewk_Settings* GetSettings();
294 _Ewk_Frame* GetMainFrame();
295 void UpdateWebKitPreferences();
296 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
297 void LoadPlainTextString(const char* plain_text);
298 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
299 void InvokeLoadError(const tizen_webview::Error &error);
300 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
301 void Find(const char* text, tizen_webview::Find_Options);
302 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
303 void SetContentSecurityPolicy(const char* policy, tizen_webview::ContentSecurityPolicyType type);
304 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
305 int selectedIndex, bool multiple);
306 Eina_Bool HidePopupMenu();
307 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
308 bool prevState, bool nextState);
309 void FormNavigate(bool direction);
310 bool IsSelectPickerShown() const;
311 void CloseSelectPicker();
312 bool FormIsNavigating() const { return formIsNavigating_; }
313 void SetFormIsNavigating(bool formIsNavigating);
314 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
315 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
316 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
317 Eina_Bool PopupMenuClose();
318 void ShowContextMenu(
319 const content::ContextMenuParams& params,
320 content::ContextMenuType type = content::MENU_TYPE_LINK,
321 bool show_selection = true);
322 void CancelContextMenu(int request_id);
323 void SetScale(double scale_factor, int x, int y);
324 bool GetScrollPosition(int* x, int* y) const;
325 void SetScroll(int x, int y);
326 void UrlRequestSet(const char* url,
327 content::NavigationController::LoadURLType loadtype,
331 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
332 #ifdef TIZEN_CONTENTS_DETECTION
333 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
335 void SelectRange(const gfx::Point& start, const gfx::Point& end);
336 void MoveCaret(const gfx::Point& point);
337 void QuerySelectionStyle();
338 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
339 void SelectClosestWord(const gfx::Point& touch_point);
340 void SelectLinkText(const gfx::Point& touch_point);
341 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
342 void GetSnapShotForRect(gfx::Rect& rect);
344 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
345 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
348 * Creates a snapshot of given rectangle from EWebView
350 * @param rect rectangle of EWebView which will be taken into snapshot
352 * @return created snapshot or NULL if error occured.
353 * @note ownership of snapshot is passed to caller
355 Evas_Object* GetSnapshot(Eina_Rectangle rect);
357 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, tizen_webview::Web_App_Screenshot_Captured_Callback callback, void* user_data);
358 void InvokePolicyResponseCallback(tizen_webview::PolicyDecision* policy_decision);
359 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
360 NavigationPolicyParams params, bool* handled);
361 void UseSettingsFont();
363 tizen_webview::Hit_Test* RequestHitTestDataAt(int x, int y,
364 tizen_webview::Hit_Test_Mode mode);
365 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
366 tizen_webview::Hit_Test_Mode mode,
367 tizen_webview::View_Hit_Test_Request_Callback,
369 tizen_webview::Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
370 tizen_webview::Hit_Test_Mode mode);
371 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
372 tizen_webview::Hit_Test_Mode mode,
373 tizen_webview::View_Hit_Test_Request_Callback,
375 void DispatchAsyncHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes, int64_t request_id);
376 void UpdateHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes);
378 int current_find_request_id() const { return current_find_request_id_; }
379 bool PlainTextGet(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
380 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
381 int SetEwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
382 void SetViewGeolocationPermissionCallback(tizen_webview::View_Geolocation_Permission_Callback callback, void* user_data);
383 bool InvokeViewGeolocationPermissionCallback(void* geolocation_permission_request_context, Eina_Bool* result);
384 void SetViewUnfocusAllowCallback(tizen_webview::View_Unfocus_Allow_Callback callback, void* user_data);
385 bool InvokeViewUnfocusAllowCallback(tizen_webview::Unfocus_Direction direction, Eina_Bool* result);
386 void DidChangeContentsSize(int width, int height);
387 const Eina_Rectangle GetContentsSize() const;
388 void GetScrollSize(int* w, int* h);
390 void SetProgressValue(double progress);
391 double GetProgressValue();
392 const char* GetTitle();
393 bool SaveAsPdf(int width, int height, const std::string& file_name);
394 void BackForwardListClear();
395 tizen_webview::BackForwardList* GetBackForwardList() const;
396 void InvokeBackForwardListChangedCallback();
397 tizen_webview::BackForwardHistory* GetBackForwardHistory() const;
398 bool WebAppCapableGet(tizen_webview::Web_App_Capable_Get_Callback callback, void *userData);
399 bool WebAppIconUrlGet(tizen_webview::Web_App_Icon_URL_Get_Callback callback, void *userData);
400 bool WebAppIconUrlsGet(tizen_webview::Web_App_Icon_URLs_Get_Callback callback, void *userData);
401 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
402 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
403 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
404 void SetNotificationPermissionCallback(tizen_webview::View_Notification_Permission_Callback callback, void* user_data);
405 bool IsNotificationPermissionCallbackSet() const;
406 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
408 bool GetMHTMLData(tizen_webview::View_MHTML_Data_Get_Callback callback, void* user_data);
409 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
411 void ExitFullscreen();
413 void DidChangePageScaleFactor(double scale_factor);
414 void SetJavaScriptAlertCallback(tizen_webview::View_JavaScript_Alert_Callback callback, void* user_data);
415 void JavaScriptAlertReply();
416 void SetJavaScriptConfirmCallback(tizen_webview::View_JavaScript_Confirm_Callback callback, void* user_data);
417 void JavaScriptConfirmReply(bool result);
418 void SetJavaScriptPromptCallback(tizen_webview::View_JavaScript_Prompt_Callback callback, void* user_data);
419 void JavaScriptPromptReply(const char* result);
420 void set_renderer_crashed();
421 void GetPageScaleRange(double *min_scale, double *max_scale);
422 void DidChangePageScaleRange(double min_scale, double max_scale);
423 void SetDrawsTransparentBackground(bool enabled);
424 void GetSessionData(const char **data, unsigned *length) const;
425 bool RestoreFromSessionData(const char *data, unsigned length);
426 void ShowFileChooser(const content::FileChooserParams&);
427 void DidChangeContentsArea(int width, int height);
428 void SetBrowserFont();
429 void SetCertificatePem(const std::string& certificate);
430 bool IsDragging() const;
432 void RequestColorPicker(int r, int g, int b, int a);
433 void DismissColorPicker();
434 bool SetColorPickerColor(int r, int g, int b, int a);
435 #if defined(OS_TIZEN)
436 void InputPickerShow(
437 ui::TextInputType input_type, std::string input_value);
439 void InputPickerShow(ui::TextInputType input_type, double input_value);
441 void FindAndRunSnapshotCallback(Evas_Object* image, int snapshotId);
443 #ifdef TIZEN_EDGE_EFFECT
444 scoped_refptr<EdgeEffect> edgeEffect() { return edge_effect_; }
446 #ifdef TIZEN_CONTENTS_DETECTION
447 void ShowContentsDetectedPopup(const char*);
451 gfx::Rect GetIMERect();
452 void ScrollFocusedEditableNode();
454 // Returns TCP port number with Inspector, or 0 if error.
455 int StartInspectorServer(int port = 0);
456 bool StopInspectorServer();
458 void LoadNotFoundErrorPage(const std::string& invalidUrl);
459 static std::string GetPlatformLocale();
460 bool GetLinkMagnifierEnabled() const;
461 void SetLinkMagnifierEnabled(bool enabled);
463 void SetOverrideEncoding(const std::string& encoding);
464 void SetViewMode(blink::WebViewMode view_mode);
466 gfx::Point GetContextMenuPosition() const;
468 /// ---- Event handling
471 bool HandleMove(int x, int y);
472 bool HandleResize(int width, int height);
473 bool HandleTextSelectionDown(int x, int y);
474 bool HandleTextSelectionUp(int x, int y);
476 void HandleRendererProcessCrash();
477 void HandlePostponedGesture(int x, int y, ui::EventType type);
479 void InitializeContent();
480 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
481 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
482 tizen_webview::Hit_Test_Mode mode,
483 WebViewAsyncRequestHitTestDataCallback* cb);
484 void HandleLongPressGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
485 tizen_webview::Hit_Test*);
486 void HandleTapGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
487 tizen_webview::Hit_Test*);
488 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
490 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
491 static void cameraResultCb(service_h request, service_h reply,
492 service_result_e result, void* data);
495 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
496 bool LaunchCamera(base::string16 mimetype);
498 content::RenderWidgetHostViewEfl* rwhv() const;
499 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
501 #if defined(OS_TIZEN)
502 void ReleasePopupMenuList();
505 tizen_webview::WebView* public_webview_;
506 scoped_refptr<tizen_webview::WebContext> context_;
507 scoped_refptr<tizen_webview::WebContext> old_context_;
508 scoped_ptr<content::WebContents> web_contents_;
509 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
510 std::string pending_url_request_;
511 scoped_ptr<Ewk_Settings> settings_;
512 scoped_ptr<_Ewk_Frame> frame_;
513 scoped_ptr<tizen_webview::PolicyDecision> window_policy_;
514 Evas_Object* evas_object_;
515 Evas_Object* native_view_;
516 bool touch_events_enabled_;
517 bool mouse_events_enabled_;
518 double text_zoom_factor_;
519 mutable std::string selected_text_;
520 mutable std::string user_agent_;
521 mutable std::string user_agent_app_name_;
522 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
524 #if defined(OS_TIZEN)
525 Eina_List* popupMenuItems_;
526 Popup_Picker* popupPicker_;
528 bool formIsNavigating_;
535 formNavigation formNavigation_;
536 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
537 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
538 #ifdef TIZEN_CONTENTS_DETECTION
539 scoped_ptr<content::PopupControllerEfl> popup_controller_;
541 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
542 base::string16 previous_text_;
543 int current_find_request_id_;
544 static int find_request_id_counter_;
545 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
546 gfx::Size contents_size_;
548 mutable std::string title_;
549 mutable std::string pem_certificate_;
550 _Ewk_Hit_Test hit_test_data_;
551 base::WaitableEvent hit_test_completion_;
552 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
553 double page_scale_factor_;
554 double min_page_scale_factor_;
555 double max_page_scale_factor_;
556 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
557 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
558 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
559 scoped_ptr<content::InputPicker> inputPicker_;
560 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
561 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
562 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
563 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
564 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
565 content::DevToolsDelegateEfl* inspector_server_;
566 #ifdef TIZEN_EDGE_EFFECT
567 scoped_refptr<EdgeEffect> edge_effect_;
570 #if defined(OS_TIZEN_MOBILE)
571 content::FileChooserParams::Mode filechooser_mode_;
573 bool is_initialized_;
575 scoped_ptr<tizen_webview::BackForwardList> back_forward_list_;
577 static content::WebContentsDelegate::WebContentsCreateCallback
578 create_new_window_web_contents_cb_;
581 Eina_Bool AsyncRequestHitTestPrivate(
582 int x, int y, tizen_webview::Hit_Test_Mode mode,
583 AsyncHitTestRequest* asyncHitTestRequest);
585 gfx::Vector2d previous_scroll_position_;
587 gfx::Point context_menu_position_;
589 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
590 // only tizen_webview::WebView can create and delete this
591 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
593 friend class tizen_webview::WebView;
594 friend class tizen_webview::WebViewEvasEventHandler;
597 namespace tizen_webview {
598 typedef ::EWebView WebViewImpl;
601 const unsigned int g_default_tilt_motion_sensitivity = 3;