[EFL] Add try_close API to handle beforeunload event
authorryuan.choi@navercorp.com <ryuan.choi@navercorp.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Nov 2015 09:29:40 +0000 (09:29 +0000)
committerryuan.choi@navercorp.com <ryuan.choi@navercorp.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Nov 2015 09:29:40 +0000 (09:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150705

Reviewed by Gyuyoung Kim.

Source/WebKit2:

This patch adds ewk_view_try_close to have a chance to call confirm callback
for beforeunload event while destryoing webview.

* UIProcess/API/efl/ewk_view.cpp:
(ewk_view_try_close):
* UIProcess/API/efl/ewk_view.h:
* UIProcess/API/efl/tests/test_ewk2_view.cpp:
(EWK2ViewTest::beforeUnloadCallback):
(EWK2ViewTest::windowCloseCallback):
(TEST_F): Added test case for ewk_view_try_close.

Tools:

* MiniBrowser/efl/main.c:
(on_window_deletion):
Call ewk_view_try_close instead of removing object directly.
(window_create): Fixed that passes wrong data.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192053 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/efl/ewk_view.cpp
Source/WebKit2/UIProcess/API/efl/ewk_view.h
Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_view.cpp
Tools/ChangeLog
Tools/MiniBrowser/efl/main.c

index 10248f4..5415625 100644 (file)
@@ -1,3 +1,21 @@
+2015-11-05  Ryuan Choi  <ryuan.choi@navercorp.com>
+
+        [EFL] Add try_close API to handle beforeunload event
+        https://bugs.webkit.org/show_bug.cgi?id=150705
+
+        Reviewed by Gyuyoung Kim.
+
+        This patch adds ewk_view_try_close to have a chance to call confirm callback
+        for beforeunload event while destryoing webview.
+
+        * UIProcess/API/efl/ewk_view.cpp:
+        (ewk_view_try_close):
+        * UIProcess/API/efl/ewk_view.h:
+        * UIProcess/API/efl/tests/test_ewk2_view.cpp:
+        (EWK2ViewTest::beforeUnloadCallback):
+        (EWK2ViewTest::windowCloseCallback):
+        (TEST_F): Added test case for ewk_view_try_close.
+
 2015-11-04  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         [GTK] Epiphany with Debug mode compiled WebKitGtk+ 2.10.3 hits ASSERT_ARG on willEnterAcceleratedCompositingMode
index c67eca5..e20dab2 100644 (file)
@@ -126,6 +126,13 @@ Evas_Object* ewk_view_add_with_context(Evas* canvas, Ewk_Context* context)
     return EWKViewCreate(ewkContext->wkContext(), 0, canvas, 0);
 }
 
+void ewk_view_try_close(Evas_Object* ewkView)
+{
+    EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl);
+
+    WKPageTryClose(impl->wkPage());
+}
+
 Ewk_Context* ewk_view_context_get(const Evas_Object* ewkView)
 {
     EWK_VIEW_IMPL_GET_OR_RETURN(ewkView, impl, nullptr);
index c0013e6..1239ebb 100644 (file)
@@ -364,6 +364,17 @@ EAPI Evas_Object *ewk_view_add(Evas *e);
 EAPI Evas_Object *ewk_view_add_with_context(Evas *e, Ewk_Context *context);
 
 /**
+ * Tries to close this view.
+ *
+ * If current web page in @a o contains onbeforeunload event, this will fire
+ * run_javascript_confirm callback in smart class.
+ * If not, this will fire window_close callback in smart class.
+ *
+ * @param o the view object to try to close.
+ */
+EAPI void ewk_view_try_close(Evas_Object *o);
+
+/**
  * Gets the Ewk_Context of this view.
  *
  * @param o the view object to get the Ewk_Context
index cbcdfc6..dce2ac7 100644 (file)
@@ -32,6 +32,7 @@ extern EWK2UnitTestEnvironment* environment;
 static bool fullScreenCallbackCalled;
 static bool obtainedPageContents = false;
 static bool scriptExecuteCallbackCalled;
+static bool windowCloseCallbackCalled = false;
 
 static const int scrollBarWidth = 10;
 
@@ -248,6 +249,16 @@ public:
         Ewk_Focus_Direction* result = static_cast<Ewk_Focus_Direction*>(userData);
         *result = *direction;
     }
+
+    static Eina_Bool beforeUnloadCallback(Ewk_View_Smart_Data*, const char*)
+    {
+        return true;
+    }
+
+    static void windowCloseCallback(Ewk_View_Smart_Data *sd)
+    {
+        windowCloseCallbackCalled = true;
+    }
 };
 
 TEST_F(EWK2ViewTest, ewk_view_type_check)
@@ -267,6 +278,19 @@ TEST_F(EWK2ViewTest, ewk_view_add)
     evas_object_del(view);
 }
 
+TEST_F(EWK2ViewTest, ewk_view_try_close)
+{
+    ewkViewClass()->run_javascript_confirm = beforeUnloadCallback;
+    ewkViewClass()->window_close = windowCloseCallback;
+
+    const char content[] = "<!doctype html><html><body onbeforeunload='return func();'><script>function func() { return 'beforeunload message'; }</script></body></html>";
+    ewk_view_html_string_load(webView(), content, 0, 0);
+    ASSERT_TRUE(waitUntilLoadFinished());
+
+    ewk_view_try_close(webView());
+    ASSERT_TRUE(waitUntilTrue(windowCloseCallbackCalled));
+}
+
 TEST_F(EWK2ViewTest, ewk_view_url_get)
 {
     ASSERT_TRUE(loadUrlSync(environment->defaultTestPageUrl()));
index e3496a5..3e62f5e 100644 (file)
@@ -1,3 +1,15 @@
+2015-11-05  Ryuan Choi  <ryuan.choi@navercorp.com>
+
+        [EFL] Add try_close API to handle beforeunload event
+        https://bugs.webkit.org/show_bug.cgi?id=150705
+
+        Reviewed by Gyuyoung Kim.
+
+        * MiniBrowser/efl/main.c:
+        (on_window_deletion):
+        Call ewk_view_try_close instead of removing object directly.
+        (window_create): Fixed that passes wrong data.
+
 2015-11-04  Wenson Hsieh  <wenson_hsieh@apple.com>
 
         Fix crashing and flaky UIScriptController-based tests in fast/events/ios
index c80675e..6da4ca2 100644 (file)
@@ -2031,7 +2031,8 @@ on_home_button_clicked(void *user_data, Evas_Object *home_button, void *event_in
 static void
 on_window_deletion(void *user_data, Evas_Object *elm_window, void *event_info)
 {
-    window_close(window_find_with_elm_window(elm_window));
+    Browser_Window *window = (Browser_Window *)user_data;
+    ewk_view_try_close(window->ewk_view);
 }
 
 static Evas_Object *
@@ -2067,7 +2068,7 @@ static Browser_Window *window_create(Evas_Object *opener, int width, int height)
     /* Create window */
     window->elm_window = elm_win_add(NULL, "minibrowser-window", ELM_WIN_BASIC);
     elm_win_title_set(window->elm_window, APP_NAME);
-    evas_object_smart_callback_add(window->elm_window, "delete,request", on_window_deletion, &window);
+    evas_object_smart_callback_add(window->elm_window, "delete,request", on_window_deletion, window);
 
     /* Create window background */
     Evas_Object *bg = elm_bg_add(window->elm_window);