summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-11 19:54:04 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-11 19:54:04 +0000
commit00b64f3980da6ce2c42007c14952f613c4adc640 (patch)
tree171f4f33470503f4538291683989d1b3f262e561 /webkit
parent316848c3ab8b40e54118c5c5700df5e25119dc3b (diff)
downloadchromium_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')
-rw-r--r--webkit/build/glue/glue.vcproj4
-rw-r--r--webkit/glue/SConscript11
-rw-r--r--webkit/glue/plugins/plugin_stream.cc96
-rw-r--r--webkit/glue/plugins/plugin_stream.h13
-rw-r--r--webkit/glue/plugins/plugin_stream_posix.cc81
-rw-r--r--webkit/glue/plugins/plugin_stream_win.cc105
6 files changed, 217 insertions, 93 deletions
diff --git a/webkit/build/glue/glue.vcproj b/webkit/build/glue/glue.vcproj
index 602dbf4..5e7a052 100644
--- a/webkit/build/glue/glue.vcproj
+++ b/webkit/build/glue/glue.vcproj
@@ -717,6 +717,10 @@
>
</File>
<File
+ RelativePath="..\..\glue\plugins\plugin_stream_win.cc"
+ >
+ </File>
+ <File
RelativePath="..\..\glue\plugins\plugin_string_stream.cc"
>
</File>
diff --git a/webkit/glue/SConscript b/webkit/glue/SConscript
index 6476ffd..0828731 100644
--- a/webkit/glue/SConscript
+++ b/webkit/glue/SConscript
@@ -51,8 +51,9 @@ input_files = [
'password_form_dom_manager.cc',
'plugins/plugin_host.cc',
'plugins/plugin_instance.cc',
- 'plugins/plugin_string_stream.cc',
+ 'plugins/plugin_stream.cc',
'plugins/plugin_stream_url.cc',
+ 'plugins/plugin_string_stream.cc',
'resource_fetcher.cc',
'resource_handle_impl.cc',
'searchable_form_data.cc',
@@ -96,13 +97,13 @@ if env['PLATFORM'] == 'win32':
'plugins/mozilla_extensions.cc',
'plugins/plugin_lib.cc',
'plugins/plugin_list.cc',
- 'plugins/plugin_stream.cc',
'plugins/webplugin_delegate_impl.cc',
'webdropdata.cc',
])
if env['PLATFORM'] == 'win32':
input_files.extend([
+ 'plugins/plugin_stream_win.cc',
'webcursor_win.cc',
'webinputevent_win.cc',
'webkit_glue_win.cc',
@@ -113,4 +114,10 @@ elif env['PLATFORM'] == 'posix':
'webinputevent_linux.cc',
])
+if env['PLATFORM'] in ('posix', 'darwin'):
+ input_files.extend([
+ 'plugins/plugin_stream_posix.cc',
+ ])
+
env.ChromeStaticLibrary('glue', input_files)
+
diff --git a/webkit/glue/plugins/plugin_stream.cc b/webkit/glue/plugins/plugin_stream.cc
index 855c3fc..0af76c5 100644
--- a/webkit/glue/plugins/plugin_stream.cc
+++ b/webkit/glue/plugins/plugin_stream.cc
@@ -16,37 +16,12 @@
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),
- opened_(false),
- requested_plugin_mode_(NP_NORMAL),
- temp_file_handle_(INVALID_HANDLE_VALUE),
- seekable_stream_(false),
- data_offset_(0) {
- memset(&stream_, 0, sizeof(stream_));
- stream_.url = _strdup(url);
- temp_file_name_[0] = '\0';
-}
-
PluginStream::~PluginStream() {
// always cleanup our temporary files.
CleanupTempFile();
free(const_cast<char*>(stream_.url));
}
-void PluginStream::UpdateUrl(const char* url) {
- DCHECK(!opened_);
- free(const_cast<char*>(stream_.url));
- stream_.url = _strdup(url);
-}
-
bool PluginStream::Open(const std::string &mime_type,
const std::string &headers,
uint32 length,
@@ -70,7 +45,7 @@ bool PluginStream::Open(const std::string &mime_type,
const char *char_mime_type = "application/x-unknown-content-type";
std::string temp_mime_type;
if (!mime_type.empty()) {
- char_mime_type = mime_type.c_str();
+ char_mime_type = mime_type.c_str();
} else {
GURL gurl(stream_.url);
std::wstring path(UTF8ToWide(gurl.path()));
@@ -122,19 +97,17 @@ int PluginStream::Write(const char *buffer, const int length,
return -1;
}
-bool PluginStream::WriteToFile(const char *buf, const int length) {
+bool PluginStream::WriteToFile(const char *buf, size_t length) {
// For ASFILEONLY, ASFILE, and SEEK modes, we need to write
// to the disk
- if (temp_file_handle_ != INVALID_HANDLE_VALUE &&
+ if (TempFileIsValid() &&
(requested_plugin_mode_ == NP_ASFILE ||
requested_plugin_mode_ == NP_ASFILEONLY) ) {
- int totalBytesWritten = 0;
- DWORD bytes;
+ size_t totalBytesWritten = 0, bytes;
do {
- if (WriteFile(temp_file_handle_, buf, length, &bytes, 0) == FALSE)
- break;
+ bytes = WriteBytes(buf, length);
totalBytesWritten += bytes;
- } while (bytes > 0 && totalBytesWritten < length);
+ } while (bytes > 0U && totalBytesWritten < length);
if (totalBytesWritten != length)
return false;
@@ -188,7 +161,6 @@ void PluginStream::OnDelayDelivery() {
int PluginStream::TryWriteToPlugin(const char *buf, const int length,
const int data_offset) {
- bool result = true;
int byte_offset = 0;
if (data_offset > 0)
@@ -229,12 +201,6 @@ int PluginStream::TryWriteToPlugin(const char *buf, const int length,
return length;
}
-void PluginStream::WriteAsFile() {
- if (requested_plugin_mode_ == NP_ASFILE ||
- requested_plugin_mode_ == NP_ASFILEONLY)
- instance_->NPP_StreamAsFile(&stream_, temp_file_name_);
-}
-
bool PluginStream::Close(NPReason reason) {
if (opened_ == true) {
opened_ = false;
@@ -252,7 +218,7 @@ bool PluginStream::Close(NPReason reason) {
// If we have a temp file, be sure to close it.
// Also, allow the plugin to access it now.
- if (temp_file_handle_ != INVALID_HANDLE_VALUE) {
+ if (TempFileIsValid()) {
CloseTempFile();
WriteAsFile();
}
@@ -268,54 +234,6 @@ bool PluginStream::Close(NPReason reason) {
return true;
}
-bool PluginStream::OpenTempFile() {
- DCHECK(temp_file_handle_ == INVALID_HANDLE_VALUE);
-
- // The reason for using all the Ascii versions of these filesystem
- // calls is that the filename which we pass back to the plugin
- // via NPAPI is an ascii filename. Otherwise, we'd use wide-chars.
- //
- // TODO:
- // This is a bug in NPAPI itself, and it needs to be fixed.
- // The case which will fail is if a user has a multibyte name,
- // but has the system locale set to english. GetTempPathA will
- // return junk in this case, causing us to be unable to open the
- // file.
-
- char temp_directory[MAX_PATH];
- if (GetTempPathA(MAX_PATH, temp_directory) == 0)
- return false;
- if (GetTempFileNameA(temp_directory, "npstream", 0, temp_file_name_) == 0)
- return false;
- temp_file_handle_ = CreateFileA(temp_file_name_,
- FILE_ALL_ACCESS,
- FILE_SHARE_READ,
- 0,
- CREATE_ALWAYS,
- FILE_ATTRIBUTE_NORMAL,
- 0);
- if (temp_file_handle_ == INVALID_HANDLE_VALUE) {
- temp_file_name_[0] = '\0';
- return false;
- }
- return true;
-}
-
-void PluginStream::CloseTempFile() {
- if (temp_file_handle_ != INVALID_HANDLE_VALUE) {
- CloseHandle(temp_file_handle_);
- temp_file_handle_ = INVALID_HANDLE_VALUE;
- }
-}
-
-void PluginStream::CleanupTempFile() {
- CloseTempFile();
- if (temp_file_name_[0] != '\0') {
- DeleteFileA(temp_file_name_);
- temp_file_name_[0] = '\0';
- }
-}
-
void PluginStream::Notify(NPReason reason) {
if (notify_needed_) {
instance_->NPP_URLNotify(stream_.url, reason, notify_data_);
diff --git a/webkit/glue/plugins/plugin_stream.h b/webkit/glue/plugins/plugin_stream.h
index c79fa47..6c5875b 100644
--- a/webkit/glue/plugins/plugin_stream.h
+++ b/webkit/glue/plugins/plugin_stream.h
@@ -8,10 +8,10 @@
#include <string>
#include <vector>
+#include "base/file_path.h"
#include "base/ref_counted.h"
#include "third_party/npapi/bindings/npapi.h"
-
class WebPluginResourceClient;
namespace NPAPI {
@@ -90,8 +90,11 @@ class PluginStream : public base::RefCounted<PluginStream> {
// Closes the temporary file if it is open and deletes the file.
void CleanupTempFile();
+ // Sends the data to the file. Called From WriteToFile.
+ size_t WriteBytes(const char *buf, size_t length);
+
// Sends the data to the file if it's open.
- bool WriteToFile(const char *buf, const int length);
+ bool WriteToFile(const char *buf, size_t length);
// Sends the data to the plugin. If it's not ready, handles buffering it
// and retrying later.
@@ -104,6 +107,9 @@ class PluginStream : public base::RefCounted<PluginStream> {
// The callback which calls TryWriteToPlugin.
void OnDelayDelivery();
+ // Returns true if the temp file is valid and open for writing.
+ bool TempFileIsValid();
+
private:
NPStream stream_;
std::string headers_;
@@ -116,6 +122,9 @@ class PluginStream : public base::RefCounted<PluginStream> {
#if defined(OS_WIN)
char temp_file_name_[MAX_PATH];
HANDLE temp_file_handle_;
+#elif defined(OS_POSIX)
+ FILE* temp_file_;
+ FilePath temp_file_path_;
#endif
std::vector<char> delivery_data_;
int data_offset_;
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
+
diff --git a/webkit/glue/plugins/plugin_stream_win.cc b/webkit/glue/plugins/plugin_stream_win.cc
new file mode 100644
index 0000000..d1c7519
--- /dev/null
+++ b/webkit/glue/plugins/plugin_stream_win.cc
@@ -0,0 +1,105 @@
+// 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 "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),
+ opened_(false),
+ requested_plugin_mode_(NP_NORMAL),
+ temp_file_handle_(INVALID_HANDLE_VALUE),
+ seekable_stream_(false),
+ data_offset_(0) {
+ memset(&stream_, 0, sizeof(stream_));
+ stream_.url = _strdup(url);
+ temp_file_name_[0] = '\0';
+}
+
+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_name_);
+}
+
+size_t PluginStream::WriteBytes(const char *buf, size_t length) {
+ DWORD bytes;
+
+ if (!WriteFile(temp_file_handle_, buf, length, &bytes, 0))
+ return 0U;
+
+ return static_cast<size_t>(bytes);
+}
+
+bool PluginStream::OpenTempFile() {
+ DCHECK(temp_file_handle_ == INVALID_HANDLE_VALUE);
+
+ // The reason for using all the Ascii versions of these filesystem
+ // calls is that the filename which we pass back to the plugin
+ // via NPAPI is an ascii filename. Otherwise, we'd use wide-chars.
+ //
+ // TODO:
+ // This is a bug in NPAPI itself, and it needs to be fixed.
+ // The case which will fail is if a user has a multibyte name,
+ // but has the system locale set to english. GetTempPathA will
+ // return junk in this case, causing us to be unable to open the
+ // file.
+
+ char temp_directory[MAX_PATH];
+ if (GetTempPathA(MAX_PATH, temp_directory) == 0)
+ return false;
+ if (GetTempFileNameA(temp_directory, "npstream", 0, temp_file_name_) == 0)
+ return false;
+ temp_file_handle_ = CreateFileA(temp_file_name_,
+ FILE_ALL_ACCESS,
+ FILE_SHARE_READ,
+ 0,
+ CREATE_ALWAYS,
+ FILE_ATTRIBUTE_NORMAL,
+ 0);
+ if (temp_file_handle_ == INVALID_HANDLE_VALUE) {
+ temp_file_name_[0] = '\0';
+ return false;
+ }
+ return true;
+}
+
+void PluginStream::CloseTempFile() {
+ if (temp_file_handle_ != INVALID_HANDLE_VALUE) {
+ CloseHandle(temp_file_handle_);
+ temp_file_handle_ = INVALID_HANDLE_VALUE;
+ }
+}
+
+void PluginStream::CleanupTempFile() {
+ CloseTempFile();
+ if (temp_file_name_[0] != '\0') {
+ DeleteFileA(temp_file_name_);
+ temp_file_name_[0] = '\0';
+ }
+}
+
+bool PluginStream::TempFileIsValid() {
+ return temp_file_handle_ != INVALID_HANDLE_VALUE;
+}
+
+} // namespace NPAPI
+