Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/browser/renderer_host/pepper/pepper_file_ref_host.h" | 5 #include "content/browser/renderer_host/pepper/pepper_file_ref_host.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "content/browser/renderer_host/pepper/pepper_external_file_ref_backend. h" | 9 #include "content/browser/renderer_host/pepper/pepper_external_file_ref_backend. h" |
| 10 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h " | 10 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h " |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 120 return backend_->GetFileSystemURLSpec(); | 120 return backend_->GetFileSystemURLSpec(); |
| 121 return std::string(); | 121 return std::string(); |
| 122 } | 122 } |
| 123 | 123 |
| 124 base::FilePath PepperFileRefHost::GetExternalPath() const { | 124 base::FilePath PepperFileRefHost::GetExternalPath() const { |
| 125 if (backend_) | 125 if (backend_) |
| 126 return backend_->GetExternalPath(); | 126 return backend_->GetExternalPath(); |
| 127 return base::FilePath(); | 127 return base::FilePath(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 int32_t PepperFileRefHost::HasPermissions(int permissions) const { | 130 int32_t PepperFileRefHost::CanRead() const { |
| 131 if (backend_) | 131 if (backend_) |
| 132 return backend_->HasPermissions(permissions); | 132 return backend_->CanRead(); |
| 133 return PP_ERROR_FAILED; | 133 return PP_ERROR_FAILED; |
| 134 } | 134 } |
| 135 | 135 |
| 136 int32_t PepperFileRefHost::CanWrite() const { | |
| 137 if (backend_) | |
| 138 return backend_->CanWrite(); | |
| 139 return PP_ERROR_FAILED; | |
| 140 } | |
| 141 | |
| 142 int32_t PepperFileRefHost::CanCreate() const { | |
| 143 if (backend_) | |
| 144 return backend_->CanCreate(); | |
| 145 return PP_ERROR_FAILED; | |
| 146 } | |
| 147 | |
| 136 int32_t PepperFileRefHost::OnResourceMessageReceived( | 148 int32_t PepperFileRefHost::OnResourceMessageReceived( |
| 137 const IPC::Message& msg, | 149 const IPC::Message& msg, |
| 138 ppapi::host::HostMessageContext* context) { | 150 ppapi::host::HostMessageContext* context) { |
| 139 if (!backend_) | 151 if (!backend_) |
| 140 return PP_ERROR_FAILED; | 152 return PP_ERROR_FAILED; |
| 141 | 153 |
| 142 IPC_BEGIN_MESSAGE_MAP(PepperFileRefHost, msg) | 154 IPC_BEGIN_MESSAGE_MAP(PepperFileRefHost, msg) |
| 143 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileRef_MakeDirectory, | 155 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileRef_MakeDirectory, |
| 144 OnMakeDirectory); | 156 OnMakeDirectory); |
| 145 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileRef_Touch, | 157 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileRef_Touch, |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 156 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileRef_GetAbsolutePath, | 168 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_FileRef_GetAbsolutePath, |
| 157 OnGetAbsolutePath); | 169 OnGetAbsolutePath); |
| 158 | 170 |
| 159 IPC_END_MESSAGE_MAP() | 171 IPC_END_MESSAGE_MAP() |
| 160 return PP_ERROR_FAILED; | 172 return PP_ERROR_FAILED; |
| 161 } | 173 } |
| 162 | 174 |
| 163 int32_t PepperFileRefHost::OnMakeDirectory( | 175 int32_t PepperFileRefHost::OnMakeDirectory( |
| 164 ppapi::host::HostMessageContext* context, | 176 ppapi::host::HostMessageContext* context, |
| 165 bool make_ancestors) { | 177 bool make_ancestors) { |
| 166 int32_t rv = HasPermissions(fileapi::kCreateFilePermissions); | 178 int32_t rv = CanCreate(); |
| 167 if (rv != PP_OK) | 179 if (rv != PP_OK) |
| 168 return rv; | 180 return rv; |
| 169 return backend_->MakeDirectory(context->MakeReplyMessageContext(), | 181 return backend_->MakeDirectory(context->MakeReplyMessageContext(), |
| 170 make_ancestors); | 182 make_ancestors); |
| 171 } | 183 } |
| 172 | 184 |
| 173 int32_t PepperFileRefHost::OnTouch(ppapi::host::HostMessageContext* context, | 185 int32_t PepperFileRefHost::OnTouch(ppapi::host::HostMessageContext* context, |
| 174 PP_Time last_access_time, | 186 PP_Time last_access_time, |
| 175 PP_Time last_modified_time) { | 187 PP_Time last_modified_time) { |
| 176 // TODO(teravest): Change this to be kWriteFilePermissions here and in | 188 // TODO(teravest): Change this to be kWriteFilePermissions here and in |
| 177 // fileapi_message_filter. | 189 // fileapi_message_filter. |
| 178 int32_t rv = HasPermissions(fileapi::kCreateFilePermissions); | 190 int32_t rv = CanCreate(); |
| 179 if (rv != PP_OK) | 191 if (rv != PP_OK) |
| 180 return rv; | 192 return rv; |
| 181 return backend_->Touch(context->MakeReplyMessageContext(), | 193 return backend_->Touch(context->MakeReplyMessageContext(), |
| 182 last_access_time, | 194 last_access_time, |
| 183 last_modified_time); | 195 last_modified_time); |
| 184 } | 196 } |
| 185 | 197 |
| 186 int32_t PepperFileRefHost::OnDelete(ppapi::host::HostMessageContext* context) { | 198 int32_t PepperFileRefHost::OnDelete(ppapi::host::HostMessageContext* context) { |
| 187 int32_t rv = HasPermissions(fileapi::kWriteFilePermissions); | 199 int32_t rv = CanWrite(); |
| 188 if (rv != PP_OK) | 200 if (rv != PP_OK) |
| 189 return rv; | 201 return rv; |
| 190 return backend_->Delete(context->MakeReplyMessageContext()); | 202 return backend_->Delete(context->MakeReplyMessageContext()); |
| 191 } | 203 } |
| 192 | 204 |
| 193 int32_t PepperFileRefHost::OnRename(ppapi::host::HostMessageContext* context, | 205 int32_t PepperFileRefHost::OnRename(ppapi::host::HostMessageContext* context, |
| 194 PP_Resource new_file_ref) { | 206 PP_Resource new_file_ref) { |
| 195 int32_t rv = HasPermissions( | 207 int32_t rv = CanRead(); |
| 196 fileapi::kReadFilePermissions | fileapi::kWriteFilePermissions); | |
| 197 if (rv != PP_OK) | 208 if (rv != PP_OK) |
| 198 return rv; | 209 return rv; |
| 199 | 210 |
| 211 rv = CanWrite(); | |
|
Tom Sepez
2013/07/19 18:39:28
Doesn't checking read/write separately have the ef
tommycli
2013/07/23 21:12:35
Done.
| |
| 212 if (rv != PP_OK) | |
| 213 return rv; | |
| 214 | |
| 200 ResourceHost* resource_host = | 215 ResourceHost* resource_host = |
| 201 host_->GetPpapiHost()->GetResourceHost(new_file_ref); | 216 host_->GetPpapiHost()->GetResourceHost(new_file_ref); |
| 202 if (!resource_host) | 217 if (!resource_host) |
| 203 return PP_ERROR_BADRESOURCE; | 218 return PP_ERROR_BADRESOURCE; |
| 204 | 219 |
| 205 PepperFileRefHost* file_ref_host = resource_host->AsPepperFileRefHost(); | 220 PepperFileRefHost* file_ref_host = resource_host->AsPepperFileRefHost(); |
| 206 if (!file_ref_host) | 221 if (!file_ref_host) |
| 207 return PP_ERROR_BADRESOURCE; | 222 return PP_ERROR_BADRESOURCE; |
| 208 | 223 |
| 209 rv = file_ref_host->HasPermissions(fileapi::kCreateFilePermissions); | 224 rv = file_ref_host->CanCreate(); |
| 210 if (rv != PP_OK) | 225 if (rv != PP_OK) |
| 211 return rv; | 226 return rv; |
| 212 | 227 |
| 213 return backend_->Rename(context->MakeReplyMessageContext(), | 228 return backend_->Rename(context->MakeReplyMessageContext(), |
| 214 file_ref_host); | 229 file_ref_host); |
| 215 } | 230 } |
| 216 | 231 |
| 217 int32_t PepperFileRefHost::OnQuery(ppapi::host::HostMessageContext* context) { | 232 int32_t PepperFileRefHost::OnQuery(ppapi::host::HostMessageContext* context) { |
| 218 int32_t rv = HasPermissions(fileapi::kReadFilePermissions); | 233 int32_t rv = CanRead(); |
| 219 if (rv != PP_OK) | 234 if (rv != PP_OK) |
| 220 return rv; | 235 return rv; |
| 221 return backend_->Query(context->MakeReplyMessageContext()); | 236 return backend_->Query(context->MakeReplyMessageContext()); |
| 222 } | 237 } |
| 223 | 238 |
| 224 int32_t PepperFileRefHost::OnReadDirectoryEntries( | 239 int32_t PepperFileRefHost::OnReadDirectoryEntries( |
| 225 ppapi::host::HostMessageContext* context) { | 240 ppapi::host::HostMessageContext* context) { |
| 226 int32_t rv = HasPermissions(fileapi::kReadFilePermissions); | 241 int32_t rv = CanRead(); |
| 227 if (rv != PP_OK) | 242 if (rv != PP_OK) |
| 228 return rv; | 243 return rv; |
| 229 return backend_->ReadDirectoryEntries(context->MakeReplyMessageContext()); | 244 return backend_->ReadDirectoryEntries(context->MakeReplyMessageContext()); |
| 230 } | 245 } |
| 231 | 246 |
| 232 int32_t PepperFileRefHost::OnGetAbsolutePath( | 247 int32_t PepperFileRefHost::OnGetAbsolutePath( |
| 233 ppapi::host::HostMessageContext* context) { | 248 ppapi::host::HostMessageContext* context) { |
| 234 if (!host_->GetPpapiHost()->permissions().HasPermission( | 249 if (!host_->GetPpapiHost()->permissions().HasPermission( |
| 235 ppapi::PERMISSION_PRIVATE)) | 250 ppapi::PERMISSION_PRIVATE)) |
| 236 return PP_ERROR_NOACCESS; | 251 return PP_ERROR_NOACCESS; |
| 237 return backend_->GetAbsolutePath(context->MakeReplyMessageContext()); | 252 return backend_->GetAbsolutePath(context->MakeReplyMessageContext()); |
| 238 } | 253 } |
| 239 | 254 |
| 240 } // namespace content | 255 } // namespace content |
| OLD | NEW |