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/input_picker/input_picker.h"
24 #include "browser/selectpicker/popup_picker.h"
25 #include "content/browser/date_time_chooser_efl.h"
26 #include "content/browser/renderer_host/event_with_latency_info.h"
27 #include "content/browser/selection/selection_controller_efl.h"
28 #include "content/public/browser/context_menu_params.h"
29 #include "content/public/browser/navigation_controller.h"
30 #include "content/public/browser/quota_permission_context.h"
31 #include "content/public/browser/web_contents_delegate.h"
32 #include "content/public/browser/web_contents_efl_delegate.h"
33 #include "content/public/common/input_event_ack_state.h"
34 #include "content_browser_client_efl.h"
35 #include "context_menu_controller_efl.h"
36 #include "eweb_context.h"
37 #include "eweb_view_callbacks.h"
38 #include "file_chooser_controller_efl.h"
39 #include "permission_popup_manager.h"
40 #include "popup_controller_efl.h"
41 #include "private/ewk_auth_challenge_private.h"
42 #include "private/ewk_back_forward_list_private.h"
43 #include "private/ewk_history_private.h"
44 #include "private/ewk_hit_test_private.h"
45 #include "private/ewk_settings_private.h"
46 #include "private/ewk_web_application_icon_data_private.h"
47 #include "public/ewk_hit_test_internal.h"
48 #include "public/ewk_touch_internal.h"
49 #include "public/ewk_view_product.h"
50 #include "scroll_detector.h"
51 #include "third_party/blink/public/common/context_menu_data/menu_item_info.h"
52 #include "third_party/blink/public/mojom/choosers/file_chooser.mojom.h"
53 #include "ui/aura/window_tree_host.h"
54 #include "ui/gfx/geometry/point.h"
55 #include "ui/gfx/geometry/size.h"
56 #include "web_contents_delegate_efl.h"
61 class WindowParentingClient;
66 class RenderFrameHost;
68 class RenderWidgetHostViewAura;
69 class WebContentsDelegateEfl;
70 class WebContentsViewAura;
71 class ContextMenuControllerEfl;
72 class PopupControllerEfl;
77 class _Ewk_Policy_Decision;
80 class WebViewEvasEventHandler;
81 class _Ewk_Quota_Permission_Request;
83 template <typename CallbackPtr, typename CallbackParameter>
84 class WebViewCallback {
86 WebViewCallback() { Set(nullptr, nullptr); }
88 void Set(CallbackPtr cb, void* data) {
93 bool IsCallbackSet() const { return callback_; }
95 Eina_Bool Run(Evas_Object* webview,
96 CallbackParameter param,
97 Eina_Bool* callback_result) {
98 CHECK(callback_result);
99 if (IsCallbackSet()) {
100 *callback_result = callback_(webview, param, user_data_);
106 void Run(Evas_Object* webview, CallbackParameter param) {
108 callback_(webview, param, user_data_);
112 CallbackPtr callback_;
116 class WebApplicationIconUrlGetCallback {
118 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
120 : func_(func), user_data_(user_data) {}
121 void Run(const std::string& url) {
123 (func_)(url.c_str(), user_data_);
128 Ewk_Web_App_Icon_URL_Get_Callback func_;
132 class WebApplicationIconUrlsGetCallback {
134 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
136 : func_(func), user_data_(user_data) {}
137 void Run(const std::map<std::string, std::string>& urls) {
139 Eina_List* list = NULL;
140 for (std::map<std::string, std::string>::const_iterator it = urls.begin();
141 it != urls.end(); ++it) {
142 _Ewk_Web_App_Icon_Data* data =
143 ewkWebAppIconDataCreate(it->first, it->second);
144 list = eina_list_append(list, data);
146 (func_)(list, user_data_);
151 Ewk_Web_App_Icon_URLs_Get_Callback func_;
155 class WebApplicationCapableGetCallback {
157 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
159 : func_(func), user_data_(user_data) {}
160 void Run(bool capable) {
162 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
167 Ewk_Web_App_Capable_Get_Callback func_;
171 class WebViewAsyncRequestHitTestDataCallback;
172 class JavaScriptDialogManagerEfl;
173 class PermissionPopupManager;
177 static EWebView* FromEvasObject(Evas_Object* eo);
179 EWebView(Ewk_Context*, Evas_Object* smart_object);
182 // initialize data members and activate event handlers.
183 // call this once after created and before use
186 bool CreateNewWindow(
187 content::WebContentsEflDelegate::WebContentsCreateCallback);
188 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
190 content::WebContentsViewAura* wcva() const;
191 content::RenderWidgetHostViewAura* rwhva() const;
192 Ewk_Context* context() const { return context_.get(); }
193 Evas_Object* evas_object() const { return evas_object_; }
194 Evas_Object* native_view() const { return native_view_; }
195 Evas_Object* GetElmWindow() const;
196 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
197 PermissionPopupManager* GetPermissionPopupManager() const {
198 return permission_popup_manager_.get();
201 content::WebContents& web_contents() const { return *web_contents_.get(); }
203 template <EWebViewCallbacks::CallbackType callbackType>
204 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
205 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
208 void set_magnifier(bool status);
211 void SetURL(const GURL& url);
212 const GURL& GetURL() const;
213 const GURL& GetOriginalURL() const;
215 void ReloadBypassingCache();
216 Eina_Bool CanGoBack();
217 Eina_Bool CanGoForward();
218 Eina_Bool HasFocus() const;
219 void SetFocus(Eina_Bool focus);
221 Eina_Bool GoForward();
225 double GetTextZoomFactor() const;
226 void SetTextZoomFactor(double text_zoom_factor);
227 double GetPageZoomFactor() const;
228 void SetPageZoomFactor(double page_zoom_factor);
229 void ExecuteEditCommand(const char* command, const char* value);
230 void SetOrientation(int orientation);
231 int GetOrientation();
232 bool TouchEventsEnabled() const;
233 void SetTouchEventsEnabled(bool enabled);
234 bool MouseEventsEnabled() const;
235 void SetMouseEventsEnabled(bool enabled);
236 void HandleTouchEvents(Ewk_Touch_Event_Type type,
237 const Eina_List* points,
238 const Evas_Modifier* modifiers);
241 bool ExecuteJavaScript(const char* script,
242 Ewk_View_Script_Execute_Callback callback,
244 bool SetUserAgent(const char* userAgent);
245 bool SetUserAgentAppName(const char* application_name);
246 bool SetPrivateBrowsing(bool incognito);
247 bool GetPrivateBrowsing() const;
248 const char* GetUserAgent() const;
249 const char* GetUserAgentAppName() const;
250 const char* CacheSelectedText();
251 Ewk_Settings* GetSettings() { return settings_.get(); }
252 _Ewk_Frame* GetMainFrame();
253 void UpdateWebKitPreferences();
254 void LoadHTMLString(const char* html,
255 const char* base_uri,
256 const char* unreachable_uri);
257 void LoadPlainTextString(const char* plain_text);
258 void LoadData(const char* data,
260 const char* mime_type,
261 const char* encoding,
262 const char* base_uri,
263 const char* unreachable_uri = NULL);
265 void InvokeLoadError(const GURL& url, int error_code, bool is_cancellation);
267 void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
269 void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
271 const std::string& realm);
272 void Find(const char* text, Ewk_Find_Options);
273 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
274 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
275 void ShowPopupMenu(const std::vector<blink::MenuItemInfo>& items,
278 Eina_Bool HidePopupMenu();
279 void UpdateFormNavigation(int formElementCount,
280 int currentNodeIndex,
283 void FormNavigate(bool direction);
284 bool IsSelectPickerShown() const;
285 void CloseSelectPicker();
286 bool FormIsNavigating() const { return formIsNavigating_; }
287 void SetFormIsNavigating(bool formIsNavigating);
288 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
289 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
290 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
291 Eina_Bool PopupMenuClose();
292 void HandleLongPressGesture(const content::ContextMenuParams&);
293 void ShowContextMenu(const content::ContextMenuParams&);
294 void CancelContextMenu(int request_id);
295 void SetScale(double scale_factor);
296 bool GetScrollPosition(int* x, int* y) const;
297 void SetScroll(int x, int y);
298 void UrlRequestSet(const char* url,
299 content::NavigationController::LoadURLType loadtype,
303 content::SelectionControllerEfl* GetSelectionController() const;
304 content::PopupControllerEfl* GetPopupController() const {
305 return popup_controller_.get();
307 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
308 void MoveCaret(const gfx::Point& point);
309 void QuerySelectionStyle();
310 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
311 void SelectLinkText(const gfx::Point& touch_point);
312 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
313 Eina_Bool ClearSelection();
315 // Callback OnCopyFromBackingStore will be called once we get the snapshot
317 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
319 void RenderViewCreated(content::RenderViewHost* render_view_host);
322 * Creates a snapshot of given rectangle from EWebView
324 * @param rect rectangle of EWebView which will be taken into snapshot
325 * @param scale_factor scale factor
326 * @return created snapshot or NULL if error occured.
327 * @note ownership of snapshot is passed to caller
329 Evas_Object* GetSnapshot(Eina_Rectangle rect, float scale_factor);
331 bool GetSnapshotAsync(Eina_Rectangle rect,
332 Ewk_Web_App_Screenshot_Captured_Callback callback,
335 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision,
337 void InvokePolicyNavigationCallback(const NavigationPolicyParams& params,
339 void UseSettingsFont();
341 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
342 Eina_Bool AsyncRequestHitTestDataAt(int x,
344 Ewk_Hit_Test_Mode mode,
345 Ewk_View_Hit_Test_Request_Callback,
347 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
349 Ewk_Hit_Test_Mode mode);
350 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
353 Ewk_Hit_Test_Mode mode,
354 Ewk_View_Hit_Test_Request_Callback,
356 void DispatchAsyncHitTestData(const Hit_Test_Params& params,
358 void UpdateHitTestData(const Hit_Test_Params& params);
360 int current_find_request_id() const { return current_find_request_id_; }
361 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
362 void InvokePlainTextGetCallback(const std::string& content_text,
363 int plain_text_get_callback_id);
364 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
366 void SetViewGeolocationPermissionCallback(
367 Ewk_View_Geolocation_Permission_Callback callback,
369 bool InvokeViewGeolocationPermissionCallback(
370 _Ewk_Geolocation_Permission_Request*
371 geolocation_permission_request_context,
373 void SetViewUserMediaPermissionCallback(
374 Ewk_View_User_Media_Permission_Callback callback,
376 bool InvokeViewUserMediaPermissionCallback(
377 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
379 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
381 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
383 void DidChangeContentsSize(int width, int height);
384 const Eina_Rectangle GetContentsSize() const;
385 void GetScrollSize(int* w, int* h);
387 void SetProgressValue(double progress);
388 double GetProgressValue();
389 const char* GetTitle();
390 bool SaveAsPdf(int width, int height, const std::string& file_name);
391 void BackForwardListClear();
392 _Ewk_Back_Forward_List* GetBackForwardList() const;
393 void InvokeBackForwardListChangedCallback();
394 _Ewk_History* GetBackForwardHistory() const;
395 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
397 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
399 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
401 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
402 void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
404 void InvokeWebAppIconUrlsGetCallback(
405 const std::map<std::string, std::string>& iconUrls,
407 void SetNotificationPermissionCallback(
408 Ewk_View_Notification_Permission_Callback callback,
410 bool IsNotificationPermissionCallbackSet() const;
411 bool InvokeNotificationPermissionCallback(
412 Ewk_Notification_Permission_Request* request);
414 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
415 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
417 void ExitFullscreen();
419 void DidChangePageScaleFactor(double scale_factor);
420 void SetScaledContentsSize();
421 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
423 void JavaScriptAlertReply();
424 void SetJavaScriptConfirmCallback(
425 Ewk_View_JavaScript_Confirm_Callback callback,
427 void JavaScriptConfirmReply(bool result);
428 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
430 void JavaScriptPromptReply(const char* result);
431 void set_renderer_crashed();
432 void GetPageScaleRange(double* min_scale, double* max_scale);
433 void SetDrawsTransparentBackground(bool enabled);
434 void GetSessionData(const char** data, unsigned* length) const;
435 bool RestoreFromSessionData(const char* data, unsigned length);
436 void ShowFileChooser(content::RenderFrameHost* render_frame_host,
437 const blink::mojom::FileChooserParams&);
438 void SetBrowserFont();
439 void SetCertificatePem(const std::string& certificate);
440 bool IsDragging() const;
442 void RequestColorPicker(int r, int g, int b, int a);
443 bool SetColorPickerColor(int r, int g, int b, int a);
444 void InputPickerShow(ui::TextInputType input_type,
446 content::DateTimeChooserEfl* date_time_chooser);
448 void ShowContentsDetectedPopup(const char*);
450 // Returns TCP port number with Inspector, or 0 if error.
451 int StartInspectorServer(int port = 0);
452 bool StopInspectorServer();
454 void LoadNotFoundErrorPage(const std::string& invalidUrl);
455 static std::string GetPlatformLocale();
456 bool GetLinkMagnifierEnabled() const;
457 void SetLinkMagnifierEnabled(bool enabled);
459 void SetOverrideEncoding(const std::string& encoding);
460 void SetQuotaPermissionRequestCallback(
461 Ewk_Quota_Permission_Request_Callback callback,
463 void InvokeQuotaPermissionRequest(
464 _Ewk_Quota_Permission_Request* request,
465 content::QuotaPermissionContext::PermissionCallback cb);
466 void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
468 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
469 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
470 void SetViewMode(blink::WebViewMode view_mode);
472 gfx::Point GetContextMenuPosition() const;
474 content::ContextMenuControllerEfl* GetContextMenuController() {
475 return context_menu_.get();
477 void ResetContextMenuController();
479 /// ---- Event handling
482 bool HandleMove(int x, int y);
483 bool HandleResize(int width, int height);
484 bool HandleTextSelectionDown(int x, int y);
485 bool HandleTextSelectionUp(int x, int y);
487 void HandleRendererProcessCrash();
488 void InvokeWebProcessCrashedCallback();
490 void HandleTapGestureForSelection(bool is_content_editable);
491 void HandleZoomGesture(blink::WebGestureEvent& event);
494 void RequestManifest(Ewk_View_Request_Manifest_Callback callback,
496 void DidRespondRequestManifest(_Ewk_View_Request_Manifest* manifest,
497 Ewk_View_Request_Manifest_Callback callback,
500 void SyncAcceptLanguages(const std::string& accept_languages);
502 void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
503 const gfx::Vector2dF& latest_overscroll_delta);
505 content::DateTimeChooserEfl* GetDateTimeChooser() {
506 return date_time_chooser_;
510 void InitializeContent();
511 void InitializeWindowTreeHost();
512 void SendDelayedMessages(content::RenderViewHost* render_view_host);
514 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
515 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
518 Ewk_Hit_Test_Mode mode,
519 WebViewAsyncRequestHitTestDataCallback* cb);
520 #if BUILDFLAG(IS_TIZEN) && !defined(EWK_BRINGUP)
521 static void cameraResultCb(service_h request,
523 service_result_e result,
527 #if BUILDFLAG(IS_TIZEN) && !defined(EWK_BRINGUP)
528 bool LaunchCamera(std::u16string mimetype);
530 #if !defined(USE_AURA)
531 content::RenderWidgetHostViewEfl* rwhv() const;
533 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
535 void ReleasePopupMenuList();
537 void ShowContextMenuInternal(const content::ContextMenuParams&);
539 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
541 void ChangeScroll(int& x, int& y);
543 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
544 scoped_refptr<Ewk_Context> context_;
545 scoped_refptr<Ewk_Context> old_context_;
546 std::unique_ptr<content::WebContents> web_contents_;
547 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
548 std::string pending_url_request_;
549 std::unique_ptr<Ewk_Settings> settings_;
550 std::unique_ptr<_Ewk_Frame> frame_;
551 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
552 Evas_Object* evas_object_;
553 Evas_Object* native_view_;
554 bool touch_events_enabled_;
555 bool mouse_events_enabled_;
556 double text_zoom_factor_;
557 mutable std::string user_agent_;
558 mutable std::string user_agent_app_name_;
559 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
560 std::string selected_text_cached_;
562 Eina_List* popupMenuItems_;
563 Popup_Picker* popupPicker_;
564 bool formIsNavigating_;
571 formNavigation formNavigation_;
572 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
573 #if !defined(EWK_BRINGUP) // FIXME: m71 bringup
574 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
576 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
577 std::u16string previous_text_;
578 int current_find_request_id_;
579 static int find_request_id_counter_;
581 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
582 EwkViewPlainTextGetCallback;
583 base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
585 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
586 MHTMLCallbackDetails;
587 base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
589 gfx::Size contents_size_;
591 mutable std::string title_;
592 mutable std::string pem_certificate_;
593 Hit_Test_Params hit_test_params_;
594 base::WaitableEvent hit_test_completion_;
595 double page_scale_factor_;
599 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
600 _Ewk_Geolocation_Permission_Request*>
601 geolocation_permission_cb_;
602 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
603 _Ewk_User_Media_Permission_Request*>
604 user_media_permission_cb_;
605 WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
607 WebViewCallback<Ewk_View_Notification_Permission_Callback,
608 Ewk_Notification_Permission_Request*>
609 notification_permission_callback_;
610 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
611 const _Ewk_Quota_Permission_Request*>
612 quota_request_callback_;
613 WebViewCallback<Ewk_View_Authentication_Callback, _Ewk_Auth_Challenge*>
616 std::unique_ptr<content::InputPicker> input_picker_;
617 base::IDMap<WebApplicationIconUrlGetCallback*>
618 web_app_icon_url_get_callback_map_;
619 base::IDMap<WebApplicationIconUrlsGetCallback*>
620 web_app_icon_urls_get_callback_map_;
621 base::IDMap<WebApplicationCapableGetCallback*>
622 web_app_capable_get_callback_map_;
623 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
624 std::unique_ptr<ScrollDetector> scroll_detector_;
626 #if BUILDFLAG(IS_TIZEN)
627 blink::mojom::FileChooserParams::Mode filechooser_mode_;
629 std::map<const _Ewk_Quota_Permission_Request*,
630 content::QuotaPermissionContext::PermissionCallback>
631 quota_permission_request_map_;
633 bool is_initialized_;
635 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
637 static content::WebContentsEflDelegate::WebContentsCreateCallback
638 create_new_window_web_contents_cb_;
641 gfx::Vector2d previous_scroll_position_;
643 gfx::Point context_menu_position_;
645 std::vector<IPC::Message*> delayed_messages_;
647 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
649 content::ContentBrowserClientEfl::AcceptLangsChangedCallback
650 accept_langs_changed_callback_;
652 std::unique_ptr<aura::WindowTreeHost> host_;
653 std::unique_ptr<aura::client::FocusClient> focus_client_;
654 std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_;
655 content::DateTimeChooserEfl* date_time_chooser_ = nullptr;
658 const unsigned int g_default_tilt_motion_sensitivity = 3;