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(EWK_BRINGUP) // FIXME: m67 bringup
9 // FIXME: appfw/app_service.h is no more in Tizen 2.3, figure out what to
11 #include <appcore-agent/service_app.h>
20 #include "base/callback.h"
21 #include "base/containers/id_map.h"
22 #include "base/synchronization/waitable_event.h"
23 #include "browser/inputpicker/InputPicker.h"
24 #include "browser/selectpicker/popup_picker.h"
25 #include "content/browser/renderer_host/event_with_latency_info.h"
26 #include "content/browser/selection/selection_controller_efl.h"
27 #include "content/public/browser/context_menu_params.h"
28 #include "content/public/browser/navigation_controller.h"
29 #include "content/public/browser/quota_permission_context.h"
30 #include "content/public/browser/web_contents_delegate.h"
31 #include "content/public/browser/web_contents_efl_delegate.h"
32 #include "content/public/common/input_event_ack_state.h"
33 #include "content_browser_client_efl.h"
34 #include "context_menu_controller_efl.h"
35 #include "eweb_context.h"
36 #include "eweb_view_callbacks.h"
37 #include "file_chooser_controller_efl.h"
38 #include "permission_popup_manager.h"
39 #include "popup_controller_efl.h"
40 #include "private/ewk_auth_challenge_private.h"
41 #include "private/ewk_back_forward_list_private.h"
42 #include "private/ewk_history_private.h"
43 #include "private/ewk_hit_test_private.h"
44 #include "private/ewk_settings_private.h"
45 #include "private/ewk_web_application_icon_data_private.h"
46 #include "public/ewk_hit_test_internal.h"
47 #include "public/ewk_touch_internal.h"
48 #include "public/ewk_view_product.h"
49 #include "scroll_detector.h"
50 #include "third_party/blink/public/common/context_menu_data/menu_item_info.h"
51 #include "third_party/blink/public/mojom/choosers/file_chooser.mojom.h"
52 #include "ui/gfx/geometry/point.h"
53 #include "ui/gfx/geometry/size.h"
54 #include "web_contents_delegate_efl.h"
57 class RenderFrameHost;
59 class RenderWidgetHostViewEfl;
60 class WebContentsDelegateEfl;
61 class ContextMenuControllerEfl;
62 class WebContentsViewEfl;
63 class PopupControllerEfl;
67 class _Ewk_Policy_Decision;
70 class WebViewEvasEventHandler;
71 class _Ewk_Quota_Permission_Request;
73 template <typename CallbackPtr, typename CallbackParameter>
74 class WebViewCallback {
76 WebViewCallback() { Set(nullptr, nullptr); }
78 void Set(CallbackPtr cb, void* data) {
83 bool IsCallbackSet() const { return callback_; }
85 Eina_Bool Run(Evas_Object* webview,
86 CallbackParameter param,
87 Eina_Bool* callback_result) {
88 CHECK(callback_result);
89 if (IsCallbackSet()) {
90 *callback_result = callback_(webview, param, user_data_);
96 void Run(Evas_Object* webview, CallbackParameter param) {
98 callback_(webview, param, user_data_);
102 CallbackPtr callback_;
106 class WebApplicationIconUrlGetCallback {
108 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
110 : func_(func), user_data_(user_data) {}
111 void Run(const std::string& url) {
113 (func_)(url.c_str(), user_data_);
118 Ewk_Web_App_Icon_URL_Get_Callback func_;
122 class WebApplicationIconUrlsGetCallback {
124 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
126 : func_(func), user_data_(user_data) {}
127 void Run(const std::map<std::string, std::string>& urls) {
129 Eina_List* list = NULL;
130 for (std::map<std::string, std::string>::const_iterator it = urls.begin();
131 it != urls.end(); ++it) {
132 _Ewk_Web_App_Icon_Data* data =
133 ewkWebAppIconDataCreate(it->first, it->second);
134 list = eina_list_append(list, data);
136 (func_)(list, user_data_);
141 Ewk_Web_App_Icon_URLs_Get_Callback func_;
145 class WebApplicationCapableGetCallback {
147 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
149 : func_(func), user_data_(user_data) {}
150 void Run(bool capable) {
152 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
157 Ewk_Web_App_Capable_Get_Callback func_;
161 class WebViewAsyncRequestHitTestDataCallback;
162 class JavaScriptDialogManagerEfl;
163 class PermissionPopupManager;
167 static EWebView* FromEvasObject(Evas_Object* eo);
169 EWebView(Ewk_Context*, Evas_Object* smart_object);
172 // initialize data members and activate event handlers.
173 // call this once after created and before use
176 void CreateNewWindow(
177 content::WebContentsEflDelegate::WebContentsCreateCallback);
178 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
180 Ewk_Context* context() const { return context_.get(); }
181 Evas_Object* evas_object() const { return evas_object_; }
182 Evas_Object* native_view() const { return native_view_; }
183 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
184 PermissionPopupManager* GetPermissionPopupManager() const {
185 return permission_popup_manager_.get();
188 content::WebContents& web_contents() const { return *web_contents_.get(); }
190 template <EWebViewCallbacks::CallbackType callbackType>
191 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
192 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
195 void set_magnifier(bool status);
198 void SetURL(const GURL& url);
199 const GURL& GetURL() const;
200 const GURL& GetOriginalURL() const;
202 void ReloadBypassingCache();
203 Eina_Bool CanGoBack();
204 Eina_Bool CanGoForward();
205 Eina_Bool HasFocus() const;
206 void SetFocus(Eina_Bool focus);
208 Eina_Bool GoForward();
212 double GetTextZoomFactor() const;
213 void SetTextZoomFactor(double text_zoom_factor);
214 double GetPageZoomFactor() const;
215 void SetPageZoomFactor(double page_zoom_factor);
216 void ExecuteEditCommand(const char* command, const char* value);
217 void SetOrientation(int orientation);
218 int GetOrientation();
219 bool TouchEventsEnabled() const;
220 void SetTouchEventsEnabled(bool enabled);
221 bool MouseEventsEnabled() const;
222 void SetMouseEventsEnabled(bool enabled);
223 void HandleTouchEvents(Ewk_Touch_Event_Type type,
224 const Eina_List* points,
225 const Evas_Modifier* modifiers);
228 bool ExecuteJavaScript(const char* script,
229 Ewk_View_Script_Execute_Callback callback,
231 bool SetUserAgent(const char* userAgent);
232 bool SetUserAgentAppName(const char* application_name);
233 bool SetPrivateBrowsing(bool incognito);
234 bool GetPrivateBrowsing() const;
235 const char* GetUserAgent() const;
236 const char* GetUserAgentAppName() const;
237 const char* GetSelectedText() const;
238 Ewk_Settings* GetSettings() { return settings_.get(); }
239 _Ewk_Frame* GetMainFrame();
240 void UpdateWebKitPreferences();
241 void LoadHTMLString(const char* html,
242 const char* base_uri,
243 const char* unreachable_uri);
244 void LoadPlainTextString(const char* plain_text);
245 void LoadData(const char* data,
247 const char* mime_type,
248 const char* encoding,
249 const char* base_uri,
250 const char* unreachable_uri = NULL);
252 void InvokeLoadError(const GURL& url,
254 const std::string& error_description,
257 void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
259 void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
261 const std::string& realm);
262 void Find(const char* text, Ewk_Find_Options);
263 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
264 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
265 void ShowPopupMenu(const std::vector<blink::MenuItemInfo>& items,
268 Eina_Bool HidePopupMenu();
269 void UpdateFormNavigation(int formElementCount,
270 int currentNodeIndex,
273 void FormNavigate(bool direction);
274 bool IsSelectPickerShown() const;
275 void CloseSelectPicker();
276 bool FormIsNavigating() const { return formIsNavigating_; }
277 void SetFormIsNavigating(bool formIsNavigating);
278 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
279 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
280 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
281 Eina_Bool PopupMenuClose();
282 void HandleLongPressGesture(const content::ContextMenuParams&);
283 void ShowContextMenu(const content::ContextMenuParams&);
284 void CancelContextMenu(int request_id);
285 void SetScale(double scale_factor, int x, int y);
286 bool GetScrollPosition(int* x, int* y) const;
287 void SetScroll(int x, int y);
288 void UrlRequestSet(const char* url,
289 content::NavigationController::LoadURLType loadtype,
293 content::SelectionControllerEfl* GetSelectionController() const;
294 content::PopupControllerEfl* GetPopupController() const {
295 return popup_controller_.get();
297 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
298 void MoveCaret(const gfx::Point& point);
299 void QuerySelectionStyle();
300 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
301 void SelectLinkText(const gfx::Point& touch_point);
302 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
303 Eina_Bool ClearSelection();
305 // Callback OnCopyFromBackingStore will be called once we get the snapshot
307 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
309 void RenderViewCreated(content::RenderViewHost* render_view_host);
312 * Creates a snapshot of given rectangle from EWebView
314 * @param rect rectangle of EWebView which will be taken into snapshot
316 * @return created snapshot or NULL if error occured.
317 * @note ownership of snapshot is passed to caller
319 Evas_Object* GetSnapshot(Eina_Rectangle rect);
321 bool GetSnapshotAsync(Eina_Rectangle rect,
322 Ewk_Web_App_Screenshot_Captured_Callback callback,
324 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
325 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
326 NavigationPolicyParams params,
328 void UseSettingsFont();
330 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
331 Eina_Bool AsyncRequestHitTestDataAt(int x,
333 Ewk_Hit_Test_Mode mode,
334 Ewk_View_Hit_Test_Request_Callback,
336 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
338 Ewk_Hit_Test_Mode mode);
339 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
342 Ewk_Hit_Test_Mode mode,
343 Ewk_View_Hit_Test_Request_Callback,
345 void DispatchAsyncHitTestData(const Hit_Test_Params& params,
347 void UpdateHitTestData(const Hit_Test_Params& params);
349 int current_find_request_id() const { return current_find_request_id_; }
350 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
351 void InvokePlainTextGetCallback(const std::string& content_text,
352 int plain_text_get_callback_id);
353 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
355 void SetViewGeolocationPermissionCallback(
356 Ewk_View_Geolocation_Permission_Callback callback,
358 bool InvokeViewGeolocationPermissionCallback(
359 _Ewk_Geolocation_Permission_Request*
360 geolocation_permission_request_context,
362 void SetViewUserMediaPermissionCallback(
363 Ewk_View_User_Media_Permission_Callback callback,
365 bool InvokeViewUserMediaPermissionCallback(
366 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
368 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
370 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
372 void DidChangeContentsSize(int width, int height);
373 const Eina_Rectangle GetContentsSize() const;
374 void GetScrollSize(int* w, int* h);
376 void SetProgressValue(double progress);
377 double GetProgressValue();
378 const char* GetTitle();
379 bool SaveAsPdf(int width, int height, const std::string& file_name);
380 void BackForwardListClear();
381 _Ewk_Back_Forward_List* GetBackForwardList() const;
382 void InvokeBackForwardListChangedCallback();
383 _Ewk_History* GetBackForwardHistory() const;
384 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
386 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
388 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
390 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
391 void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
393 void InvokeWebAppIconUrlsGetCallback(
394 const std::map<std::string, std::string>& iconUrls,
396 void SetNotificationPermissionCallback(
397 Ewk_View_Notification_Permission_Callback callback,
399 bool IsNotificationPermissionCallbackSet() const;
400 bool InvokeNotificationPermissionCallback(
401 Ewk_Notification_Permission_Request* request);
403 bool GetMHTMLData(Ewk_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(Ewk_View_JavaScript_Alert_Callback callback,
411 void JavaScriptAlertReply();
412 void SetJavaScriptConfirmCallback(
413 Ewk_View_JavaScript_Confirm_Callback callback,
415 void JavaScriptConfirmReply(bool result);
416 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
418 void JavaScriptPromptReply(const char* result);
419 void set_renderer_crashed();
420 void GetPageScaleRange(double* min_scale, double* max_scale);
421 void SetDrawsTransparentBackground(bool enabled);
422 void GetSessionData(const char** data, unsigned* length) const;
423 bool RestoreFromSessionData(const char* data, unsigned length);
424 void ShowFileChooser(content::RenderFrameHost* render_frame_host,
425 const blink::mojom::FileChooserParams&);
426 void SetBrowserFont();
427 void SetCertificatePem(const std::string& certificate);
428 bool IsDragging() const;
430 void RequestColorPicker(int r, int g, int b, int a);
431 void DismissColorPicker();
432 bool SetColorPickerColor(int r, int g, int b, int a);
433 void InputPickerShow(ui::TextInputType input_type, double input_value);
435 void ShowContentsDetectedPopup(const char*);
437 // Returns TCP port number with Inspector, or 0 if error.
438 int StartInspectorServer(int port = 0);
439 bool StopInspectorServer();
441 void LoadNotFoundErrorPage(const std::string& invalidUrl);
442 static std::string GetPlatformLocale();
443 bool GetLinkMagnifierEnabled() const;
444 void SetLinkMagnifierEnabled(bool enabled);
446 void SetOverrideEncoding(const std::string& encoding);
447 void SetQuotaPermissionRequestCallback(
448 Ewk_Quota_Permission_Request_Callback callback,
450 void InvokeQuotaPermissionRequest(
451 _Ewk_Quota_Permission_Request* request,
452 content::QuotaPermissionContext::PermissionCallback cb);
453 void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
455 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
456 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
457 void SetViewMode(blink::WebViewMode view_mode);
459 gfx::Point GetContextMenuPosition() const;
461 content::ContextMenuControllerEfl* GetContextMenuController() {
462 return context_menu_.get();
464 void ResetContextMenuController();
466 /// ---- Event handling
469 bool HandleMove(int x, int y);
470 bool HandleResize(int width, int height);
471 bool HandleTextSelectionDown(int x, int y);
472 bool HandleTextSelectionUp(int x, int y);
474 void HandleRendererProcessCrash();
475 void InvokeWebProcessCrashedCallback();
477 void HandleTapGestureForSelection(bool is_content_editable);
478 void HandleZoomGesture(blink::WebGestureEvent& event);
481 void SyncAcceptLanguages(const std::string& accept_languages);
483 void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
484 const gfx::Vector2dF& latest_overscroll_delta);
487 void InitializeContent();
488 void SendDelayedMessages(content::RenderViewHost* render_view_host);
490 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
491 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
494 Ewk_Hit_Test_Mode mode,
495 WebViewAsyncRequestHitTestDataCallback* cb);
497 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
499 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
500 static void cameraResultCb(service_h request,
502 service_result_e result,
506 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
507 bool LaunchCamera(std::u16string mimetype);
509 content::RenderWidgetHostViewEfl* rwhv() const;
510 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
512 void ReleasePopupMenuList();
514 void ShowContextMenuInternal(const content::ContextMenuParams&);
516 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
518 void ChangeScroll(int& x, int& y);
520 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
521 scoped_refptr<Ewk_Context> context_;
522 scoped_refptr<Ewk_Context> old_context_;
523 std::unique_ptr<content::WebContents> web_contents_;
524 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
525 std::string pending_url_request_;
526 std::unique_ptr<Ewk_Settings> settings_;
527 std::unique_ptr<_Ewk_Frame> frame_;
528 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
529 Evas_Object* evas_object_;
530 Evas_Object* native_view_;
531 bool touch_events_enabled_;
532 bool mouse_events_enabled_;
533 double text_zoom_factor_;
534 mutable std::string user_agent_;
535 mutable std::string user_agent_app_name_;
536 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
538 Eina_List* popupMenuItems_;
539 Popup_Picker* popupPicker_;
540 bool formIsNavigating_;
547 formNavigation formNavigation_;
548 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
549 #if !defined(EWK_BRINGUP) // FIXME: m71 bringup
550 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
552 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
553 std::u16string previous_text_;
554 int current_find_request_id_;
555 static int find_request_id_counter_;
557 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
558 EwkViewPlainTextGetCallback;
559 base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
561 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
562 MHTMLCallbackDetails;
563 base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
565 gfx::Size contents_size_;
567 mutable std::string title_;
568 mutable std::string pem_certificate_;
569 Hit_Test_Params hit_test_params_;
570 base::WaitableEvent hit_test_completion_;
571 double page_scale_factor_;
575 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
576 _Ewk_Geolocation_Permission_Request*>
577 geolocation_permission_cb_;
578 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
579 _Ewk_User_Media_Permission_Request*>
580 user_media_permission_cb_;
581 WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
583 WebViewCallback<Ewk_View_Notification_Permission_Callback,
584 Ewk_Notification_Permission_Request*>
585 notification_permission_callback_;
586 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
587 const _Ewk_Quota_Permission_Request*>
588 quota_request_callback_;
589 WebViewCallback<Ewk_View_Authentication_Callback, _Ewk_Auth_Challenge*>
592 std::unique_ptr<content::InputPicker> inputPicker_;
593 base::IDMap<WebApplicationIconUrlGetCallback*>
594 web_app_icon_url_get_callback_map_;
595 base::IDMap<WebApplicationIconUrlsGetCallback*>
596 web_app_icon_urls_get_callback_map_;
597 base::IDMap<WebApplicationCapableGetCallback*>
598 web_app_capable_get_callback_map_;
599 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
600 std::unique_ptr<ScrollDetector> scroll_detector_;
602 #if defined(OS_TIZEN)
603 blink::mojom::FileChooserParams::Mode filechooser_mode_;
605 std::map<const _Ewk_Quota_Permission_Request*,
606 content::QuotaPermissionContext::PermissionCallback>
607 quota_permission_request_map_;
609 bool is_initialized_;
611 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
613 static content::WebContentsEflDelegate::WebContentsCreateCallback
614 create_new_window_web_contents_cb_;
617 gfx::Vector2d previous_scroll_position_;
619 gfx::Point context_menu_position_;
621 std::vector<IPC::Message*> delayed_messages_;
623 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
625 content::ContentBrowserClientEfl::AcceptLangsChangedCallback
626 accept_langs_changed_callback_;
629 const unsigned int g_default_tilt_motion_sensitivity = 3;