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 59 ~HostedNetscapePluginStream(); 60 streamID()61 uint32_t streamID() const { return m_streamID; } 62 63 void startStreamWithResponse(NSURLResponse *response); 64 void didReceiveData(WebCore::NetscapePlugInStreamLoader*, const char* bytes, int length); 65 void didFinishLoading(WebCore::NetscapePlugInStreamLoader*); 66 void didFail(WebCore::NetscapePlugInStreamLoader*, const WebCore::ResourceError&); 67 68 void start(); 69 void stop(); 70 71 void cancelLoad(NPReason reason); 72 73 static NPReason reasonForError(NSError* error); 74 75 private: 76 NSError *errorForReason(NPReason) const; 77 void cancelLoad(NSError *); 78 79 HostedNetscapePluginStream(NetscapePluginInstanceProxy*, uint32_t streamID, NSURLRequest *); 80 HostedNetscapePluginStream(NetscapePluginInstanceProxy*, WebCore::FrameLoader*); 81 82 void startStream(NSURL *, long long expectedContentLength, NSDate *lastModifiedDate, NSString *mimeType, NSData *headers); 83 84 NSError *pluginCancelledConnectionError() const; 85 86 // NetscapePlugInStreamLoaderClient methods. 87 void didReceiveResponse(WebCore::NetscapePlugInStreamLoader*, const WebCore::ResourceResponse&); 88 bool wantsAllStreams() const; 89 90 RefPtr<NetscapePluginInstanceProxy> m_instance; 91 uint32_t m_streamID; 92 bool m_isTerminated; 93 RetainPtr<NSMutableURLRequest> m_request; 94 95 RetainPtr<NSURL> m_requestURL; 96 RetainPtr<NSURL> m_responseURL; 97 RetainPtr<NSString> m_mimeType; 98 99 WebCore::FrameLoader* m_frameLoader; 100 RefPtr<WebCore::NetscapePlugInStreamLoader> m_loader; 101 }; 102 103 } 104 105 #endif // HostedNetscapePluginStream_h 106 #endif // USE(PLUGIN_HOST_PROCESS) 107