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 "ui/gfx/geometry/point.h"
51 #include "ui/gfx/geometry/size.h"
52 #include "web_contents_delegate_efl.h"
55 class RenderFrameHost;
57 class RenderWidgetHostViewEfl;
58 class WebContentsDelegateEfl;
59 class ContextMenuControllerEfl;
60 class WebContentsViewEfl;
61 class PopupControllerEfl;
65 class _Ewk_Policy_Decision;
68 class WebViewEvasEventHandler;
69 class _Ewk_Quota_Permission_Request;
71 template <typename CallbackPtr, typename CallbackParameter>
72 class WebViewCallback {
74 WebViewCallback() { Set(nullptr, nullptr); }
76 void Set(CallbackPtr cb, void* data) {
81 bool IsCallbackSet() const { return callback_; }
83 Eina_Bool Run(Evas_Object* webview,
84 CallbackParameter param,
85 Eina_Bool* callback_result) {
86 CHECK(callback_result);
87 if (IsCallbackSet()) {
88 *callback_result = callback_(webview, param, user_data_);
94 void Run(Evas_Object* webview, CallbackParameter param) {
96 callback_(webview, param, user_data_);
100 CallbackPtr callback_;
104 class WebApplicationIconUrlGetCallback {
106 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
108 : func_(func), user_data_(user_data) {}
109 void Run(const std::string& url) {
111 (func_)(url.c_str(), user_data_);
116 Ewk_Web_App_Icon_URL_Get_Callback func_;
120 class WebApplicationIconUrlsGetCallback {
122 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
124 : func_(func), user_data_(user_data) {}
125 void Run(const std::map<std::string, std::string>& urls) {
127 Eina_List* list = NULL;
128 for (std::map<std::string, std::string>::const_iterator it = urls.begin();
129 it != urls.end(); ++it) {
130 _Ewk_Web_App_Icon_Data* data =
131 ewkWebAppIconDataCreate(it->first, it->second);
132 list = eina_list_append(list, data);
134 (func_)(list, user_data_);
139 Ewk_Web_App_Icon_URLs_Get_Callback func_;
143 class WebApplicationCapableGetCallback {
145 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
147 : func_(func), user_data_(user_data) {}
148 void Run(bool capable) {
150 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
155 Ewk_Web_App_Capable_Get_Callback func_;
159 class WebViewAsyncRequestHitTestDataCallback;
160 class JavaScriptDialogManagerEfl;
161 class PermissionPopupManager;
165 static EWebView* FromEvasObject(Evas_Object* eo);
166 static int GetOrientation();
168 EWebView(Ewk_Context*, Evas_Object* smart_object);
171 // initialize data members and activate event handlers.
172 // call this once after created and before use
175 void CreateNewWindow(
176 content::WebContentsEflDelegate::WebContentsCreateCallback);
177 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
179 Ewk_Context* context() const { return context_.get(); }
180 Evas_Object* evas_object() const { return evas_object_; }
181 Evas_Object* native_view() const { return native_view_; }
182 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
183 PermissionPopupManager* GetPermissionPopupManager() const {
184 return permission_popup_manager_.get();
187 content::WebContents& web_contents() const { return *web_contents_.get(); }
189 template <EWebViewCallbacks::CallbackType callbackType>
190 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
191 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
194 void set_magnifier(bool status);
197 void SetURL(const GURL& url);
198 const GURL& GetURL() const;
200 void ReloadBypassingCache();
201 Eina_Bool CanGoBack();
202 Eina_Bool CanGoForward();
203 Eina_Bool HasFocus() const;
204 void SetFocus(Eina_Bool focus);
206 Eina_Bool GoForward();
210 double GetTextZoomFactor() const;
211 void SetTextZoomFactor(double text_zoom_factor);
212 double GetPageZoomFactor() const;
213 void SetPageZoomFactor(double page_zoom_factor);
214 void ExecuteEditCommand(const char* command, const char* value);
215 void SetOrientation(int orientation);
216 bool TouchEventsEnabled() const;
217 void SetTouchEventsEnabled(bool enabled);
218 bool MouseEventsEnabled() const;
219 void SetMouseEventsEnabled(bool enabled);
220 void HandleTouchEvents(Ewk_Touch_Event_Type type,
221 const Eina_List* points,
222 const Evas_Modifier* modifiers);
225 bool ExecuteJavaScript(const char* script,
226 Ewk_View_Script_Execute_Callback callback,
228 bool SetUserAgent(const char* userAgent);
229 bool SetUserAgentAppName(const char* application_name);
230 bool SetPrivateBrowsing(bool incognito);
231 bool GetPrivateBrowsing() const;
232 const char* GetUserAgent() const;
233 const char* GetUserAgentAppName() const;
234 const char* GetSelectedText() const;
235 Ewk_Settings* GetSettings() { return settings_.get(); }
236 _Ewk_Frame* GetMainFrame();
237 void UpdateWebKitPreferences();
238 void LoadHTMLString(const char* html,
239 const char* base_uri,
240 const char* unreachable_uri);
241 void LoadPlainTextString(const char* plain_text);
242 void LoadData(const char* data,
244 const char* mime_type,
245 const char* encoding,
246 const char* base_uri,
247 const char* unreachable_uri = NULL);
249 void InvokeLoadError(const GURL& url,
251 const std::string& error_description,
253 void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
255 const std::string& realm);
256 void Find(const char* text, Ewk_Find_Options);
257 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
258 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
259 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
262 Eina_Bool HidePopupMenu();
263 void UpdateFormNavigation(int formElementCount,
264 int currentNodeIndex,
267 void FormNavigate(bool direction);
268 bool IsSelectPickerShown() const;
269 void CloseSelectPicker();
270 bool FormIsNavigating() const { return formIsNavigating_; }
271 void SetFormIsNavigating(bool formIsNavigating);
272 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
273 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
274 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
275 Eina_Bool PopupMenuClose();
276 void HandleLongPressGesture(const content::ContextMenuParams&);
277 void ShowContextMenu(const content::ContextMenuParams&);
278 void CancelContextMenu(int request_id);
279 void SetScale(double scale_factor, int x, int y);
280 bool GetScrollPosition(int* x, int* y) const;
281 void SetScroll(int x, int y);
282 void UrlRequestSet(const char* url,
283 content::NavigationController::LoadURLType loadtype,
287 content::SelectionControllerEfl* GetSelectionController() const;
288 content::PopupControllerEfl* GetPopupController() const {
289 return popup_controller_.get();
291 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
292 void MoveCaret(const gfx::Point& point);
293 void QuerySelectionStyle();
294 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
295 void SelectLinkText(const gfx::Point& touch_point);
296 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
297 Eina_Bool ClearSelection();
299 // Callback OnCopyFromBackingStore will be called once we get the snapshot
301 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
303 void RenderViewCreated(content::RenderViewHost* render_view_host);
306 * Creates a snapshot of given rectangle from EWebView
308 * @param rect rectangle of EWebView which will be taken into snapshot
310 * @return created snapshot or NULL if error occured.
311 * @note ownership of snapshot is passed to caller
313 Evas_Object* GetSnapshot(Eina_Rectangle rect);
315 bool GetSnapshotAsync(Eina_Rectangle rect,
316 Ewk_Web_App_Screenshot_Captured_Callback callback,
318 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
319 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
320 NavigationPolicyParams params,
322 void UseSettingsFont();
324 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
325 Eina_Bool AsyncRequestHitTestDataAt(int x,
327 Ewk_Hit_Test_Mode mode,
328 Ewk_View_Hit_Test_Request_Callback,
330 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
332 Ewk_Hit_Test_Mode mode);
333 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
336 Ewk_Hit_Test_Mode mode,
337 Ewk_View_Hit_Test_Request_Callback,
339 void DispatchAsyncHitTestData(const Hit_Test_Params& params,
341 void UpdateHitTestData(const Hit_Test_Params& params);
343 int current_find_request_id() const { return current_find_request_id_; }
344 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
345 void InvokePlainTextGetCallback(const std::string& content_text,
346 int plain_text_get_callback_id);
347 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
349 void SetViewGeolocationPermissionCallback(
350 Ewk_View_Geolocation_Permission_Callback callback,
352 bool InvokeViewGeolocationPermissionCallback(
353 _Ewk_Geolocation_Permission_Request*
354 geolocation_permission_request_context,
356 void SetViewUserMediaPermissionCallback(
357 Ewk_View_User_Media_Permission_Callback callback,
359 bool InvokeViewUserMediaPermissionCallback(
360 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
362 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
364 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
366 void DidChangeContentsSize(int width, int height);
367 const Eina_Rectangle GetContentsSize() const;
368 void GetScrollSize(int* w, int* h);
370 void SetProgressValue(double progress);
371 double GetProgressValue();
372 const char* GetTitle();
373 bool SaveAsPdf(int width, int height, const std::string& file_name);
374 void BackForwardListClear();
375 _Ewk_Back_Forward_List* GetBackForwardList() const;
376 void InvokeBackForwardListChangedCallback();
377 _Ewk_History* GetBackForwardHistory() const;
378 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
380 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
382 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
384 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
385 void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
387 void InvokeWebAppIconUrlsGetCallback(
388 const std::map<std::string, std::string>& iconUrls,
390 void SetNotificationPermissionCallback(
391 Ewk_View_Notification_Permission_Callback callback,
393 bool IsNotificationPermissionCallbackSet() const;
394 bool InvokeNotificationPermissionCallback(
395 Ewk_Notification_Permission_Request* request);
397 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
398 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
400 void ExitFullscreen();
402 void DidChangePageScaleFactor(double scale_factor);
403 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
405 void JavaScriptAlertReply();
406 void SetJavaScriptConfirmCallback(
407 Ewk_View_JavaScript_Confirm_Callback callback,
409 void JavaScriptConfirmReply(bool result);
410 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
412 void JavaScriptPromptReply(const char* result);
413 void set_renderer_crashed();
414 void GetPageScaleRange(double* min_scale, double* max_scale);
415 void SetDrawsTransparentBackground(bool enabled);
416 void GetSessionData(const char** data, unsigned* length) const;
417 bool RestoreFromSessionData(const char* data, unsigned length);
418 void ShowFileChooser(content::RenderFrameHost* render_frame_host,
419 const blink::mojom::FileChooserParams&);
420 void SetBrowserFont();
421 void SetCertificatePem(const std::string& certificate);
422 bool IsDragging() const;
424 void RequestColorPicker(int r, int g, int b, int a);
425 void DismissColorPicker();
426 bool SetColorPickerColor(int r, int g, int b, int a);
427 void InputPickerShow(ui::TextInputType input_type, double input_value);
429 void ShowContentsDetectedPopup(const char*);
431 // Returns TCP port number with Inspector, or 0 if error.
432 int StartInspectorServer(int port = 0);
433 bool StopInspectorServer();
435 void LoadNotFoundErrorPage(const std::string& invalidUrl);
436 static std::string GetPlatformLocale();
437 bool GetLinkMagnifierEnabled() const;
438 void SetLinkMagnifierEnabled(bool enabled);
440 void SetOverrideEncoding(const std::string& encoding);
441 void SetQuotaPermissionRequestCallback(
442 Ewk_Quota_Permission_Request_Callback callback,
444 void InvokeQuotaPermissionRequest(
445 _Ewk_Quota_Permission_Request* request,
446 const content::QuotaPermissionContext::PermissionCallback& cb);
447 void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
449 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
450 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
451 void SetViewMode(blink::WebViewMode view_mode);
453 gfx::Point GetContextMenuPosition() const;
455 content::ContextMenuControllerEfl* GetContextMenuController() {
456 return context_menu_.get();
458 void ResetContextMenuController();
460 /// ---- Event handling
463 bool HandleMove(int x, int y);
464 bool HandleResize(int width, int height);
465 bool HandleTextSelectionDown(int x, int y);
466 bool HandleTextSelectionUp(int x, int y);
468 void HandleRendererProcessCrash();
469 void InvokeWebProcessCrashedCallback();
471 void HandleTapGestureForSelection(bool is_content_editable);
472 void HandleZoomGesture(blink::WebGestureEvent& event);
475 void InitializeContent();
476 void SendDelayedMessages(content::RenderViewHost* render_view_host);
478 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
479 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
482 Ewk_Hit_Test_Mode mode,
483 WebViewAsyncRequestHitTestDataCallback* cb);
485 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
487 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
488 static void cameraResultCb(service_h request,
490 service_result_e result,
494 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
495 bool LaunchCamera(base::string16 mimetype);
497 content::RenderWidgetHostViewEfl* rwhv() const;
498 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
500 void ReleasePopupMenuList();
502 void ShowContextMenuInternal(const content::ContextMenuParams&);
504 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
506 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
507 scoped_refptr<Ewk_Context> context_;
508 scoped_refptr<Ewk_Context> old_context_;
509 std::unique_ptr<content::WebContents> web_contents_;
510 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
511 std::string pending_url_request_;
512 std::unique_ptr<Ewk_Settings> settings_;
513 std::unique_ptr<_Ewk_Frame> frame_;
514 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
515 Evas_Object* evas_object_;
516 Evas_Object* native_view_;
517 bool touch_events_enabled_;
518 bool mouse_events_enabled_;
519 double text_zoom_factor_;
520 mutable std::string user_agent_;
521 mutable std::string user_agent_app_name_;
522 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
524 Eina_List* popupMenuItems_;
525 Popup_Picker* popupPicker_;
526 bool formIsNavigating_;
533 formNavigation formNavigation_;
534 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
535 #if !defined(EWK_BRINGUP) // FIXME: m71 bringup
536 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
538 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
539 base::string16 previous_text_;
540 int current_find_request_id_;
541 static int find_request_id_counter_;
543 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
544 EwkViewPlainTextGetCallback;
545 base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
547 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
548 MHTMLCallbackDetails;
549 base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
551 gfx::Size contents_size_;
553 mutable std::string title_;
554 mutable std::string pem_certificate_;
555 Hit_Test_Params hit_test_params_;
556 base::WaitableEvent hit_test_completion_;
557 double page_scale_factor_;
558 double min_page_scale_factor_;
559 double max_page_scale_factor_;
561 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
562 _Ewk_Geolocation_Permission_Request*>
563 geolocation_permission_cb_;
564 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
565 _Ewk_User_Media_Permission_Request*>
566 user_media_permission_cb_;
567 WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
569 WebViewCallback<Ewk_View_Notification_Permission_Callback,
570 Ewk_Notification_Permission_Request*>
571 notification_permission_callback_;
572 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
573 const _Ewk_Quota_Permission_Request*>
574 quota_request_callback_;
576 std::unique_ptr<content::InputPicker> inputPicker_;
577 base::IDMap<WebApplicationIconUrlGetCallback*>
578 web_app_icon_url_get_callback_map_;
579 base::IDMap<WebApplicationIconUrlsGetCallback*>
580 web_app_icon_urls_get_callback_map_;
581 base::IDMap<WebApplicationCapableGetCallback*>
582 web_app_capable_get_callback_map_;
583 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
584 std::unique_ptr<ScrollDetector> scroll_detector_;
586 #if defined(OS_TIZEN)
587 blink::mojom::FileChooserParams::Mode filechooser_mode_;
589 std::map<const _Ewk_Quota_Permission_Request*,
590 content::QuotaPermissionContext::PermissionCallback>
591 quota_permission_request_map_;
593 bool is_initialized_;
595 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
597 static content::WebContentsEflDelegate::WebContentsCreateCallback
598 create_new_window_web_contents_cb_;
601 gfx::Vector2d previous_scroll_position_;
603 gfx::Point context_menu_position_;
605 std::vector<IPC::Message*> delayed_messages_;
607 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
610 const unsigned int g_default_tilt_motion_sensitivity = 3;