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 WebContentsDelegateEfl;
68 class ContextMenuControllerEfl;
69 class PopupControllerEfl;
73 class _Ewk_Policy_Decision;
76 class WebViewEvasEventHandler;
77 class _Ewk_Quota_Permission_Request;
79 template <typename CallbackPtr, typename CallbackParameter>
80 class WebViewCallback {
82 WebViewCallback() { Set(nullptr, nullptr); }
84 void Set(CallbackPtr cb, void* data) {
89 bool IsCallbackSet() const { return callback_; }
91 Eina_Bool Run(Evas_Object* webview,
92 CallbackParameter param,
93 Eina_Bool* callback_result) {
94 CHECK(callback_result);
95 if (IsCallbackSet()) {
96 *callback_result = callback_(webview, param, user_data_);
102 void Run(Evas_Object* webview, CallbackParameter param) {
104 callback_(webview, param, user_data_);
108 CallbackPtr callback_;
112 class WebApplicationIconUrlGetCallback {
114 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
116 : func_(func), user_data_(user_data) {}
117 void Run(const std::string& url) {
119 (func_)(url.c_str(), user_data_);
124 Ewk_Web_App_Icon_URL_Get_Callback func_;
128 class WebApplicationIconUrlsGetCallback {
130 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
132 : func_(func), user_data_(user_data) {}
133 void Run(const std::map<std::string, std::string>& urls) {
135 Eina_List* list = NULL;
136 for (std::map<std::string, std::string>::const_iterator it = urls.begin();
137 it != urls.end(); ++it) {
138 _Ewk_Web_App_Icon_Data* data =
139 ewkWebAppIconDataCreate(it->first, it->second);
140 list = eina_list_append(list, data);
142 (func_)(list, user_data_);
147 Ewk_Web_App_Icon_URLs_Get_Callback func_;
151 class WebApplicationCapableGetCallback {
153 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
155 : func_(func), user_data_(user_data) {}
156 void Run(bool capable) {
158 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
163 Ewk_Web_App_Capable_Get_Callback func_;
167 class WebViewAsyncRequestHitTestDataCallback;
168 class JavaScriptDialogManagerEfl;
169 class PermissionPopupManager;
173 static EWebView* FromEvasObject(Evas_Object* eo);
175 EWebView(Ewk_Context*, Evas_Object* smart_object);
178 // initialize data members and activate event handlers.
179 // call this once after created and before use
182 void CreateNewWindow(
183 content::WebContentsEflDelegate::WebContentsCreateCallback);
184 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
186 Ewk_Context* context() const { return context_.get(); }
187 Evas_Object* evas_object() const { return evas_object_; }
188 Evas_Object* native_view() const { return native_view_; }
189 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
190 PermissionPopupManager* GetPermissionPopupManager() const {
191 return permission_popup_manager_.get();
194 content::WebContents& web_contents() const { return *web_contents_.get(); }
196 template <EWebViewCallbacks::CallbackType callbackType>
197 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
198 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
201 void set_magnifier(bool status);
204 void SetURL(const GURL& url);
205 const GURL& GetURL() const;
206 const GURL& GetOriginalURL() const;
208 void ReloadBypassingCache();
209 Eina_Bool CanGoBack();
210 Eina_Bool CanGoForward();
211 Eina_Bool HasFocus() const;
212 void SetFocus(Eina_Bool focus);
214 Eina_Bool GoForward();
218 double GetTextZoomFactor() const;
219 void SetTextZoomFactor(double text_zoom_factor);
220 double GetPageZoomFactor() const;
221 void SetPageZoomFactor(double page_zoom_factor);
222 void ExecuteEditCommand(const char* command, const char* value);
223 void SetOrientation(int orientation);
224 int GetOrientation();
225 bool TouchEventsEnabled() const;
226 void SetTouchEventsEnabled(bool enabled);
227 bool MouseEventsEnabled() const;
228 void SetMouseEventsEnabled(bool enabled);
229 void HandleTouchEvents(Ewk_Touch_Event_Type type,
230 const Eina_List* points,
231 const Evas_Modifier* modifiers);
234 bool ExecuteJavaScript(const char* script,
235 Ewk_View_Script_Execute_Callback callback,
237 bool SetUserAgent(const char* userAgent);
238 bool SetUserAgentAppName(const char* application_name);
239 bool SetPrivateBrowsing(bool incognito);
240 bool GetPrivateBrowsing() const;
241 const char* GetUserAgent() const;
242 const char* GetUserAgentAppName() const;
243 const char* GetSelectedText() const;
244 Ewk_Settings* GetSettings() { return settings_.get(); }
245 _Ewk_Frame* GetMainFrame();
246 void UpdateWebKitPreferences();
247 void LoadHTMLString(const char* html,
248 const char* base_uri,
249 const char* unreachable_uri);
250 void LoadPlainTextString(const char* plain_text);
251 void LoadData(const char* data,
253 const char* mime_type,
254 const char* encoding,
255 const char* base_uri,
256 const char* unreachable_uri = NULL);
258 void InvokeLoadError(const GURL& url,
260 const std::string& error_description,
263 void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
265 void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
267 const std::string& realm);
268 void Find(const char* text, Ewk_Find_Options);
269 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
270 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
271 void ShowPopupMenu(const std::vector<blink::MenuItemInfo>& items,
274 Eina_Bool HidePopupMenu();
275 void UpdateFormNavigation(int formElementCount,
276 int currentNodeIndex,
279 void FormNavigate(bool direction);
280 bool IsSelectPickerShown() const;
281 void CloseSelectPicker();
282 bool FormIsNavigating() const { return formIsNavigating_; }
283 void SetFormIsNavigating(bool formIsNavigating);
284 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
285 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
286 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
287 Eina_Bool PopupMenuClose();
288 void HandleLongPressGesture(const content::ContextMenuParams&);
289 void ShowContextMenu(const content::ContextMenuParams&);
290 void CancelContextMenu(int request_id);
291 void SetScale(double scale_factor, int x, int y);
292 bool GetScrollPosition(int* x, int* y) const;
293 void SetScroll(int x, int y);
294 void UrlRequestSet(const char* url,
295 content::NavigationController::LoadURLType loadtype,
299 content::SelectionControllerEfl* GetSelectionController() const;
300 content::PopupControllerEfl* GetPopupController() const {
301 return popup_controller_.get();
303 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
304 void MoveCaret(const gfx::Point& point);
305 void QuerySelectionStyle();
306 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
307 void SelectLinkText(const gfx::Point& touch_point);
308 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
309 Eina_Bool ClearSelection();
311 // Callback OnCopyFromBackingStore will be called once we get the snapshot
313 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
315 void RenderViewCreated(content::RenderViewHost* render_view_host);
318 * Creates a snapshot of given rectangle from EWebView
320 * @param rect rectangle of EWebView which will be taken into snapshot
322 * @return created snapshot or NULL if error occured.
323 * @note ownership of snapshot is passed to caller
325 Evas_Object* GetSnapshot(Eina_Rectangle rect);
327 bool GetSnapshotAsync(Eina_Rectangle rect,
328 Ewk_Web_App_Screenshot_Captured_Callback callback,
330 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
331 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
332 NavigationPolicyParams params,
334 void UseSettingsFont();
336 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
337 Eina_Bool AsyncRequestHitTestDataAt(int x,
339 Ewk_Hit_Test_Mode mode,
340 Ewk_View_Hit_Test_Request_Callback,
342 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
344 Ewk_Hit_Test_Mode mode);
345 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
348 Ewk_Hit_Test_Mode mode,
349 Ewk_View_Hit_Test_Request_Callback,
351 void DispatchAsyncHitTestData(const Hit_Test_Params& params,
353 void UpdateHitTestData(const Hit_Test_Params& params);
355 int current_find_request_id() const { return current_find_request_id_; }
356 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
357 void InvokePlainTextGetCallback(const std::string& content_text,
358 int plain_text_get_callback_id);
359 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
361 void SetViewGeolocationPermissionCallback(
362 Ewk_View_Geolocation_Permission_Callback callback,
364 bool InvokeViewGeolocationPermissionCallback(
365 _Ewk_Geolocation_Permission_Request*
366 geolocation_permission_request_context,
368 void SetViewUserMediaPermissionCallback(
369 Ewk_View_User_Media_Permission_Callback callback,
371 bool InvokeViewUserMediaPermissionCallback(
372 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
374 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
376 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
378 void DidChangeContentsSize(int width, int height);
379 const Eina_Rectangle GetContentsSize() const;
380 void GetScrollSize(int* w, int* h);
382 void SetProgressValue(double progress);
383 double GetProgressValue();
384 const char* GetTitle();
385 bool SaveAsPdf(int width, int height, const std::string& file_name);
386 void BackForwardListClear();
387 _Ewk_Back_Forward_List* GetBackForwardList() const;
388 void InvokeBackForwardListChangedCallback();
389 _Ewk_History* GetBackForwardHistory() const;
390 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
392 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
394 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
396 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
397 void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
399 void InvokeWebAppIconUrlsGetCallback(
400 const std::map<std::string, std::string>& iconUrls,
402 void SetNotificationPermissionCallback(
403 Ewk_View_Notification_Permission_Callback callback,
405 bool IsNotificationPermissionCallbackSet() const;
406 bool InvokeNotificationPermissionCallback(
407 Ewk_Notification_Permission_Request* request);
409 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
410 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
412 void ExitFullscreen();
414 void DidChangePageScaleFactor(double scale_factor);
415 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
417 void JavaScriptAlertReply();
418 void SetJavaScriptConfirmCallback(
419 Ewk_View_JavaScript_Confirm_Callback callback,
421 void JavaScriptConfirmReply(bool result);
422 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
424 void JavaScriptPromptReply(const char* result);
425 void set_renderer_crashed();
426 void GetPageScaleRange(double* min_scale, double* max_scale);
427 void SetDrawsTransparentBackground(bool enabled);
428 void GetSessionData(const char** data, unsigned* length) const;
429 bool RestoreFromSessionData(const char* data, unsigned length);
430 void ShowFileChooser(content::RenderFrameHost* render_frame_host,
431 const blink::mojom::FileChooserParams&);
432 void SetBrowserFont();
433 void SetCertificatePem(const std::string& certificate);
434 bool IsDragging() const;
436 void RequestColorPicker(int r, int g, int b, int a);
437 void DismissColorPicker();
438 bool SetColorPickerColor(int r, int g, int b, int a);
439 void InputPickerShow(ui::TextInputType input_type, double input_value);
441 void ShowContentsDetectedPopup(const char*);
443 // Returns TCP port number with Inspector, or 0 if error.
444 int StartInspectorServer(int port = 0);
445 bool StopInspectorServer();
447 void LoadNotFoundErrorPage(const std::string& invalidUrl);
448 static std::string GetPlatformLocale();
449 bool GetLinkMagnifierEnabled() const;
450 void SetLinkMagnifierEnabled(bool enabled);
452 void SetOverrideEncoding(const std::string& encoding);
453 void SetQuotaPermissionRequestCallback(
454 Ewk_Quota_Permission_Request_Callback callback,
456 void InvokeQuotaPermissionRequest(
457 _Ewk_Quota_Permission_Request* request,
458 content::QuotaPermissionContext::PermissionCallback cb);
459 void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
461 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
462 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
463 void SetViewMode(blink::WebViewMode view_mode);
465 gfx::Point GetContextMenuPosition() const;
467 content::ContextMenuControllerEfl* GetContextMenuController() {
468 return context_menu_.get();
470 void ResetContextMenuController();
472 /// ---- Event handling
475 bool HandleMove(int x, int y);
476 bool HandleResize(int width, int height);
477 bool HandleTextSelectionDown(int x, int y);
478 bool HandleTextSelectionUp(int x, int y);
480 void HandleRendererProcessCrash();
481 void InvokeWebProcessCrashedCallback();
483 void HandleTapGestureForSelection(bool is_content_editable);
484 void HandleZoomGesture(blink::WebGestureEvent& event);
487 void SyncAcceptLanguages(const std::string& accept_languages);
489 void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
490 const gfx::Vector2dF& latest_overscroll_delta);
493 void InitializeContent();
494 void InitializeWindowTreeHost();
495 void SendDelayedMessages(content::RenderViewHost* render_view_host);
497 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
498 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
501 Ewk_Hit_Test_Mode mode,
502 WebViewAsyncRequestHitTestDataCallback* cb);
503 #if !defined(USE_AURA)
504 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
506 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
507 static void cameraResultCb(service_h request,
509 service_result_e result,
513 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
514 bool LaunchCamera(std::u16string mimetype);
516 #if !defined(USE_AURA)
517 content::RenderWidgetHostViewEfl* rwhv() const;
519 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
521 void ReleasePopupMenuList();
523 void ShowContextMenuInternal(const content::ContextMenuParams&);
525 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
527 void ChangeScroll(int& x, int& y);
529 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
530 scoped_refptr<Ewk_Context> context_;
531 scoped_refptr<Ewk_Context> old_context_;
532 std::unique_ptr<content::WebContents> web_contents_;
533 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
534 std::string pending_url_request_;
535 std::unique_ptr<Ewk_Settings> settings_;
536 std::unique_ptr<_Ewk_Frame> frame_;
537 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
538 Evas_Object* evas_object_;
539 Evas_Object* native_view_;
540 bool touch_events_enabled_;
541 bool mouse_events_enabled_;
542 double text_zoom_factor_;
543 mutable std::string user_agent_;
544 mutable std::string user_agent_app_name_;
545 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
547 Eina_List* popupMenuItems_;
548 Popup_Picker* popupPicker_;
549 bool formIsNavigating_;
556 formNavigation formNavigation_;
557 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
558 #if !defined(EWK_BRINGUP) // FIXME: m71 bringup
559 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
561 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
562 std::u16string previous_text_;
563 int current_find_request_id_;
564 static int find_request_id_counter_;
566 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
567 EwkViewPlainTextGetCallback;
568 base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
570 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
571 MHTMLCallbackDetails;
572 base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
574 gfx::Size contents_size_;
576 mutable std::string title_;
577 mutable std::string pem_certificate_;
578 Hit_Test_Params hit_test_params_;
579 base::WaitableEvent hit_test_completion_;
580 double page_scale_factor_;
584 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
585 _Ewk_Geolocation_Permission_Request*>
586 geolocation_permission_cb_;
587 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
588 _Ewk_User_Media_Permission_Request*>
589 user_media_permission_cb_;
590 WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
592 WebViewCallback<Ewk_View_Notification_Permission_Callback,
593 Ewk_Notification_Permission_Request*>
594 notification_permission_callback_;
595 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
596 const _Ewk_Quota_Permission_Request*>
597 quota_request_callback_;
598 WebViewCallback<Ewk_View_Authentication_Callback, _Ewk_Auth_Challenge*>
601 std::unique_ptr<content::InputPicker> inputPicker_;
602 base::IDMap<WebApplicationIconUrlGetCallback*>
603 web_app_icon_url_get_callback_map_;
604 base::IDMap<WebApplicationIconUrlsGetCallback*>
605 web_app_icon_urls_get_callback_map_;
606 base::IDMap<WebApplicationCapableGetCallback*>
607 web_app_capable_get_callback_map_;
608 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
609 std::unique_ptr<ScrollDetector> scroll_detector_;
611 #if defined(OS_TIZEN)
612 blink::mojom::FileChooserParams::Mode filechooser_mode_;
614 std::map<const _Ewk_Quota_Permission_Request*,
615 content::QuotaPermissionContext::PermissionCallback>
616 quota_permission_request_map_;
618 bool is_initialized_;
620 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
622 static content::WebContentsEflDelegate::WebContentsCreateCallback
623 create_new_window_web_contents_cb_;
626 gfx::Vector2d previous_scroll_position_;
628 gfx::Point context_menu_position_;
630 std::vector<IPC::Message*> delayed_messages_;
632 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
634 content::ContentBrowserClientEfl::AcceptLangsChangedCallback
635 accept_langs_changed_callback_;
637 std::unique_ptr<aura::WindowTreeHost> host_;
638 std::unique_ptr<aura::client::FocusClient> focus_client_;
639 std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_;
642 const unsigned int g_default_tilt_motion_sensitivity = 3;