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/file_chooser_params.h"
33 #include "content/public/common/input_event_ack_state.h"
34 #include "content/public/common/menu_item.h"
35 #include "context_menu_controller_efl.h"
36 #include "eweb_context.h"
37 #include "eweb_view_callbacks.h"
38 #include "file_chooser_controller_efl.h"
39 #include "permission_popup_manager.h"
40 #include "popup_controller_efl.h"
41 #include "private/ewk_auth_challenge_private.h"
42 #include "private/ewk_back_forward_list_private.h"
43 #include "private/ewk_history_private.h"
44 #include "private/ewk_hit_test_private.h"
45 #include "private/ewk_settings_private.h"
46 #include "private/ewk_web_application_icon_data_private.h"
47 #include "public/ewk_hit_test_internal.h"
48 #include "public/ewk_touch_internal.h"
49 #include "public/ewk_view_product.h"
50 #include "scroll_detector.h"
51 #include "ui/gfx/geometry/point.h"
52 #include "ui/gfx/geometry/size.h"
53 #include "web_contents_delegate_efl.h"
54 //#include "third_party/blink/public/web/WebViewModeEnums.h"
57 class RenderFrameHost;
59 class RenderWidgetHostViewEfl;
60 class WebContentsDelegateEfl;
61 class ContextMenuControllerEfl;
62 class WebContentsViewEfl;
63 class PopupControllerEfl;
67 class _Ewk_Policy_Decision;
70 class WebViewEvasEventHandler;
71 class _Ewk_Quota_Permission_Request;
73 template <typename CallbackPtr, typename CallbackParameter>
74 class WebViewCallback {
76 WebViewCallback() { Set(nullptr, nullptr); }
78 void Set(CallbackPtr cb, void* data) {
83 bool IsCallbackSet() const { return callback_; }
85 Eina_Bool Run(Evas_Object* webview,
86 CallbackParameter param,
87 Eina_Bool* callback_result) {
88 CHECK(callback_result);
89 if (IsCallbackSet()) {
90 *callback_result = callback_(webview, param, user_data_);
96 void Run(Evas_Object* webview, CallbackParameter param) {
98 callback_(webview, param, user_data_);
102 CallbackPtr callback_;
106 class WebApplicationIconUrlGetCallback {
108 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
110 : func_(func), user_data_(user_data) {}
111 void Run(const std::string& url) {
113 (func_)(url.c_str(), user_data_);
118 Ewk_Web_App_Icon_URL_Get_Callback func_;
122 class WebApplicationIconUrlsGetCallback {
124 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
126 : func_(func), user_data_(user_data) {}
127 void Run(const std::map<std::string, std::string>& urls) {
129 Eina_List* list = NULL;
130 for (std::map<std::string, std::string>::const_iterator it = urls.begin();
131 it != urls.end(); ++it) {
132 _Ewk_Web_App_Icon_Data* data =
133 ewkWebAppIconDataCreate(it->first, it->second);
134 list = eina_list_append(list, data);
136 (func_)(list, user_data_);
141 Ewk_Web_App_Icon_URLs_Get_Callback func_;
145 class WebApplicationCapableGetCallback {
147 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
149 : func_(func), user_data_(user_data) {}
150 void Run(bool capable) {
152 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
157 Ewk_Web_App_Capable_Get_Callback func_;
161 class WebViewAsyncRequestHitTestDataCallback;
162 class JavaScriptDialogManagerEfl;
163 class PermissionPopupManager;
167 static EWebView* FromEvasObject(Evas_Object* eo);
168 static int GetOrientation();
170 EWebView(Ewk_Context*, Evas_Object* smart_object);
173 // initialize data members and activate event handlers.
174 // call this once after created and before use
177 void CreateNewWindow(
178 content::WebContentsEflDelegate::WebContentsCreateCallback);
179 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
181 Ewk_Context* context() const { return context_.get(); }
182 Evas_Object* evas_object() const { return evas_object_; }
183 Evas_Object* native_view() const { return native_view_; }
184 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
185 PermissionPopupManager* GetPermissionPopupManager() const {
186 return permission_popup_manager_.get();
189 content::WebContents& web_contents() const { return *web_contents_.get(); }
191 template <EWebViewCallbacks::CallbackType callbackType>
192 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
193 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
196 void set_magnifier(bool status);
199 void SetURL(const GURL& url);
200 const GURL& GetURL() const;
202 void ReloadBypassingCache();
203 Eina_Bool CanGoBack();
204 Eina_Bool CanGoForward();
205 Eina_Bool HasFocus() const;
206 void SetFocus(Eina_Bool focus);
208 Eina_Bool GoForward();
212 double GetTextZoomFactor() const;
213 void SetTextZoomFactor(double text_zoom_factor);
214 double GetPageZoomFactor() const;
215 void SetPageZoomFactor(double page_zoom_factor);
216 void ExecuteEditCommand(const char* command, const char* value);
217 void SetOrientation(int orientation);
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 content::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 const 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);
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 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 content::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;