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/point.h"
49 #include "ui/gfx/size.h"
50 #include "browser/inputpicker/InputPicker.h"
51 #include "tizen_webview/public/tw_hit_test.h"
53 #ifdef TIZEN_CONTENTS_DETECTION
54 #include "popup_controller_efl.h"
58 #include "browser/selectpicker/popup_picker.h"
61 #include "tizen_webview/public/tw_hit_test.h"
62 #include "tizen_webview/public/tw_callbacks.h"
66 class RenderWidgetHostViewEfl;
67 class WebContentsDelegateEfl;
68 class ContextMenuControllerEfl;
69 class DevToolsDelegateEfl;
70 class WebContentsViewEfl;
71 #ifdef TIZEN_CONTENTS_DETECTION
72 class PopupControllerEfl;
77 class GestureRecognizer;
82 namespace tizen_webview {
86 class WebViewDelegate;
87 class WebViewEvasEventHandler;
91 class _Ewk_Policy_Decision;
93 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
95 WebAppScreenshotCapturedCallback(tizen_webview::Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
96 : func_(func), user_data_(user_data), canvas_(canvas) {}
97 void Run(Evas_Object* image) {
99 (func_)(image, user_data_);
103 tizen_webview::Web_App_Screenshot_Captured_Callback func_;
108 class EwkViewPlainTextGetCallback {
110 EwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback,
112 : callback_(callback), user_data_(user_data)
114 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
117 tizen_webview::View_Plain_Text_Get_Callback callback_;
121 class OrientationLockCallback {
123 OrientationLockCallback(tizen_webview::Orientation_Lock_Cb lock,
126 user_data_(user_data)
129 tizen_webview::Orientation_Lock_Cb lock_;
133 class MHTMLCallbackDetails {
135 MHTMLCallbackDetails(tizen_webview::View_MHTML_Data_Get_Callback callback_func, void *user_data)
136 : callback_func_(callback_func),
137 user_data_(user_data)
139 void Run(Evas_Object* obj, const std::string& mhtml_content);
141 tizen_webview::View_MHTML_Data_Get_Callback callback_func_;
145 class WebApplicationIconUrlGetCallback {
147 WebApplicationIconUrlGetCallback(tizen_webview::Web_App_Icon_URL_Get_Callback func, void *user_data)
148 : func_(func), user_data_(user_data)
150 void Run(const std::string &url) {
152 (func_)(url.c_str(), user_data_);
157 tizen_webview::Web_App_Icon_URL_Get_Callback func_;
161 class WebApplicationIconUrlsGetCallback {
163 WebApplicationIconUrlsGetCallback(tizen_webview::Web_App_Icon_URLs_Get_Callback func, void *user_data)
164 : func_(func), user_data_(user_data)
166 void Run(const std::map<std::string, std::string> &urls) {
168 Eina_List *list = NULL;
169 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
170 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
171 list = eina_list_append(list, data);
173 (func_)(list, user_data_);
178 tizen_webview::Web_App_Icon_URLs_Get_Callback func_;
182 class WebApplicationCapableGetCallback {
184 WebApplicationCapableGetCallback(tizen_webview::Web_App_Capable_Get_Callback func, void *user_data)
185 : func_(func), user_data_(user_data)
187 void Run(bool capable) {
189 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
194 tizen_webview::Web_App_Capable_Get_Callback func_;
198 class AsyncHitTestRequest;
199 class NotificationPermissionCallback {
201 NotificationPermissionCallback(
203 tizen_webview::View_Notification_Permission_Callback func,
205 : obj_(obj), func_(func), user_data_(user_data) {}
206 bool Run(Ewk_Notification_Permission_Request* request) {
208 return (func_)(obj_, request, user_data_) == EINA_TRUE;
215 tizen_webview::View_Notification_Permission_Callback func_;
219 class WebViewAsyncRequestHitTestDataCallback;
220 class JavaScriptDialogManagerEfl;
221 class WebViewGeolocationPermissionCallback;
222 class WebViewUnfocusAllowCallback;
226 static EWebView* FromEvasObject(Evas_Object* eo);
227 static int GetOrientation();
229 // initialize data members and activate event handlers.
230 // call this once after created and before use
233 void CreateNewWindow(content::WebContentsDelegate::WebContentsCreateCallback);
234 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
236 tizen_webview::WebView* GetPublicWebView();
237 tizen_webview::WebContext* context() const { return context_.get(); }
238 Evas_Object* evas_object() const { return evas_object_; }
239 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
241 content::WebContents& web_contents() const
243 return *web_contents_.get();
246 template<EWebViewCallbacks::CallbackType callbackType>
247 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
249 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
252 void set_magnifier(bool status);
255 void SetURL(const char* url_string);
256 const char* GetURL() const;
258 void ReloadIgnoringCache();
259 Eina_Bool CanGoBack();
260 Eina_Bool CanGoForward();
261 Eina_Bool HasFocus() const;
262 void SetFocus(Eina_Bool focus);
264 Eina_Bool GoForward();
268 double GetTextZoomFactor() const;
269 void SetTextZoomFactor(double text_zoom_factor);
270 void ExecuteEditCommand(const char* command, const char* value);
271 void SetOrientation(int orientation);
272 void SetOrientationLockCallback(tizen_webview::Orientation_Lock_Cb func, void* data);
273 bool TouchEventsEnabled() const;
274 void SetTouchEventsEnabled(bool enabled);
275 bool MouseEventsEnabled() const;
276 void SetMouseEventsEnabled(bool enabled);
277 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
280 bool ExecuteJavaScript(const char* script, tizen_webview::View_Script_Execute_Callback callback, void* userdata);
281 bool SetUserAgent(const char* userAgent);
282 bool SetUserAgentAppName(const char* application_name);
283 bool SetPrivateBrowsing(bool incognito);
284 bool GetPrivateBrowsing() const;
285 const char* GetUserAgent() const;
286 const char* GetUserAgentAppName() const;
287 const char* GetSelectedText() const;
288 bool IsLastAvailableTextEmpty() const;
289 Ewk_Settings* GetSettings();
290 _Ewk_Frame* GetMainFrame();
291 void UpdateWebKitPreferences();
292 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
293 void LoadPlainTextString(const char* plain_text);
294 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
295 void InvokeLoadError(const ErrorParams &error);
296 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
297 void Find(const char* text, Ewk_Find_Options);
298 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
299 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
300 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
301 int selectedIndex, bool multiple);
302 Eina_Bool HidePopupMenu();
303 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
304 bool prevState, bool nextState);
305 void FormNavigate(bool direction);
306 bool IsSelectPickerShown() const;
307 void CloseSelectPicker();
308 bool FormIsNavigating() const { return formIsNavigating_; }
309 void SetFormIsNavigating(bool formIsNavigating);
310 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
311 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
312 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
313 Eina_Bool PopupMenuClose();
314 void ShowContextMenu(
315 const content::ContextMenuParams& params,
316 content::ContextMenuType type = content::MENU_TYPE_LINK,
317 bool show_selection = true);
318 void CancelContextMenu(int request_id);
319 void SetScale(double scale_factor, int x, int y);
320 bool GetScrollPosition(int* x, int* y) const;
321 void SetScroll(int x, int y);
322 void UrlRequestSet(const char* url,
323 content::NavigationController::LoadURLType loadtype,
327 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
328 #ifdef TIZEN_CONTENTS_DETECTION
329 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
331 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
332 void SelectRange(const gfx::Point& start, const gfx::Point& end);
333 void MoveCaret(const gfx::Point& point);
334 void QuerySelectionStyle();
335 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
336 void SelectClosestWord(const gfx::Point& touch_point);
337 void SelectLinkText(const gfx::Point& touch_point);
338 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
339 void GetSnapShotForRect(gfx::Rect& rect);
341 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
342 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
345 * Creates a snapshot of given rectangle from EWebView
347 * @param rect rectangle of EWebView which will be taken into snapshot
349 * @return created snapshot or NULL if error occured.
350 * @note ownership of snapshot is passed to caller
352 Evas_Object* GetSnapshot(Eina_Rectangle rect);
354 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, tizen_webview::Web_App_Screenshot_Captured_Callback callback, void* user_data);
355 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
356 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
357 NavigationPolicyParams params, bool* handled);
358 void UseSettingsFont();
360 tizen_webview::Hit_Test* RequestHitTestDataAt(int x, int y,
361 tizen_webview::Hit_Test_Mode mode);
362 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
363 tizen_webview::Hit_Test_Mode mode,
364 tizen_webview::View_Hit_Test_Request_Callback,
366 tizen_webview::Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
367 tizen_webview::Hit_Test_Mode mode);
368 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
369 tizen_webview::Hit_Test_Mode mode,
370 tizen_webview::View_Hit_Test_Request_Callback,
372 void DispatchAsyncHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes, int64_t request_id);
373 void UpdateHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes);
375 int current_find_request_id() const { return current_find_request_id_; }
376 bool PlainTextGet(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
377 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
378 int SetEwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
379 void SetViewGeolocationPermissionCallback(tizen_webview::View_Geolocation_Permission_Callback callback, void* user_data);
380 bool InvokeViewGeolocationPermissionCallback(void* geolocation_permission_request_context, Eina_Bool* result);
381 void SetViewUnfocusAllowCallback(tizen_webview::View_Unfocus_Allow_Callback callback, void* user_data);
382 bool InvokeViewUnfocusAllowCallback(tizen_webview::Unfocus_Direction direction, Eina_Bool* result);
383 void DidChangeContentsSize(int width, int height);
384 const Eina_Rectangle GetContentsSize() const;
385 void GetScrollSize(int* w, int* h);
387 void SetProgressValue(double progress);
388 double GetProgressValue();
389 const char* GetTitle();
390 bool SaveAsPdf(int width, int height, const std::string& file_name);
391 void BackForwardListClear();
392 _Ewk_Back_Forward_List* GetBackForwardList() const;
393 void InvokeBackForwardListChangedCallback();
394 _Ewk_History* GetBackForwardHistory() const;
395 bool WebAppCapableGet(tizen_webview::Web_App_Capable_Get_Callback callback, void *userData);
396 bool WebAppIconUrlGet(tizen_webview::Web_App_Icon_URL_Get_Callback callback, void *userData);
397 bool WebAppIconUrlsGet(tizen_webview::Web_App_Icon_URLs_Get_Callback callback, void *userData);
398 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
399 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
400 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
401 void SetNotificationPermissionCallback(tizen_webview::View_Notification_Permission_Callback callback, void* user_data);
402 bool IsNotificationPermissionCallbackSet() const;
403 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
405 bool GetMHTMLData(tizen_webview::View_MHTML_Data_Get_Callback callback, void* user_data);
406 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
408 void ExitFullscreen();
410 void DidChangePageScaleFactor(double scale_factor);
411 void SetJavaScriptAlertCallback(tizen_webview::View_JavaScript_Alert_Callback callback, void* user_data);
412 void JavaScriptAlertReply();
413 void SetJavaScriptConfirmCallback(tizen_webview::View_JavaScript_Confirm_Callback callback, void* user_data);
414 void JavaScriptConfirmReply(bool result);
415 void SetJavaScriptPromptCallback(tizen_webview::View_JavaScript_Prompt_Callback callback, void* user_data);
416 void JavaScriptPromptReply(const char* result);
417 void set_renderer_crashed();
418 void GetPageScaleRange(double *min_scale, double *max_scale);
419 void DidChangePageScaleRange(double min_scale, double max_scale);
420 void SetDrawsTransparentBackground(bool enabled);
421 void GetSessionData(const char **data, unsigned *length) const;
422 bool RestoreFromSessionData(const char *data, unsigned length);
423 void ShowFileChooser(const content::FileChooserParams&);
424 void DidChangeContentsArea(int width, int height);
425 void SetBrowserFont();
426 void SetCertificatePem(const std::string& certificate);
427 bool IsDragging() const;
429 void RequestColorPicker(int r, int g, int b, int a);
430 void DismissColorPicker();
431 bool SetColorPickerColor(int r, int g, int b, int a);
432 #if defined(OS_TIZEN)
433 void InputPickerShow(
434 ui::TextInputType input_type, std::string input_value);
436 void InputPickerShow(ui::TextInputType input_type, double input_value);
438 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
440 #ifdef TIZEN_CONTENTS_DETECTION
441 void ShowContentsDetectedPopup(const char*);
445 gfx::Rect GetIMERect();
446 void ScrollFocusedEditableNode();
448 // Returns TCP port number with Inspector, or 0 if error.
449 int StartInspectorServer(int port = 0);
450 bool StopInspectorServer();
452 void LoadNotFoundErrorPage(const std::string& invalidUrl);
453 static std::string GetPlatformLocale();
454 bool GetLinkMagnifierEnabled() const;
455 void SetLinkMagnifierEnabled(bool enabled);
457 void SetOverrideEncoding(const std::string& encoding);
458 void SetViewMode(blink::WebViewMode view_mode);
460 gfx::Point GetContextMenuPosition() const;
462 /// ---- Event handling
465 bool HandleMove(int x, int y);
466 bool HandleResize(int width, int height);
467 bool HandleTextSelectionDown(int x, int y);
468 bool HandleTextSelectionUp(int x, int y);
470 void HandleRendererProcessCrash();
471 void HandlePostponedGesture(int x, int y, ui::EventType type);
473 void InitializeContent();
474 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
475 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
476 tizen_webview::Hit_Test_Mode mode,
477 WebViewAsyncRequestHitTestDataCallback* cb);
478 void HandleLongPressGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
479 tizen_webview::Hit_Test*);
480 void HandleTapGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
481 tizen_webview::Hit_Test*);
482 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
484 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
485 static void cameraResultCb(service_h request, service_h reply,
486 service_result_e result, void* data);
489 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
490 bool LaunchCamera(base::string16 mimetype);
492 content::RenderWidgetHostViewEfl* rwhv() const;
493 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
495 #if defined(OS_TIZEN)
496 void ReleasePopupMenuList();
499 tizen_webview::WebView* public_webview_;
500 scoped_refptr<tizen_webview::WebContext> context_;
501 scoped_refptr<tizen_webview::WebContext> old_context_;
502 scoped_ptr<content::WebContents> web_contents_;
503 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
504 std::string pending_url_request_;
505 scoped_ptr<Ewk_Settings> settings_;
506 scoped_ptr<_Ewk_Frame> frame_;
507 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
508 Evas_Object* evas_object_;
509 Evas_Object* native_view_;
510 bool touch_events_enabled_;
511 bool mouse_events_enabled_;
512 double text_zoom_factor_;
513 mutable std::string selected_text_;
514 mutable std::string user_agent_;
515 mutable std::string user_agent_app_name_;
516 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
518 #if defined(OS_TIZEN)
519 Eina_List* popupMenuItems_;
520 Popup_Picker* popupPicker_;
522 bool formIsNavigating_;
529 formNavigation formNavigation_;
530 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
531 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
532 #ifdef TIZEN_CONTENTS_DETECTION
533 scoped_ptr<content::PopupControllerEfl> popup_controller_;
535 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
536 base::string16 previous_text_;
537 int current_find_request_id_;
538 static int find_request_id_counter_;
539 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
540 gfx::Size contents_size_;
542 mutable std::string title_;
543 mutable std::string pem_certificate_;
544 _Ewk_Hit_Test hit_test_data_;
545 base::WaitableEvent hit_test_completion_;
546 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
547 double page_scale_factor_;
548 double min_page_scale_factor_;
549 double max_page_scale_factor_;
550 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
551 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
552 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
553 scoped_ptr<content::InputPicker> inputPicker_;
554 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
555 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
556 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
557 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
558 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
559 content::DevToolsDelegateEfl* inspector_server_;
560 scoped_ptr<ScrollDetector> scroll_detector_;
561 #if defined(OS_TIZEN_MOBILE)
562 content::FileChooserParams::Mode filechooser_mode_;
564 bool is_initialized_;
566 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
568 static content::WebContentsDelegate::WebContentsCreateCallback
569 create_new_window_web_contents_cb_;
572 Eina_Bool AsyncRequestHitTestPrivate(
573 int x, int y, tizen_webview::Hit_Test_Mode mode,
574 AsyncHitTestRequest* asyncHitTestRequest);
576 gfx::Vector2d previous_scroll_position_;
578 gfx::Point context_menu_position_;
580 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
581 // only tizen_webview::WebView can create and delete this
582 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
584 friend class tizen_webview::WebView;
585 friend class tizen_webview::WebViewEvasEventHandler;
588 namespace tizen_webview {
589 typedef ::EWebView WebViewImpl;
592 const unsigned int g_default_tilt_motion_sensitivity = 3;