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 "third_party/WebKit/Source/platform/text/TextDirection.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;
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 void SelectRange(const gfx::Point& start, const gfx::Point& end);
332 void MoveCaret(const gfx::Point& point);
333 void QuerySelectionStyle();
334 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
335 void SelectClosestWord(const gfx::Point& touch_point);
336 void SelectLinkText(const gfx::Point& touch_point);
337 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
338 void GetSnapShotForRect(gfx::Rect& rect);
340 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
341 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
344 * Creates a snapshot of given rectangle from EWebView
346 * @param rect rectangle of EWebView which will be taken into snapshot
348 * @return created snapshot or NULL if error occured.
349 * @note ownership of snapshot is passed to caller
351 Evas_Object* GetSnapshot(Eina_Rectangle rect);
353 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, tizen_webview::Web_App_Screenshot_Captured_Callback callback, void* user_data);
354 void InvokePolicyResponseCallback(tizen_webview::PolicyDecision* policy_decision);
355 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
356 NavigationPolicyParams params, bool* handled);
357 void UseSettingsFont();
359 tizen_webview::Hit_Test* RequestHitTestDataAt(int x, int y,
360 tizen_webview::Hit_Test_Mode mode);
361 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
362 tizen_webview::Hit_Test_Mode mode,
363 tizen_webview::View_Hit_Test_Request_Callback,
365 tizen_webview::Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
366 tizen_webview::Hit_Test_Mode mode);
367 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
368 tizen_webview::Hit_Test_Mode mode,
369 tizen_webview::View_Hit_Test_Request_Callback,
371 void DispatchAsyncHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes, int64_t request_id);
372 void UpdateHitTestData(const _Ewk_Hit_Test& hit_test_data, const NodeAttributesMap& node_attributes);
374 int current_find_request_id() const { return current_find_request_id_; }
375 bool PlainTextGet(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
376 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
377 int SetEwkViewPlainTextGetCallback(tizen_webview::View_Plain_Text_Get_Callback callback, void* user_data);
378 void SetViewGeolocationPermissionCallback(tizen_webview::View_Geolocation_Permission_Callback callback, void* user_data);
379 bool InvokeViewGeolocationPermissionCallback(void* geolocation_permission_request_context, Eina_Bool* result);
380 void SetViewUnfocusAllowCallback(tizen_webview::View_Unfocus_Allow_Callback callback, void* user_data);
381 bool InvokeViewUnfocusAllowCallback(tizen_webview::Unfocus_Direction direction, Eina_Bool* result);
382 void DidChangeContentsSize(int width, int height);
383 const Eina_Rectangle GetContentsSize() const;
384 void GetScrollSize(int* w, int* h);
386 void SetProgressValue(double progress);
387 double GetProgressValue();
388 const char* GetTitle();
389 bool SaveAsPdf(int width, int height, const std::string& file_name);
390 void BackForwardListClear();
391 _Ewk_Back_Forward_List* GetBackForwardList() const;
392 void InvokeBackForwardListChangedCallback();
393 _Ewk_History* GetBackForwardHistory() const;
394 bool WebAppCapableGet(tizen_webview::Web_App_Capable_Get_Callback callback, void *userData);
395 bool WebAppIconUrlGet(tizen_webview::Web_App_Icon_URL_Get_Callback callback, void *userData);
396 bool WebAppIconUrlsGet(tizen_webview::Web_App_Icon_URLs_Get_Callback callback, void *userData);
397 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
398 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
399 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
400 void SetNotificationPermissionCallback(tizen_webview::View_Notification_Permission_Callback callback, void* user_data);
401 bool IsNotificationPermissionCallbackSet() const;
402 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
404 bool GetMHTMLData(tizen_webview::View_MHTML_Data_Get_Callback callback, void* user_data);
405 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
407 void ExitFullscreen();
409 void DidChangePageScaleFactor(double scale_factor);
410 void SetJavaScriptAlertCallback(tizen_webview::View_JavaScript_Alert_Callback callback, void* user_data);
411 void JavaScriptAlertReply();
412 void SetJavaScriptConfirmCallback(tizen_webview::View_JavaScript_Confirm_Callback callback, void* user_data);
413 void JavaScriptConfirmReply(bool result);
414 void SetJavaScriptPromptCallback(tizen_webview::View_JavaScript_Prompt_Callback callback, void* user_data);
415 void JavaScriptPromptReply(const char* result);
416 void set_renderer_crashed();
417 void GetPageScaleRange(double *min_scale, double *max_scale);
418 void DidChangePageScaleRange(double min_scale, double max_scale);
419 void SetDrawsTransparentBackground(bool enabled);
420 void GetSessionData(const char **data, unsigned *length) const;
421 bool RestoreFromSessionData(const char *data, unsigned length);
422 void ShowFileChooser(const content::FileChooserParams&);
423 void DidChangeContentsArea(int width, int height);
424 void SetBrowserFont();
425 void SetCertificatePem(const std::string& certificate);
426 bool IsDragging() const;
428 void RequestColorPicker(int r, int g, int b, int a);
429 void DismissColorPicker();
430 bool SetColorPickerColor(int r, int g, int b, int a);
431 #if defined(OS_TIZEN)
432 void InputPickerShow(
433 ui::TextInputType input_type, std::string input_value);
435 void InputPickerShow(ui::TextInputType input_type, double input_value);
437 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
439 #ifdef TIZEN_CONTENTS_DETECTION
440 void ShowContentsDetectedPopup(const char*);
444 gfx::Rect GetIMERect();
445 void ScrollFocusedEditableNode();
447 // Returns TCP port number with Inspector, or 0 if error.
448 int StartInspectorServer(int port = 0);
449 bool StopInspectorServer();
451 void LoadNotFoundErrorPage(const std::string& invalidUrl);
452 static std::string GetPlatformLocale();
453 bool GetLinkMagnifierEnabled() const;
454 void SetLinkMagnifierEnabled(bool enabled);
456 void SetOverrideEncoding(const std::string& encoding);
457 void SetViewMode(blink::WebViewMode view_mode);
459 gfx::Point GetContextMenuPosition() const;
461 /// ---- Event handling
464 bool HandleMove(int x, int y);
465 bool HandleResize(int width, int height);
466 bool HandleTextSelectionDown(int x, int y);
467 bool HandleTextSelectionUp(int x, int y);
469 void HandleRendererProcessCrash();
470 void HandlePostponedGesture(int x, int y, ui::EventType type);
472 void InitializeContent();
473 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
474 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
475 tizen_webview::Hit_Test_Mode mode,
476 WebViewAsyncRequestHitTestDataCallback* cb);
477 void HandleLongPressGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
478 tizen_webview::Hit_Test*);
479 void HandleTapGesture(int x, int y, tizen_webview::Hit_Test_Mode mode,
480 tizen_webview::Hit_Test*);
481 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
483 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
484 static void cameraResultCb(service_h request, service_h reply,
485 service_result_e result, void* data);
488 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
489 bool LaunchCamera(base::string16 mimetype);
491 content::RenderWidgetHostViewEfl* rwhv() const;
492 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
494 #if defined(OS_TIZEN)
495 void ReleasePopupMenuList();
498 tizen_webview::WebView* public_webview_;
499 scoped_refptr<tizen_webview::WebContext> context_;
500 scoped_refptr<tizen_webview::WebContext> old_context_;
501 scoped_ptr<content::WebContents> web_contents_;
502 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
503 std::string pending_url_request_;
504 scoped_ptr<Ewk_Settings> settings_;
505 scoped_ptr<_Ewk_Frame> frame_;
506 scoped_ptr<tizen_webview::PolicyDecision> window_policy_;
507 Evas_Object* evas_object_;
508 Evas_Object* native_view_;
509 bool touch_events_enabled_;
510 bool mouse_events_enabled_;
511 double text_zoom_factor_;
512 mutable std::string selected_text_;
513 mutable std::string user_agent_;
514 mutable std::string user_agent_app_name_;
515 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
517 #if defined(OS_TIZEN)
518 Eina_List* popupMenuItems_;
519 Popup_Picker* popupPicker_;
521 bool formIsNavigating_;
528 formNavigation formNavigation_;
529 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
530 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
531 #ifdef TIZEN_CONTENTS_DETECTION
532 scoped_ptr<content::PopupControllerEfl> popup_controller_;
534 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
535 base::string16 previous_text_;
536 int current_find_request_id_;
537 static int find_request_id_counter_;
538 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
539 gfx::Size contents_size_;
541 mutable std::string title_;
542 mutable std::string pem_certificate_;
543 _Ewk_Hit_Test hit_test_data_;
544 base::WaitableEvent hit_test_completion_;
545 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
546 double page_scale_factor_;
547 double min_page_scale_factor_;
548 double max_page_scale_factor_;
549 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
550 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
551 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
552 scoped_ptr<content::InputPicker> inputPicker_;
553 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
554 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
555 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
556 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
557 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
558 content::DevToolsDelegateEfl* inspector_server_;
560 #if defined(OS_TIZEN_MOBILE)
561 content::FileChooserParams::Mode filechooser_mode_;
563 bool is_initialized_;
565 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
567 static content::WebContentsDelegate::WebContentsCreateCallback
568 create_new_window_web_contents_cb_;
571 Eina_Bool AsyncRequestHitTestPrivate(
572 int x, int y, tizen_webview::Hit_Test_Mode mode,
573 AsyncHitTestRequest* asyncHitTestRequest);
575 gfx::Vector2d previous_scroll_position_;
577 gfx::Point context_menu_position_;
579 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
580 // only tizen_webview::WebView can create and delete this
581 EWebView(tizen_webview::WebView* owner, tizen_webview::WebContext*, Evas_Object* smart_object);
583 friend class tizen_webview::WebView;
584 friend class tizen_webview::WebViewEvasEventHandler;
587 namespace tizen_webview {
588 typedef ::EWebView WebViewImpl;
591 const unsigned int g_default_tilt_motion_sensitivity = 3;