[EFL][CustomProtocol] Do not add duplicated custom scheme
authorgyuyoung.kim@webkit.org <gyuyoung.kim@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Jun 2015 07:00:22 +0000 (07:00 +0000)
committergyuyoung.kim@webkit.org <gyuyoung.kim@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Jun 2015 07:00:22 +0000 (07:00 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146199

Reviewed by Carlos Garcia Campos.

WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol generates
a crash when duplicated scheme is registered on debug mode, or just registers it on release mode.
However application can register duplicate scheme by mistake or on purpose. Thus it would be good
if we don't register it instead of registering it or generating a crash when trying to regiseter
duplicated scheme.

EFL port want to allow user to change registered callback, thus EWK2ContextTest::ewk_context_url_scheme_register()
is modified to test it.

Test: ewk_context_url_scheme_register() in test_ewk2_context.cpp.

* UIProcess/API/efl/ewk_context.h: Added a comment to replace registered callback.
* UIProcess/API/efl/tests/test_ewk2_context.cpp:
(EWK2ContextTest::schemeRequestCallback1):
(EWK2ContextTest::schemeRequestCallback2):
(TEST_F):
(EWK2ContextTest::schemeRequestCallback): Deleted.
* UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp:
(WebKit::WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/efl/ewk_context.h
Source/WebKit2/UIProcess/API/efl/tests/test_ewk2_context.cpp
Source/WebKit2/UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp

index eeb6fd7..4160143 100644 (file)
@@ -1,3 +1,30 @@
+2015-06-22  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
+
+        [EFL][CustomProtocol] Do not add duplicated custom scheme
+        https://bugs.webkit.org/show_bug.cgi?id=146199
+
+        Reviewed by Carlos Garcia Campos.
+
+        WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol generates
+        a crash when duplicated scheme is registered on debug mode, or just registers it on release mode.
+        However application can register duplicate scheme by mistake or on purpose. Thus it would be good
+        if we don't register it instead of registering it or generating a crash when trying to regiseter
+        duplicated scheme.
+
+        EFL port want to allow user to change registered callback, thus EWK2ContextTest::ewk_context_url_scheme_register()
+        is modified to test it.
+
+        Test: ewk_context_url_scheme_register() in test_ewk2_context.cpp.
+
+        * UIProcess/API/efl/ewk_context.h: Added a comment to replace registered callback.
+        * UIProcess/API/efl/tests/test_ewk2_context.cpp:
+        (EWK2ContextTest::schemeRequestCallback1):
+        (EWK2ContextTest::schemeRequestCallback2):
+        (TEST_F):
+        (EWK2ContextTest::schemeRequestCallback): Deleted.
+        * UIProcess/Network/CustomProtocols/soup/WebSoupCustomProtocolRequestManager.cpp:
+        (WebKit::WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol):
+
 2015-06-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Update OptionsGTK.cmake and NEWS for 2.9.3 release.
index beffc75..b67397f 100644 (file)
@@ -304,6 +304,9 @@ EAPI Ewk_Storage_Manager *ewk_context_storage_manager_get(const Ewk_Context *con
  * #Ewk_Url_Scheme_Request and calling ewk_url_scheme_request_finish() later when the data of
  * the request is available.
  *
+ * To replace registered callback with new callback, calls ewk_context_url_scheme_register()
+ * with new callback again.
+ *
  * @param context a #Ewk_Context object.
  * @param scheme the network scheme to register
  * @param callback the function to be called when an URL request with @a scheme is made.
index 530f9fc..44a0e3e 100644 (file)
@@ -44,7 +44,7 @@ static constexpr double testTimeoutSeconds = 2.0;
 
 class EWK2ContextTest : public EWK2UnitTestBase {
 public:
-    static void schemeRequestCallback(Ewk_Url_Scheme_Request* request, void* userData)
+    static void schemeRequestCallback1(Ewk_Url_Scheme_Request* request, void* userData)
     {
         const char* scheme = ewk_url_scheme_request_scheme_get(request);
         ASSERT_STREQ("fooscheme", scheme);
@@ -56,6 +56,19 @@ public:
 
         finishTest = true;
     }
+
+    static void schemeRequestCallback2(Ewk_Url_Scheme_Request* request, void* userData)
+    {
+        const char* scheme = ewk_url_scheme_request_scheme_get(request);
+        ASSERT_STREQ("fooscheme", scheme);
+        const char* url = ewk_url_scheme_request_url_get(request);
+        ASSERT_STREQ("fooscheme:MyNewPath", url);
+        const char* path = ewk_url_scheme_request_path_get(request);
+        ASSERT_STREQ("MyNewPath", path);
+        ASSERT_TRUE(ewk_url_scheme_request_finish(request, htmlReply, strlen(htmlReply), "text/html"));
+
+        finishTest = true;
+    }
 };
 
 class EWK2ContextTestMultipleProcesses : public EWK2UnitTestBase {
@@ -132,9 +145,13 @@ TEST_F(EWK2ContextTest, ewk_context_storage_manager_get)
 
 TEST_F(EWK2ContextTest, ewk_context_url_scheme_register)
 {
-    ewk_context_url_scheme_register(ewk_view_context_get(webView()), "fooscheme", schemeRequestCallback, nullptr);
+    ewk_context_url_scheme_register(ewk_view_context_get(webView()), "fooscheme", schemeRequestCallback1, nullptr);
     ewk_view_url_set(webView(), "fooscheme:MyPath");
+    ASSERT_TRUE(waitUntilTrue(finishTest, testTimeoutSeconds));
 
+    finishTest = false;
+    ewk_context_url_scheme_register(ewk_view_context_get(webView()), "fooscheme", schemeRequestCallback2, nullptr);
+    ewk_view_url_set(webView(), "fooscheme:MyNewPath");
     ASSERT_TRUE(waitUntilTrue(finishTest, testTimeoutSeconds));
 }
 
index d0bb204..b655e43 100644 (file)
@@ -80,12 +80,15 @@ void WebSoupCustomProtocolRequestManager::derefWebContextSupplement()
 
 void WebSoupCustomProtocolRequestManager::registerSchemeForCustomProtocol(const String& scheme)
 {
+    ASSERT(!scheme.isNull());
+    if (m_registeredSchemes.contains(scheme))
+        return;
+
     if (!processPool())
         return;
 
     processPool()->registerSchemeForCustomProtocol(scheme);
 
-    ASSERT(!m_registeredSchemes.contains(scheme));
     m_registeredSchemes.append(scheme);
 }