| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_STREAM_H__ | 5 #ifndef WEBKIT_GLUE_PLUGIN_PLUGIN_STREAM_H__ |
| 6 #define WEBKIT_GLUE_PLUGIN_PLUGIN_STREAM_H__ | 6 #define WEBKIT_GLUE_PLUGIN_PLUGIN_STREAM_H__ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 12 #include "third_party/npapi/bindings/npapi.h" | 12 #include "third_party/npapi/bindings/npapi.h" |
| 13 | 13 |
| 14 | 14 |
| 15 class WebPluginResourceClient; |
| 16 |
| 15 namespace NPAPI { | 17 namespace NPAPI { |
| 16 | 18 |
| 17 class PluginInstance; | 19 class PluginInstance; |
| 18 | 20 |
| 19 // Base class for a NPAPI stream. Tracks basic elements | 21 // Base class for a NPAPI stream. Tracks basic elements |
| 20 // of a stream for NPAPI notifications and stream position. | 22 // of a stream for NPAPI notifications and stream position. |
| 21 class PluginStream : public base::RefCounted<PluginStream> { | 23 class PluginStream : public base::RefCounted<PluginStream> { |
| 22 public: | 24 public: |
| 23 // Create a new PluginStream object. If needNotify is true, then the | 25 // Create a new PluginStream object. If needNotify is true, then the |
| 24 // plugin will be notified when the stream has been fully sent. | 26 // plugin will be notified when the stream has been fully sent. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 // If the mime-type is not specified, we'll try to find one based on the | 38 // If the mime-type is not specified, we'll try to find one based on the |
| 37 // mime-types table and the extension (if any) in the URL. | 39 // mime-types table and the extension (if any) in the URL. |
| 38 // If the size of the stream is known, use length to set the size. If | 40 // If the size of the stream is known, use length to set the size. If |
| 39 // not known, set length to 0. | 41 // not known, set length to 0. |
| 40 bool Open(const std::string &mime_type, | 42 bool Open(const std::string &mime_type, |
| 41 const std::string &headers, | 43 const std::string &headers, |
| 42 uint32 length, | 44 uint32 length, |
| 43 uint32 last_modified); | 45 uint32 last_modified); |
| 44 | 46 |
| 45 // Writes to the stream. | 47 // Writes to the stream. |
| 46 int Write(const char *buf, const int len); | 48 int Write(const char *buf, const int len, int data_offset); |
| 47 | 49 |
| 48 // Write the result as a file. | 50 // Write the result as a file. |
| 49 void WriteAsFile(); | 51 void WriteAsFile(); |
| 50 | 52 |
| 51 // Notify the plugin that a stream is complete. | 53 // Notify the plugin that a stream is complete. |
| 52 void Notify(NPReason reason); | 54 void Notify(NPReason reason); |
| 53 | 55 |
| 54 // Close the stream. | 56 // Close the stream. |
| 55 virtual bool Close(NPReason reason); | 57 virtual bool Close(NPReason reason); |
| 56 | 58 |
| 57 const NPStream* stream() const { | 59 virtual WebPluginResourceClient* AsResourceClient() { return NULL; } |
| 58 return &stream_; | 60 |
| 59 } | 61 // Cancels any HTTP requests initiated by the stream. |
| 62 virtual void CancelRequest() {} |
| 63 |
| 64 const NPStream* stream() const { return &stream_; } |
| 65 |
| 66 // setter/getter for the seekable attribute on the stream. |
| 67 bool seekable() const { return seekable_stream_; } |
| 68 |
| 69 void set_seekable(bool seekable) { seekable_stream_ = seekable; } |
| 70 |
| 71 // getters for reading the notification related attributes on the stream. |
| 72 bool notify_needed() const { return notify_needed_; } |
| 73 |
| 74 void* notify_data() const { return notify_data_; } |
| 60 | 75 |
| 61 protected: | 76 protected: |
| 62 PluginInstance* instance() { return instance_.get(); } | 77 PluginInstance* instance() { return instance_.get(); } |
| 63 // Check if the stream is open. | 78 // Check if the stream is open. |
| 64 bool open() { return opened_; } | 79 bool open() { return opened_; } |
| 65 | 80 |
| 66 private: | 81 private: |
| 67 // Open a temporary file for this stream. | 82 // Open a temporary file for this stream. |
| 68 // If successful, will set temp_file_name_, temp_file_handle_, and | 83 // If successful, will set temp_file_name_, temp_file_handle_, and |
| 69 // return true. | 84 // return true. |
| 70 bool OpenTempFile(); | 85 bool OpenTempFile(); |
| 71 | 86 |
| 72 // Closes the temporary file if it is open. | 87 // Closes the temporary file if it is open. |
| 73 void CloseTempFile(); | 88 void CloseTempFile(); |
| 74 | 89 |
| 75 // Closes the temporary file if it is open and deletes the file. | 90 // Closes the temporary file if it is open and deletes the file. |
| 76 void CleanupTempFile(); | 91 void CleanupTempFile(); |
| 77 | 92 |
| 78 // Sends the data to the file if it's open. | 93 // Sends the data to the file if it's open. |
| 79 bool WriteToFile(const char *buf, const int length); | 94 bool WriteToFile(const char *buf, const int length); |
| 80 | 95 |
| 81 // Sends the data to the plugin. If it's not ready, handles buffering it | 96 // Sends the data to the plugin. If it's not ready, handles buffering it |
| 82 // and retrying later. | 97 // and retrying later. |
| 83 bool WriteToPlugin(const char *buf, const int length); | 98 bool WriteToPlugin(const char *buf, const int length, const int data_offset); |
| 84 | 99 |
| 85 // Send the data to the plugin, returning how many bytes it accepted, or -1 | 100 // Send the data to the plugin, returning how many bytes it accepted, or -1 |
| 86 // if an error occurred. | 101 // if an error occurred. |
| 87 int TryWriteToPlugin(const char *buf, const int length); | 102 int TryWriteToPlugin(const char *buf, const int length, const int data_offset)
; |
| 88 | 103 |
| 89 // The callback which calls TryWriteToPlugin. | 104 // The callback which calls TryWriteToPlugin. |
| 90 void OnDelayDelivery(); | 105 void OnDelayDelivery(); |
| 91 | 106 |
| 92 private: | 107 private: |
| 93 NPStream stream_; | 108 NPStream stream_; |
| 94 std::string headers_; | 109 std::string headers_; |
| 95 scoped_refptr<PluginInstance> instance_; | 110 scoped_refptr<PluginInstance> instance_; |
| 96 int bytes_sent_; | |
| 97 bool notify_needed_; | 111 bool notify_needed_; |
| 98 void * notify_data_; | 112 void * notify_data_; |
| 99 bool close_on_write_data_; | 113 bool close_on_write_data_; |
| 100 uint16 requested_plugin_mode_; | 114 uint16 requested_plugin_mode_; |
| 101 bool opened_; | 115 bool opened_; |
| 102 char temp_file_name_[MAX_PATH]; | 116 char temp_file_name_[MAX_PATH]; |
| 103 HANDLE temp_file_handle_; | 117 HANDLE temp_file_handle_; |
| 104 std::vector<char> delivery_data_; | 118 std::vector<char> delivery_data_; |
| 105 | 119 int data_offset_; |
| 120 bool seekable_stream_; |
| 121 std::string mime_type_; |
| 106 DISALLOW_EVIL_CONSTRUCTORS(PluginStream); | 122 DISALLOW_EVIL_CONSTRUCTORS(PluginStream); |
| 107 }; | 123 }; |
| 108 | 124 |
| 109 } // namespace NPAPI | 125 } // namespace NPAPI |
| 110 | 126 |
| 111 #endif // WEBKIT_GLUE_PLUGIN_PLUGIN_STREAM_H__ | 127 #endif // WEBKIT_GLUE_PLUGIN_PLUGIN_STREAM_H__ |
| 112 | 128 |
| OLD | NEW |