WebNetscapePluginStream.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2005 Apple Computer, 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. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  14. * its contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  18. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  19. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  20. * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  21. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  22. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  23. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  24. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. */
  28. #if ENABLE(NETSCAPE_PLUGIN_API)
  29. #import <Foundation/Foundation.h>
  30. #import <WebCore/Timer.h>
  31. #import <WebCore/NetscapePlugInStreamLoader.h>
  32. #import <WebKit/npfunctions.h>
  33. #import <wtf/PassRefPtr.h>
  34. #import <wtf/RefCounted.h>
  35. #import <wtf/RefPtr.h>
  36. #import <wtf/RetainPtr.h>
  37. #import <wtf/text/CString.h>
  38. #import "WebNetscapePluginView.h"
  39. namespace WebCore {
  40. class FrameLoader;
  41. class NetscapePlugInStreamLoader;
  42. }
  43. @class WebNetscapePluginView;
  44. @class NSURLResponse;
  45. class WebNetscapePluginStream : public RefCounted<WebNetscapePluginStream>
  46. , private WebCore::NetscapePlugInStreamLoaderClient
  47. {
  48. public:
  49. static PassRefPtr<WebNetscapePluginStream> create(NSURLRequest *request, NPP plugin, bool sendNotification, void* notifyData)
  50. {
  51. return adoptRef(new WebNetscapePluginStream(request, plugin, sendNotification, notifyData));
  52. }
  53. static PassRefPtr<WebNetscapePluginStream> create(WebCore::FrameLoader* frameLoader)
  54. {
  55. return adoptRef(new WebNetscapePluginStream(frameLoader));
  56. }
  57. virtual ~WebNetscapePluginStream();
  58. NPP plugin() const { return m_plugin; }
  59. void setPlugin(NPP);
  60. static NPP ownerForStream(NPStream *);
  61. static NPReason reasonForError(NSError *);
  62. NSError *errorForReason(NPReason) const;
  63. void cancelLoadAndDestroyStreamWithError(NSError *);
  64. void setRequestURL(const WebCore::KURL& requestURL) { m_requestURL = requestURL; }
  65. void start();
  66. void stop();
  67. void startStreamWithResponse(NSURLResponse *response);
  68. void didReceiveData(WebCore::NetscapePlugInStreamLoader*, const char* bytes, int length);
  69. void destroyStreamWithError(NSError *);
  70. void didFinishLoading(WebCore::NetscapePlugInStreamLoader*);
  71. private:
  72. void destroyStream();
  73. void cancelLoadWithError(NSError *);
  74. void destroyStreamWithReason(NPReason);
  75. void deliverDataToFile(NSData *data);
  76. void deliverData();
  77. void startStream(NSURL *, long long expectedContentLength, NSDate *lastModifiedDate, const WTF::String& mimeType, NSData *headers);
  78. NSError *pluginCancelledConnectionError() const;
  79. // NetscapePlugInStreamLoaderClient methods.
  80. void didReceiveResponse(WebCore::NetscapePlugInStreamLoader*, const WebCore::ResourceResponse&);
  81. void didFail(WebCore::NetscapePlugInStreamLoader*, const WebCore::ResourceError&);
  82. bool wantsAllStreams() const;
  83. RetainPtr<NSMutableData> m_deliveryData;
  84. WebCore::KURL m_requestURL;
  85. RetainPtr<NSURL> m_responseURL;
  86. CString m_mimeType;
  87. NPP m_plugin;
  88. uint16_t m_transferMode;
  89. int32_t m_offset;
  90. NPStream m_stream;
  91. RetainPtr<NSString> m_path;
  92. int m_fileDescriptor;
  93. BOOL m_sendNotification;
  94. void *m_notifyData;
  95. char *m_headers;
  96. RetainPtr<WebNetscapePluginView> m_pluginView;
  97. NPReason m_reason;
  98. bool m_isTerminated;
  99. bool m_newStreamSuccessful;
  100. WebCore::FrameLoader* m_frameLoader;
  101. RefPtr<WebCore::NetscapePlugInStreamLoader> m_loader;
  102. RetainPtr<NSMutableURLRequest> m_request;
  103. NPPluginFuncs *m_pluginFuncs;
  104. void deliverDataTimerFired(WebCore::Timer<WebNetscapePluginStream>* timer);
  105. WebCore::Timer<WebNetscapePluginStream> m_deliverDataTimer;
  106. WebNetscapePluginStream(WebCore::FrameLoader*);
  107. WebNetscapePluginStream(NSURLRequest *, NPP, bool sendNotification, void* notifyData);
  108. };
  109. #endif