diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 19:54:04 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-11 19:54:04 +0000 |
commit | 00b64f3980da6ce2c42007c14952f613c4adc640 (patch) | |
tree | 171f4f33470503f4538291683989d1b3f262e561 /webkit/glue/plugins/plugin_stream_posix.cc | |
parent | 316848c3ab8b40e54118c5c5700df5e25119dc3b (diff) | |
download | chromium_src-00b64f3980da6ce2c42007c14952f613c4adc640.zip chromium_src-00b64f3980da6ce2c42007c14952f613c4adc640.tar.gz chromium_src-00b64f3980da6ce2c42007c14952f613c4adc640.tar.bz2 |
Ported plugin_stream to posix.
Review URL: http://codereview.chromium.org/10278
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5197 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins/plugin_stream_posix.cc')
-rw-r--r-- | webkit/glue/plugins/plugin_stream_posix.cc | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/webkit/glue/plugins/plugin_stream_posix.cc b/webkit/glue/plugins/plugin_stream_posix.cc new file mode 100644 index 0000000..3eb7c4a --- /dev/null +++ b/webkit/glue/plugins/plugin_stream_posix.cc @@ -0,0 +1,81 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "webkit/glue/plugins/plugin_stream.h" + +#include <string.h> + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/logging.h" +#include "webkit/glue/plugins/plugin_instance.h" + +namespace NPAPI { + +PluginStream::PluginStream( + PluginInstance *instance, + const char *url, + bool need_notify, + void *notify_data) + : instance_(instance), + notify_needed_(need_notify), + notify_data_(notify_data), + close_on_write_data_(false), + requested_plugin_mode_(NP_NORMAL), + opened_(false), + temp_file_(NULL), + temp_file_path_(), + data_offset_(0), + seekable_stream_(false) { + memset(&stream_, 0, sizeof(stream_)); + stream_.url = strdup(url); +} + +void PluginStream::UpdateUrl(const char* url) { + DCHECK(!opened_); + free(const_cast<char*>(stream_.url)); + stream_.url = strdup(url); +} + +void PluginStream::WriteAsFile() { + if (requested_plugin_mode_ == NP_ASFILE || + requested_plugin_mode_ == NP_ASFILEONLY) + instance_->NPP_StreamAsFile(&stream_, temp_file_path_.value().c_str()); +} + +size_t PluginStream::WriteBytes(const char *buf, size_t length) { + return fwrite(buf, sizeof(char), length, temp_file_); +} + +bool PluginStream::OpenTempFile() { + DCHECK(temp_file_ == NULL); + + if (file_util::CreateTemporaryFileName(&temp_file_path_)) + temp_file_ = file_util::OpenFile(temp_file_path_, "a"); + + if (!temp_file_) { + temp_file_path_ = FilePath(""); + return false; + } + + return true; +} + +void PluginStream::CloseTempFile() { + file_util::CloseFile(temp_file_); + temp_file_ = NULL; +} + +void PluginStream::CleanupTempFile() { + CloseTempFile(); + file_util::Delete(temp_file_path_, false); + temp_file_path_ = FilePath(""); +} + +bool PluginStream::TempFileIsValid() { + return temp_file_ != NULL; +} + +} // namespace NPAPI + |