OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 #include "webkit/glue/plugins/plugin_stream.h" | |
6 | |
7 #include <string.h> | |
8 | |
9 #include "base/file_path.h" | |
10 #include "base/file_util.h" | |
11 #include "base/logging.h" | |
12 #include "webkit/glue/plugins/plugin_instance.h" | |
13 | |
14 namespace NPAPI { | |
15 | |
16 PluginStream::PluginStream( | |
17 PluginInstance *instance, | |
18 const char *url, | |
19 bool need_notify, | |
20 void *notify_data) | |
21 : instance_(instance), | |
22 notify_needed_(need_notify), | |
23 notify_data_(notify_data), | |
24 close_on_write_data_(false), | |
25 requested_plugin_mode_(NP_NORMAL), | |
26 opened_(false), | |
27 temp_file_(NULL), | |
28 temp_file_path_(), | |
29 data_offset_(0), | |
30 seekable_stream_(false) { | |
31 memset(&stream_, 0, sizeof(stream_)); | |
32 stream_.url = strdup(url); | |
33 } | |
34 | |
35 void PluginStream::UpdateUrl(const char* url) { | |
36 DCHECK(!opened_); | |
37 free(const_cast<char*>(stream_.url)); | |
38 stream_.url = strdup(url); | |
39 } | |
40 | |
41 void PluginStream::WriteAsFile() { | |
42 if (requested_plugin_mode_ == NP_ASFILE || | |
43 requested_plugin_mode_ == NP_ASFILEONLY) | |
44 instance_->NPP_StreamAsFile(&stream_, temp_file_path_.value().c_str()); | |
45 } | |
46 | |
47 size_t PluginStream::WriteBytes(const char *buf, size_t length) { | |
48 return fwrite(buf, sizeof(char), length, temp_file_); | |
49 } | |
50 | |
51 bool PluginStream::OpenTempFile() { | |
52 DCHECK(temp_file_ == NULL); | |
53 | |
54 if (file_util::CreateTemporaryFile(&temp_file_path_)) | |
55 temp_file_ = file_util::OpenFile(temp_file_path_, "a"); | |
56 | |
57 if (!temp_file_) { | |
58 temp_file_path_ = FilePath(""); | |
59 return false; | |
60 } | |
61 | |
62 return true; | |
63 } | |
64 | |
65 void PluginStream::CloseTempFile() { | |
66 file_util::CloseFile(temp_file_); | |
67 temp_file_ = NULL; | |
68 } | |
69 | |
70 bool PluginStream::TempFileIsValid() { | |
71 return temp_file_ != NULL; | |
72 } | |
73 | |
74 } // namespace NPAPI | |
OLD | NEW |