| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/renderer/pepper/pepper_file_system_host.h" | 5 #include "content/renderer/pepper/pepper_file_system_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/child/child_thread.h" | 9 #include "content/child/child_thread.h" |
| 10 #include "content/child/fileapi/file_system_dispatcher.h" | 10 #include "content/child/fileapi/file_system_dispatcher.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 } | 85 } |
| 86 | 86 |
| 87 int32_t PepperFileSystemHost::OnHostMsgOpen( | 87 int32_t PepperFileSystemHost::OnHostMsgOpen( |
| 88 ppapi::host::HostMessageContext* context, | 88 ppapi::host::HostMessageContext* context, |
| 89 int64_t expected_size) { | 89 int64_t expected_size) { |
| 90 // Not allow multiple opens. | 90 // Not allow multiple opens. |
| 91 if (called_open_) | 91 if (called_open_) |
| 92 return PP_ERROR_INPROGRESS; | 92 return PP_ERROR_INPROGRESS; |
| 93 called_open_ = true; | 93 called_open_ = true; |
| 94 | 94 |
| 95 fileapi::FileSystemType file_system_type = | 95 storage::FileSystemType file_system_type = |
| 96 PepperFileSystemTypeToFileSystemType(type_); | 96 PepperFileSystemTypeToFileSystemType(type_); |
| 97 if (file_system_type == fileapi::kFileSystemTypeUnknown) | 97 if (file_system_type == storage::kFileSystemTypeUnknown) |
| 98 return PP_ERROR_FAILED; | 98 return PP_ERROR_FAILED; |
| 99 | 99 |
| 100 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); | 100 GURL document_url = renderer_ppapi_host_->GetDocumentURL(pp_instance()); |
| 101 if (!document_url.is_valid()) | 101 if (!document_url.is_valid()) |
| 102 return PP_ERROR_FAILED; | 102 return PP_ERROR_FAILED; |
| 103 | 103 |
| 104 FileSystemDispatcher* file_system_dispatcher = | 104 FileSystemDispatcher* file_system_dispatcher = |
| 105 ChildThread::current()->file_system_dispatcher(); | 105 ChildThread::current()->file_system_dispatcher(); |
| 106 reply_context_ = context->MakeReplyMessageContext(); | 106 reply_context_ = context->MakeReplyMessageContext(); |
| 107 file_system_dispatcher->OpenFileSystem( | 107 file_system_dispatcher->OpenFileSystem( |
| 108 document_url.GetOrigin(), | 108 document_url.GetOrigin(), |
| 109 file_system_type, | 109 file_system_type, |
| 110 base::Bind(&PepperFileSystemHost::DidOpenFileSystem, | 110 base::Bind(&PepperFileSystemHost::DidOpenFileSystem, |
| 111 weak_factory_.GetWeakPtr()), | 111 weak_factory_.GetWeakPtr()), |
| 112 base::Bind(&PepperFileSystemHost::DidFailOpenFileSystem, | 112 base::Bind(&PepperFileSystemHost::DidFailOpenFileSystem, |
| 113 weak_factory_.GetWeakPtr())); | 113 weak_factory_.GetWeakPtr())); |
| 114 return PP_OK_COMPLETIONPENDING; | 114 return PP_OK_COMPLETIONPENDING; |
| 115 } | 115 } |
| 116 | 116 |
| 117 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( | 117 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( |
| 118 ppapi::host::HostMessageContext* context, | 118 ppapi::host::HostMessageContext* context, |
| 119 const std::string& fsid, | 119 const std::string& fsid, |
| 120 PP_IsolatedFileSystemType_Private type) { | 120 PP_IsolatedFileSystemType_Private type) { |
| 121 // Do not allow multiple opens. | 121 // Do not allow multiple opens. |
| 122 if (called_open_) | 122 if (called_open_) |
| 123 return PP_ERROR_INPROGRESS; | 123 return PP_ERROR_INPROGRESS; |
| 124 called_open_ = true; | 124 called_open_ = true; |
| 125 | 125 |
| 126 // Do a sanity check. | 126 // Do a sanity check. |
| 127 if (!fileapi::ValidateIsolatedFileSystemId(fsid)) | 127 if (!storage::ValidateIsolatedFileSystemId(fsid)) |
| 128 return PP_ERROR_BADARGUMENT; | 128 return PP_ERROR_BADARGUMENT; |
| 129 | 129 |
| 130 RenderView* view = | 130 RenderView* view = |
| 131 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()); | 131 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()); |
| 132 if (!view) | 132 if (!view) |
| 133 return PP_ERROR_FAILED; | 133 return PP_ERROR_FAILED; |
| 134 | 134 |
| 135 const GURL& url = view->GetWebView()->mainFrame()->document().url(); | 135 const GURL& url = view->GetWebView()->mainFrame()->document().url(); |
| 136 const std::string root_name = ppapi::IsolatedFileSystemTypeToRootName(type); | 136 const std::string root_name = ppapi::IsolatedFileSystemTypeToRootName(type); |
| 137 if (root_name.empty()) | 137 if (root_name.empty()) |
| 138 return PP_ERROR_BADARGUMENT; | 138 return PP_ERROR_BADARGUMENT; |
| 139 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( | 139 root_url_ = GURL(storage::GetIsolatedFileSystemRootURIString( |
| 140 url.GetOrigin(), fsid, root_name)); | 140 url.GetOrigin(), fsid, root_name)); |
| 141 opened_ = true; | 141 opened_ = true; |
| 142 return PP_OK; | 142 return PP_OK; |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace content | 145 } // namespace content |
| OLD | NEW |