1 /* 2 * Copyright (C) 2008 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. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #if USE(PLUGIN_HOST_PROCESS) 27 28 #ifndef HostedNetscapePluginStream_h 29 #define HostedNetscapePluginStream_h 30 31 #include <WebCore/NetscapePlugInStreamLoader.h> 32 #include <WebKit/npapi.h> 33 #include <wtf/PassRefPtr.h> 34 #include <wtf/RefCounted.h> 35 #include <wtf/RefPtr.h> 36 #include <wtf/RetainPtr.h> 37 38 namespace WebCore { 39 class FrameLoader; 40 class NetscapePlugInStreamLoader; 41 } 42 43 namespace WebKit { 44 45 class NetscapePluginInstanceProxy; 46 47 class HostedNetscapePluginStream : public RefCounted<HostedNetscapePluginStream> 48 , private WebCore::NetscapePlugInStreamLoaderClient { 49 public: create(NetscapePluginInstanceProxy * instance,uint32_t streamID,NSURLRequest * request)50 static PassRefPtr<HostedNetscapePluginStream> create(NetscapePluginInstanceProxy* instance, uint32_t streamID, NSURLRequest *request) 51 { 52 return adoptRef(new HostedNetscapePluginStream(instance, streamID, request)); 53 } create(NetscapePluginInstanceProxy * instance,WebCore::FrameLoader * frameLoader)54 static PassRefPtr<HostedNetscapePluginStream> create(NetscapePluginInstanceProxy* instance, WebCore::FrameLoader* frameLoader) 55 { 56 return adoptRef(new HostedNetscapePluginStream(instance, frameLoader)); 57 } 58 streamID()59 uint32_t streamID() const { return m_streamID; } 60 61 void startStreamWithResponse(NSURLResponse *response); 62 void didReceiveData(WebCore::NetscapePlugInStreamLoader*, const char* bytes, int length); 63 void didFinishLoading(WebCore::NetscapePlugInStreamLoader*); 64 void didFail(WebCore::NetscapePlugInStreamLoader*, const WebCore::ResourceError&); 65 66 void start(); 67 void stop(); 68 69 void cancelLoad(NPReason reason); 70 71 private: 72 NSError *errorForReason(NPReason) const; 73 void cancelLoad(NSError *); 74 75 HostedNetscapePluginStream(NetscapePluginInstanceProxy*, uint32_t streamID, NSURLRequest *); 76 HostedNetscapePluginStream(NetscapePluginInstanceProxy*, WebCore::FrameLoader*); 77 78 void startStream(NSURL *, long long expectedContentLength, NSDate *lastModifiedDate, NSString *mimeType, NSData *headers); 79 80 NSError *pluginCancelledConnectionError() const; 81 82 // NetscapePlugInStreamLoaderClient methods. 83 void didReceiveResponse(WebCore::NetscapePlugInStreamLoader*, const WebCore::ResourceResponse&); 84 bool wantsAllStreams() const; 85 86 RefPtr<NetscapePluginInstanceProxy> m_instance; 87 uint32_t m_streamID; 88 bool m_isTerminated; 89 RetainPtr<NSMutableURLRequest> m_request; 90 91 RetainPtr<NSURL> m_requestURL; 92 RetainPtr<NSURL> m_responseURL; 93 RetainPtr<NSString> m_mimeType; 94 95 WebCore::FrameLoader* m_frameLoader; 96 RefPtr<WebCore::NetscapePlugInStreamLoader> m_loader; 97 }; 98 99 } 100 101 #endif // HostedNetscapePluginStream_h 102 #endif // USE(PLUGIN_HOST_PROCESS) 103