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 "selection_controller_efl.h"
44 #include "web_contents_delegate_efl.h"
45 #include "context_menu_controller_efl.h"
46 #include "file_chooser_controller_efl.h"
47 #include "ui/gfx/point.h"
48 #include "ui/gfx/size.h"
49 #include "browser/inputpicker/InputPicker.h"
50 #include "tizen_webview/public/tw_hit_test.h"
52 #ifdef TIZEN_CONTENTS_DETECTION
53 #include "popup_controller_efl.h"
57 #include "browser/selectpicker/popup_picker.h"
60 #include "tizen_webview/public/tw_hit_test.h"
61 #include "tizen_webview/public/tw_callbacks.h"
65 class RenderWidgetHostViewEfl;
66 class WebContentsDelegateEfl;
67 class ContextMenuControllerEfl;
68 class DevToolsDelegateEfl;
69 class WebContentsViewEfl;
70 #ifdef TIZEN_CONTENTS_DETECTION
71 class PopupControllerEfl;
76 class GestureRecognizer;
81 namespace tizen_webview {
85 class WebViewDelegate;
86 class WebViewEvasEventHandler;
92 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
94 WebAppScreenshotCapturedCallback(tizen_webview::Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
95 : func_(func), user_data_(user_data), canvas_(canvas) {}
96 void Run(Evas_Object* image) {
98 (func_)(image, user_data_);
102 tizen_webview::Web_App_Screenshot_Captured_Callback func_;
107 class EwkViewPlainTextGetCallback {
109 EwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback,
111 : callback_(callback), user_data_(user_data)
113 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
116 tizen_webview::View_Plain_Text_Get_Callback callback_;
120 class OrientationLockCallback {
122 OrientationLockCallback(tizen_webview::Orientation_Lock_Cb lock,
125 user_data_(user_data)
128 tizen_webview::Orientation_Lock_Cb lock_;
132 class MHTMLCallbackDetails {
134 MHTMLCallbackDetails(tizen_webview::View_MHTML_Data_Get_Callback callback_func, void *user_data)
135 : callback_func_(callback_func),
136 user_data_(user_data)
138 void Run(Evas_Object* obj, const std::string& mhtml_content);
140 tizen_webview::View_MHTML_Data_Get_Callback callback_func_;
144 class WebApplicationIconUrlGetCallback {
146 WebApplicationIconUrlGetCallback(tizen_webview::Web_App_Icon_URL_Get_Callback func, void *user_data)
147 : func_(func), user_data_(user_data)
149 void Run(const std::string &url) {
151 (func_)(url.c_str(), user_data_);
156 tizen_webview::Web_App_Icon_URL_Get_Callback func_;
160 class WebApplicationIconUrlsGetCallback {
162 WebApplicationIconUrlsGetCallback(tizen_webview::Web_App_Icon_URLs_Get_Callback func, void *user_data)
163 : func_(func), user_data_(user_data)
165 void Run(const std::map<std::string, std::string> &urls) {
167 Eina_List *list = NULL;
168 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
169 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
170 list = eina_list_append(list, data);
172 (func_)(list, user_data_);
177 tizen_webview::Web_App_Icon_URLs_Get_Callback func_;
181 class WebApplicationCapableGetCallback {
183 WebApplicationCapableGetCallback(tizen_webview::Web_App_Capable_Get_Callback func, void *user_data)
184 : func_(func), user_data_(user_data)
186 void Run(bool capable) {
188 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
193 tizen_webview::Web_App_Capable_Get_Callback func_;
197 class AsyncHitTestRequest;
198 class NotificationPermissionCallback {
200 NotificationPermissionCallback(
202 tizen_webview::View_Notification_Permission_Callback func,
204 : obj_(obj), func_(func), user_data_(user_data) {}
205 bool Run(Ewk_Notification_Permission_Request* request) {
207 return (func_)(obj_, request, user_data_) == EINA_TRUE;
214 tizen_webview::View_Notification_Permission_Callback func_;
218 class WebViewAsyncRequestHitTestDataCallback;
219 class JavaScriptDialogManagerEfl;
220 class WebViewGeolocationPermissionCallback;
221 class WebViewUnfocusAllowCallback;
225 static EWebView* FromEvasObject(Evas_Object* eo);
226 static int GetOrientation();
228 // initialize data members and activate event handlers.
229 // call this once after created and before use
232 void CreateNewWindow(content::WebContentsDelegate::WebContentsCreateCallback);
233 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
235 tizen_webview::WebView* GetPublicWebView();
236 tizen_webview::WebContext* context() const { return context_.get(); }
237 Evas_Object* evas_object() const { return evas_object_; }
238 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
240 content::WebContents& web_contents() const
242 return *web_contents_.get();
245 template<EWebViewCallbacks::CallbackType callbackType>
246 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
248 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
251 void set_magnifier(bool status);
254 void SetURL(const char* url_string);
255 const char* GetURL() const;
257 void ReloadIgnoringCache();
258 Eina_Bool CanGoBack();
259 Eina_Bool CanGoForward();
260 Eina_Bool HasFocus() const;
261 void SetFocus(Eina_Bool focus);
263 Eina_Bool GoForward();
267 double GetTextZoomFactor() const;
268 void SetTextZoomFactor(double text_zoom_factor);
269 void ExecuteEditCommand(const char* command, const char* value);
270 void SetOrientation(int orientation);
271 void SetOrientationLockCallback(tizen_webview::Orientation_Lock_Cb func, void* data);
272 bool TouchEventsEnabled() const;
273 void SetTouchEventsEnabled(bool enabled);
274 bool MouseEventsEnabled() const;
275 void SetMouseEventsEnabled(bool enabled);
276 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
279 bool ExecuteJavaScript(const char* script, tizen_webview::View_Script_Execute_Callback callback, void* userdata);
280 bool SetUserAgent(const char* userAgent);
281 bool SetUserAgentAppName(const char* application_name);
282 bool SetPrivateBrowsing(bool incognito);
283 bool GetPrivateBrowsing() const;
284 const char* GetUserAgent() const;
285 const char* GetUserAgentAppName() const;
286 const char* GetSelectedText() const;
287 bool IsLastAvailableTextEmpty() const;
288 Ewk_Settings* GetSettings();
289 _Ewk_Frame* GetMainFrame();
290 void UpdateWebKitPreferences();
291 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
292 void LoadPlainTextString(const char* plain_text);
293 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
294 void InvokeLoadError(const ErrorParams &error);
295 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
296 void Find(const char* text, Ewk_Find_Options);
297 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
298 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
299 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
300 int selectedIndex, bool multiple);
301 Eina_Bool HidePopupMenu();
302 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
303 bool prevState, bool nextState);
304 void FormNavigate(bool direction);
305 bool IsSelectPickerShown() const;
306 void CloseSelectPicker();
307 bool FormIsNavigating() const { return formIsNavigating_; }
308 void SetFormIsNavigating(bool formIsNavigating);
309 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
310 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
311 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
312 Eina_Bool PopupMenuClose();
313 void ShowContextMenu(
314 const content::ContextMenuParams& params,
315 content::ContextMenuType type = content::MENU_TYPE_LINK,
316 bool show_selection = true);
317 void CancelContextMenu(int request_id);
318 void SetScale(double scale_factor, int x, int y);
319 bool GetScrollPosition(int* x, int* y) const;
320 void SetScroll(int x, int y);
321 void UrlRequestSet(const char* url,
322 content::NavigationController::LoadURLType loadtype,
326 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
327 #ifdef TIZEN_CONTENTS_DETECTION
328 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
330 void SelectRange(const gfx::Point& start, const gfx::Point& end);
331 void MoveCaret(const gfx::Point& point);
332 void QuerySelectionStyle();
333 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
334 void SelectClosestWord(const gfx::Point& touch_point);
335 void SelectLinkText(const gfx::Point& touch_point);
336 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
337 void GetSnapShotForRect(gfx::Rect& rect);
339 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
340 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
343 * Creates a snapshot of given rectangle from EWebView
345 * @param rect rectangle of EWebView which will be taken into snapshot
347 * @return created snapshot or NULL if error occured.
348 * @note ownership of snapshot is passed to caller
350 Evas_Object* GetSnapshot(Eina_Rectangle rect);
352 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, tizen_webview::Web_App_Screenshot_Captured_Callback callback, void* user_data);
353 void InvokePolicyResponseCallback(tizen_webview::PolicyDecision* policy_decision);
354 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
355 NavigationPolicyParams params, bool* handled);
356 void UseSettingsFont();
358 tizen_webview::Hit_Test* RequestHitTestDataAt(int x, int y,
359 tizen_webview::Hit_Test_Mode mode);
360 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
361 tizen_webview::Hit_Test_Mode mode,
362 tizen_webview::View_Hit_Test_Request_Callback,
364 tizen_webview::Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
365 tizen_webview::Hit_Test_Mode mode);
366 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
367 tizen_webview::Hit_Test_Mode mode,
368 tizen_webview::View_Hit_Test_Request_Callback,
370 void DispatchAsyncHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes, int64_t request_id);
371 void UpdateHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes);
373 int current_find_request_id() const { return current_find_request_id_; }
374 bool PlainTextGet(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
375 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
376 int SetEwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
377 void SetViewGeolocationPermissionCallback(tizen_webview::View_Geolocation_Permission_Callback callback, void* user_data);
378 bool InvokeViewGeolocationPermissionCallback(void* geolocation_permission_request_context, Eina_Bool* result);
379 void SetViewUnfocusAllowCallback(tizen_webview::View_Unfocus_Allow_Callback callback, void* user_data);
380 bool InvokeViewUnfocusAllowCallback(tizen_webview::Unfocus_Direction direction, Eina_Bool* result);
381 void DidChangeContentsSize(int width, int height);
382 const Eina_Rectangle GetContentsSize() const;
383 void GetScrollSize(int* w, int* h);
385 void SetProgressValue(double progress);
386 double GetProgressValue();
387 const char* GetTitle();
388 bool SaveAsPdf(int width, int height, const std::string& file_name);
389 void BackForwardListClear();
390 _Ewk_Back_Forward_List* GetBackForwardList() const;
391 void InvokeBackForwardListChangedCallback();
392 _Ewk_History* GetBackForwardHistory() const;
393 bool WebAppCapableGet(tizen_webview::Web_App_Capable_Get_Callback callback, void *userData);
394 bool WebAppIconUrlGet(tizen_webview::Web_App_Icon_URL_Get_Callback callback, void *userData);
395 bool WebAppIconUrlsGet(tizen_webview::Web_App_Icon_URLs_Get_Callback callback, void *userData);
396 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
397 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
398 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
399 void SetNotificationPermissionCallback(tizen_webview::View_Notification_Permission_Callback callback, void* user_data);
400 bool IsNotificationPermissionCallbackSet() const;
401 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
403 bool GetMHTMLData(tizen_webview::View_MHTML_Data_Get_Callback callback, void* user_data);
404 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
406 void ExitFullscreen();
408 void DidChangePageScaleFactor(double scale_factor);
409 void SetJavaScriptAlertCallback(tizen_webview::View_JavaScript_Alert_Callback callback, void* user_data);
410 void JavaScriptAlertReply();
411 void SetJavaScriptConfirmCallback(tizen_webview::View_JavaScript_Confirm_Callback callback, void* user_data);
412 void JavaScriptConfirmReply(bool result);
413 void SetJavaScriptPromptCallback(tizen_webview::View_JavaScript_Prompt_Callback callback, void* user_data);
414 void JavaScriptPromptReply(const char* result);
415 void set_renderer_crashed();
416 void GetPageScaleRange(double *min_scale, double *max_scale);
417 void DidChangePageScaleRange(double min_scale, double max_scale);
418 void SetDrawsTransparentBackground(bool enabled);
419 void GetSessionData(const char **data, unsigned *length) const;
420 bool RestoreFromSessionData(const char *data, unsigned length);
421 void ShowFileChooser(const content::FileChooserParams&);
422 void DidChangeContentsArea(int width, int height);
423 void SetBrowserFont();
424 void SetCertificatePem(const std::string& certificate);
425 bool IsDragging() const;
427 void RequestColorPicker(int r, int g, int b, int a);
428 void DismissColorPicker();
429 bool SetColorPickerColor(int r, int g, int b, int a);
430 #if defined(OS_TIZEN)
431 void InputPickerShow(
432 ui::TextInputType input_type, std::string input_value);
434 void InputPickerShow(ui::TextInputType input_type, double input_value);
436 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
438 #ifdef TIZEN_CONTENTS_DETECTION
439 void ShowContentsDetectedPopup(const char*);
443 gfx::Rect GetIMERect();
444 void ScrollFocusedEditableNode();
446 // Returns TCP port number with Inspector, or 0 if error.
447 int StartInspectorServer(int port = 0);
448 bool StopInspectorServer();
450 void LoadNotFoundErrorPage(const std::string& invalidUrl);
451 static std::string GetPlatformLocale();
452 bool GetLinkMagnifierEnabled() const;
453 void SetLinkMagnifierEnabled(bool enabled);
455 void SetOverrideEncoding(const std::string& encoding);
456 void SetViewMode(blink::WebViewMode view_mode);
458 gfx::Point GetContextMenuPosition() const;
460 /// ---- Event handling
463 bool HandleMove(int x, int y);
464 bool HandleResize(int width, int height);
465 bool HandleTextSelectionDown(int x, int y);
466 bool HandleTextSelectionUp(int x, int y);
468 void HandleRendererProcessCrash();
469 void HandlePostponedGesture(int x, int y, ui::EventType type);
471 void InitializeContent();
472 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
473 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
474 tizen_webview::Hit_Test_Mode mode,
475 WebViewAsyncRequestHitTestDataCallback* cb);
476 void HandleLongPressGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
477 tizen_webview::Hit_Test*);
478 void HandleTapGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
479 tizen_webview::Hit_Test*);
480 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
482 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
483 static void cameraResultCb(service_h request, service_h reply,
484 service_result_e result, void* data);
487 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
488 bool LaunchCamera(base::string16 mimetype);
490 content::RenderWidgetHostViewEfl* rwhv() const;
491 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
493 #if defined(OS_TIZEN)
494 void ReleasePopupMenuList();
497 tizen_webview::WebView* public_webview_;
498 scoped_refptr<tizen_webview::WebContext> context_;
499 scoped_refptr<tizen_webview::WebContext> old_context_;
500 scoped_ptr<content::WebContents> web_contents_;
501 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
502 std::string pending_url_request_;
503 scoped_ptr<Ewk_Settings> settings_;
504 scoped_ptr<_Ewk_Frame> frame_;
505 scoped_ptr<tizen_webview::PolicyDecision> window_policy_;
506 Evas_Object* evas_object_;
507 Evas_Object* native_view_;
508 bool touch_events_enabled_;
509 bool mouse_events_enabled_;
510 double text_zoom_factor_;
511 mutable std::string selected_text_;
512 mutable std::string user_agent_;
513 mutable std::string user_agent_app_name_;
514 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
516 #if defined(OS_TIZEN)
517 Eina_List* popupMenuItems_;
518 Popup_Picker* popupPicker_;
520 bool formIsNavigating_;
527 formNavigation formNavigation_;
528 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
529 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
530 #ifdef TIZEN_CONTENTS_DETECTION
531 scoped_ptr<content::PopupControllerEfl> popup_controller_;
533 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
534 base::string16 previous_text_;
535 int current_find_request_id_;
536 static int find_request_id_counter_;
537 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
538 gfx::Size contents_size_;
540 mutable std::string title_;
541 mutable std::string pem_certificate_;
542 _Ewk_Hit_Test hit_test_data_;
543 base::WaitableEvent hit_test_completion_;
544 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
545 double page_scale_factor_;
546 double min_page_scale_factor_;
547 double max_page_scale_factor_;
548 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
549 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
550 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
551 scoped_ptr<content::InputPicker> inputPicker_;
552 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
553 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
554 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
555 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
556 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
557 content::DevToolsDelegateEfl* inspector_server_;
559 #if defined(OS_TIZEN_MOBILE)
560 content::FileChooserParams::Mode filechooser_mode_;
562 bool is_initialized_;
564 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
566 static content::WebContentsDelegate::WebContentsCreateCallback
567 create_new_window_web_contents_cb_;
570 Eina_Bool AsyncRequestHitTestPrivate(
571 int x, int y, tizen_webview::Hit_Test_Mode mode,
572 AsyncHitTestRequest* asyncHitTestRequest);
574 gfx::Vector2d previous_scroll_position_;
576 gfx::Point context_menu_position_;
578 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
579 // only tizen_webview::WebView can create and delete this
580 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
582 friend class tizen_webview::WebView;
583 friend class tizen_webview::WebViewEvasEventHandler;
586 namespace tizen_webview {
587 typedef ::EWebView WebViewImpl;
590 const unsigned int g_default_tilt_motion_sensitivity = 3;