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/memory/scoped_ptr.h"
23 #include "base/synchronization/waitable_event.h"
24 #include "content/public/common/context_menu_params.h"
25 #include "content/public/common/file_chooser_params.h"
26 #include "content/browser/renderer_host/event_with_latency_info.h"
27 #include "content/common/input/input_event_ack_state.h"
28 #include "content/public/browser/navigation_controller.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/menu_item.h"
32 #include "base/id_map.h"
33 #include "context_menu_controller_efl.h"
34 #include "eweb_context.h"
35 #include "ewk_touch.h"
36 #include "private/ewk_history_private.h"
37 #include "private/ewk_hit_test_private.h"
38 #include "private/ewk_auth_challenge_private.h"
39 #include "private/ewk_back_forward_list_private.h"
40 #include "private/ewk_settings_private.h"
41 #include "private/ewk_web_application_icon_data_private.h"
42 #include "public/ewk_hit_test.h"
43 #include "public/ewk_view.h"
44 #include "eweb_view_callbacks.h"
45 #include "scroll_detector.h"
46 #include "selection_controller_efl.h"
47 #include "web_contents_delegate_efl.h"
48 #include "context_menu_controller_efl.h"
49 #include "file_chooser_controller_efl.h"
50 #include "ui/gfx/geometry/point.h"
51 #include "ui/gfx/geometry/size.h"
52 #include "browser/inputpicker/InputPicker.h"
53 #include "popup_controller_efl.h"
55 #include "browser/selectpicker/popup_picker.h"
59 class RenderWidgetHostViewEfl;
60 class WebContentsDelegateEfl;
61 class ContextMenuControllerEfl;
62 class DevToolsDelegateEfl;
63 class WebContentsViewEfl;
64 class PopupControllerEfl;
68 class _Ewk_Policy_Decision;
71 class WebViewEvasEventHandler;
73 class WebAppScreenshotCapturedCallback : public base::RefCounted<WebAppScreenshotCapturedCallback> {
75 WebAppScreenshotCapturedCallback(Ewk_Web_App_Screenshot_Captured_Callback func, void *user_data, Evas* canvas)
76 : func_(func), user_data_(user_data), canvas_(canvas) {}
77 void Run(Evas_Object* image) {
79 (func_)(image, user_data_);
83 Ewk_Web_App_Screenshot_Captured_Callback func_;
88 class EwkViewPlainTextGetCallback {
90 EwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
92 : callback_(callback), user_data_(user_data)
94 void TriggerCallback(Evas_Object* obj, const std::string& content_text);
97 Ewk_View_Plain_Text_Get_Callback callback_;
101 class OrientationLockCallback {
103 OrientationLockCallback(Ewk_Orientation_Lock_Cb lock,
106 user_data_(user_data)
109 Ewk_Orientation_Lock_Cb lock_;
113 class MHTMLCallbackDetails {
115 MHTMLCallbackDetails(Ewk_View_MHTML_Data_Get_Callback callback_func, void *user_data)
116 : callback_func_(callback_func),
117 user_data_(user_data)
119 void Run(Evas_Object* obj, const std::string& mhtml_content);
121 Ewk_View_MHTML_Data_Get_Callback callback_func_;
125 class WebApplicationIconUrlGetCallback {
127 WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func, void *user_data)
128 : func_(func), user_data_(user_data)
130 void Run(const std::string &url) {
132 (func_)(url.c_str(), user_data_);
137 Ewk_Web_App_Icon_URL_Get_Callback func_;
141 class WebApplicationIconUrlsGetCallback {
143 WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func, void *user_data)
144 : func_(func), user_data_(user_data)
146 void Run(const std::map<std::string, std::string> &urls) {
148 Eina_List *list = NULL;
149 for (std::map<std::string, std::string>::const_iterator it = urls.begin(); it != urls.end(); ++it) {
150 _Ewk_Web_App_Icon_Data *data = ewkWebAppIconDataCreate(it->first, it->second);
151 list = eina_list_append(list, data);
153 (func_)(list, user_data_);
158 Ewk_Web_App_Icon_URLs_Get_Callback func_;
162 class WebApplicationCapableGetCallback {
164 WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func, void *user_data)
165 : func_(func), user_data_(user_data)
167 void Run(bool capable) {
169 (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
174 Ewk_Web_App_Capable_Get_Callback func_;
178 class AsyncHitTestRequest;
179 class NotificationPermissionCallback {
181 NotificationPermissionCallback(
183 Ewk_View_Notification_Permission_Callback func,
185 : obj_(obj), func_(func), user_data_(user_data) {}
186 bool Run(Ewk_Notification_Permission_Request* request) {
188 return (func_)(obj_, request, user_data_) == EINA_TRUE;
195 Ewk_View_Notification_Permission_Callback func_;
199 class WebViewAsyncRequestHitTestDataCallback;
200 class JavaScriptDialogManagerEfl;
201 class WebViewGeolocationPermissionCallback;
202 class WebViewUnfocusAllowCallback;
206 static EWebView* FromEvasObject(Evas_Object* eo);
207 static int GetOrientation();
209 EWebView(Ewk_Context*, Evas_Object* smart_object);
212 // initialize data members and activate event handlers.
213 // call this once after created and before use
216 void CreateNewWindow(content::WebContentsEflDelegate::WebContentsCreateCallback);
217 static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
219 Ewk_Context* context() const { return context_.get(); }
220 Evas_Object* evas_object() const { return evas_object_; }
221 Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
223 content::WebContents& web_contents() const
225 return *web_contents_.get();
228 template<EWebViewCallbacks::CallbackType callbackType>
229 EWebViewCallbacks::CallBack<callbackType> SmartCallback() const
231 return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
234 void set_magnifier(bool status);
237 void SetURL(const char* url_string);
238 const char* GetURL() const;
240 void ReloadIgnoringCache();
241 Eina_Bool CanGoBack();
242 Eina_Bool CanGoForward();
243 Eina_Bool HasFocus() const;
244 void SetFocus(Eina_Bool focus);
246 Eina_Bool GoForward();
250 double GetTextZoomFactor() const;
251 void SetTextZoomFactor(double text_zoom_factor);
252 void ExecuteEditCommand(const char* command, const char* value);
253 void SetOrientation(int orientation);
254 void SetOrientationLockCallback(Ewk_Orientation_Lock_Cb func, void* data);
255 bool TouchEventsEnabled() const;
256 void SetTouchEventsEnabled(bool enabled);
257 bool MouseEventsEnabled() const;
258 void SetMouseEventsEnabled(bool enabled);
259 void HandleTouchEvents(Ewk_Touch_Event_Type type, const Eina_List *points, const Evas_Modifier *modifiers);
262 bool ExecuteJavaScript(const char* script, Ewk_View_Script_Execute_Callback callback, void* userdata);
263 bool SetUserAgent(const char* userAgent);
264 bool SetUserAgentAppName(const char* application_name);
265 bool SetPrivateBrowsing(bool incognito);
266 bool GetPrivateBrowsing() const;
267 const char* GetUserAgent() const;
268 const char* GetUserAgentAppName() const;
269 const char* GetSelectedText() const;
270 Ewk_Settings* GetSettings();
271 _Ewk_Frame* GetMainFrame();
272 void UpdateWebKitPreferences();
273 void LoadHTMLString(const char* html, const char* base_uri, const char* unreachable_uri);
274 void LoadPlainTextString(const char* plain_text);
275 void LoadData(const char* data, size_t size, const char* mime_type, const char* encoding, const char* base_uri, const char* unreachable_uri = NULL);
276 void InvokeLoadError(const ErrorParams &error);
277 void InvokeAuthCallback(LoginDelegateEfl* login_delegate, const GURL& url, const std::string& realm);
278 void Find(const char* text, Ewk_Find_Options);
279 void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
280 void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
281 void ShowPopupMenu(const std::vector<content::MenuItem>& items,
282 int selectedIndex, bool multiple);
283 Eina_Bool HidePopupMenu();
284 void UpdateFormNavigation(int formElementCount, int currentNodeIndex,
285 bool prevState, bool nextState);
286 void FormNavigate(bool direction);
287 bool IsSelectPickerShown() const;
288 void CloseSelectPicker();
289 bool FormIsNavigating() const { return formIsNavigating_; }
290 void SetFormIsNavigating(bool formIsNavigating);
291 Eina_Bool PopupMenuUpdate(Eina_List* items, int selectedIndex);
292 Eina_Bool DidSelectPopupMenuItem(int selectedIndex);
293 Eina_Bool DidMultipleSelectPopupMenuItem(std::vector<int>& selectedIndices);
294 Eina_Bool PopupMenuClose();
295 void ShowContextMenu(
296 const content::ContextMenuParams& params,
297 content::ContextMenuType type = content::MENU_TYPE_LINK,
298 bool show_selection = true);
299 void CancelContextMenu(int request_id);
300 void SetScale(double scale_factor, int x, int y);
301 bool GetScrollPosition(int* x, int* y) const;
302 void SetScroll(int x, int y);
303 void UrlRequestSet(const char* url,
304 content::NavigationController::LoadURLType loadtype,
308 content::SelectionControllerEfl* GetSelectionController() const { return selection_controller_.get(); }
309 content::PopupControllerEfl* GetPopupController() const { return popup_controller_.get(); }
310 ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
311 void MoveCaret(const gfx::Point& point);
312 void QuerySelectionStyle();
313 void OnQuerySelectionStyleReply(const SelectionStylePrams& params);
314 void SelectClosestWord(const gfx::Point& touch_point);
315 void SelectLinkText(const gfx::Point& touch_point);
316 bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
317 void GetSnapShotForRect(gfx::Rect& rect);
319 // Callback OnCopyFromBackingStore will be called once we get the snapshot from render
320 void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
322 void RenderViewCreated(content::RenderViewHost* render_view_host);
325 * Creates a snapshot of given rectangle from EWebView
327 * @param rect rectangle of EWebView which will be taken into snapshot
329 * @return created snapshot or NULL if error occured.
330 * @note ownership of snapshot is passed to caller
332 Evas_Object* GetSnapshot(Eina_Rectangle rect);
334 bool GetSnapshotAsync(Eina_Rectangle rect, Evas* canvas, Ewk_Web_App_Screenshot_Captured_Callback callback, void* user_data);
335 void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision);
336 void InvokePolicyNavigationCallback(content::RenderViewHost* rvh,
337 NavigationPolicyParams params, bool* handled);
338 void UseSettingsFont();
340 _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
341 Eina_Bool AsyncRequestHitTestDataAt(int x, int y,
342 Ewk_Hit_Test_Mode mode,
343 Ewk_View_Hit_Test_Request_Callback,
345 _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x, int y,
346 Ewk_Hit_Test_Mode mode);
347 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
348 Ewk_Hit_Test_Mode mode,
349 Ewk_View_Hit_Test_Request_Callback,
351 void DispatchAsyncHitTestData(const Hit_Test_Params& params, int64_t request_id);
352 void UpdateHitTestData(const Hit_Test_Params& params);
354 int current_find_request_id() const { return current_find_request_id_; }
355 bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
356 void InvokePlainTextGetCallback(const std::string& content_text, int plain_text_get_callback_id);
357 int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
358 void SetViewGeolocationPermissionCallback(Ewk_View_Geolocation_Permission_Callback callback, void* user_data);
359 bool InvokeViewGeolocationPermissionCallback(_Ewk_Geolocation_Permission_Request* geolocation_permission_request_context, Eina_Bool* result);
360 void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback, void* user_data);
361 bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction, Eina_Bool* result);
362 void DidChangeContentsSize(int width, int height);
363 const Eina_Rectangle GetContentsSize() const;
364 void GetScrollSize(int* w, int* h);
366 void SetProgressValue(double progress);
367 double GetProgressValue();
368 const char* GetTitle();
369 bool SaveAsPdf(int width, int height, const std::string& file_name);
370 void BackForwardListClear();
371 _Ewk_Back_Forward_List* GetBackForwardList() const;
372 void InvokeBackForwardListChangedCallback();
373 _Ewk_History* GetBackForwardHistory() const;
374 bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback, void *userData);
375 bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback, void *userData);
376 bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback, void *userData);
377 void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
378 void InvokeWebAppIconUrlGetCallback(const std::string &iconUrl, int callbackId);
379 void InvokeWebAppIconUrlsGetCallback(const std::map<std::string, std::string> &iconUrls, int callbackId);
380 void SetNotificationPermissionCallback(Ewk_View_Notification_Permission_Callback callback, void* user_data);
381 bool IsNotificationPermissionCallbackSet() const;
382 bool InvokeNotificationPermissionCallback(Ewk_Notification_Permission_Request* request);
384 bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
385 void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
387 void ExitFullscreen();
389 void DidChangePageScaleFactor(double scale_factor);
390 void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback, void* user_data);
391 void JavaScriptAlertReply();
392 void SetJavaScriptConfirmCallback(Ewk_View_JavaScript_Confirm_Callback callback, void* user_data);
393 void JavaScriptConfirmReply(bool result);
394 void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback, void* user_data);
395 void JavaScriptPromptReply(const char* result);
396 void set_renderer_crashed();
397 void GetPageScaleRange(double *min_scale, double *max_scale);
398 void DidChangePageScaleRange(double min_scale, double max_scale);
399 void SetDrawsTransparentBackground(bool enabled);
400 void GetSessionData(const char **data, unsigned *length) const;
401 bool RestoreFromSessionData(const char *data, unsigned length);
402 void ShowFileChooser(const content::FileChooserParams&);
403 void DidChangeContentsArea(int width, int height);
404 void SetBrowserFont();
405 void SetCertificatePem(const std::string& certificate);
406 bool IsDragging() const;
408 void RequestColorPicker(int r, int g, int b, int a);
409 void DismissColorPicker();
410 bool SetColorPickerColor(int r, int g, int b, int a);
411 void InputPickerShow(ui::TextInputType input_type, double input_value);
412 void OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId);
414 void ShowContentsDetectedPopup(const char*);
416 // Returns TCP port number with Inspector, or 0 if error.
417 int StartInspectorServer(int port = 0);
418 bool StopInspectorServer();
420 void LoadNotFoundErrorPage(const std::string& invalidUrl);
421 static std::string GetPlatformLocale();
422 bool GetLinkMagnifierEnabled() const;
423 void SetLinkMagnifierEnabled(bool enabled);
425 void SetOverrideEncoding(const std::string& encoding);
426 void SetViewMode(blink::WebViewMode view_mode);
428 gfx::Point GetContextMenuPosition() const;
430 content::ContextMenuControllerEfl* GetContextMenuController() {
431 return context_menu_.get();
433 void ResetContextMenuController();
435 /// ---- Event handling
438 bool HandleMove(int x, int y);
439 bool HandleResize(int width, int height);
440 bool HandleTextSelectionDown(int x, int y);
441 bool HandleTextSelectionUp(int x, int y);
443 void HandleRendererProcessCrash();
444 void HandlePostponedGesture(int x, int y, ui::EventType type);
446 void InitializeContent();
447 void SendDelayedMessages(content::RenderViewHost* render_view_host);
449 void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
450 Eina_Bool AsyncRequestHitTestDataAtBlinkCords(int x, int y,
451 Ewk_Hit_Test_Mode mode,
452 WebViewAsyncRequestHitTestDataCallback* cb);
453 void HandleLongPressGesture(int x, int y, Ewk_Hit_Test_Mode mode,
455 void HandleTapGesture(int x, int y, Ewk_Hit_Test_Mode mode,
457 content::WebContentsViewEfl* GetWebContentsViewEfl() const;
459 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
460 static void cameraResultCb(service_h request, service_h reply,
461 service_result_e result, void* data);
464 #if defined(OS_TIZEN_MOBILE) && !defined(EWK_BRINGUP)
465 bool LaunchCamera(base::string16 mimetype);
467 content::RenderWidgetHostViewEfl* rwhv() const;
468 JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
470 void ReleasePopupMenuList();
472 scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
473 scoped_refptr<Ewk_Context> context_;
474 scoped_refptr<Ewk_Context> old_context_;
475 scoped_ptr<content::WebContents> web_contents_;
476 scoped_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
477 std::string pending_url_request_;
478 scoped_ptr<Ewk_Settings> settings_;
479 scoped_ptr<_Ewk_Frame> frame_;
480 scoped_ptr<_Ewk_Policy_Decision> window_policy_;
481 Evas_Object* evas_object_;
482 Evas_Object* native_view_;
483 bool touch_events_enabled_;
484 bool mouse_events_enabled_;
485 double text_zoom_factor_;
486 mutable std::string selected_text_;
487 mutable std::string user_agent_;
488 mutable std::string user_agent_app_name_;
489 scoped_ptr<_Ewk_Auth_Challenge> auth_challenge_;
491 Eina_List* popupMenuItems_;
492 Popup_Picker* popupPicker_;
493 bool formIsNavigating_;
500 formNavigation formNavigation_;
501 scoped_ptr<content::ContextMenuControllerEfl> context_menu_;
502 scoped_ptr<content::FileChooserControllerEfl> file_chooser_;
503 scoped_ptr<content::PopupControllerEfl> popup_controller_;
504 scoped_ptr<content::SelectionControllerEfl> selection_controller_;
505 base::string16 previous_text_;
506 int current_find_request_id_;
507 static int find_request_id_counter_;
508 IDMap<EwkViewPlainTextGetCallback, IDMapOwnPointer> plain_text_get_callback_map_;
509 gfx::Size contents_size_;
511 mutable std::string title_;
512 mutable std::string pem_certificate_;
513 Hit_Test_Params hit_test_params_;
514 base::WaitableEvent hit_test_completion_;
515 IDMap<MHTMLCallbackDetails, IDMapOwnPointer> mhtml_callback_map_;
516 double page_scale_factor_;
517 double min_page_scale_factor_;
518 double max_page_scale_factor_;
519 scoped_ptr<OrientationLockCallback> orientation_lock_callback_;
520 scoped_ptr<WebViewGeolocationPermissionCallback> geolocation_permission_cb_;
521 scoped_ptr<WebViewUnfocusAllowCallback> unfocus_allow_cb_;
522 scoped_ptr<content::InputPicker> inputPicker_;
523 IDMap<WebApplicationIconUrlGetCallback, IDMapOwnPointer> web_app_icon_url_get_callback_map_;
524 IDMap<WebApplicationIconUrlsGetCallback, IDMapOwnPointer> web_app_icon_urls_get_callback_map_;
525 IDMap<WebApplicationCapableGetCallback, IDMapOwnPointer> web_app_capable_get_callback_map_;
526 IDMap< WebAppScreenshotCapturedCallback, IDMapOwnPointer> screen_capture_cb_map_;
527 scoped_ptr<NotificationPermissionCallback> notification_permission_callback_;
528 content::DevToolsDelegateEfl* inspector_server_;
529 scoped_ptr<ScrollDetector> scroll_detector_;
530 #if defined(OS_TIZEN_MOBILE)
531 content::FileChooserParams::Mode filechooser_mode_;
533 bool is_initialized_;
535 scoped_ptr<_Ewk_Back_Forward_List> back_forward_list_;
537 static content::WebContentsEflDelegate::WebContentsCreateCallback
538 create_new_window_web_contents_cb_;
541 Eina_Bool AsyncRequestHitTestPrivate(
542 int x, int y, Ewk_Hit_Test_Mode mode,
543 AsyncHitTestRequest* asyncHitTestRequest);
545 gfx::Vector2d previous_scroll_position_;
547 gfx::Point context_menu_position_;
549 std::set<IPC::Message*> delayed_messages_;
551 std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
554 const unsigned int g_default_tilt_motion_sensitivity = 3;