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 MoveCaret(const gfx::Point& point);
322 void QuerySelectionStyle();
323 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
324 void SelectClosestWord(const gfx::Point& touch_point);
325 void SelectLinkText(const gfx::Point& touch_point);
326 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
327 void GetSnapShotForRect(gfx::Rect& rect);
329 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
330 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
333 * Creates a snapshot of given rectangle from EWebView
335 * @param rect rectangle of EWebView which will be taken into snapshot
337 * @return created snapshot or NULL if error occured.
338 * @note ownership of snapshot is passed to caller
340 Evas_Object* GetSnapshot(Eina_Rectangle rect);
342 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
343 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
344 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
345 NavigationPolicyParams params, bool* handled);
346 void UseSettingsFont();
348 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
349 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
350 Ewk_Hit_Test_Mode mode,
351 Ewk_View_Hit_Test_Request_Callback,
353 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
354 Ewk_Hit_Test_Mode mode);
355 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
356 Ewk_Hit_Test_Mode mode,
357 Ewk_View_Hit_Test_Request_Callback,
359 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
360 void UpdateHitTestData(const Hit_Test_Params& params);
362 int current_find_request_id() const { return current_find_request_id_; }
363 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
364 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
365 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
366 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
367 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
368 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
369 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
370 void DidChangeContentsSize(int width, int height);
371 const Eina_Rectangle GetContentsSize() const;
372 void GetScrollSize(int* w, int* h);
374 void SetProgressValue(double progress);
375 double GetProgressValue();
376 const char* GetTitle();
377 bool SaveAsPdf(int width, int height, const std::string& file_name);
378 void BackForwardListClear();
379 _Ewk_Back_Forward_List* GetBackForwardList() const;
380 void InvokeBackForwardListChangedCallback();
381 _Ewk_History* GetBackForwardHistory() const;
382 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
383 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
384 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
385 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
386 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
387 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
388 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
389 bool IsNotificationPermissionCallbackSet() const;
390 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
392 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
393 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
395 void ExitFullscreen();
397 void DidChangePageScaleFactor(double scale_factor);
398 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
399 void JavaScriptAlertReply();
400 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
401 void JavaScriptConfirmReply(bool result);
402 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
403 void JavaScriptPromptReply(const char* result);
404 void set_renderer_crashed();
405 void GetPageScaleRange(double *min_scale, double *max_scale);
406 void DidChangePageScaleRange(double min_scale, double max_scale);
407 void SetDrawsTransparentBackground(bool enabled);
408 void GetSessionData(const char **data, unsigned *length) const;
409 bool RestoreFromSessionData(const char *data, unsigned length);
410 void ShowFileChooser(const content::FileChooserParams&);
411 void DidChangeContentsArea(int width, int height);
412 void SetBrowserFont();
413 void SetCertificatePem(const std::string& certificate);
414 bool IsDragging() const;
416 void RequestColorPicker(int r, int g, int b, int a);
417 void DismissColorPicker();
418 bool SetColorPickerColor(int r, int g, int b, int a);
419 void InputPickerShow(ui::TextInputType input_type, double input_value);
420 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
422 void ShowContentsDetectedPopup(const char*);
424 // Returns TCP port number with Inspector, or 0 if error.
425 int StartInspectorServer(int port = 0);
426 bool StopInspectorServer();
428 void LoadNotFoundErrorPage(const std::string& invalidUrl);
429 static std::string GetPlatformLocale();
430 bool GetLinkMagnifierEnabled() const;
431 void SetLinkMagnifierEnabled(bool enabled);
433 void SetOverrideEncoding(const std::string& encoding);
434 void SetViewMode(blink::WebViewMode view_mode);
436 gfx::Point GetContextMenuPosition() const;
438 void SendDelayedMessages(content::RenderViewHost* render_view_host);
440 /// ---- Event handling
443 bool HandleMove(int x, int y);
444 bool HandleResize(int width, int height);
445 bool HandleTextSelectionDown(int x, int y);
446 bool HandleTextSelectionUp(int x, int y);
448 void HandleRendererProcessCrash();
449 void HandlePostponedGesture(int x, int y, ui::EventType type);
451 void InitializeContent();
452 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
453 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
454 Ewk_Hit_Test_Mode mode,
455 WebViewAsyncRequestHitTestDataCallback* cb);
456 void HandleLongPressGesture(int x, int y, Ewk_Hit_Test_Mode mode,
458 void HandleTapGesture(int x, int y, Ewk_Hit_Test_Mode mode,
460 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
462 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
463 static void cameraResultCb(service_h request, service_h reply,
464 service_result_e result, void* data);
467 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
468 bool LaunchCamera(base::string16 mimetype);
470 content::RenderWidgetHostViewEfl* rwhv() const;
471 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
473 #if defined(OS_TIZEN)
474 void ReleasePopupMenuList();
477 tizen_webview::WebView* public_webview_;
478 scoped_refptr<tizen_webview::WebContext> context_;
479 scoped_refptr<tizen_webview::WebContext> old_context_;
480 scoped_ptr<content::WebContents> web_contents_;
481 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
482 std::string pending_url_request_;
483 scoped_ptr<Ewk_Settings> settings_;
484 scoped_ptr<_Ewk_Frame> frame_;
485 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
486 Evas_Object* evas_object_;
487 Evas_Object* native_view_;
488 bool touch_events_enabled_;
489 bool mouse_events_enabled_;
490 double text_zoom_factor_;
491 mutable std::string selected_text_;
492 mutable std::string user_agent_;
493 mutable std::string user_agent_app_name_;
494 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
496 #if defined(OS_TIZEN)
497 Eina_List* popupMenuItems_;
498 Popup_Picker* popupPicker_;
500 bool formIsNavigating_;
507 formNavigation formNavigation_;
508 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
509 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
510 scoped_ptr<content::PopupControllerEfl> popup_controller_;
511 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
512 base::string16 previous_text_;
513 int current_find_request_id_;
514 static int find_request_id_counter_;
515 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
516 gfx::Size contents_size_;
518 mutable std::string title_;
519 mutable std::string pem_certificate_;
520 Hit_Test_Params hit_test_params_;
521 base::WaitableEvent hit_test_completion_;
522 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
523 double page_scale_factor_;
524 double min_page_scale_factor_;
525 double max_page_scale_factor_;
526 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
527 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
528 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
529 scoped_ptr<content::InputPicker> inputPicker_;
530 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
531 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
532 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
533 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
534 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
535 content::DevToolsDelegateEfl* inspector_server_;
536 scoped_ptr<ScrollDetector> scroll_detector_;
537 #if defined(OS_TIZEN_MOBILE)
538 content::FileChooserParams::Mode filechooser_mode_;
540 bool is_initialized_;
542 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
544 static content::WebContentsDelegate::WebContentsCreateCallback
545 create_new_window_web_contents_cb_;
548 Eina_Bool AsyncRequestHitTestPrivate(
549 int x, int y, Ewk_Hit_Test_Mode mode,
550 AsyncHitTestRequest* asyncHitTestRequest);
552 gfx::Vector2d previous_scroll_position_;
554 gfx::Point context_menu_position_;
556 std::set<IPC::Message*> delayed_messages_;
558 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
559 // only tizen_webview::WebView can create and delete this
560 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
562 friend class tizen_webview::WebView;
563 friend class tizen_webview::WebViewEvasEventHandler;
566 namespace tizen_webview {
567 typedef ::EWebView WebViewImpl;
570 const unsigned int g_default_tilt_motion_sensitivity = 3;