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(OS_TIZEN_MOBILE)
9 #if !defined(EWK_BRINGUP)
10 // FIXME: appfw/app_service.h is no more in Tizen 2.3, figure out what to include instead.
11 #include <appcore-agent/service_app.h>
21 #include "base/callback.h"
22 #include "base/id_map.h"
23 #include "base/synchronization/waitable_event.h"
24 #include "browser/inputpicker/InputPicker.h"
25 #include "browser/selectpicker/popup_picker.h"
26 #include "content/public/common/context_menu_params.h"
27 #include "content/public/common/file_chooser_params.h"
28 #include "content/browser/renderer_host/event_with_latency_info.h"
29 #include "content/browser/selection/selection_controller_efl.h"
30 #include "content/common/input/input_event_ack_state.h"
31 #include "content/public/browser/navigation_controller.h"
32 #include "content/public/browser/quota_permission_context.h"
33 #include "content/public/browser/web_contents_delegate.h"
34 #include "content/public/browser/web_contents_efl_delegate.h"
35 #include "content/public/common/menu_item.h"
36 #include "context_menu_controller_efl.h"
37 #include "eweb_context.h"
38 #include "eweb_view_callbacks.h"
39 #include "ewk_touch.h"
40 #include "file_chooser_controller_efl.h"
41 #include "permission_popup_manager.h"
42 #include "popup_controller_efl.h"
43 #include "private/ewk_history_private.h"
44 #include "private/ewk_hit_test_private.h"
45 #include "private/ewk_auth_challenge_private.h"
46 #include "private/ewk_back_forward_list_private.h"
47 #include "private/ewk_settings_private.h"
48 #include "private/ewk_web_application_icon_data_private.h"
49 #include "public/ewk_hit_test.h"
50 #include "public/ewk_view.h"
51 #include "scroll_detector.h"
52 #include "ui/gfx/geometry/point.h"
53 #include "ui/gfx/geometry/size.h"
54 #include "web_contents_delegate_efl.h"
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 {
86 Eina_Bool Run(Evas_Object* webview, CallbackParameter param, 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, void *user_data)
108 : 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, void *user_data)
124 : 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(); it != urls.end(); ++it) {
130 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
131 list = eina_list_append(list, data);
133 (func_)(list, user_data_);
138 Ewk_Web_App_Icon_URLs_Get_Callback func_;
142 class WebApplicationCapableGetCallback {
144 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func, void *user_data)
145 : func_(func), user_data_(user_data)
147 void Run(bool capable) {
149 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
154 Ewk_Web_App_Capable_Get_Callback func_;
158 class WebViewAsyncRequestHitTestDataCallback;
159 class JavaScriptDialogManagerEfl;
160 class PermissionPopupManager;
164 static EWebView* FromEvasObject(Evas_Object* eo);
165 static int GetOrientation();
167 EWebView(Ewk_Context*, Evas_Object* smart_object);
170 // initialize data members and activate event handlers.
171 // call this once after created and before use
174 void CreateNewWindow(content::WebContentsEflDelegate::WebContentsCreateCallback);
175 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
177 Ewk_Context* context() const { return context_.get(); }
178 Evas_Object* evas_object() const { return evas_object_; }
179 Evas_Object* native_view() const { return native_view_; }
180 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
181 PermissionPopupManager* GetPermissionPopupManager() const
183 return permission_popup_manager_.get();
186 content::WebContents& web_contents() const
188 return *web_contents_.get();
191 template<EWebViewCallbacks::CallbackType callbackType>
192 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
194 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
197 void set_magnifier(bool status);
200 void SetURL(const GURL& url);
201 const GURL& GetURL() const;
203 void ReloadBypassingCache();
204 Eina_Bool CanGoBack();
205 Eina_Bool CanGoForward();
206 Eina_Bool HasFocus() const;
207 void SetFocus(Eina_Bool focus);
209 Eina_Bool GoForward();
213 double GetTextZoomFactor() const;
214 void SetTextZoomFactor(double text_zoom_factor);
215 double GetPageZoomFactor() const;
216 void SetPageZoomFactor(double page_zoom_factor);
217 void ExecuteEditCommand(const char* command, const char* value);
218 void SetOrientation(int orientation);
219 bool TouchEventsEnabled() const;
220 void SetTouchEventsEnabled(bool enabled);
221 bool MouseEventsEnabled() const;
222 void SetMouseEventsEnabled(bool enabled);
223 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
226 bool ExecuteJavaScript(const char* script, Ewk_View_Script_Execute_Callback callback, void* userdata);
227 bool SetUserAgent(const char* userAgent);
228 bool SetUserAgentAppName(const char* application_name);
229 bool SetPrivateBrowsing(bool incognito);
230 bool GetPrivateBrowsing() const;
231 const char* GetUserAgent() const;
232 const char* GetUserAgentAppName() const;
233 const char* GetSelectedText() const;
234 Ewk_Settings* GetSettings() { return settings_.get(); }
235 _Ewk_Frame* GetMainFrame();
236 void UpdateWebKitPreferences();
237 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
238 void LoadPlainTextString(const char* plain_text);
239 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
241 void InvokeLoadError(const GURL& url, int error_code,
242 const std::string& error_description, bool is_main_frame);
243 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
244 void Find(const char* text, Ewk_Find_Options);
245 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
246 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
247 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
248 int selectedIndex, bool multiple);
249 Eina_Bool HidePopupMenu();
250 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
251 bool prevState, bool nextState);
252 void FormNavigate(bool direction);
253 bool IsSelectPickerShown() const;
254 void CloseSelectPicker();
255 bool FormIsNavigating() const { return formIsNavigating_; }
256 void SetFormIsNavigating(bool formIsNavigating);
257 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
258 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
259 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
260 Eina_Bool PopupMenuClose();
261 void HandleLongPressGesture(const content::ContextMenuParams&);
262 void ShowContextMenu(const content::ContextMenuParams&);
263 void CancelContextMenu(int request_id);
264 void SetScale(double scale_factor, int x, int y);
265 bool GetScrollPosition(int* x, int* y) const;
266 void SetScroll(int x, int y);
267 void UrlRequestSet(const char* url,
268 content::NavigationController::LoadURLType loadtype,
272 content::SelectionControllerEfl* GetSelectionController() const;
273 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
274 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
275 void MoveCaret(const gfx::Point& point);
276 void QuerySelectionStyle();
277 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
278 void SelectLinkText(const gfx::Point& touch_point);
279 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
280 Eina_Bool ClearSelection();
282 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
283 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
285 void RenderViewCreated(content::RenderViewHost* render_view_host);
288 * Creates a snapshot of given rectangle from EWebView
290 * @param rect rectangle of EWebView which will be taken into snapshot
292 * @return created snapshot or NULL if error occured.
293 * @note ownership of snapshot is passed to caller
295 Evas_Object* GetSnapshot(Eina_Rectangle rect);
297 bool GetSnapshotAsync(Eina_Rectangle rect, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
298 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
299 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
300 NavigationPolicyParams params, bool* handled);
301 void UseSettingsFont();
303 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
304 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
305 Ewk_Hit_Test_Mode mode,
306 Ewk_View_Hit_Test_Request_Callback,
308 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
309 Ewk_Hit_Test_Mode mode);
310 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
311 Ewk_Hit_Test_Mode mode,
312 Ewk_View_Hit_Test_Request_Callback,
314 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
315 void UpdateHitTestData(const Hit_Test_Params& params);
317 int current_find_request_id() const { return current_find_request_id_; }
318 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
319 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
320 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
321 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
322 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
323 void SetViewUserMediaPermissionCallback(
324 Ewk_View_User_Media_Permission_Callback callback,
326 bool InvokeViewUserMediaPermissionCallback(
327 _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
329 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
330 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
331 void DidChangeContentsSize(int width, int height);
332 const Eina_Rectangle GetContentsSize() const;
333 void GetScrollSize(int* w, int* h);
335 void SetProgressValue(double progress);
336 double GetProgressValue();
337 const char* GetTitle();
338 bool SaveAsPdf(int width, int height, const std::string& file_name);
339 void BackForwardListClear();
340 _Ewk_Back_Forward_List* GetBackForwardList() const;
341 void InvokeBackForwardListChangedCallback();
342 _Ewk_History* GetBackForwardHistory() const;
343 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
344 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
345 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
346 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
347 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
348 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
349 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
350 bool IsNotificationPermissionCallbackSet() const;
351 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
353 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
354 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
356 void ExitFullscreen();
358 void DidChangePageScaleFactor(double scale_factor);
359 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
360 void JavaScriptAlertReply();
361 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
362 void JavaScriptConfirmReply(bool result);
363 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
364 void JavaScriptPromptReply(const char* result);
365 void set_renderer_crashed();
366 void GetPageScaleRange(double *min_scale, double *max_scale);
367 void SetDrawsTransparentBackground(bool enabled);
368 void GetSessionData(const char **data, unsigned *length) const;
369 bool RestoreFromSessionData(const char *data, unsigned length);
370 void ShowFileChooser(const content::FileChooserParams&);
371 void SetBrowserFont();
372 void SetCertificatePem(const std::string& certificate);
373 bool IsDragging() const;
375 void RequestColorPicker(int r, int g, int b, int a);
376 void DismissColorPicker();
377 bool SetColorPickerColor(int r, int g, int b, int a);
378 void InputPickerShow(ui::TextInputType input_type, double input_value);
380 void ShowContentsDetectedPopup(const char*);
382 // Returns TCP port number with Inspector, or 0 if error.
383 int StartInspectorServer(int port = 0);
384 bool StopInspectorServer();
386 void LoadNotFoundErrorPage(const std::string& invalidUrl);
387 static std::string GetPlatformLocale();
388 bool GetLinkMagnifierEnabled() const;
389 void SetLinkMagnifierEnabled(bool enabled);
391 void SetOverrideEncoding(const std::string& encoding);
392 void SetQuotaPermissionRequestCallback(Ewk_Quota_Permission_Request_Callback callback,
394 void InvokeQuotaPermissionRequest(_Ewk_Quota_Permission_Request* request,
395 const content::QuotaPermissionContext::PermissionCallback& cb);
396 void QuotaRequestReply(const _Ewk_Quota_Permission_Request *request,
398 void QuotaRequestCancel(const _Ewk_Quota_Permission_Request *request);
400 void SetViewMode(blink::WebViewMode view_mode);
402 gfx::Point GetContextMenuPosition() const;
404 content::ContextMenuControllerEfl* GetContextMenuController() {
405 return context_menu_.get();
407 void ResetContextMenuController();
409 /// ---- Event handling
412 bool HandleMove(int x, int y);
413 bool HandleResize(int width, int height);
414 bool HandleTextSelectionDown(int x, int y);
415 bool HandleTextSelectionUp(int x, int y);
417 void HandleRendererProcessCrash();
418 void InvokeWebProcessCrashedCallback();
420 void HandleTapGestureForSelection(bool is_content_editable);
421 void HandleZoomGesture(blink::WebGestureEvent& event);
424 void InitializeContent();
425 void SendDelayedMessages(content::RenderViewHost* render_view_host);
427 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
428 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
429 Ewk_Hit_Test_Mode mode,
430 WebViewAsyncRequestHitTestDataCallback* cb);
432 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
434 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
435 static void cameraResultCb(service_h request, service_h reply,
436 service_result_e result, void* data);
439 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
440 bool LaunchCamera(base::string16 mimetype);
442 content::RenderWidgetHostViewEfl* rwhv() const;
443 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
445 void ReleasePopupMenuList();
447 void ShowContextMenuInternal(const content::ContextMenuParams&);
449 void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
451 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
452 scoped_refptr<Ewk_Context> context_;
453 scoped_refptr<Ewk_Context> old_context_;
454 std::unique_ptr<content::WebContents> web_contents_;
455 std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
456 std::string pending_url_request_;
457 std::unique_ptr<Ewk_Settings> settings_;
458 std::unique_ptr<_Ewk_Frame> frame_;
459 std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
460 Evas_Object* evas_object_;
461 Evas_Object* native_view_;
462 bool touch_events_enabled_;
463 bool mouse_events_enabled_;
464 double text_zoom_factor_;
465 mutable std::string user_agent_;
466 mutable std::string user_agent_app_name_;
467 std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
469 Eina_List* popupMenuItems_;
470 Popup_Picker* popupPicker_;
471 bool formIsNavigating_;
478 formNavigation formNavigation_;
479 std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
480 std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
481 std::unique_ptr<content::PopupControllerEfl> popup_controller_;
482 base::string16 previous_text_;
483 int current_find_request_id_;
484 static int find_request_id_counter_;
486 typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*> EwkViewPlainTextGetCallback;
487 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
489 typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*> MHTMLCallbackDetails;
490 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
492 gfx::Size contents_size_;
494 mutable std::string title_;
495 mutable std::string pem_certificate_;
496 Hit_Test_Params hit_test_params_;
497 base::WaitableEvent hit_test_completion_;
498 double page_scale_factor_;
499 double min_page_scale_factor_;
500 double max_page_scale_factor_;
502 WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
503 _Ewk_Geolocation_Permission_Request*> geolocation_permission_cb_;
504 WebViewCallback<Ewk_View_User_Media_Permission_Callback,
505 _Ewk_User_Media_Permission_Request*> user_media_permission_cb_;
506 WebViewCallback<Ewk_View_Unfocus_Allow_Callback,
507 Ewk_Unfocus_Direction> unfocus_allow_cb_;
508 WebViewCallback<Ewk_View_Notification_Permission_Callback,
509 Ewk_Notification_Permission_Request*> notification_permission_callback_;
510 WebViewCallback<Ewk_Quota_Permission_Request_Callback,
511 const _Ewk_Quota_Permission_Request*> quota_request_callback_;
513 std::unique_ptr<content::InputPicker> inputPicker_;
514 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
515 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
516 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
517 std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
518 std::unique_ptr<ScrollDetector> scroll_detector_;
520 #if defined(OS_TIZEN_MOBILE)
521 content::FileChooserParams::Mode filechooser_mode_;
523 std::map<const _Ewk_Quota_Permission_Request*, content::QuotaPermissionContext::PermissionCallback> quota_permission_request_map_;
525 bool is_initialized_;
527 std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
529 static content::WebContentsEflDelegate::WebContentsCreateCallback
530 create_new_window_web_contents_cb_;
533 gfx::Vector2d previous_scroll_position_;
535 gfx::Point context_menu_position_;
537 std::vector<IPC::Message*> delayed_messages_;
539 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
542 const unsigned int g_default_tilt_motion_sensitivity = 3;