1 /* 2 * Copyright (C) 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef NetscapePluginStream_h 27 #define NetscapePluginStream_h 28 29 #include "RunLoop.h" 30 #include <WebCore/FileSystem.h> 31 #include <WebCore/npruntime_internal.h> 32 #include <wtf/Forward.h> 33 #include <wtf/PassRefPtr.h> 34 #include <wtf/RefCounted.h> 35 #include <wtf/RefPtr.h> 36 #include <wtf/text/CString.h> 37 38 namespace WebCore { 39 class KURL; 40 } 41 42 namespace WebKit { 43 44 class NetscapePlugin; 45 46 class NetscapePluginStream : public RefCounted<NetscapePluginStream> { 47 public: create(PassRefPtr<NetscapePlugin> plugin,uint64_t streamID,bool sendNotification,void * notificationData)48 static PassRefPtr<NetscapePluginStream> create(PassRefPtr<NetscapePlugin> plugin, uint64_t streamID, bool sendNotification, void* notificationData) 49 { 50 return adoptRef(new NetscapePluginStream(plugin, streamID, sendNotification, notificationData)); 51 } 52 ~NetscapePluginStream(); 53 streamID()54 uint64_t streamID() const { return m_streamID; } npStream()55 const NPStream* npStream() const { return &m_npStream; } 56 57 void didReceiveResponse(const WebCore::KURL& responseURL, uint32_t streamLength, 58 uint32_t lastModifiedTime, const String& mimeType, const String& headers); 59 void didReceiveData(const char* bytes, int length); 60 void didFinishLoading(); 61 void didFail(bool wasCancelled); 62 63 void sendJavaScriptStream(const String& requestURLString, const String& result); 64 65 void stop(NPReason); 66 NPError destroy(NPReason); 67 68 private: 69 NetscapePluginStream(PassRefPtr<NetscapePlugin>, uint64_t streamID, bool sendNotification, void* notificationData); 70 71 bool start(const String& responseURLString, uint32_t streamLength, 72 uint32_t lastModifiedTime, const String& mimeType, const String& headers); 73 74 void cancel(); 75 void notifyAndDestroyStream(NPReason); 76 77 void deliverData(const char* bytes, int length); 78 void deliverDataToPlugin(); 79 void deliverDataToFile(const char* bytes, int length); 80 81 RefPtr<NetscapePlugin> m_plugin; 82 uint64_t m_streamID; 83 84 bool m_sendNotification; 85 void* m_notificationData; 86 87 NPStream m_npStream; 88 uint16_t m_transferMode; 89 int32_t m_offset; 90 91 String m_filePath; 92 WebCore::PlatformFileHandle m_fileHandle; 93 94 // Whether NPP_NewStream has successfully been called. 95 bool m_isStarted; 96 97 #if !ASSERT_DISABLED 98 bool m_urlNotifyHasBeenCalled; 99 #endif 100 101 CString m_responseURL; 102 CString m_mimeType; 103 CString m_headers; 104 105 RunLoop::Timer<NetscapePluginStream> m_deliveryDataTimer; 106 OwnPtr< Vector<uint8_t> > m_deliveryData; 107 bool m_stopStreamWhenDoneDelivering; 108 }; 109 110 } // namespace WebKit 111 112 #endif // NetscapePluginStream_h 113