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

Side by Side Diff: webkit/glue/plugins/pepper_file_ref.cc

Issue 3255003: Pull new PPAPI, rename non-P0 interfaces to Dev, rename DeviceContext2D to Gr... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 3 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/glue/plugins/pepper_file_ref.h ('k') | webkit/glue/plugins/pepper_file_system.h » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include "webkit/glue/plugins/pepper_file_ref.h" 5 #include "webkit/glue/plugins/pepper_file_ref.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "webkit/glue/plugins/pepper_plugin_instance.h" 8 #include "webkit/glue/plugins/pepper_plugin_instance.h"
9 #include "webkit/glue/plugins/pepper_var.h" 9 #include "webkit/glue/plugins/pepper_var.h"
10 #include "webkit/glue/plugins/pepper_resource_tracker.h" 10 #include "webkit/glue/plugins/pepper_resource_tracker.h"
(...skipping 15 matching lines...) Expand all
26 } 26 }
27 27
28 void TrimTrailingSlash(std::string* path) { 28 void TrimTrailingSlash(std::string* path) {
29 // If this path ends with a slash, then normalize it away unless path is the 29 // If this path ends with a slash, then normalize it away unless path is the
30 // root path. 30 // root path.
31 if (path->size() > 1 && path->at(path->size() - 1) == '/') 31 if (path->size() > 1 && path->at(path->size() - 1) == '/')
32 path->erase(path->size() - 1, 1); 32 path->erase(path->size() - 1, 1);
33 } 33 }
34 34
35 PP_Resource CreateFileRef(PP_Instance instance_id, 35 PP_Resource CreateFileRef(PP_Instance instance_id,
36 PP_FileSystemType fs_type, 36 PP_FileSystemType_Dev fs_type,
37 const char* path) { 37 const char* path) {
38 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id); 38 PluginInstance* instance = PluginInstance::FromPPInstance(instance_id);
39 if (!instance) 39 if (!instance)
40 return 0; 40 return 0;
41 41
42 std::string origin; // TODO(darin): Extract from PluginInstance. 42 std::string origin; // TODO(darin): Extract from PluginInstance.
43 43
44 std::string validated_path(path); 44 std::string validated_path(path);
45 if (!IsValidLocalPath(validated_path)) 45 if (!IsValidLocalPath(validated_path))
46 return 0; 46 return 0;
(...skipping 11 matching lines...) Expand all
58 } 58 }
59 59
60 PP_Resource CreateTemporaryFileRef(PP_Instance instance_id, const char* path) { 60 PP_Resource CreateTemporaryFileRef(PP_Instance instance_id, const char* path) {
61 return CreateFileRef(instance_id, PP_FILESYSTEMTYPE_LOCALTEMPORARY, path); 61 return CreateFileRef(instance_id, PP_FILESYSTEMTYPE_LOCALTEMPORARY, path);
62 } 62 }
63 63
64 bool IsFileRef(PP_Resource resource) { 64 bool IsFileRef(PP_Resource resource) {
65 return !!Resource::GetAs<FileRef>(resource); 65 return !!Resource::GetAs<FileRef>(resource);
66 } 66 }
67 67
68 PP_FileSystemType GetFileSystemType(PP_Resource file_ref_id) { 68 PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref_id) {
69 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); 69 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
70 if (!file_ref) 70 if (!file_ref)
71 return PP_FILESYSTEMTYPE_EXTERNAL; 71 return PP_FILESYSTEMTYPE_EXTERNAL;
72
73 return file_ref->file_system_type(); 72 return file_ref->file_system_type();
74 } 73 }
75 74
76 PP_Var GetName(PP_Resource file_ref_id) { 75 PP_Var GetName(PP_Resource file_ref_id) {
77 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); 76 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
78 if (!file_ref) 77 if (!file_ref)
79 return PP_MakeVoid(); 78 return PP_MakeVoid();
80
81 return StringToPPVar(file_ref->GetName()); 79 return StringToPPVar(file_ref->GetName());
82 } 80 }
83 81
84 PP_Var GetPath(PP_Resource file_ref_id) { 82 PP_Var GetPath(PP_Resource file_ref_id) {
85 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); 83 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
86 if (!file_ref) 84 if (!file_ref)
87 return PP_MakeVoid(); 85 return PP_MakeVoid();
88 86
89 if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL) 87 if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
90 return PP_MakeVoid(); 88 return PP_MakeVoid();
91 89
92 return StringToPPVar(file_ref->path()); 90 return StringToPPVar(file_ref->path());
93 } 91 }
94 92
95 PP_Resource GetParent(PP_Resource file_ref_id) { 93 PP_Resource GetParent(PP_Resource file_ref_id) {
96 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id)); 94 scoped_refptr<FileRef> file_ref(Resource::GetAs<FileRef>(file_ref_id));
97 if (!file_ref) 95 if (!file_ref)
98 return 0; 96 return 0;
99 97
100 if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL) 98 if (file_ref->file_system_type() == PP_FILESYSTEMTYPE_EXTERNAL)
101 return 0; 99 return 0;
102 100
103 scoped_refptr<FileRef> parent_ref(file_ref->GetParent()); 101 scoped_refptr<FileRef> parent_ref(file_ref->GetParent());
104 if (!parent_ref) 102 if (!parent_ref)
105 return 0; 103 return 0;
106 104
107 return parent_ref->GetReference(); 105 return parent_ref->GetReference();
108 } 106 }
109 107
110 const PPB_FileRef ppb_fileref = { 108 const PPB_FileRef_Dev ppb_fileref = {
111 &CreatePersistentFileRef, 109 &CreatePersistentFileRef,
112 &CreateTemporaryFileRef, 110 &CreateTemporaryFileRef,
113 &IsFileRef, 111 &IsFileRef,
114 &GetFileSystemType, 112 &GetFileSystemType,
115 &GetName, 113 &GetName,
116 &GetPath, 114 &GetPath,
117 &GetParent 115 &GetParent
118 }; 116 };
119 117
120 } // namespace 118 } // namespace
121 119
122 FileRef::FileRef(PluginModule* module, 120 FileRef::FileRef(PluginModule* module,
123 PP_FileSystemType file_system_type, 121 PP_FileSystemType_Dev file_system_type,
124 const std::string& validated_path, 122 const std::string& validated_path,
125 const std::string& origin) 123 const std::string& origin)
126 : Resource(module), 124 : Resource(module),
127 fs_type_(file_system_type), 125 fs_type_(file_system_type),
128 path_(validated_path), 126 path_(validated_path),
129 origin_(origin) { 127 origin_(origin) {
130 // TODO(darin): Need to initialize system_path_. 128 // TODO(darin): Need to initialize system_path_.
131 } 129 }
132 130
133 FileRef::FileRef(PluginModule* module, 131 FileRef::FileRef(PluginModule* module,
134 const FilePath& external_file_path) 132 const FilePath& external_file_path)
135 : Resource(module), 133 : Resource(module),
136 system_path_(external_file_path), 134 system_path_(external_file_path),
137 fs_type_(PP_FILESYSTEMTYPE_EXTERNAL) { 135 fs_type_(PP_FILESYSTEMTYPE_EXTERNAL) {
138 } 136 }
139 137
140 FileRef::~FileRef() { 138 FileRef::~FileRef() {
141 } 139 }
142 140
143 // static 141 // static
144 const PPB_FileRef* FileRef::GetInterface() { 142 const PPB_FileRef_Dev* FileRef::GetInterface() {
145 return &ppb_fileref; 143 return &ppb_fileref;
146 } 144 }
147 145
148 std::string FileRef::GetName() const { 146 std::string FileRef::GetName() const {
149 if (path_.size() == 1 && path_[0] == '/') 147 if (path_.size() == 1 && path_[0] == '/')
150 return path_; 148 return path_;
151 149
152 // There should always be a leading slash at least! 150 // There should always be a leading slash at least!
153 size_t pos = path_.rfind('/'); 151 size_t pos = path_.rfind('/');
154 DCHECK(pos != std::string::npos); 152 DCHECK(pos != std::string::npos);
(...skipping 12 matching lines...) Expand all
167 // If the path is "/foo", then we want to include the slash. 165 // If the path is "/foo", then we want to include the slash.
168 if (pos == 0) 166 if (pos == 0)
169 pos++; 167 pos++;
170 std::string parent_path = path_.substr(0, pos); 168 std::string parent_path = path_.substr(0, pos);
171 169
172 FileRef* parent_ref = new FileRef(module(), fs_type_, parent_path, origin_); 170 FileRef* parent_ref = new FileRef(module(), fs_type_, parent_path, origin_);
173 return parent_ref; 171 return parent_ref;
174 } 172 }
175 173
176 } // namespace pepper 174 } // namespace pepper
OLDNEW
« no previous file with comments | « webkit/glue/plugins/pepper_file_ref.h ('k') | webkit/glue/plugins/pepper_file_system.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698