Implement NPAPI redirect handling
[WebKit-https.git] / Source / WebKit2 / WebProcess / Plugins / PluginView.cpp
index 24d42f4..baf5671 100644 (file)
@@ -115,6 +115,7 @@ public:
 
     void start();
     void cancel();
+    void continueLoad();
 
     uint64_t streamID() const { return m_streamID; }
 
@@ -128,15 +129,17 @@ private:
     }
 
     // NetscapePluginStreamLoaderClient
-    virtual void didReceiveResponse(NetscapePlugInStreamLoader*, const ResourceResponse&);
-    virtual void didReceiveData(NetscapePlugInStreamLoader*, const char*, int);
-    virtual void didFail(NetscapePlugInStreamLoader*, const ResourceError&);
-    virtual void didFinishLoading(NetscapePlugInStreamLoader*);
+    void willSendRequest(NetscapePlugInStreamLoader*, ResourceRequest&&, const ResourceResponse& redirectResponse, std::function<void (ResourceRequest&&)>&&) override;
+    void didReceiveResponse(NetscapePlugInStreamLoader*, const ResourceResponse&) override;
+    void didReceiveData(NetscapePlugInStreamLoader*, const char*, int) override;
+    void didFail(NetscapePlugInStreamLoader*, const ResourceError&) override;
+    void didFinishLoading(NetscapePlugInStreamLoader*) override;
 
     PluginView* m_pluginView;
     uint64_t m_streamID;
-    const ResourceRequest m_request;
-    
+    ResourceRequest m_request;
+    std::function<void (ResourceRequest)> m_loadCallback;
+
     // True if the stream was explicitly cancelled by calling cancel().
     // (As opposed to being cancelled by the user hitting the stop button for example.
     bool m_streamWasCancelled;
@@ -169,6 +172,14 @@ void PluginView::Stream::cancel()
     m_loader = nullptr;
 }
 
+void PluginView::Stream::continueLoad()
+{
+    ASSERT(m_pluginView->m_plugin);
+    ASSERT(m_loadCallback);
+
+    m_loadCallback(m_request);
+}
+
 static String buildHTTPHeaders(const ResourceResponse& response, long long& expectedContentLength)
 {
     if (!response.isHTTP())
@@ -210,6 +221,16 @@ static uint32_t lastModifiedDateMS(const ResourceResponse& response)
     return std::chrono::duration_cast<std::chrono::milliseconds>(lastModified.value().time_since_epoch()).count();
 }
 
+void PluginView::Stream::willSendRequest(NetscapePlugInStreamLoader*, ResourceRequest&& request, const ResourceResponse& redirectResponse, std::function<void (ResourceRequest&&)>&& decisionHandler)
+{
+    const URL& requestURL = request.url();
+    const URL& redirectResponseURL = redirectResponse.url();
+
+    m_loadCallback = decisionHandler;
+    m_request = request;
+    m_pluginView->m_plugin->streamWillSendRequest(m_streamID, requestURL, redirectResponseURL, redirectResponse.httpStatusCode());
+}
+
 void PluginView::Stream::didReceiveResponse(NetscapePlugInStreamLoader*, const ResourceResponse& response)
 {
     // Compute the stream related data from the resource response.
@@ -1404,6 +1425,15 @@ void PluginView::cancelStreamLoad(uint64_t streamID)
     ASSERT(!m_streams.contains(streamID));
 }
 
+void PluginView::continueStreamLoad(uint64_t streamID)
+{
+    RefPtr<Stream> stream = m_streams.get(streamID);
+    if (!stream)
+        return;
+
+    stream->continueLoad();
+}
+
 void PluginView::cancelManualStreamLoad()
 {
     if (!frame())