[WPE] Downloads never have a web view associated in WPE
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Jun 2017 11:55:07 +0000 (11:55 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Jun 2017 11:55:07 +0000 (11:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173709

Reviewed by Žan Doberšek.

Convert the WPE view client into an API client and add handleDownloadRequest(). WebKitWebView now uses it to
associate itself to the download like the GTK+ port does.

* PlatformWPE.cmake:
* UIProcess/API/C/wpe/WKView.cpp:
(WKViewSetViewClient): Add C API client implementation here.
* UIProcess/API/glib/WebKitWebView.cpp:
(webkitWebViewConstructed): Set the view client in WPE.
* UIProcess/API/wpe/APIViewClient.h: Renamed from Source/WebKit2/UIProcess/API/wpe/WPEViewClient.h.
(API::ViewClient::frameDisplayed):
(API::ViewClient::handleDownloadRequest):
* UIProcess/API/wpe/PageClientImpl.cpp:
(WebKit::PageClientImpl::handleDownloadRequest): Call WKWPE::View::handleDownloadRequest().
* UIProcess/API/wpe/WPEView.cpp:
(WKWPE::View::View): Initialize the view client.
(WKWPE::View::setClient): Set or reset the client.
(WKWPE::View::handleDownloadRequest): Notify the client.
* UIProcess/API/wpe/WPEView.h:
* UIProcess/API/wpe/WPEViewClient.cpp: Removed.

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

Source/WebKit2/ChangeLog
Source/WebKit2/PlatformWPE.cmake
Source/WebKit2/UIProcess/API/C/wpe/WKView.cpp
Source/WebKit2/UIProcess/API/glib/WebKitWebView.cpp
Source/WebKit2/UIProcess/API/wpe/APIViewClient.h [moved from Source/WebKit2/UIProcess/API/wpe/WPEViewClient.h with 82% similarity]
Source/WebKit2/UIProcess/API/wpe/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/wpe/WPEView.cpp
Source/WebKit2/UIProcess/API/wpe/WPEView.h
Source/WebKit2/UIProcess/API/wpe/WPEViewClient.cpp [deleted file]

index 2f45c61..4624866 100644 (file)
@@ -1,5 +1,32 @@
 2017-06-22  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [WPE] Downloads never have a web view associated in WPE
+        https://bugs.webkit.org/show_bug.cgi?id=173709
+
+        Reviewed by Žan Doberšek.
+
+        Convert the WPE view client into an API client and add handleDownloadRequest(). WebKitWebView now uses it to
+        associate itself to the download like the GTK+ port does.
+
+        * PlatformWPE.cmake:
+        * UIProcess/API/C/wpe/WKView.cpp:
+        (WKViewSetViewClient): Add C API client implementation here.
+        * UIProcess/API/glib/WebKitWebView.cpp:
+        (webkitWebViewConstructed): Set the view client in WPE.
+        * UIProcess/API/wpe/APIViewClient.h: Renamed from Source/WebKit2/UIProcess/API/wpe/WPEViewClient.h.
+        (API::ViewClient::frameDisplayed):
+        (API::ViewClient::handleDownloadRequest):
+        * UIProcess/API/wpe/PageClientImpl.cpp:
+        (WebKit::PageClientImpl::handleDownloadRequest): Call WKWPE::View::handleDownloadRequest().
+        * UIProcess/API/wpe/WPEView.cpp:
+        (WKWPE::View::View): Initialize the view client.
+        (WKWPE::View::setClient): Set or reset the client.
+        (WKWPE::View::handleDownloadRequest): Notify the client.
+        * UIProcess/API/wpe/WPEView.h:
+        * UIProcess/API/wpe/WPEViewClient.cpp: Removed.
+
+2017-06-22  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [WPE] Page should be closed on WebKitWebView dispose
         https://bugs.webkit.org/show_bug.cgi?id=173707
 
index 9c53c75..b6564e9 100644 (file)
@@ -193,7 +193,6 @@ list(APPEND WebKit2_SOURCES
     UIProcess/API/wpe/ScrollGestureController.cpp
     UIProcess/API/wpe/WebKitWebViewWPE.cpp
     UIProcess/API/wpe/WPEView.cpp
-    UIProcess/API/wpe/WPEViewClient.cpp
 
     UIProcess/Launcher/wpe/ProcessLauncherWPE.cpp
 
index ccbb237..adc3de0 100644 (file)
 #include "WKView.h"
 
 #include "APIPageConfiguration.h"
+#include "APIViewClient.h"
 #include "PageClientImpl.h"
 #include "WKAPICast.h"
 #include "WPEView.h"
 
 using namespace WebKit;
 
+namespace API {
+template<> struct ClientTraits<WKViewClientBase> {
+    typedef std::tuple<WKViewClientV0> Versions;
+};
+}
+
 WKViewRef WKViewCreate(WKPageConfigurationRef configuration)
 {
     return toAPI(WKWPE::View::create(nullptr, *toImpl(configuration)));
@@ -55,5 +62,21 @@ void WKViewSetViewState(WKViewRef view, WKViewState viewState)
 
 void WKViewSetViewClient(WKViewRef view, const WKViewClientBase* client)
 {
-    toImpl(view)->initializeClient(client);
+    class ViewClient final : public API::Client<WKViewClientBase>, public API::ViewClient {
+    public:
+        explicit ViewClient(const WKViewClientBase* client)
+        {
+            initialize(client);
+        }
+
+    private:
+        void frameDisplayed(WKWPE::View& view) override
+        {
+            if (!m_client.frameDisplayed)
+                return;
+            m_client.frameDisplayed(toAPI(&view), m_client.base.clientInfo);
+        }
+    };
+
+    toImpl(view)->setClient(std::make_unique<ViewClient>(client));
 }
index 345cdb1..29ffb04 100644 (file)
@@ -77,6 +77,7 @@
 #endif
 
 #if PLATFORM(WPE)
+#include "APIViewClient.h"
 #include "WPEView.h"
 #endif
 
@@ -335,6 +336,24 @@ private:
     WebKitWebView* m_webView;
 };
 
+#if PLATFORM(WPE)
+class WebViewClient final : public API::ViewClient {
+public:
+    explicit WebViewClient(WebKitWebView* webView)
+        : m_webView(webView)
+    {
+    }
+
+private:
+    void handleDownloadRequest(WKWPE::View&, DownloadProxy& downloadProxy) override
+    {
+        webkitWebViewHandleDownloadRequest(m_webView, &downloadProxy);
+    }
+
+    WebKitWebView* m_webView;
+};
+#endif
+
 static gboolean webkitWebViewLoadFail(WebKitWebView* webView, WebKitLoadEvent, const char* failingURI, GError* error)
 {
     if (g_error_matches(error, WEBKIT_NETWORK_ERROR, WEBKIT_NETWORK_ERROR_CANCELLED)
@@ -615,6 +634,10 @@ static void webkitWebViewConstructed(GObject* object)
     attachContextMenuClientToView(webView);
     attachFormClientToView(webView);
 
+#if PLATFORM(WPE)
+    priv->view->setClient(std::make_unique<WebViewClient>(webView));
+#endif
+
     // This needs to be after attachUIClientToView() because WebPageProxy::setUIClient() calls setCanRunModal() with true.
     // See https://bugs.webkit.org/show_bug.cgi?id=135412.
     webkitWebViewUpdateSettings(webView);
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2016 Igalia S.L.
+ * Copyright (C) 2017 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 
 #pragma once
 
-#include "APIClient.h"
-#include <WebKit/WKView.h>
-
-namespace API {
-template<> struct ClientTraits<WKViewClientBase> {
-    typedef std::tuple<WKViewClientV0> Versions;
-};
+namespace WebKit {
+class DownloadProxy;
 }
 
 namespace WKWPE {
-
 class View;
+}
+
+namespace API {
 
-class ViewClient : public API::Client<WKViewClientBase> {
+class ViewClient {
 public:
-    void frameDisplayed(View&);
+    virtual ~ViewClient() = default;
+
+    virtual void frameDisplayed(WKWPE::View&) { }
+    virtual void handleDownloadRequest(WKWPE::View&, WebKit::DownloadProxy&) { }
 };
 
-} // namespace WebKit
+} // namespace API
index b102dee..0eaee89 100644 (file)
@@ -112,8 +112,10 @@ void PageClientImpl::didCommitLoadForMainFrame(const String&, bool)
 {
 }
 
-void PageClientImpl::handleDownloadRequest(DownloadProxy*)
+void PageClientImpl::handleDownloadRequest(DownloadProxy* download)
 {
+    ASSERT(download);
+    m_view.handleDownloadRequest(*download);
 }
 
 void PageClientImpl::didChangeContentSize(const WebCore::IntSize&)
index 2f67f04..94bb5ca 100644 (file)
@@ -27,6 +27,7 @@
 #include "WPEView.h"
 
 #include "APIPageConfiguration.h"
+#include "APIViewClient.h"
 #include "DrawingAreaProxy.h"
 #include "NativeWebKeyboardEvent.h"
 #include "NativeWebMouseEvent.h"
@@ -41,7 +42,8 @@ using namespace WebKit;
 namespace WKWPE {
 
 View::View(struct wpe_view_backend* backend, const API::PageConfiguration& baseConfiguration)
-    : m_pageClient(std::make_unique<PageClientImpl>(*this))
+    : m_client(std::make_unique<API::ViewClient>())
+    , m_pageClient(std::make_unique<PageClientImpl>(*this))
     , m_size { 800, 600 }
     , m_viewStateFlags(WebCore::ActivityState::WindowIsActive | WebCore::ActivityState::IsFocused | WebCore::ActivityState::IsVisible | WebCore::ActivityState::IsInWindow)
     , m_compositingManagerProxy(*this)
@@ -130,14 +132,22 @@ View::~View()
     wpe_view_backend_destroy(m_backend);
 }
 
-void View::initializeClient(const WKViewClientBase* client)
+void View::setClient(std::unique_ptr<API::ViewClient>&& client)
 {
-    m_client.initialize(client);
+    if (!client)
+        m_client = std::make_unique<API::ViewClient>();
+    else
+        m_client = WTFMove(client);
 }
 
 void View::frameDisplayed()
 {
-    m_client.frameDisplayed(*this);
+    m_client->frameDisplayed(*this);
+}
+
+void View::handleDownloadRequest(DownloadProxy& download)
+{
+    m_client->handleDownloadRequest(*this, download);
 }
 
 void View::setSize(const WebCore::IntSize& size)
index dc6160e..9305b26 100644 (file)
@@ -28,7 +28,6 @@
 #include "APIObject.h"
 #include "CompositingManagerProxy.h"
 #include "PageClientImpl.h"
-#include "WPEViewClient.h"
 #include "WebPageProxy.h"
 #include <WebCore/ActivityState.h>
 #include <memory>
 
 struct wpe_view_backend;
 
+namespace API {
+class ViewClient;
+}
+
 namespace WebKit {
+class DownloadProxy;
 class WebPageGroup;
 class WebProcessPool;
 }
@@ -52,8 +56,9 @@ public:
     virtual ~View();
 
     // Client methods
-    void initializeClient(const WKViewClientBase*);
+    void setClient(std::unique_ptr<API::ViewClient>&&);
     void frameDisplayed();
+    void handleDownloadRequest(WebKit::DownloadProxy&);
 
     WebKit::WebPageProxy& page() { return *m_pageProxy; }
 
@@ -71,7 +76,7 @@ private:
 
     void setSize(const WebCore::IntSize&);
 
-    ViewClient m_client;
+    std::unique_ptr<API::ViewClient> m_client;
 
     std::unique_ptr<WebKit::PageClientImpl> m_pageClient;
     RefPtr<WebKit::WebPageProxy> m_pageProxy;
diff --git a/Source/WebKit2/UIProcess/API/wpe/WPEViewClient.cpp b/Source/WebKit2/UIProcess/API/wpe/WPEViewClient.cpp
deleted file mode 100644 (file)
index 444ac98..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (C) 2016 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
- * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
- * THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "WPEViewClient.h"
-
-#include "WKAPICast.h"
-#include "WKBase.h"
-#include "WPEView.h"
-
-using namespace WebKit;
-
-namespace WKWPE {
-
-void ViewClient::frameDisplayed(View& view)
-{
-    if (m_client.frameDisplayed)
-        m_client.frameDisplayed(toAPI(&view), m_client.base.clientInfo);
-}
-
-} // namespace WKWPE