PluginStream.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
  3. * Copyright (C) 2008 Collabora, Ltd. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  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. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef PluginStream_h
  27. #define PluginStream_h
  28. #include "FileSystem.h"
  29. #include "KURL.h"
  30. #include "NetscapePlugInStreamLoader.h"
  31. #include "PluginQuirkSet.h"
  32. #include "ResourceRequest.h"
  33. #include "ResourceResponse.h"
  34. #include "Timer.h"
  35. #include "npruntime_internal.h"
  36. #include <wtf/HashMap.h>
  37. #include <wtf/OwnPtr.h>
  38. #include <wtf/RefCounted.h>
  39. #include <wtf/Vector.h>
  40. #include <wtf/text/CString.h>
  41. #include <wtf/text/StringHash.h>
  42. #include <wtf/text/WTFString.h>
  43. namespace WebCore {
  44. class Frame;
  45. class PluginStream;
  46. enum PluginStreamState { StreamBeforeStarted, StreamStarted, StreamStopped };
  47. class PluginStreamClient {
  48. public:
  49. virtual ~PluginStreamClient() {}
  50. virtual void streamDidFinishLoading(PluginStream*) {}
  51. };
  52. class PluginStream : public RefCounted<PluginStream>, private NetscapePlugInStreamLoaderClient {
  53. public:
  54. static PassRefPtr<PluginStream> create(PluginStreamClient* client, Frame* frame, const ResourceRequest& request, bool sendNotification, void* notifyData, const NPPluginFuncs* functions, NPP instance, const PluginQuirkSet& quirks)
  55. {
  56. return adoptRef(new PluginStream(client, frame, request, sendNotification, notifyData, functions, instance, quirks));
  57. }
  58. virtual ~PluginStream();
  59. void start();
  60. void stop();
  61. void startStream();
  62. void setLoadManually(bool loadManually) { m_loadManually = loadManually; }
  63. void sendJavaScriptStream(const KURL& requestURL, const WTF::CString& resultString);
  64. void cancelAndDestroyStream(NPReason);
  65. static NPP ownerForStream(NPStream*);
  66. // NetscapePlugInStreamLoaderClient
  67. virtual void didReceiveResponse(NetscapePlugInStreamLoader*, const ResourceResponse&);
  68. virtual void didReceiveData(NetscapePlugInStreamLoader*, const char*, int);
  69. virtual void didFail(NetscapePlugInStreamLoader*, const ResourceError&);
  70. virtual void didFinishLoading(NetscapePlugInStreamLoader*);
  71. virtual bool wantsAllStreams() const;
  72. private:
  73. PluginStream(PluginStreamClient*, Frame*, const ResourceRequest&, bool sendNotification, void* notifyData, const NPPluginFuncs*, NPP instance, const PluginQuirkSet&);
  74. void deliverData();
  75. void destroyStream(NPReason);
  76. void destroyStream();
  77. ResourceRequest m_resourceRequest;
  78. ResourceResponse m_resourceResponse;
  79. PluginStreamClient* m_client;
  80. Frame* m_frame;
  81. RefPtr<NetscapePlugInStreamLoader> m_loader;
  82. void* m_notifyData;
  83. bool m_sendNotification;
  84. PluginStreamState m_streamState;
  85. bool m_loadManually;
  86. Timer<PluginStream> m_delayDeliveryTimer;
  87. void delayDeliveryTimerFired(Timer<PluginStream>*);
  88. OwnPtr< Vector<char> > m_deliveryData;
  89. PlatformFileHandle m_tempFileHandle;
  90. const NPPluginFuncs* m_pluginFuncs;
  91. NPP m_instance;
  92. uint16_t m_transferMode;
  93. int32_t m_offset;
  94. CString m_headers;
  95. String m_path;
  96. NPReason m_reason;
  97. NPStream m_stream;
  98. PluginQuirkSet m_quirks;
  99. };
  100. } // namespace WebCore
  101. #endif