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_hit_test.h"
42 #include "public/ewk_view.h"
43 #include "eweb_view_callbacks.h"
44 #include "scroll_detector.h"
45 #include "selection_controller_efl.h"
46 #include "web_contents_delegate_efl.h"
47 #include "context_menu_controller_efl.h"
48 #include "file_chooser_controller_efl.h"
49 #include "ui/gfx/geometry/point.h"
50 #include "ui/gfx/geometry/size.h"
51 #include "browser/inputpicker/InputPicker.h"
52 #include "popup_controller_efl.h"
55 #include "browser/selectpicker/popup_picker.h"
60 class RenderWidgetHostViewEfl;
61 class WebContentsDelegateEfl;
62 class ContextMenuControllerEfl;
63 class DevToolsDelegateEfl;
64 class WebContentsViewEfl;
65 class PopupControllerEfl;
69 class GestureRecognizer;
74 namespace tizen_webview {
77 class WebViewDelegate;
78 class WebViewEvasEventHandler;
82 class _Ewk_Policy_Decision;
85 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
87 WebAppScreenshotCapturedCallback(Ewk_Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
88 : func_(func), user_data_(user_data), canvas_(canvas) {}
89 void Run(Evas_Object* image) {
91 (func_)(image, user_data_);
95 Ewk_Web_App_Screenshot_Captured_Callback func_;
100 class EwkViewPlainTextGetCallback {
102 EwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
104 : callback_(callback), user_data_(user_data)
106 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
109 Ewk_View_Plain_Text_Get_Callback callback_;
113 class OrientationLockCallback {
115 OrientationLockCallback(Ewk_Orientation_Lock_Cb lock,
118 user_data_(user_data)
121 Ewk_Orientation_Lock_Cb lock_;
125 class MHTMLCallbackDetails {
127 MHTMLCallbackDetails(Ewk_View_MHTML_Data_Get_Callback callback_func, void *user_data)
128 : callback_func_(callback_func),
129 user_data_(user_data)
131 void Run(Evas_Object* obj, const std::string& mhtml_content);
133 Ewk_View_MHTML_Data_Get_Callback callback_func_;
137 class WebApplicationIconUrlGetCallback {
139 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func, void *user_data)
140 : func_(func), user_data_(user_data)
142 void Run(const std::string &url) {
144 (func_)(url.c_str(), user_data_);
149 Ewk_Web_App_Icon_URL_Get_Callback func_;
153 class WebApplicationIconUrlsGetCallback {
155 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func, void *user_data)
156 : func_(func), user_data_(user_data)
158 void Run(const std::map<std::string, std::string> &urls) {
160 Eina_List *list = NULL;
161 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
162 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
163 list = eina_list_append(list, data);
165 (func_)(list, user_data_);
170 Ewk_Web_App_Icon_URLs_Get_Callback func_;
174 class WebApplicationCapableGetCallback {
176 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func, void *user_data)
177 : func_(func), user_data_(user_data)
179 void Run(bool capable) {
181 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
186 Ewk_Web_App_Capable_Get_Callback func_;
190 class AsyncHitTestRequest;
191 class NotificationPermissionCallback {
193 NotificationPermissionCallback(
195 Ewk_View_Notification_Permission_Callback func,
197 : obj_(obj), func_(func), user_data_(user_data) {}
198 bool Run(Ewk_Notification_Permission_Request* request) {
200 return (func_)(obj_, request, user_data_) == EINA_TRUE;
207 Ewk_View_Notification_Permission_Callback func_;
211 class WebViewAsyncRequestHitTestDataCallback;
212 class JavaScriptDialogManagerEfl;
213 class WebViewGeolocationPermissionCallback;
214 class WebViewUnfocusAllowCallback;
218 static EWebView* FromEvasObject(Evas_Object* eo);
219 static int GetOrientation();
221 // initialize data members and activate event handlers.
222 // call this once after created and before use
225 void CreateNewWindow(content::WebContentsDelegate::WebContentsCreateCallback);
226 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
228 tizen_webview::WebView* GetPublicWebView();
229 tizen_webview::WebContext* context() const { return context_.get(); }
230 Evas_Object* evas_object() const { return evas_object_; }
231 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
233 content::WebContents& web_contents() const
235 return *web_contents_.get();
238 template<EWebViewCallbacks::CallbackType callbackType>
239 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
241 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
244 void set_magnifier(bool status);
247 void SetURL(const char* url_string);
248 const char* GetURL() const;
250 void ReloadIgnoringCache();
251 Eina_Bool CanGoBack();
252 Eina_Bool CanGoForward();
253 Eina_Bool HasFocus() const;
254 void SetFocus(Eina_Bool focus);
256 Eina_Bool GoForward();
260 double GetTextZoomFactor() const;
261 void SetTextZoomFactor(double text_zoom_factor);
262 void ExecuteEditCommand(const char* command, const char* value);
263 void SetOrientation(int orientation);
264 void SetOrientationLockCallback(Ewk_Orientation_Lock_Cb func, void* data);
265 bool TouchEventsEnabled() const;
266 void SetTouchEventsEnabled(bool enabled);
267 bool MouseEventsEnabled() const;
268 void SetMouseEventsEnabled(bool enabled);
269 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
272 bool ExecuteJavaScript(const char* script, Ewk_View_Script_Execute_Callback callback, void* userdata);
273 bool SetUserAgent(const char* userAgent);
274 bool SetUserAgentAppName(const char* application_name);
275 bool SetPrivateBrowsing(bool incognito);
276 bool GetPrivateBrowsing() const;
277 const char* GetUserAgent() const;
278 const char* GetUserAgentAppName() const;
279 const char* GetSelectedText() const;
280 Ewk_Settings* GetSettings();
281 _Ewk_Frame* GetMainFrame();
282 void UpdateWebKitPreferences();
283 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
284 void LoadPlainTextString(const char* plain_text);
285 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
286 void InvokeLoadError(const ErrorParams &error);
287 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
288 void Find(const char* text, Ewk_Find_Options);
289 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
290 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
291 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
292 int selectedIndex, bool multiple);
293 Eina_Bool HidePopupMenu();
294 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
295 bool prevState, bool nextState);
296 void FormNavigate(bool direction);
297 bool IsSelectPickerShown() const;
298 void CloseSelectPicker();
299 bool FormIsNavigating() const { return formIsNavigating_; }
300 void SetFormIsNavigating(bool formIsNavigating);
301 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
302 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
303 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
304 Eina_Bool PopupMenuClose();
305 void ShowContextMenu(
306 const content::ContextMenuParams& params,
307 content::ContextMenuType type = content::MENU_TYPE_LINK,
308 bool show_selection = true);
309 void CancelContextMenu(int request_id);
310 void SetScale(double scale_factor, int x, int y);
311 bool GetScrollPosition(int* x, int* y) const;
312 void SetScroll(int x, int y);
313 void UrlRequestSet(const char* url,
314 content::NavigationController::LoadURLType loadtype,
318 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
319 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
320 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
321 void SelectRange(const gfx::Point& start, const gfx::Point& end);
322 void MoveCaret(const gfx::Point& point);
323 void QuerySelectionStyle();
324 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
325 void SelectClosestWord(const gfx::Point& touch_point);
326 void SelectLinkText(const gfx::Point& touch_point);
327 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
328 void GetSnapShotForRect(gfx::Rect& rect);
330 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
331 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
334 * Creates a snapshot of given rectangle from EWebView
336 * @param rect rectangle of EWebView which will be taken into snapshot
338 * @return created snapshot or NULL if error occured.
339 * @note ownership of snapshot is passed to caller
341 Evas_Object* GetSnapshot(Eina_Rectangle rect);
343 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
344 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
345 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
346 NavigationPolicyParams params, bool* handled);
347 void UseSettingsFont();
349 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
350 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
351 Ewk_Hit_Test_Mode mode,
352 Ewk_View_Hit_Test_Request_Callback,
354 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
355 Ewk_Hit_Test_Mode mode);
356 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
357 Ewk_Hit_Test_Mode mode,
358 Ewk_View_Hit_Test_Request_Callback,
360 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
361 void UpdateHitTestData(const Hit_Test_Params& params);
363 int current_find_request_id() const { return current_find_request_id_; }
364 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
365 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
366 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
367 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
368 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
369 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
370 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
371 void DidChangeContentsSize(int width, int height);
372 const Eina_Rectangle GetContentsSize() const;
373 void GetScrollSize(int* w, int* h);
375 void SetProgressValue(double progress);
376 double GetProgressValue();
377 const char* GetTitle();
378 bool SaveAsPdf(int width, int height, const std::string& file_name);
379 void BackForwardListClear();
380 _Ewk_Back_Forward_List* GetBackForwardList() const;
381 void InvokeBackForwardListChangedCallback();
382 _Ewk_History* GetBackForwardHistory() const;
383 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
384 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
385 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
386 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
387 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
388 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
389 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
390 bool IsNotificationPermissionCallbackSet() const;
391 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
393 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
394 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
396 void ExitFullscreen();
398 void DidChangePageScaleFactor(double scale_factor);
399 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
400 void JavaScriptAlertReply();
401 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
402 void JavaScriptConfirmReply(bool result);
403 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
404 void JavaScriptPromptReply(const char* result);
405 void set_renderer_crashed();
406 void GetPageScaleRange(double *min_scale, double *max_scale);
407 void DidChangePageScaleRange(double min_scale, double max_scale);
408 void SetDrawsTransparentBackground(bool enabled);
409 void GetSessionData(const char **data, unsigned *length) const;
410 bool RestoreFromSessionData(const char *data, unsigned length);
411 void ShowFileChooser(const content::FileChooserParams&);
412 void DidChangeContentsArea(int width, int height);
413 void SetBrowserFont();
414 void SetCertificatePem(const std::string& certificate);
415 bool IsDragging() const;
417 void RequestColorPicker(int r, int g, int b, int a);
418 void DismissColorPicker();
419 bool SetColorPickerColor(int r, int g, int b, int a);
420 void InputPickerShow(ui::TextInputType input_type, double input_value);
421 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
423 void ShowContentsDetectedPopup(const char*);
425 // Returns TCP port number with Inspector, or 0 if error.
426 int StartInspectorServer(int port = 0);
427 bool StopInspectorServer();
429 void LoadNotFoundErrorPage(const std::string& invalidUrl);
430 static std::string GetPlatformLocale();
431 bool GetLinkMagnifierEnabled() const;
432 void SetLinkMagnifierEnabled(bool enabled);
434 void SetOverrideEncoding(const std::string& encoding);
435 void SetViewMode(blink::WebViewMode view_mode);
437 gfx::Point GetContextMenuPosition() const;
439 void SendDelayedMessages(content::RenderViewHost* render_view_host);
441 /// ---- Event handling
444 bool HandleMove(int x, int y);
445 bool HandleResize(int width, int height);
446 bool HandleTextSelectionDown(int x, int y);
447 bool HandleTextSelectionUp(int x, int y);
449 void HandleRendererProcessCrash();
450 void HandlePostponedGesture(int x, int y, ui::EventType type);
452 void InitializeContent();
453 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
454 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
455 Ewk_Hit_Test_Mode mode,
456 WebViewAsyncRequestHitTestDataCallback* cb);
457 void HandleLongPressGesture(int x, int y, Ewk_Hit_Test_Mode mode,
459 void HandleTapGesture(int x, int y, Ewk_Hit_Test_Mode mode,
461 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
463 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
464 static void cameraResultCb(service_h request, service_h reply,
465 service_result_e result, void* data);
468 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
469 bool LaunchCamera(base::string16 mimetype);
471 content::RenderWidgetHostViewEfl* rwhv() const;
472 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
474 #if defined(OS_TIZEN)
475 void ReleasePopupMenuList();
478 tizen_webview::WebView* public_webview_;
479 scoped_refptr<tizen_webview::WebContext> context_;
480 scoped_refptr<tizen_webview::WebContext> old_context_;
481 scoped_ptr<content::WebContents> web_contents_;
482 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
483 std::string pending_url_request_;
484 scoped_ptr<Ewk_Settings> settings_;
485 scoped_ptr<_Ewk_Frame> frame_;
486 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
487 Evas_Object* evas_object_;
488 Evas_Object* native_view_;
489 bool touch_events_enabled_;
490 bool mouse_events_enabled_;
491 double text_zoom_factor_;
492 mutable std::string selected_text_;
493 mutable std::string user_agent_;
494 mutable std::string user_agent_app_name_;
495 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
497 #if defined(OS_TIZEN)
498 Eina_List* popupMenuItems_;
499 Popup_Picker* popupPicker_;
501 bool formIsNavigating_;
508 formNavigation formNavigation_;
509 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
510 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
511 scoped_ptr<content::PopupControllerEfl> popup_controller_;
512 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
513 base::string16 previous_text_;
514 int current_find_request_id_;
515 static int find_request_id_counter_;
516 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
517 gfx::Size contents_size_;
519 mutable std::string title_;
520 mutable std::string pem_certificate_;
521 Hit_Test_Params hit_test_params_;
522 base::WaitableEvent hit_test_completion_;
523 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
524 double page_scale_factor_;
525 double min_page_scale_factor_;
526 double max_page_scale_factor_;
527 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
528 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
529 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
530 scoped_ptr<content::InputPicker> inputPicker_;
531 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
532 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
533 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
534 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
535 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
536 content::DevToolsDelegateEfl* inspector_server_;
537 scoped_ptr<ScrollDetector> scroll_detector_;
538 #if defined(OS_TIZEN_MOBILE)
539 content::FileChooserParams::Mode filechooser_mode_;
541 bool is_initialized_;
543 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
545 static content::WebContentsDelegate::WebContentsCreateCallback
546 create_new_window_web_contents_cb_;
549 Eina_Bool AsyncRequestHitTestPrivate(
550 int x, int y, Ewk_Hit_Test_Mode mode,
551 AsyncHitTestRequest* asyncHitTestRequest);
553 gfx::Vector2d previous_scroll_position_;
555 gfx::Point context_menu_position_;
557 std::set<IPC::Message*> delayed_messages_;
559 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
560 // only tizen_webview::WebView can create and delete this
561 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
563 friend class tizen_webview::WebView;
564 friend class tizen_webview::WebViewEvasEventHandler;
567 namespace tizen_webview {
568 typedef ::EWebView WebViewImpl;
571 const unsigned int g_default_tilt_motion_sensitivity = 3;