OLD | NEW |
| (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 #include "webkit/plugins/npapi/plugin_stream.h" | |
6 | |
7 #include <string.h> | |
8 | |
9 #include "base/file_util.h" | |
10 #include "base/files/file_path.h" | |
11 #include "base/logging.h" | |
12 #include "webkit/plugins/npapi/plugin_instance.h" | |
13 | |
14 namespace webkit { | |
15 namespace npapi { | |
16 | |
17 void PluginStream::ResetTempFileHandle() { | |
18 temp_file_ = NULL; | |
19 } | |
20 | |
21 void PluginStream::ResetTempFileName() { | |
22 temp_file_path_ = base::FilePath(); | |
23 } | |
24 | |
25 void PluginStream::WriteAsFile() { | |
26 if (RequestedPluginModeIsAsFile()) | |
27 instance_->NPP_StreamAsFile(&stream_, temp_file_path_.value().c_str()); | |
28 } | |
29 | |
30 size_t PluginStream::WriteBytes(const char* buf, size_t length) { | |
31 return fwrite(buf, sizeof(char), length, temp_file_); | |
32 } | |
33 | |
34 bool PluginStream::OpenTempFile() { | |
35 DCHECK_EQ(static_cast<FILE*>(NULL), temp_file_); | |
36 | |
37 if (file_util::CreateTemporaryFile(&temp_file_path_)) | |
38 temp_file_ = file_util::OpenFile(temp_file_path_, "a"); | |
39 | |
40 if (!temp_file_) { | |
41 base::DeleteFile(temp_file_path_, false); | |
42 ResetTempFileName(); | |
43 return false; | |
44 } | |
45 return true; | |
46 } | |
47 | |
48 void PluginStream::CloseTempFile() { | |
49 if (!TempFileIsValid()) | |
50 return; | |
51 | |
52 file_util::CloseFile(temp_file_); | |
53 ResetTempFileHandle(); | |
54 } | |
55 | |
56 bool PluginStream::TempFileIsValid() const { | |
57 return temp_file_ != NULL; | |
58 } | |
59 | |
60 } // namespace npapi | |
61 } // namespace webkit | |
OLD | NEW |