Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CONTENT_CHILD_NPAPI_PLUGIN_STREAM_H_ | 5 #ifndef CONTENT_CHILD_NPAPI_PLUGIN_STREAM_H_ |
| 6 #define CONTENT_CHILD_NPAPI_PLUGIN_STREAM_H_ | 6 #define CONTENT_CHILD_NPAPI_PLUGIN_STREAM_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "third_party/npapi/bindings/npapi.h" | 14 #include "third_party/npapi/bindings/npapi.h" |
| 15 | 15 |
| 16 namespace content { | 16 namespace content { |
| 17 | 17 |
| 18 class PluginInstance; | 18 class PluginInstance; |
| 19 class WebPluginResourceClient; | 19 class WebPluginResourceClient; |
| 20 | 20 |
| 21 // Base class for a NPAPI stream. Tracks basic elements | 21 // Base class for a NPAPI stream. Tracks basic elements |
| 22 // of a stream for NPAPI notifications and stream position. | 22 // of a stream for NPAPI notifications and stream position. |
| 23 class PluginStream : public base::RefCounted<PluginStream> { | 23 class PluginStream : public base::RefCounted<PluginStream> { |
|
dcheng
2015/11/18 18:38:18
And probably this thing too. KILL IT ALL.
Nate Chapin
2015/11/18 23:28:50
Done.
| |
| 24 public: | 24 public: |
| 25 // Create a new PluginStream object. If needNotify is true, then the | 25 // Create a new PluginStream object. |
| 26 // plugin will be notified when the stream has been fully sent. | |
| 27 PluginStream(PluginInstance* instance, | 26 PluginStream(PluginInstance* instance, |
| 28 const char* url, | 27 const char* url); |
| 29 bool need_notify, | |
| 30 void* notify_data); | |
| 31 | 28 |
| 32 // Opens the stream to the Plugin. | 29 // Opens the stream to the Plugin. |
| 33 // If the mime-type is not specified, we'll try to find one based on the | 30 // If the mime-type is not specified, we'll try to find one based on the |
| 34 // mime-types table and the extension (if any) in the URL. | 31 // mime-types table and the extension (if any) in the URL. |
| 35 // If the size of the stream is known, use length to set the size. If | 32 // If the size of the stream is known, use length to set the size. If |
| 36 // not known, set length to 0. | 33 // not known, set length to 0. |
| 37 // The request_is_seekable parameter indicates whether byte range requests | 34 // The request_is_seekable parameter indicates whether byte range requests |
| 38 // can be issued on the stream. | 35 // can be issued on the stream. |
| 39 bool Open(const std::string &mime_type, | 36 bool Open(const std::string &mime_type, |
| 40 const std::string &headers, | 37 const std::string &headers, |
| 41 uint32 length, | 38 uint32 length, |
| 42 uint32 last_modified, | 39 uint32 last_modified, |
| 43 bool request_is_seekable); | 40 bool request_is_seekable); |
| 44 | 41 |
| 45 // Writes to the stream. | 42 // Writes to the stream. |
| 46 int Write(const char* buf, const int len, int data_offset); | 43 int Write(const char* buf, const int len, int data_offset); |
| 47 | 44 |
| 48 // Write the result as a file. | 45 // Write the result as a file. |
| 49 void WriteAsFile(); | 46 void WriteAsFile(); |
| 50 | 47 |
| 51 // Notify the plugin that a stream is complete. | |
| 52 void Notify(NPReason reason); | |
| 53 | |
| 54 // Close the stream. | 48 // Close the stream. |
| 55 virtual bool Close(NPReason reason); | 49 virtual bool Close(NPReason reason); |
| 56 | 50 |
| 57 virtual WebPluginResourceClient* AsResourceClient(); | 51 virtual WebPluginResourceClient* AsResourceClient(); |
| 58 | 52 |
| 59 // Cancels any HTTP requests initiated by the stream. | 53 // Cancels any HTTP requests initiated by the stream. |
| 60 virtual void CancelRequest() {} | 54 virtual void CancelRequest() {} |
| 61 | 55 |
| 62 NPStream* stream() { return &stream_; } | 56 NPStream* stream() { return &stream_; } |
| 63 | 57 |
| 64 PluginInstance* instance() { return instance_.get(); } | 58 PluginInstance* instance() { return instance_.get(); } |
| 65 | 59 |
| 66 // setter/getter for the seekable attribute on the stream. | 60 // setter/getter for the seekable attribute on the stream. |
| 67 bool seekable() const { return seekable_stream_; } | 61 bool seekable() const { return seekable_stream_; } |
| 68 | 62 |
| 69 void set_seekable(bool seekable) { seekable_stream_ = seekable; } | 63 void set_seekable(bool seekable) { seekable_stream_ = seekable; } |
| 70 | 64 |
| 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_; } | |
| 75 | |
| 76 protected: | 65 protected: |
| 77 friend class base::RefCounted<PluginStream>; | 66 friend class base::RefCounted<PluginStream>; |
| 78 | 67 |
| 79 virtual ~PluginStream(); | 68 virtual ~PluginStream(); |
| 80 | 69 |
| 81 // Check if the stream is open. | 70 // Check if the stream is open. |
| 82 bool open() { return opened_; } | 71 bool open() { return opened_; } |
| 83 | 72 |
| 84 private: | 73 private: |
| 85 // Per platform method to reset the temporary file handle. | 74 // Per platform method to reset the temporary file handle. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 // Returns true if the temp file is valid and open for writing. | 106 // Returns true if the temp file is valid and open for writing. |
| 118 bool TempFileIsValid() const; | 107 bool TempFileIsValid() const; |
| 119 | 108 |
| 120 // Returns true if |requested_plugin_mode_| is NP_ASFILE or NP_ASFILEONLY. | 109 // Returns true if |requested_plugin_mode_| is NP_ASFILE or NP_ASFILEONLY. |
| 121 bool RequestedPluginModeIsAsFile() const; | 110 bool RequestedPluginModeIsAsFile() const; |
| 122 | 111 |
| 123 private: | 112 private: |
| 124 NPStream stream_; | 113 NPStream stream_; |
| 125 std::string headers_; | 114 std::string headers_; |
| 126 scoped_refptr<PluginInstance> instance_; | 115 scoped_refptr<PluginInstance> instance_; |
| 127 bool notify_needed_; | |
| 128 void* notify_data_; | |
| 129 bool close_on_write_data_; | 116 bool close_on_write_data_; |
| 130 uint16 requested_plugin_mode_; | 117 uint16 requested_plugin_mode_; |
| 131 bool opened_; | 118 bool opened_; |
| 132 #if defined(OS_WIN) | 119 #if defined(OS_WIN) |
| 133 char temp_file_name_[MAX_PATH]; | 120 char temp_file_name_[MAX_PATH]; |
| 134 HANDLE temp_file_handle_; | 121 HANDLE temp_file_handle_; |
| 135 #elif defined(OS_POSIX) | 122 #elif defined(OS_POSIX) |
| 136 FILE* temp_file_; | 123 FILE* temp_file_; |
| 137 base::FilePath temp_file_path_; | 124 base::FilePath temp_file_path_; |
| 138 #endif | 125 #endif |
| 139 std::vector<char> delivery_data_; | 126 std::vector<char> delivery_data_; |
| 140 int data_offset_; | 127 int data_offset_; |
| 141 bool seekable_stream_; | 128 bool seekable_stream_; |
| 142 std::string mime_type_; | 129 std::string mime_type_; |
| 143 DISALLOW_COPY_AND_ASSIGN(PluginStream); | 130 DISALLOW_COPY_AND_ASSIGN(PluginStream); |
| 144 }; | 131 }; |
| 145 | 132 |
| 146 } // namespace content | 133 } // namespace content |
| 147 | 134 |
| 148 #endif // CONTENT_CHILD_NPAPI_PLUGIN_STREAM_H_ | 135 #endif // CONTENT_CHILD_NPAPI_PLUGIN_STREAM_H_ |
| OLD | NEW |