Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: webkit/plugins/npapi/plugin_stream.h

Issue 19761007: Move NPAPI implementation out of webkit/plugins/npapi and into content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix mac Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef WEBKIT_PLUGINS_NPAPI_PLUGIN_STREAM_H_
6 #define WEBKIT_PLUGINS_NPAPI_PLUGIN_STREAM_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/files/file_path.h"
12 #include "base/memory/ref_counted.h"
13 #include "build/build_config.h"
14 #include "third_party/npapi/bindings/npapi.h"
15
16 namespace webkit {
17 namespace npapi {
18
19 class PluginInstance;
20 class WebPluginResourceClient;
21
22 // Base class for a NPAPI stream. Tracks basic elements
23 // of a stream for NPAPI notifications and stream position.
24 class PluginStream : public base::RefCounted<PluginStream> {
25 public:
26 // Create a new PluginStream object. If needNotify is true, then the
27 // plugin will be notified when the stream has been fully sent.
28 PluginStream(PluginInstance* instance,
29 const char* url,
30 bool need_notify,
31 void* notify_data);
32
33 // In case of a redirect, this can be called to update the url. But it must
34 // be called before Open().
35 void UpdateUrl(const char* url);
36
37 // Opens the stream to the Plugin.
38 // If the mime-type is not specified, we'll try to find one based on the
39 // mime-types table and the extension (if any) in the URL.
40 // If the size of the stream is known, use length to set the size. If
41 // not known, set length to 0.
42 // The request_is_seekable parameter indicates whether byte range requests
43 // can be issued on the stream.
44 bool Open(const std::string &mime_type,
45 const std::string &headers,
46 uint32 length,
47 uint32 last_modified,
48 bool request_is_seekable);
49
50 // Writes to the stream.
51 int Write(const char* buf, const int len, int data_offset);
52
53 // Write the result as a file.
54 void WriteAsFile();
55
56 // Notify the plugin that a stream is complete.
57 void Notify(NPReason reason);
58
59 // Close the stream.
60 virtual bool Close(NPReason reason);
61
62 virtual WebPluginResourceClient* AsResourceClient();
63
64 // Cancels any HTTP requests initiated by the stream.
65 virtual void CancelRequest() {}
66
67 const NPStream* stream() const { return &stream_; }
68
69 // setter/getter for the seekable attribute on the stream.
70 bool seekable() const { return seekable_stream_; }
71
72 void set_seekable(bool seekable) { seekable_stream_ = seekable; }
73
74 // getters for reading the notification related attributes on the stream.
75 bool notify_needed() const { return notify_needed_; }
76
77 void* notify_data() const { return notify_data_; }
78
79 std::string pending_redirect_url() const { return pending_redirect_url_; }
80
81 protected:
82 friend class base::RefCounted<PluginStream>;
83
84 virtual ~PluginStream();
85
86 PluginInstance* instance() { return instance_.get(); }
87
88 // Check if the stream is open.
89 bool open() { return opened_; }
90
91 // If the plugin participates in HTTP URL redirect handling then this member
92 // holds the url being redirected to while we wait for the plugin to make a
93 // decision on whether to allow or deny the redirect.
94 std::string pending_redirect_url_;
95
96 private:
97 // Per platform method to reset the temporary file handle.
98 void ResetTempFileHandle();
99
100 // Per platform method to reset the temporary file name.
101 void ResetTempFileName();
102
103 // Open a temporary file for this stream.
104 // If successful, will set temp_file_name_, temp_file_handle_, and
105 // return true.
106 bool OpenTempFile();
107
108 // Closes the temporary file if it is open.
109 void CloseTempFile();
110
111 // Sends the data to the file. Called From WriteToFile.
112 size_t WriteBytes(const char* buf, size_t length);
113
114 // Sends the data to the file if it's open.
115 bool WriteToFile(const char* buf, size_t length);
116
117 // Sends the data to the plugin. If it's not ready, handles buffering it
118 // and retrying later.
119 bool WriteToPlugin(const char* buf, const int length, const int data_offset);
120
121 // Send the data to the plugin, returning how many bytes it accepted, or -1
122 // if an error occurred.
123 int TryWriteToPlugin(const char* buf, const int length,
124 const int data_offset);
125
126 // The callback which calls TryWriteToPlugin.
127 void OnDelayDelivery();
128
129 // Returns true if the temp file is valid and open for writing.
130 bool TempFileIsValid() const;
131
132 // Returns true if |requested_plugin_mode_| is NP_ASFILE or NP_ASFILEONLY.
133 bool RequestedPluginModeIsAsFile() const;
134
135 private:
136 NPStream stream_;
137 std::string headers_;
138 scoped_refptr<PluginInstance> instance_;
139 bool notify_needed_;
140 void* notify_data_;
141 bool close_on_write_data_;
142 uint16 requested_plugin_mode_;
143 bool opened_;
144 #if defined(OS_WIN)
145 char temp_file_name_[MAX_PATH];
146 HANDLE temp_file_handle_;
147 #elif defined(OS_POSIX)
148 FILE* temp_file_;
149 base::FilePath temp_file_path_;
150 #endif
151 std::vector<char> delivery_data_;
152 int data_offset_;
153 bool seekable_stream_;
154 std::string mime_type_;
155 DISALLOW_COPY_AND_ASSIGN(PluginStream);
156 };
157
158 } // namespace npapi
159 } // namespace webkit
160
161 #endif // WEBKIT_PLUGINS_NPAPI_PLUGIN_STREAM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698