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/aura/window_tree_host.h"
53 #include "ui/gfx/geometry/point.h"
54 #include "ui/gfx/geometry/size.h"
55 #include "web_contents_delegate_efl.h"
60 class WindowParentingClient;
65 class RenderFrameHost;
67 class RenderWidgetHostViewAura;
68 class WebContentsDelegateEfl;
69 class ContextMenuControllerEfl;
70 class PopupControllerEfl;
74 class _Ewk_Policy_Decision;
77 class WebViewEvasEventHandler;
78 class _Ewk_Quota_Permission_Request;
80 template <typename CallbackPtr, typename CallbackParameter>
81 class WebViewCallback {
83 WebViewCallback() { Set(nullptr, nullptr); }
85 void Set(CallbackPtr cb, void* data) {
90 bool IsCallbackSet() const { return callback_; }
92 Eina_Bool Run(Evas_Object* webview,
93 CallbackParameter param,
94 Eina_Bool* callback_result) {
95 CHECK(callback_result);
96 if (IsCallbackSet()) {
97 *callback_result = callback_(webview, param, user_data_);
103 void Run(Evas_Object* webview, CallbackParameter param) {
105 callback_(webview, param, user_data_);
109 CallbackPtr callback_;
113 class WebApplicationIconUrlGetCallback {
115 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
117 : func_(func), user_data_(user_data) {}
118 void Run(const std::string& url) {
120 (func_)(url.c_str(), user_data_);
125 Ewk_Web_App_Icon_URL_Get_Callback func_;
129 class WebApplicationIconUrlsGetCallback {
131 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
133 : func_(func), user_data_(user_data) {}
134 void Run(const std::map<std::string, std::string>& urls) {
136 Eina_List* list = NULL;
137 for (std::map<std::string, std::string>::const_iterator it = urls.begin();
138 it != urls.end(); ++it) {
139 _Ewk_Web_App_Icon_Data* data =
140 ewkWebAppIconDataCreate(it->first, it->second);
141 list = eina_list_append(list, data);
143 (func_)(list, user_data_);
148 Ewk_Web_App_Icon_URLs_Get_Callback func_;
152 class WebApplicationCapableGetCallback {
154 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
156 : func_(func), user_data_(user_data) {}
157 void Run(bool capable) {
159 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
164 Ewk_Web_App_Capable_Get_Callback func_;
168 class WebViewAsyncRequestHitTestDataCallback;
169 class JavaScriptDialogManagerEfl;
170 class PermissionPopupManager;
174 static EWebView* FromEvasObject(Evas_Object* eo);
176 EWebView(Ewk_Context*, Evas_Object* smart_object);
179 // initialize data members and activate event handlers.
180 // call this once after created and before use
183 bool CreateNewWindow(
184 content::WebContentsEflDelegate::WebContentsCreateCallback);
185 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
187 content::RenderWidgetHostViewAura* rwhva() const;
188 Ewk_Context* context() const { return context_.get(); }
189 Evas_Object* evas_object() const { return evas_object_; }
190 Evas_Object* native_view() const { return native_view_; }
191 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
192 PermissionPopupManager* GetPermissionPopupManager() const {
193 return permission_popup_manager_.get();
196 content::WebContents& web_contents() const { return *web_contents_.get(); }
198 template <EWebViewCallbacks::CallbackType callbackType>
199 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
200 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
203 void set_magnifier(bool status);
206 void SetURL(const GURL& url);
207 const GURL& GetURL() const;
208 const GURL& GetOriginalURL() const;
210 void ReloadBypassingCache();
211 Eina_Bool CanGoBack();
212 Eina_Bool CanGoForward();
213 Eina_Bool HasFocus() const;
214 void SetFocus(Eina_Bool focus);
216 Eina_Bool GoForward();
220 double GetTextZoomFactor() const;
221 void SetTextZoomFactor(double text_zoom_factor);
222 double GetPageZoomFactor() const;
223 void SetPageZoomFactor(double page_zoom_factor);
224 void ExecuteEditCommand(const char* command, const char* value);
225 void SetOrientation(int orientation);
226 int GetOrientation();
227 bool TouchEventsEnabled() const;
228 void SetTouchEventsEnabled(bool enabled);
229 bool MouseEventsEnabled() const;
230 void SetMouseEventsEnabled(bool enabled);
231 void HandleTouchEvents(Ewk_Touch_Event_Type type,
232 const Eina_List* points,
233 const Evas_Modifier* modifiers);
236 bool ExecuteJavaScript(const char* script,
237 Ewk_View_Script_Execute_Callback callback,
239 bool SetUserAgent(const char* userAgent);
240 bool SetUserAgentAppName(const char* application_name);
241 bool SetPrivateBrowsing(bool incognito);
242 bool GetPrivateBrowsing() const;
243 const char* GetUserAgent() const;
244 const char* GetUserAgentAppName() const;
245 const char* GetSelectedText() const;
246 Ewk_Settings* GetSettings() { return settings_.get(); }
247 _Ewk_Frame* GetMainFrame();
248 void UpdateWebKitPreferences();
249 void LoadHTMLString(const char* html,
250 const char* base_uri,
251 const char* unreachable_uri);
252 void LoadPlainTextString(const char* plain_text);
253 void LoadData(const char* data,
255 const char* mime_type,
256 const char* encoding,
257 const char* base_uri,
258 const char* unreachable_uri = NULL);
260 void InvokeLoadError(const GURL& url,
262 const std::string& error_description,
265 void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
267 void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
269 const std::string& realm);
270 void Find(const char* text, Ewk_Find_Options);
271 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
272 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
273 void ShowPopupMenu(const std::vector<blink::MenuItemInfo>& items,
276 Eina_Bool HidePopupMenu();
277 void UpdateFormNavigation(int formElementCount,
278 int currentNodeIndex,
281 void FormNavigate(bool direction);
282 bool IsSelectPickerShown() const;
283 void CloseSelectPicker();
284 bool FormIsNavigating() const { return formIsNavigating_; }
285 void SetFormIsNavigating(bool formIsNavigating);
286 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
287 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
288 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
289 Eina_Bool PopupMenuClose();
290 void HandleLongPressGesture(const content::ContextMenuParams&);
291 void ShowContextMenu(const content::ContextMenuParams&);
292 void CancelContextMenu(int request_id);
293 void SetScale(double scale_factor, int x, int y);
294 bool GetScrollPosition(int* x, int* y) const;
295 void SetScroll(int x, int y);
296 void UrlRequestSet(const char* url,
297 content::NavigationController::LoadURLType loadtype,
301 content::SelectionControllerEfl* GetSelectionController() const;
302 content::PopupControllerEfl* GetPopupController() const {
303 return popup_controller_.get();
305 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
306 void MoveCaret(const gfx::Point& point);
307 void QuerySelectionStyle();
308 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
309 void SelectLinkText(const gfx::Point& touch_point);
310 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
311 Eina_Bool ClearSelection();
313 // Callback OnCopyFromBackingStore will be called once we get the snapshot
315 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
317 void RenderViewCreated(content::RenderViewHost* render_view_host);
320 * Creates a snapshot of given rectangle from EWebView
322 * @param rect rectangle of EWebView which will be taken into snapshot
324 * @return created snapshot or NULL if error occured.
325 * @note ownership of snapshot is passed to caller
327 Evas_Object* GetSnapshot(Eina_Rectangle rect);
329 bool GetSnapshotAsync(Eina_Rectangle rect,
330 Ewk_Web_App_Screenshot_Captured_Callback callback,
332 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
333 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
334 NavigationPolicyParams params,
336 void UseSettingsFont();
338 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
339 Eina_Bool AsyncRequestHitTestDataAt(int x,
341 Ewk_Hit_Test_Mode mode,
342 Ewk_View_Hit_Test_Request_Callback,
344 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
346 Ewk_Hit_Test_Mode mode);
347 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
350 Ewk_Hit_Test_Mode mode,
351 Ewk_View_Hit_Test_Request_Callback,
353 void DispatchAsyncHitTestData(const Hit_Test_Params& params,
355 void UpdateHitTestData(const Hit_Test_Params& params);
357 int current_find_request_id() const { return current_find_request_id_; }
358 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
359 void InvokePlainTextGetCallback(const std::string& content_text,
360 int plain_text_get_callback_id);
361 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
363 void SetViewGeolocationPermissionCallback(
364 Ewk_View_Geolocation_Permission_Callback callback,
366 bool InvokeViewGeolocationPermissionCallback(
367 _Ewk_Geolocation_Permission_Request*
368 geolocation_permission_request_context,
370 void SetViewUserMediaPermissionCallback(
371 Ewk_View_User_Media_Permission_Callback callback,
373 bool InvokeViewUserMediaPermissionCallback(
374 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
376 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
378 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
380 void DidChangeContentsSize(int width, int height);
381 const Eina_Rectangle GetContentsSize() const;
382 void GetScrollSize(int* w, int* h);
384 void SetProgressValue(double progress);
385 double GetProgressValue();
386 const char* GetTitle();
387 bool SaveAsPdf(int width, int height, const std::string& file_name);
388 void BackForwardListClear();
389 _Ewk_Back_Forward_List* GetBackForwardList() const;
390 void InvokeBackForwardListChangedCallback();
391 _Ewk_History* GetBackForwardHistory() const;
392 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
394 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
396 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
398 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
399 void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
401 void InvokeWebAppIconUrlsGetCallback(
402 const std::map<std::string, std::string>& iconUrls,
404 void SetNotificationPermissionCallback(
405 Ewk_View_Notification_Permission_Callback callback,
407 bool IsNotificationPermissionCallbackSet() const;
408 bool InvokeNotificationPermissionCallback(
409 Ewk_Notification_Permission_Request* request);
411 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
412 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
414 void ExitFullscreen();
416 void DidChangePageScaleFactor(double scale_factor);
417 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
419 void JavaScriptAlertReply();
420 void SetJavaScriptConfirmCallback(
421 Ewk_View_JavaScript_Confirm_Callback callback,
423 void JavaScriptConfirmReply(bool result);
424 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
426 void JavaScriptPromptReply(const char* result);
427 void set_renderer_crashed();
428 void GetPageScaleRange(double* min_scale, double* max_scale);
429 void SetDrawsTransparentBackground(bool enabled);
430 void GetSessionData(const char** data, unsigned* length) const;
431 bool RestoreFromSessionData(const char* data, unsigned length);
432 void ShowFileChooser(content::RenderFrameHost* render_frame_host,
433 const blink::mojom::FileChooserParams&);
434 void SetBrowserFont();
435 void SetCertificatePem(const std::string& certificate);
436 bool IsDragging() const;
438 void RequestColorPicker(int r, int g, int b, int a);
439 void DismissColorPicker();
440 bool SetColorPickerColor(int r, int g, int b, int a);
441 void InputPickerShow(ui::TextInputType input_type, double input_value);
443 void ShowContentsDetectedPopup(const char*);
445 // Returns TCP port number with Inspector, or 0 if error.
446 int StartInspectorServer(int port = 0);
447 bool StopInspectorServer();
449 void LoadNotFoundErrorPage(const std::string& invalidUrl);
450 static std::string GetPlatformLocale();
451 bool GetLinkMagnifierEnabled() const;
452 void SetLinkMagnifierEnabled(bool enabled);
454 void SetOverrideEncoding(const std::string& encoding);
455 void SetQuotaPermissionRequestCallback(
456 Ewk_Quota_Permission_Request_Callback callback,
458 void InvokeQuotaPermissionRequest(
459 _Ewk_Quota_Permission_Request* request,
460 content::QuotaPermissionContext::PermissionCallback cb);
461 void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
463 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
464 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
465 void SetViewMode(blink::WebViewMode view_mode);
467 gfx::Point GetContextMenuPosition() const;
469 content::ContextMenuControllerEfl* GetContextMenuController() {
470 return context_menu_.get();
472 void ResetContextMenuController();
474 /// ---- Event handling
477 bool HandleMove(int x, int y);
478 bool HandleResize(int width, int height);
479 bool HandleTextSelectionDown(int x, int y);
480 bool HandleTextSelectionUp(int x, int y);
482 void HandleRendererProcessCrash();
483 void InvokeWebProcessCrashedCallback();
485 void HandleTapGestureForSelection(bool is_content_editable);
486 void HandleZoomGesture(blink::WebGestureEvent& event);
489 void SyncAcceptLanguages(const std::string& accept_languages);
491 void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
492 const gfx::Vector2dF& latest_overscroll_delta);
495 void InitializeContent();
496 void InitializeWindowTreeHost();
497 void SendDelayedMessages(content::RenderViewHost* render_view_host);
499 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
500 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
503 Ewk_Hit_Test_Mode mode,
504 WebViewAsyncRequestHitTestDataCallback* cb);
505 #if !defined(USE_AURA)
506 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
508 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
509 static void cameraResultCb(service_h request,
511 service_result_e result,
515 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
516 bool LaunchCamera(std::u16string mimetype);
518 #if !defined(USE_AURA)
519 content::RenderWidgetHostViewEfl* rwhv() const;
521 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
523 void ReleasePopupMenuList();
525 void ShowContextMenuInternal(const content::ContextMenuParams&);
527 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
529 void ChangeScroll(int& x, int& y);
531 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
532 scoped_refptr<Ewk_Context> context_;
533 scoped_refptr<Ewk_Context> old_context_;
534 std::unique_ptr<content::WebContents> web_contents_;
535 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
536 std::string pending_url_request_;
537 std::unique_ptr<Ewk_Settings> settings_;
538 std::unique_ptr<_Ewk_Frame> frame_;
539 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
540 Evas_Object* evas_object_;
541 Evas_Object* native_view_;
542 bool touch_events_enabled_;
543 bool mouse_events_enabled_;
544 double text_zoom_factor_;
545 mutable std::string user_agent_;
546 mutable std::string user_agent_app_name_;
547 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
549 Eina_List* popupMenuItems_;
550 Popup_Picker* popupPicker_;
551 bool formIsNavigating_;
558 formNavigation formNavigation_;
559 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
560 #if !defined(EWK_BRINGUP) // FIXME: m71 bringup
561 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
563 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
564 std::u16string previous_text_;
565 int current_find_request_id_;
566 static int find_request_id_counter_;
568 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
569 EwkViewPlainTextGetCallback;
570 base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
572 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
573 MHTMLCallbackDetails;
574 base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
576 gfx::Size contents_size_;
578 mutable std::string title_;
579 mutable std::string pem_certificate_;
580 Hit_Test_Params hit_test_params_;
581 base::WaitableEvent hit_test_completion_;
582 double page_scale_factor_;
586 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
587 _Ewk_Geolocation_Permission_Request*>
588 geolocation_permission_cb_;
589 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
590 _Ewk_User_Media_Permission_Request*>
591 user_media_permission_cb_;
592 WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
594 WebViewCallback<Ewk_View_Notification_Permission_Callback,
595 Ewk_Notification_Permission_Request*>
596 notification_permission_callback_;
597 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
598 const _Ewk_Quota_Permission_Request*>
599 quota_request_callback_;
600 WebViewCallback<Ewk_View_Authentication_Callback, _Ewk_Auth_Challenge*>
603 std::unique_ptr<content::InputPicker> inputPicker_;
604 base::IDMap<WebApplicationIconUrlGetCallback*>
605 web_app_icon_url_get_callback_map_;
606 base::IDMap<WebApplicationIconUrlsGetCallback*>
607 web_app_icon_urls_get_callback_map_;
608 base::IDMap<WebApplicationCapableGetCallback*>
609 web_app_capable_get_callback_map_;
610 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
611 std::unique_ptr<ScrollDetector> scroll_detector_;
613 #if defined(OS_TIZEN)
614 blink::mojom::FileChooserParams::Mode filechooser_mode_;
616 std::map<const _Ewk_Quota_Permission_Request*,
617 content::QuotaPermissionContext::PermissionCallback>
618 quota_permission_request_map_;
620 bool is_initialized_;
622 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
624 static content::WebContentsEflDelegate::WebContentsCreateCallback
625 create_new_window_web_contents_cb_;
628 gfx::Vector2d previous_scroll_position_;
630 gfx::Point context_menu_position_;
632 std::vector<IPC::Message*> delayed_messages_;
634 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
636 content::ContentBrowserClientEfl::AcceptLangsChangedCallback
637 accept_langs_changed_callback_;
639 std::unique_ptr<aura::WindowTreeHost> host_;
640 std::unique_ptr<aura::client::FocusClient> focus_client_;
641 std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_;
644 const unsigned int g_default_tilt_motion_sensitivity = 3;