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/navigation_controller.h"
28 #include "content/public/browser/quota_permission_context.h"
29 #include "content/public/browser/web_contents_delegate.h"
30 #include "content/public/browser/web_contents_efl_delegate.h"
31 #include "content/public/common/context_menu_params.h"
32 #include "content/public/common/input_event_ack_state.h"
33 #include "content/public/common/menu_item.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/mojom/choosers/file_chooser.mojom.h"
51 #include "ui/gfx/geometry/point.h"
52 #include "ui/gfx/geometry/size.h"
53 #include "web_contents_delegate_efl.h"
56 class RenderFrameHost;
58 class RenderWidgetHostViewEfl;
59 class WebContentsDelegateEfl;
60 class ContextMenuControllerEfl;
61 class WebContentsViewEfl;
62 class PopupControllerEfl;
66 class _Ewk_Policy_Decision;
69 class WebViewEvasEventHandler;
70 class _Ewk_Quota_Permission_Request;
72 template <typename CallbackPtr, typename CallbackParameter>
73 class WebViewCallback {
75 WebViewCallback() { Set(nullptr, nullptr); }
77 void Set(CallbackPtr cb, void* data) {
82 bool IsCallbackSet() const { return callback_; }
84 Eina_Bool Run(Evas_Object* webview,
85 CallbackParameter param,
86 Eina_Bool* callback_result) {
87 CHECK(callback_result);
88 if (IsCallbackSet()) {
89 *callback_result = callback_(webview, param, user_data_);
95 void Run(Evas_Object* webview, CallbackParameter param) {
97 callback_(webview, param, user_data_);
101 CallbackPtr callback_;
105 class WebApplicationIconUrlGetCallback {
107 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
109 : func_(func), user_data_(user_data) {}
110 void Run(const std::string& url) {
112 (func_)(url.c_str(), user_data_);
117 Ewk_Web_App_Icon_URL_Get_Callback func_;
121 class WebApplicationIconUrlsGetCallback {
123 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
125 : func_(func), user_data_(user_data) {}
126 void Run(const std::map<std::string, std::string>& urls) {
128 Eina_List* list = NULL;
129 for (std::map<std::string, std::string>::const_iterator it = urls.begin();
130 it != urls.end(); ++it) {
131 _Ewk_Web_App_Icon_Data* data =
132 ewkWebAppIconDataCreate(it->first, it->second);
133 list = eina_list_append(list, data);
135 (func_)(list, user_data_);
140 Ewk_Web_App_Icon_URLs_Get_Callback func_;
144 class WebApplicationCapableGetCallback {
146 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
148 : func_(func), user_data_(user_data) {}
149 void Run(bool capable) {
151 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
156 Ewk_Web_App_Capable_Get_Callback func_;
160 class WebViewAsyncRequestHitTestDataCallback;
161 class JavaScriptDialogManagerEfl;
162 class PermissionPopupManager;
166 static EWebView* FromEvasObject(Evas_Object* eo);
167 static int GetOrientation();
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;
201 void ReloadBypassingCache();
202 Eina_Bool CanGoBack();
203 Eina_Bool CanGoForward();
204 Eina_Bool HasFocus() const;
205 void SetFocus(Eina_Bool focus);
207 Eina_Bool GoForward();
211 double GetTextZoomFactor() const;
212 void SetTextZoomFactor(double text_zoom_factor);
213 double GetPageZoomFactor() const;
214 void SetPageZoomFactor(double page_zoom_factor);
215 void ExecuteEditCommand(const char* command, const char* value);
216 void SetOrientation(int orientation);
217 bool TouchEventsEnabled() const;
218 void SetTouchEventsEnabled(bool enabled);
219 bool MouseEventsEnabled() const;
220 void SetMouseEventsEnabled(bool enabled);
221 void HandleTouchEvents(Ewk_Touch_Event_Type type,
222 const Eina_List* points,
223 const Evas_Modifier* modifiers);
226 bool ExecuteJavaScript(const char* script,
227 Ewk_View_Script_Execute_Callback callback,
229 bool SetUserAgent(const char* userAgent);
230 bool SetUserAgentAppName(const char* application_name);
231 bool SetPrivateBrowsing(bool incognito);
232 bool GetPrivateBrowsing() const;
233 const char* GetUserAgent() const;
234 const char* GetUserAgentAppName() const;
235 const char* GetSelectedText() const;
236 Ewk_Settings* GetSettings() { return settings_.get(); }
237 _Ewk_Frame* GetMainFrame();
238 void UpdateWebKitPreferences();
239 void LoadHTMLString(const char* html,
240 const char* base_uri,
241 const char* unreachable_uri);
242 void LoadPlainTextString(const char* plain_text);
243 void LoadData(const char* data,
245 const char* mime_type,
246 const char* encoding,
247 const char* base_uri,
248 const char* unreachable_uri = NULL);
250 void InvokeLoadError(const GURL& url,
252 const std::string& error_description,
254 void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
256 const std::string& realm);
257 void Find(const char* text, Ewk_Find_Options);
258 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
259 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
260 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
263 Eina_Bool HidePopupMenu();
264 void UpdateFormNavigation(int formElementCount,
265 int currentNodeIndex,
268 void FormNavigate(bool direction);
269 bool IsSelectPickerShown() const;
270 void CloseSelectPicker();
271 bool FormIsNavigating() const { return formIsNavigating_; }
272 void SetFormIsNavigating(bool formIsNavigating);
273 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
274 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
275 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
276 Eina_Bool PopupMenuClose();
277 void HandleLongPressGesture(const content::ContextMenuParams&);
278 void ShowContextMenu(const content::ContextMenuParams&);
279 void CancelContextMenu(int request_id);
280 void SetScale(double scale_factor, int x, int y);
281 bool GetScrollPosition(int* x, int* y) const;
282 void SetScroll(int x, int y);
283 void UrlRequestSet(const char* url,
284 content::NavigationController::LoadURLType loadtype,
288 content::SelectionControllerEfl* GetSelectionController() const;
289 content::PopupControllerEfl* GetPopupController() const {
290 return popup_controller_.get();
292 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
293 void MoveCaret(const gfx::Point& point);
294 void QuerySelectionStyle();
295 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
296 void SelectLinkText(const gfx::Point& touch_point);
297 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
298 Eina_Bool ClearSelection();
300 // Callback OnCopyFromBackingStore will be called once we get the snapshot
302 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
304 void RenderViewCreated(content::RenderViewHost* render_view_host);
307 * Creates a snapshot of given rectangle from EWebView
309 * @param rect rectangle of EWebView which will be taken into snapshot
311 * @return created snapshot or NULL if error occured.
312 * @note ownership of snapshot is passed to caller
314 Evas_Object* GetSnapshot(Eina_Rectangle rect);
316 bool GetSnapshotAsync(Eina_Rectangle rect,
317 Ewk_Web_App_Screenshot_Captured_Callback callback,
319 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
320 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
321 NavigationPolicyParams params,
323 void UseSettingsFont();
325 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
326 Eina_Bool AsyncRequestHitTestDataAt(int x,
328 Ewk_Hit_Test_Mode mode,
329 Ewk_View_Hit_Test_Request_Callback,
331 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
333 Ewk_Hit_Test_Mode mode);
334 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
337 Ewk_Hit_Test_Mode mode,
338 Ewk_View_Hit_Test_Request_Callback,
340 void DispatchAsyncHitTestData(const Hit_Test_Params& params,
342 void UpdateHitTestData(const Hit_Test_Params& params);
344 int current_find_request_id() const { return current_find_request_id_; }
345 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
346 void InvokePlainTextGetCallback(const std::string& content_text,
347 int plain_text_get_callback_id);
348 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
350 void SetViewGeolocationPermissionCallback(
351 Ewk_View_Geolocation_Permission_Callback callback,
353 bool InvokeViewGeolocationPermissionCallback(
354 _Ewk_Geolocation_Permission_Request*
355 geolocation_permission_request_context,
357 void SetViewUserMediaPermissionCallback(
358 Ewk_View_User_Media_Permission_Callback callback,
360 bool InvokeViewUserMediaPermissionCallback(
361 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
363 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
365 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
367 void DidChangeContentsSize(int width, int height);
368 const Eina_Rectangle GetContentsSize() const;
369 void GetScrollSize(int* w, int* h);
371 void SetProgressValue(double progress);
372 double GetProgressValue();
373 const char* GetTitle();
374 bool SaveAsPdf(int width, int height, const std::string& file_name);
375 void BackForwardListClear();
376 _Ewk_Back_Forward_List* GetBackForwardList() const;
377 void InvokeBackForwardListChangedCallback();
378 _Ewk_History* GetBackForwardHistory() const;
379 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
381 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
383 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
385 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
386 void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
388 void InvokeWebAppIconUrlsGetCallback(
389 const std::map<std::string, std::string>& iconUrls,
391 void SetNotificationPermissionCallback(
392 Ewk_View_Notification_Permission_Callback callback,
394 bool IsNotificationPermissionCallbackSet() const;
395 bool InvokeNotificationPermissionCallback(
396 Ewk_Notification_Permission_Request* request);
398 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
399 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
401 void ExitFullscreen();
403 void DidChangePageScaleFactor(double scale_factor);
404 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
406 void JavaScriptAlertReply();
407 void SetJavaScriptConfirmCallback(
408 Ewk_View_JavaScript_Confirm_Callback callback,
410 void JavaScriptConfirmReply(bool result);
411 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
413 void JavaScriptPromptReply(const char* result);
414 void set_renderer_crashed();
415 void GetPageScaleRange(double* min_scale, double* max_scale);
416 void SetDrawsTransparentBackground(bool enabled);
417 void GetSessionData(const char** data, unsigned* length) const;
418 bool RestoreFromSessionData(const char* data, unsigned length);
419 void ShowFileChooser(content::RenderFrameHost* render_frame_host,
420 const blink::mojom::FileChooserParams&);
421 void SetBrowserFont();
422 void SetCertificatePem(const std::string& certificate);
423 bool IsDragging() const;
425 void RequestColorPicker(int r, int g, int b, int a);
426 void DismissColorPicker();
427 bool SetColorPickerColor(int r, int g, int b, int a);
428 void InputPickerShow(ui::TextInputType input_type, double input_value);
430 void ShowContentsDetectedPopup(const char*);
432 // Returns TCP port number with Inspector, or 0 if error.
433 int StartInspectorServer(int port = 0);
434 bool StopInspectorServer();
436 void LoadNotFoundErrorPage(const std::string& invalidUrl);
437 static std::string GetPlatformLocale();
438 bool GetLinkMagnifierEnabled() const;
439 void SetLinkMagnifierEnabled(bool enabled);
441 void SetOverrideEncoding(const std::string& encoding);
442 void SetQuotaPermissionRequestCallback(
443 Ewk_Quota_Permission_Request_Callback callback,
445 void InvokeQuotaPermissionRequest(
446 _Ewk_Quota_Permission_Request* request,
447 const content::QuotaPermissionContext::PermissionCallback& cb);
448 void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
450 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
451 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
452 void SetViewMode(blink::WebViewMode view_mode);
454 gfx::Point GetContextMenuPosition() const;
456 content::ContextMenuControllerEfl* GetContextMenuController() {
457 return context_menu_.get();
459 void ResetContextMenuController();
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 InvokeWebProcessCrashedCallback();
472 void HandleTapGestureForSelection(bool is_content_editable);
473 void HandleZoomGesture(blink::WebGestureEvent& event);
477 void InitializeContent();
478 void SendDelayedMessages(content::RenderViewHost* render_view_host);
480 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
481 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
484 Ewk_Hit_Test_Mode mode,
485 WebViewAsyncRequestHitTestDataCallback* cb);
487 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
489 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
490 static void cameraResultCb(service_h request,
492 service_result_e result,
496 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
497 bool LaunchCamera(base::string16 mimetype);
499 content::RenderWidgetHostViewEfl* rwhv() const;
500 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
502 void ReleasePopupMenuList();
504 void ShowContextMenuInternal(const content::ContextMenuParams&);
506 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
508 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
509 scoped_refptr<Ewk_Context> context_;
510 scoped_refptr<Ewk_Context> old_context_;
511 std::unique_ptr<content::WebContents> web_contents_;
512 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
513 std::string pending_url_request_;
514 std::unique_ptr<Ewk_Settings> settings_;
515 std::unique_ptr<_Ewk_Frame> frame_;
516 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
517 Evas_Object* evas_object_;
518 Evas_Object* native_view_;
519 bool touch_events_enabled_;
520 bool mouse_events_enabled_;
521 double text_zoom_factor_;
522 mutable std::string user_agent_;
523 mutable std::string user_agent_app_name_;
524 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
526 Eina_List* popupMenuItems_;
527 Popup_Picker* popupPicker_;
528 bool formIsNavigating_;
535 formNavigation formNavigation_;
536 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
537 #if !defined(EWK_BRINGUP) // FIXME: m71 bringup
538 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
540 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
541 base::string16 previous_text_;
542 int current_find_request_id_;
543 static int find_request_id_counter_;
545 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
546 EwkViewPlainTextGetCallback;
547 base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
549 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
550 MHTMLCallbackDetails;
551 base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
553 gfx::Size contents_size_;
555 mutable std::string title_;
556 mutable std::string pem_certificate_;
557 Hit_Test_Params hit_test_params_;
558 base::WaitableEvent hit_test_completion_;
559 double page_scale_factor_;
560 double min_page_scale_factor_;
561 double max_page_scale_factor_;
563 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
564 _Ewk_Geolocation_Permission_Request*>
565 geolocation_permission_cb_;
566 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
567 _Ewk_User_Media_Permission_Request*>
568 user_media_permission_cb_;
569 WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
571 WebViewCallback<Ewk_View_Notification_Permission_Callback,
572 Ewk_Notification_Permission_Request*>
573 notification_permission_callback_;
574 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
575 const _Ewk_Quota_Permission_Request*>
576 quota_request_callback_;
578 std::unique_ptr<content::InputPicker> inputPicker_;
579 base::IDMap<WebApplicationIconUrlGetCallback*>
580 web_app_icon_url_get_callback_map_;
581 base::IDMap<WebApplicationIconUrlsGetCallback*>
582 web_app_icon_urls_get_callback_map_;
583 base::IDMap<WebApplicationCapableGetCallback*>
584 web_app_capable_get_callback_map_;
585 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
586 std::unique_ptr<ScrollDetector> scroll_detector_;
588 #if defined(OS_TIZEN)
589 blink::mojom::FileChooserParams::Mode filechooser_mode_;
591 std::map<const _Ewk_Quota_Permission_Request*,
592 content::QuotaPermissionContext::PermissionCallback>
593 quota_permission_request_map_;
595 bool is_initialized_;
597 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
599 static content::WebContentsEflDelegate::WebContentsCreateCallback
600 create_new_window_web_contents_cb_;
603 gfx::Vector2d previous_scroll_position_;
605 gfx::Point context_menu_position_;
607 std::vector<IPC::Message*> delayed_messages_;
609 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
612 const unsigned int g_default_tilt_motion_sensitivity = 3;