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/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);
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;
199 const GURL& GetOriginalURL() 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 int GetOrientation();
218 bool TouchEventsEnabled() const;
219 void SetTouchEventsEnabled(bool enabled);
220 bool MouseEventsEnabled() const;
221 void SetMouseEventsEnabled(bool enabled);
222 void HandleTouchEvents(Ewk_Touch_Event_Type type,
223 const Eina_List* points,
224 const Evas_Modifier* modifiers);
227 bool ExecuteJavaScript(const char* script,
228 Ewk_View_Script_Execute_Callback callback,
230 bool SetUserAgent(const char* userAgent);
231 bool SetUserAgentAppName(const char* application_name);
232 bool SetPrivateBrowsing(bool incognito);
233 bool GetPrivateBrowsing() const;
234 const char* GetUserAgent() const;
235 const char* GetUserAgentAppName() const;
236 const char* GetSelectedText() const;
237 Ewk_Settings* GetSettings() { return settings_.get(); }
238 _Ewk_Frame* GetMainFrame();
239 void UpdateWebKitPreferences();
240 void LoadHTMLString(const char* html,
241 const char* base_uri,
242 const char* unreachable_uri);
243 void LoadPlainTextString(const char* plain_text);
244 void LoadData(const char* data,
246 const char* mime_type,
247 const char* encoding,
248 const char* base_uri,
249 const char* unreachable_uri = NULL);
251 void InvokeLoadError(const GURL& url,
253 const std::string& error_description,
255 void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
257 const std::string& realm);
258 void Find(const char* text, Ewk_Find_Options);
259 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
260 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
261 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
264 Eina_Bool HidePopupMenu();
265 void UpdateFormNavigation(int formElementCount,
266 int currentNodeIndex,
269 void FormNavigate(bool direction);
270 bool IsSelectPickerShown() const;
271 void CloseSelectPicker();
272 bool FormIsNavigating() const { return formIsNavigating_; }
273 void SetFormIsNavigating(bool formIsNavigating);
274 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
275 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
276 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
277 Eina_Bool PopupMenuClose();
278 void HandleLongPressGesture(const content::ContextMenuParams&);
279 void ShowContextMenu(const content::ContextMenuParams&);
280 void CancelContextMenu(int request_id);
281 void SetScale(double scale_factor, int x, int y);
282 bool GetScrollPosition(int* x, int* y) const;
283 void SetScroll(int x, int y);
284 void UrlRequestSet(const char* url,
285 content::NavigationController::LoadURLType loadtype,
289 content::SelectionControllerEfl* GetSelectionController() const;
290 content::PopupControllerEfl* GetPopupController() const {
291 return popup_controller_.get();
293 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
294 void MoveCaret(const gfx::Point& point);
295 void QuerySelectionStyle();
296 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
297 void SelectLinkText(const gfx::Point& touch_point);
298 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
299 Eina_Bool ClearSelection();
301 // Callback OnCopyFromBackingStore will be called once we get the snapshot
303 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
305 void RenderViewCreated(content::RenderViewHost* render_view_host);
308 * Creates a snapshot of given rectangle from EWebView
310 * @param rect rectangle of EWebView which will be taken into snapshot
312 * @return created snapshot or NULL if error occured.
313 * @note ownership of snapshot is passed to caller
315 Evas_Object* GetSnapshot(Eina_Rectangle rect);
317 bool GetSnapshotAsync(Eina_Rectangle rect,
318 Ewk_Web_App_Screenshot_Captured_Callback callback,
320 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
321 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
322 NavigationPolicyParams params,
324 void UseSettingsFont();
326 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
327 Eina_Bool AsyncRequestHitTestDataAt(int x,
329 Ewk_Hit_Test_Mode mode,
330 Ewk_View_Hit_Test_Request_Callback,
332 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
334 Ewk_Hit_Test_Mode mode);
335 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
338 Ewk_Hit_Test_Mode mode,
339 Ewk_View_Hit_Test_Request_Callback,
341 void DispatchAsyncHitTestData(const Hit_Test_Params& params,
343 void UpdateHitTestData(const Hit_Test_Params& params);
345 int current_find_request_id() const { return current_find_request_id_; }
346 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
347 void InvokePlainTextGetCallback(const std::string& content_text,
348 int plain_text_get_callback_id);
349 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
351 void SetViewGeolocationPermissionCallback(
352 Ewk_View_Geolocation_Permission_Callback callback,
354 bool InvokeViewGeolocationPermissionCallback(
355 _Ewk_Geolocation_Permission_Request*
356 geolocation_permission_request_context,
358 void SetViewUserMediaPermissionCallback(
359 Ewk_View_User_Media_Permission_Callback callback,
361 bool InvokeViewUserMediaPermissionCallback(
362 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
364 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
366 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
368 void DidChangeContentsSize(int width, int height);
369 const Eina_Rectangle GetContentsSize() const;
370 void GetScrollSize(int* w, int* h);
372 void SetProgressValue(double progress);
373 double GetProgressValue();
374 const char* GetTitle();
375 bool SaveAsPdf(int width, int height, const std::string& file_name);
376 void BackForwardListClear();
377 _Ewk_Back_Forward_List* GetBackForwardList() const;
378 void InvokeBackForwardListChangedCallback();
379 _Ewk_History* GetBackForwardHistory() const;
380 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
382 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
384 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
386 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
387 void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
389 void InvokeWebAppIconUrlsGetCallback(
390 const std::map<std::string, std::string>& iconUrls,
392 void SetNotificationPermissionCallback(
393 Ewk_View_Notification_Permission_Callback callback,
395 bool IsNotificationPermissionCallbackSet() const;
396 bool InvokeNotificationPermissionCallback(
397 Ewk_Notification_Permission_Request* request);
399 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
400 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
402 void ExitFullscreen();
404 void DidChangePageScaleFactor(double scale_factor);
405 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
407 void JavaScriptAlertReply();
408 void SetJavaScriptConfirmCallback(
409 Ewk_View_JavaScript_Confirm_Callback callback,
411 void JavaScriptConfirmReply(bool result);
412 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
414 void JavaScriptPromptReply(const char* result);
415 void set_renderer_crashed();
416 void GetPageScaleRange(double* min_scale, double* max_scale);
417 void SetDrawsTransparentBackground(bool enabled);
418 void GetSessionData(const char** data, unsigned* length) const;
419 bool RestoreFromSessionData(const char* data, unsigned length);
420 void ShowFileChooser(content::RenderFrameHost* render_frame_host,
421 const blink::mojom::FileChooserParams&);
422 void SetBrowserFont();
423 void SetCertificatePem(const std::string& certificate);
424 bool IsDragging() const;
426 void RequestColorPicker(int r, int g, int b, int a);
427 void DismissColorPicker();
428 bool SetColorPickerColor(int r, int g, int b, int a);
429 void InputPickerShow(ui::TextInputType input_type, double input_value);
431 void ShowContentsDetectedPopup(const char*);
433 // Returns TCP port number with Inspector, or 0 if error.
434 int StartInspectorServer(int port = 0);
435 bool StopInspectorServer();
437 void LoadNotFoundErrorPage(const std::string& invalidUrl);
438 static std::string GetPlatformLocale();
439 bool GetLinkMagnifierEnabled() const;
440 void SetLinkMagnifierEnabled(bool enabled);
442 void SetOverrideEncoding(const std::string& encoding);
443 void SetQuotaPermissionRequestCallback(
444 Ewk_Quota_Permission_Request_Callback callback,
446 void InvokeQuotaPermissionRequest(
447 _Ewk_Quota_Permission_Request* request,
448 content::QuotaPermissionContext::PermissionCallback cb);
449 void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
451 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
452 #if !defined(EWK_BRINGUP) // FIXME: m67 bringup
453 void SetViewMode(blink::WebViewMode view_mode);
455 gfx::Point GetContextMenuPosition() const;
457 content::ContextMenuControllerEfl* GetContextMenuController() {
458 return context_menu_.get();
460 void ResetContextMenuController();
462 /// ---- Event handling
465 bool HandleMove(int x, int y);
466 bool HandleResize(int width, int height);
467 bool HandleTextSelectionDown(int x, int y);
468 bool HandleTextSelectionUp(int x, int y);
470 void HandleRendererProcessCrash();
471 void InvokeWebProcessCrashedCallback();
473 void HandleTapGestureForSelection(bool is_content_editable);
474 void HandleZoomGesture(blink::WebGestureEvent& event);
478 void InitializeContent();
479 void SendDelayedMessages(content::RenderViewHost* render_view_host);
481 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
482 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
485 Ewk_Hit_Test_Mode mode,
486 WebViewAsyncRequestHitTestDataCallback* cb);
488 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
490 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
491 static void cameraResultCb(service_h request,
493 service_result_e result,
497 #if defined(OS_TIZEN) && !defined(EWK_BRINGUP)
498 bool LaunchCamera(base::string16 mimetype);
500 content::RenderWidgetHostViewEfl* rwhv() const;
501 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
503 void ReleasePopupMenuList();
505 void ShowContextMenuInternal(const content::ContextMenuParams&);
507 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
509 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
510 scoped_refptr<Ewk_Context> context_;
511 scoped_refptr<Ewk_Context> old_context_;
512 std::unique_ptr<content::WebContents> web_contents_;
513 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
514 std::string pending_url_request_;
515 std::unique_ptr<Ewk_Settings> settings_;
516 std::unique_ptr<_Ewk_Frame> frame_;
517 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
518 Evas_Object* evas_object_;
519 Evas_Object* native_view_;
520 bool touch_events_enabled_;
521 bool mouse_events_enabled_;
522 double text_zoom_factor_;
523 mutable std::string user_agent_;
524 mutable std::string user_agent_app_name_;
525 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
527 Eina_List* popupMenuItems_;
528 Popup_Picker* popupPicker_;
529 bool formIsNavigating_;
536 formNavigation formNavigation_;
537 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
538 #if !defined(EWK_BRINGUP) // FIXME: m71 bringup
539 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
541 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
542 base::string16 previous_text_;
543 int current_find_request_id_;
544 static int find_request_id_counter_;
546 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
547 EwkViewPlainTextGetCallback;
548 base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
550 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
551 MHTMLCallbackDetails;
552 base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
554 gfx::Size contents_size_;
556 mutable std::string title_;
557 mutable std::string pem_certificate_;
558 Hit_Test_Params hit_test_params_;
559 base::WaitableEvent hit_test_completion_;
560 double page_scale_factor_;
561 double min_page_scale_factor_;
562 double max_page_scale_factor_;
564 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
565 _Ewk_Geolocation_Permission_Request*>
566 geolocation_permission_cb_;
567 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
568 _Ewk_User_Media_Permission_Request*>
569 user_media_permission_cb_;
570 WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
572 WebViewCallback<Ewk_View_Notification_Permission_Callback,
573 Ewk_Notification_Permission_Request*>
574 notification_permission_callback_;
575 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
576 const _Ewk_Quota_Permission_Request*>
577 quota_request_callback_;
579 std::unique_ptr<content::InputPicker> inputPicker_;
580 base::IDMap<WebApplicationIconUrlGetCallback*>
581 web_app_icon_url_get_callback_map_;
582 base::IDMap<WebApplicationIconUrlsGetCallback*>
583 web_app_icon_urls_get_callback_map_;
584 base::IDMap<WebApplicationCapableGetCallback*>
585 web_app_capable_get_callback_map_;
586 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
587 std::unique_ptr<ScrollDetector> scroll_detector_;
589 #if defined(OS_TIZEN)
590 blink::mojom::FileChooserParams::Mode filechooser_mode_;
592 std::map<const _Ewk_Quota_Permission_Request*,
593 content::QuotaPermissionContext::PermissionCallback>
594 quota_permission_request_map_;
596 bool is_initialized_;
598 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
600 static content::WebContentsEflDelegate::WebContentsCreateCallback
601 create_new_window_web_contents_cb_;
604 gfx::Vector2d previous_scroll_position_;
606 gfx::Point context_menu_position_;
608 std::vector<IPC::Message*> delayed_messages_;
610 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
613 const unsigned int g_default_tilt_motion_sensitivity = 3;