[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

andersca at apple.com andersca at apple.com
Wed Dec 22 11:14:07 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 83986a5990928f37554536cab964bc73c571ac56
Author: andersca at apple.com <andersca at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Jul 15 18:19:27 2010 +0000

    Send JavaScript stream data to plug-ins
    https://bugs.webkit.org/show_bug.cgi?id=42384
    
    Reviewed by Darin Adler.
    
    * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
    (WebKit::NetscapePlugin::NPP_WriteReady):
    (WebKit::NetscapePlugin::NPP_Write):
    * WebProcess/Plugins/Netscape/NetscapePlugin.h:
    Add NPP_ wrappers.
    
    * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp:
    (WebKit::NetscapePluginStream::NetscapePluginStream):
    Initialize m_deliveryDataTimer and m_stopstreamWhenDoneDelivering.
    
    (WebKit::NetscapePluginStream::sendJavaScriptStream):
    Call deliverData and stop.
    
    (WebKit::NetscapePluginStream::deliverData):
    Add the data to m_deliveryData and call deliverDataToPlugin.
    
    (WebKit::NetscapePluginStream::deliverDataToPlugin):
    Deliver the data in m_deliveryData to the plug-in. Call NPP_WriteReady to see how much
    data the plug-in can handle right now. If the plug-in returns zero or a negative value, delay the
    delivery using the delivery data timer. Otherwise, call NPP_Write in chunks until all the data has been
    delivered, then stop the stream if needed.
    
    (WebKit::NetscapePluginStream::stop):
    If the reason for stopping the stream is that it's finished and the plug-in hasn't processed all the data,
    don't close the stream now. Instead, set m_stopStreamWhenDoneDelivering to true which will cause the stream to be
    closed once all data has been delivered.
    
    * WebProcess/Plugins/Netscape/NetscapePluginStream.h:
    Add member functions and member variables.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@63439 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebKit2/ChangeLog b/WebKit2/ChangeLog
index a267b8d..9302306 100644
--- a/WebKit2/ChangeLog
+++ b/WebKit2/ChangeLog
@@ -1,3 +1,40 @@
+2010-07-15  Anders Carlsson  <andersca at apple.com>
+
+        Reviewed by Darin Adler.
+
+        Send JavaScript stream data to plug-ins
+        https://bugs.webkit.org/show_bug.cgi?id=42384
+
+        * WebProcess/Plugins/Netscape/NetscapePlugin.cpp:
+        (WebKit::NetscapePlugin::NPP_WriteReady):
+        (WebKit::NetscapePlugin::NPP_Write):
+        * WebProcess/Plugins/Netscape/NetscapePlugin.h:
+        Add NPP_ wrappers.
+        
+        * WebProcess/Plugins/Netscape/NetscapePluginStream.cpp:
+        (WebKit::NetscapePluginStream::NetscapePluginStream):
+        Initialize m_deliveryDataTimer and m_stopstreamWhenDoneDelivering.
+
+        (WebKit::NetscapePluginStream::sendJavaScriptStream):
+        Call deliverData and stop.
+
+        (WebKit::NetscapePluginStream::deliverData):
+        Add the data to m_deliveryData and call deliverDataToPlugin.
+
+        (WebKit::NetscapePluginStream::deliverDataToPlugin):
+        Deliver the data in m_deliveryData to the plug-in. Call NPP_WriteReady to see how much
+        data the plug-in can handle right now. If the plug-in returns zero or a negative value, delay the
+        delivery using the delivery data timer. Otherwise, call NPP_Write in chunks until all the data has been
+        delivered, then stop the stream if needed.
+
+        (WebKit::NetscapePluginStream::stop):
+        If the reason for stopping the stream is that it's finished and the plug-in hasn't processed all the data,
+        don't close the stream now. Instead, set m_stopStreamWhenDoneDelivering to true which will cause the stream to be
+        closed once all data has been delivered.
+
+        * WebProcess/Plugins/Netscape/NetscapePluginStream.h:
+        Add member functions and member variables.
+
 2010-07-14  Brent Fulgham  <bfulgham at webkit.org>
 
         Reviewed by Steve Falkenburg.
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp b/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
index 0a1c876..f9a4e3f 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
+++ b/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.cpp
@@ -158,6 +158,16 @@ NPError NetscapePlugin::NPP_DestroyStream(NPStream* stream, NPReason reason)
     return m_pluginModule->pluginFuncs().destroystream(&m_npp, stream, reason);
 }
 
+int32_t NetscapePlugin::NPP_WriteReady(NPStream* stream)
+{
+    return m_pluginModule->pluginFuncs().writeready(&m_npp, stream);
+}
+
+int32_t NetscapePlugin::NPP_Write(NPStream* stream, int32_t offset, int32_t len, void* buffer)
+{
+    return m_pluginModule->pluginFuncs().write(&m_npp, stream, offset, len, buffer);
+}
+
 void NetscapePlugin::NPP_URLNotify(const char* url, NPReason reason, void* notifyData)
 {
     m_pluginModule->pluginFuncs().urlnotify(&m_npp, url, reason, notifyData);
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h b/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
index 4786034..b7862a8 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
+++ b/WebKit2/WebProcess/Plugins/Netscape/NetscapePlugin.h
@@ -62,6 +62,9 @@ public:
     NPError NPP_SetWindow(NPWindow*);
     NPError NPP_NewStream(NPMIMEType, NPStream*, NPBool seekable, uint16_t* stype);
     NPError NPP_DestroyStream(NPStream*, NPReason);
+    int32_t NPP_WriteReady(NPStream*);
+    int32_t NPP_Write(NPStream*, int32_t offset, int32_t len, void* buffer);
+
     void NPP_URLNotify(const char* url, NPReason reason, void* notifyData);
 
 private:
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp b/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
index 651b6f9..7816e9e 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
+++ b/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.cpp
@@ -26,8 +26,10 @@
 #include "NetscapePluginStream.h"
 
 #include "NetscapePlugin.h"
+#include <utility>
 
 using namespace WebCore;
+using namespace std;
 
 namespace WebKit {
 
@@ -40,6 +42,8 @@ NetscapePluginStream::NetscapePluginStream(PassRefPtr<NetscapePlugin> plugin, ui
     , m_transferMode(NP_NORMAL)
     , m_offset(0)
     , m_isStarted(false)
+    , m_deliveryDataTimer(RunLoop::main(), this, &NetscapePluginStream::deliverDataToPlugin)
+    , m_stopStreamWhenDoneDelivering(false)
 {
 }
 
@@ -62,7 +66,8 @@ void NetscapePluginStream::sendJavaScriptStream(const String& requestURLString,
         return;
     }
 
-    // FIXME: Send the JavaScript string as well.
+    deliverData(resultCString.data(), resultCString.length());
+    stop(NPRES_DONE);
 }
 
 bool NetscapePluginStream::start(const WebCore::String& responseURLString, uint32_t expectedContentLength, 
@@ -100,14 +105,93 @@ bool NetscapePluginStream::start(const WebCore::String& responseURLString, uint3
 
     return true;
 }
-    
+
+void NetscapePluginStream::deliverData(const char* bytes, int length)
+{
+    ASSERT(m_isStarted);
+
+    if (m_transferMode != NP_ASFILEONLY) {
+        if (!m_deliveryData)
+            m_deliveryData.set(new Vector<char>);
+
+        m_deliveryData->reserveCapacity(m_deliveryData->size() + length);
+        m_deliveryData->append(bytes, length);
+        
+        deliverDataToPlugin();
+    }
+
+    // FIXME: Deliver the data to a file as well if needed.
+}
+
+void NetscapePluginStream::deliverDataToPlugin()
+{
+    ASSERT(m_isStarted);
+
+    int32_t numBytesToDeliver = m_deliveryData->size();
+    int32_t numBytesDelivered = 0;
+
+    while (numBytesDelivered < numBytesToDeliver) {
+        int32_t numBytesPluginCanHandle = m_plugin->NPP_WriteReady(&m_npStream);
+        
+        if (numBytesPluginCanHandle <= 0) {
+            // The plug-in can't handle more data, we'll send the rest later
+            m_deliveryDataTimer.startOneShot(0);
+            break;
+        }
+
+        // Figure out how much data to send to the plug-in.
+        int32_t dataLength = min(numBytesPluginCanHandle, numBytesToDeliver - numBytesDelivered);
+        char* data = m_deliveryData->data() + numBytesDelivered;
+
+        int32_t numBytesWritten = m_plugin->NPP_Write(&m_npStream, m_offset, dataLength, data);
+        if (numBytesWritten < 0) {
+            // FIXME: Destroy the stream!
+            ASSERT_NOT_REACHED();
+        }
+
+        numBytesWritten = min(numBytesWritten, dataLength);
+        m_offset += numBytesWritten;
+        numBytesDelivered += numBytesWritten;
+    }
+
+    // We didn't write anything.
+    if (!numBytesDelivered)
+        return;
+
+    if (numBytesDelivered < numBytesToDeliver) {
+        // Remove the bytes that we actually delivered.
+        m_deliveryData->remove(0, numBytesDelivered);
+    } else {
+        m_deliveryData->clear();
+
+        if (m_stopStreamWhenDoneDelivering)
+            stop(NPRES_DONE);
+    }
+}
+
 void NetscapePluginStream::stop(NPReason reason)
 {
     if (m_isStarted) {
+        if (reason == NPRES_DONE && m_deliveryData && !m_deliveryData->isEmpty()) {
+            // There is still data left that the plug-in hasn't been able to consume yet.
+            ASSERT(m_deliveryDataTimer.isActive());
+            
+            // Set m_stopStreamWhenDoneDelivering to true so that the next time the delivery timer fires
+            // and calls deliverDataToPlugin the stream will be closed if all the remaining data was
+            // successfully delivered.
+            m_stopStreamWhenDoneDelivering = true;
+            return;
+        }
+
+        m_deliveryData = 0;
+        m_deliveryDataTimer.stop();
+
         m_plugin->NPP_DestroyStream(&m_npStream, reason);
         m_isStarted = false;
     }
 
+    ASSERT(!m_deliveryDataTimer.isActive());
+
     if (m_sendNotification)
         m_plugin->NPP_URLNotify(m_responseURL.data(), reason, m_notificationData);
 
@@ -115,4 +199,3 @@ void NetscapePluginStream::stop(NPReason reason)
 }
 
 } // namespace WebKit
-
diff --git a/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h b/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h
index e02d707..f97dbf2 100644
--- a/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h
+++ b/WebKit2/WebProcess/Plugins/Netscape/NetscapePluginStream.h
@@ -26,6 +26,7 @@
 #ifndef NetscapePluginStream_h
 #define NetscapePluginStream_h
 
+#include "RunLoop.h"
 #include <WebCore/npapi.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
@@ -59,6 +60,9 @@ private:
                uint32_t lastModifiedTime, const WebCore::String& mimeType, const WebCore::String& headers);
     void stop(NPReason);
 
+    void deliverData(const char* bytes, int length);
+    void deliverDataToPlugin();
+
     RefPtr<NetscapePlugin> m_plugin;
     uint64_t m_streamID;
     
@@ -75,6 +79,10 @@ private:
     CString m_responseURL;
     CString m_mimeType;
     CString m_headers;
+
+    RunLoop::Timer<NetscapePluginStream> m_deliveryDataTimer;
+    OwnPtr< Vector<char> > m_deliveryData;
+    bool m_stopStreamWhenDoneDelivering;
 };
 
 } // namespace WebKit

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list