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

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

Issue 10495008: Further cleanup in PluginStream. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: rebase Created 8 years, 4 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
« no previous file with comments | « webkit/plugins/npapi/plugin_stream.h ('k') | webkit/plugins/npapi/plugin_stream_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // TODO : Support NP_ASFILEONLY mode 5 // TODO : Support NP_ASFILEONLY mode
6 // TODO : Support NP_SEEK mode 6 // TODO : Support NP_SEEK mode
7 // TODO : Support SEEKABLE=true in NewStream 7 // TODO : Support SEEKABLE=true in NewStream
8 8
9 #include "webkit/plugins/npapi/plugin_stream.h" 9 #include "webkit/plugins/npapi/plugin_stream.h"
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return false; 102 return false;
103 } 103 }
104 104
105 opened_ = true; 105 opened_ = true;
106 106
107 if (requested_plugin_mode_ == NP_SEEK) { 107 if (requested_plugin_mode_ == NP_SEEK) {
108 seekable_stream_ = true; 108 seekable_stream_ = true;
109 } 109 }
110 // If the plugin has requested certain modes, then we need a copy 110 // If the plugin has requested certain modes, then we need a copy
111 // of this file on disk. Open it and save it as we go. 111 // of this file on disk. Open it and save it as we go.
112 if (requested_plugin_mode_ == NP_ASFILEONLY || 112 if (RequestedPluginModeIsAsFile()) {
113 requested_plugin_mode_ == NP_ASFILE) {
114 if (OpenTempFile() == false) { 113 if (OpenTempFile() == false) {
115 return false; 114 return false;
116 } 115 }
117 } 116 }
118 117
119 mime_type_ = char_mime_type; 118 mime_type_ = char_mime_type;
120 return true; 119 return true;
121 } 120 }
122 121
123 int PluginStream::Write(const char* buffer, const int length, 122 int PluginStream::Write(const char* buffer, const int length,
(...skipping 10 matching lines...) Expand all
134 WriteToPlugin(buffer, length, data_offset)) { 133 WriteToPlugin(buffer, length, data_offset)) {
135 return length; 134 return length;
136 } 135 }
137 136
138 return -1; 137 return -1;
139 } 138 }
140 139
141 bool PluginStream::WriteToFile(const char* buf, size_t length) { 140 bool PluginStream::WriteToFile(const char* buf, size_t length) {
142 // For ASFILEONLY, ASFILE, and SEEK modes, we need to write 141 // For ASFILEONLY, ASFILE, and SEEK modes, we need to write
143 // to the disk 142 // to the disk
144 if (TempFileIsValid() && 143 if (TempFileIsValid() && RequestedPluginModeIsAsFile()) {
145 (requested_plugin_mode_ == NP_ASFILE ||
146 requested_plugin_mode_ == NP_ASFILEONLY) ) {
147 size_t totalBytesWritten = 0, bytes; 144 size_t totalBytesWritten = 0, bytes;
148 do { 145 do {
149 bytes = WriteBytes(buf, length); 146 bytes = WriteBytes(buf, length);
150 totalBytesWritten += bytes; 147 totalBytesWritten += bytes;
151 } while (bytes > 0U && totalBytesWritten < length); 148 } while (bytes > 0U && totalBytesWritten < length);
152 149
153 if (totalBytesWritten != length) 150 if (totalBytesWritten != length) {
154 return false; 151 return false;
152 }
155 } 153 }
156 154
157 return true; 155 return true;
158 } 156 }
159 157
160 bool PluginStream::WriteToPlugin(const char* buf, const int length, 158 bool PluginStream::WriteToPlugin(const char* buf, const int length,
161 const int data_offset) { 159 const int data_offset) {
162 // For NORMAL and ASFILE modes, we send the data to the plugin now 160 // For NORMAL and ASFILE modes, we send the data to the plugin now
163 if (requested_plugin_mode_ != NP_NORMAL && 161 if (requested_plugin_mode_ != NP_NORMAL &&
164 requested_plugin_mode_ != NP_ASFILE && 162 requested_plugin_mode_ != NP_ASFILE &&
(...skipping 19 matching lines...) Expand all
184 return true; 182 return true;
185 } 183 }
186 184
187 void PluginStream::OnDelayDelivery() { 185 void PluginStream::OnDelayDelivery() {
188 // It is possible that the plugin stream may have closed before the task 186 // It is possible that the plugin stream may have closed before the task
189 // was hit. 187 // was hit.
190 if (!opened_) 188 if (!opened_)
191 return; 189 return;
192 190
193 int size = static_cast<int>(delivery_data_.size()); 191 int size = static_cast<int>(delivery_data_.size());
194 int written = TryWriteToPlugin(&delivery_data_.front(), size, 192 int written = TryWriteToPlugin(&delivery_data_.front(), size, data_offset_);
195 data_offset_);
196 if (written > 0) { 193 if (written > 0) {
197 // Remove the data that we already wrote. 194 // Remove the data that we already wrote.
198 delivery_data_.erase(delivery_data_.begin(), 195 delivery_data_.erase(delivery_data_.begin(),
199 delivery_data_.begin() + written); 196 delivery_data_.begin() + written);
200 } 197 }
201 } 198 }
202 199
203 int PluginStream::TryWriteToPlugin(const char* buf, const int length, 200 int PluginStream::TryWriteToPlugin(const char* buf, const int length,
204 const int data_offset) { 201 const int data_offset) {
205 int byte_offset = 0; 202 int byte_offset = 0;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 return NULL; 277 return NULL;
281 } 278 }
282 279
283 void PluginStream::Notify(NPReason reason) { 280 void PluginStream::Notify(NPReason reason) {
284 if (notify_needed_) { 281 if (notify_needed_) {
285 instance_->NPP_URLNotify(stream_.url, reason, notify_data_); 282 instance_->NPP_URLNotify(stream_.url, reason, notify_data_);
286 notify_needed_ = false; 283 notify_needed_ = false;
287 } 284 }
288 } 285 }
289 286
287 bool PluginStream::RequestedPluginModeIsAsFile() const {
288 return (requested_plugin_mode_ == NP_ASFILE ||
289 requested_plugin_mode_ == NP_ASFILEONLY);
290 }
291
290 } // namespace npapi 292 } // namespace npapi
291 } // namespace webkit 293 } // namespace webkit
OLDNEW
« no previous file with comments | « webkit/plugins/npapi/plugin_stream.h ('k') | webkit/plugins/npapi/plugin_stream_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698