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_system_browser_host.h
" | 5 #include "content/browser/renderer_host/pepper/pepper_file_system_browser_host.h
" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "content/public/browser/browser_ppapi_host.h" | 9 #include "content/public/browser/browser_ppapi_host.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| 11 #include "content/public/browser/child_process_security_policy.h" |
11 #include "content/public/browser/render_process_host.h" | 12 #include "content/public/browser/render_process_host.h" |
12 #include "content/public/browser/storage_partition.h" | 13 #include "content/public/browser/storage_partition.h" |
13 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
14 #include "ppapi/host/dispatch_host_message.h" | 15 #include "ppapi/host/dispatch_host_message.h" |
15 #include "ppapi/host/ppapi_host.h" | 16 #include "ppapi/host/ppapi_host.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "ppapi/shared_impl/file_type_conversion.h" | 18 #include "ppapi/shared_impl/file_type_conversion.h" |
18 #include "webkit/browser/fileapi/file_system_context.h" | 19 #include "webkit/browser/fileapi/file_system_context.h" |
19 #include "webkit/browser/fileapi/file_system_operation_runner.h" | 20 #include "webkit/browser/fileapi/file_system_operation_runner.h" |
20 #include "webkit/common/fileapi/file_system_util.h" | 21 #include "webkit/common/fileapi/file_system_util.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived( | 90 int32_t PepperFileSystemBrowserHost::OnResourceMessageReceived( |
90 const IPC::Message& msg, | 91 const IPC::Message& msg, |
91 ppapi::host::HostMessageContext* context) { | 92 ppapi::host::HostMessageContext* context) { |
92 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemBrowserHost, msg) | 93 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemBrowserHost, msg) |
93 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 94 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
94 PpapiHostMsg_FileSystem_Open, | 95 PpapiHostMsg_FileSystem_Open, |
95 OnHostMsgOpen) | 96 OnHostMsgOpen) |
96 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 97 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
97 PpapiHostMsg_FileSystem_InitIsolatedFileSystem, | 98 PpapiHostMsg_FileSystem_InitIsolatedFileSystem, |
98 OnHostMsgInitIsolatedFileSystem) | 99 OnHostMsgInitIsolatedFileSystem) |
| 100 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0( |
| 101 PpapiHostMsg_FileSystem_OpenPluginPrivateFileSystem, |
| 102 OnHostMsgOpenPluginPrivateFileSystem) |
99 IPC_END_MESSAGE_MAP() | 103 IPC_END_MESSAGE_MAP() |
100 return PP_ERROR_FAILED; | 104 return PP_ERROR_FAILED; |
101 } | 105 } |
102 | 106 |
103 bool PepperFileSystemBrowserHost::IsFileSystemHost() { | 107 bool PepperFileSystemBrowserHost::IsFileSystemHost() { |
104 return true; | 108 return true; |
105 } | 109 } |
106 | 110 |
107 int32_t PepperFileSystemBrowserHost::OnHostMsgOpen( | 111 int32_t PepperFileSystemBrowserHost::OnHostMsgOpen( |
108 ppapi::host::HostMessageContext* context, | 112 ppapi::host::HostMessageContext* context, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 scoped_refptr<fileapi::FileSystemContext> fs_context) { | 176 scoped_refptr<fileapi::FileSystemContext> fs_context) { |
173 fs_context_ = fs_context; | 177 fs_context_ = fs_context; |
174 if (fs_context.get()) | 178 if (fs_context.get()) |
175 reply_context.params.set_result(PP_OK); | 179 reply_context.params.set_result(PP_OK); |
176 else | 180 else |
177 reply_context.params.set_result(PP_ERROR_FAILED); | 181 reply_context.params.set_result(PP_ERROR_FAILED); |
178 host()->SendReply(reply_context, | 182 host()->SendReply(reply_context, |
179 PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply()); | 183 PpapiPluginMsg_FileSystem_InitIsolatedFileSystemReply()); |
180 } | 184 } |
181 | 185 |
| 186 void PepperFileSystemBrowserHost::GotFileSystemContextForPluginPrivate( |
| 187 ppapi::host::ReplyMessageContext reply_context, |
| 188 scoped_refptr<fileapi::FileSystemContext> fs_context) { |
| 189 if (!fs_context.get()) { |
| 190 OpenFileSystemComplete( |
| 191 reply_context, GURL(), std::string(), base::PLATFORM_FILE_ERROR_FAILED); |
| 192 return; |
| 193 } |
| 194 fs_context_ = fs_context; |
| 195 |
| 196 GURL origin = browser_ppapi_host_->GetDocumentURLForInstance( |
| 197 pp_instance()).GetOrigin(); |
| 198 |
| 199 // TODO(nhiroki): Generate a real plugin_id from the plugin's MIME type. |
| 200 std::string dummy_plugin_id = "plugin_id"; |
| 201 fs_context->OpenPluginPrivateFileSystem( |
| 202 origin, fileapi::kFileSystemTypePluginPrivate, dummy_plugin_id, |
| 203 fileapi::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 204 base::Bind( |
| 205 &PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete, |
| 206 weak_factory_.GetWeakPtr(), reply_context)); |
| 207 } |
| 208 |
182 void PepperFileSystemBrowserHost::OpenFileSystemComplete( | 209 void PepperFileSystemBrowserHost::OpenFileSystemComplete( |
183 ppapi::host::ReplyMessageContext reply_context, | 210 ppapi::host::ReplyMessageContext reply_context, |
184 const GURL& root, | 211 const GURL& root, |
185 const std::string& /* unused */, | 212 const std::string& /* unused */, |
186 base::PlatformFileError error) { | 213 base::PlatformFileError error) { |
187 int32 pp_error = ppapi::PlatformFileErrorToPepperError(error); | 214 int32 pp_error = ppapi::PlatformFileErrorToPepperError(error); |
188 if (pp_error == PP_OK) { | 215 if (pp_error == PP_OK) { |
189 opened_ = true; | 216 opened_ = true; |
190 root_url_ = root; | 217 root_url_ = root; |
191 } | 218 } |
192 reply_context.params.set_result(pp_error); | 219 reply_context.params.set_result(pp_error); |
193 host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply()); | 220 host()->SendReply(reply_context, PpapiPluginMsg_FileSystem_OpenReply()); |
194 } | 221 } |
195 | 222 |
| 223 void PepperFileSystemBrowserHost::OpenPluginPrivateFileSystemComplete( |
| 224 ppapi::host::ReplyMessageContext reply_context, |
| 225 const GURL& root, |
| 226 const std::string& fsid, |
| 227 base::PlatformFileError error) { |
| 228 int32 pp_error = ppapi::PlatformFileErrorToPepperError(error); |
| 229 if (pp_error != PP_OK) { |
| 230 reply_context.params.set_result(pp_error); |
| 231 host()->SendReply( |
| 232 reply_context, |
| 233 PpapiPluginMsg_FileSystem_OpenPluginPrivateFileSystemReply( |
| 234 std::string())); |
| 235 return; |
| 236 } |
| 237 |
| 238 int render_process_id = 0; |
| 239 int unused; |
| 240 if (!browser_ppapi_host_->GetRenderViewIDsForInstance(pp_instance(), |
| 241 &render_process_id, |
| 242 &unused)) { |
| 243 reply_context.params.set_result(PP_ERROR_FAILED); |
| 244 host()->SendReply( |
| 245 reply_context, |
| 246 PpapiPluginMsg_FileSystem_OpenPluginPrivateFileSystemReply( |
| 247 std::string())); |
| 248 return; |
| 249 } |
| 250 |
| 251 opened_ = true; |
| 252 root_url_ = root; |
| 253 |
| 254 content::ChildProcessSecurityPolicy* policy = |
| 255 content::ChildProcessSecurityPolicy::GetInstance(); |
| 256 policy->GrantCreateReadWriteFileSystem(render_process_id, fsid); |
| 257 |
| 258 reply_context.params.set_result(PP_OK); |
| 259 host()->SendReply( |
| 260 reply_context, |
| 261 PpapiPluginMsg_FileSystem_OpenPluginPrivateFileSystemReply(fsid)); |
| 262 } |
| 263 |
196 int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem( | 264 int32_t PepperFileSystemBrowserHost::OnHostMsgInitIsolatedFileSystem( |
197 ppapi::host::HostMessageContext* context, | 265 ppapi::host::HostMessageContext* context, |
198 const std::string& fsid) { | 266 const std::string& fsid) { |
199 // Do not allow multiple opens. | 267 // Do not allow multiple opens. |
200 if (called_open_) | 268 if (called_open_) |
201 return PP_ERROR_INPROGRESS; | 269 return PP_ERROR_INPROGRESS; |
202 called_open_ = true; | 270 called_open_ = true; |
203 // Do a sanity check. | 271 // Do a sanity check. |
204 if (!LooksLikeAGuid(fsid)) | 272 if (!LooksLikeAGuid(fsid)) |
205 return PP_ERROR_BADARGUMENT; | 273 return PP_ERROR_BADARGUMENT; |
(...skipping 13 matching lines...) Expand all Loading... |
219 BrowserThread::PostTaskAndReplyWithResult( | 287 BrowserThread::PostTaskAndReplyWithResult( |
220 BrowserThread::UI, | 288 BrowserThread::UI, |
221 FROM_HERE, | 289 FROM_HERE, |
222 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), | 290 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), |
223 base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext, | 291 base::Bind(&PepperFileSystemBrowserHost::GotIsolatedFileSystemContext, |
224 weak_factory_.GetWeakPtr(), | 292 weak_factory_.GetWeakPtr(), |
225 context->MakeReplyMessageContext())); | 293 context->MakeReplyMessageContext())); |
226 return PP_OK_COMPLETIONPENDING; | 294 return PP_OK_COMPLETIONPENDING; |
227 } | 295 } |
228 | 296 |
| 297 int32_t PepperFileSystemBrowserHost::OnHostMsgOpenPluginPrivateFileSystem( |
| 298 ppapi::host::HostMessageContext* context) { |
| 299 // Do not allow multiple opens. |
| 300 if (called_open_) |
| 301 return PP_ERROR_INPROGRESS; |
| 302 called_open_ = true; |
| 303 |
| 304 int render_process_id = 0; |
| 305 int unused; |
| 306 if (!browser_ppapi_host_->GetRenderViewIDsForInstance(pp_instance(), |
| 307 &render_process_id, |
| 308 &unused)) { |
| 309 return PP_ERROR_FAILED; |
| 310 } |
| 311 |
| 312 BrowserThread::PostTaskAndReplyWithResult( |
| 313 BrowserThread::UI, |
| 314 FROM_HERE, |
| 315 base::Bind(&GetFileSystemContextFromRenderId, render_process_id), |
| 316 base::Bind( |
| 317 &PepperFileSystemBrowserHost::GotFileSystemContextForPluginPrivate, |
| 318 weak_factory_.GetWeakPtr(), context->MakeReplyMessageContext())); |
| 319 return PP_OK_COMPLETIONPENDING; |
| 320 } |
| 321 |
229 } // namespace content | 322 } // namespace content |
OLD | NEW |