Chromium Code Reviews| 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/common/child_thread.h" | 9 #include "content/common/child_thread.h" |
| 10 #include "content/common/fileapi/file_system_dispatcher.h" | 10 #include "content/common/fileapi/file_system_dispatcher.h" |
| 11 #include "content/public/renderer/renderer_ppapi_host.h" | 11 #include "content/public/renderer/renderer_ppapi_host.h" |
| 12 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" | 12 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" |
| 13 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 14 #include "ppapi/host/dispatch_host_message.h" | 14 #include "ppapi/host/dispatch_host_message.h" |
| 15 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
| 16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 17 #include "ppapi/shared_impl/file_type_conversion.h" | 17 #include "ppapi/shared_impl/file_type_conversion.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 22 #include "webkit/fileapi/file_system_util.h" | |
| 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 23 | 24 |
| 24 namespace content { | 25 namespace content { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { | 29 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { |
| 29 public: | 30 public: |
| 30 explicit PlatformCallbackAdaptor( | 31 explicit PlatformCallbackAdaptor( |
| 31 const base::WeakPtr<PepperFileSystemHost>& weak_host) | 32 const base::WeakPtr<PepperFileSystemHost>& weak_host) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 43 if (weak_host_) { | 44 if (weak_host_) { |
| 44 weak_host_->OpenFileSystemReply( | 45 weak_host_->OpenFileSystemReply( |
| 45 ppapi::PlatformFileErrorToPepperError(platform_error), GURL()); | 46 ppapi::PlatformFileErrorToPepperError(platform_error), GURL()); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 49 private: | 50 private: |
| 50 base::WeakPtr<PepperFileSystemHost> weak_host_; | 51 base::WeakPtr<PepperFileSystemHost> weak_host_; |
| 51 }; | 52 }; |
| 52 | 53 |
| 54 bool LooksLikeAGuid(const std::string& fsid) { | |
| 55 const int kExpectedFsIdSize = 32; | |
| 56 if (fsid.size() != kExpectedFsIdSize) | |
| 57 return false; | |
| 58 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { | |
| 59 if (('A' <= *it && *it <= 'F') || | |
| 60 ('0' <= *it && *it <= '9')) | |
| 61 continue; | |
| 62 return false; | |
| 63 } | |
| 64 return true; | |
| 65 } | |
| 66 | |
| 53 } // namespace | 67 } // namespace |
| 54 | 68 |
| 55 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, | 69 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, |
| 56 PP_Instance instance, | 70 PP_Instance instance, |
| 57 PP_Resource resource, | 71 PP_Resource resource, |
| 58 PP_FileSystemType type) | 72 PP_FileSystemType type) |
| 59 : ResourceHost(host->GetPpapiHost(), instance, resource), | 73 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 60 renderer_ppapi_host_(host), | 74 renderer_ppapi_host_(host), |
| 61 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 75 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 62 type_(type), | 76 type_(type), |
| 63 opened_(false), | 77 opened_(false), |
| 64 called_open_(false) { | 78 called_open_(false) { |
| 79 ppapi::host::FileSystemRegistry::GetInstance()->Register(pp_instance(), | |
| 80 pp_resource(), | |
| 81 this); | |
| 65 } | 82 } |
| 66 | 83 |
| 67 PepperFileSystemHost::~PepperFileSystemHost() { | 84 PepperFileSystemHost::~PepperFileSystemHost() { |
| 85 ppapi::host::FileSystemRegistry::GetInstance()->Unregister(pp_instance(), | |
| 86 pp_resource()); | |
| 68 } | 87 } |
| 69 | 88 |
| 70 int32_t PepperFileSystemHost::OnResourceMessageReceived( | 89 int32_t PepperFileSystemHost::OnResourceMessageReceived( |
| 71 const IPC::Message& msg, | 90 const IPC::Message& msg, |
| 72 ppapi::host::HostMessageContext* context) { | 91 ppapi::host::HostMessageContext* context) { |
| 73 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) | 92 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) |
| 74 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileSystem_Open, | 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
| 75 OnHostMsgOpen) | 94 PpapiHostMsg_FileSystem_Open, |
| 95 OnHostMsgOpen) | |
| 96 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
| 97 PpapiHostMsg_FileSystem_InitIsolatedFileSystem, | |
| 98 OnHostMsgInitIsolatedFileSystem) | |
| 76 IPC_END_MESSAGE_MAP() | 99 IPC_END_MESSAGE_MAP() |
| 77 return PP_ERROR_FAILED; | 100 return PP_ERROR_FAILED; |
| 78 } | 101 } |
| 79 | 102 |
| 103 PP_FileSystemType PepperFileSystemHost::GetType() const { | |
| 104 return type_; | |
| 105 } | |
| 106 | |
| 107 bool PepperFileSystemHost::IsOpened() const { | |
| 108 return opened_; | |
| 109 } | |
| 110 | |
| 111 const GURL& PepperFileSystemHost::GetRootUrl() const { | |
| 112 return root_url_; | |
| 113 } | |
| 114 | |
| 80 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, | 115 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, |
| 81 const GURL& root) { | 116 const GURL& root) { |
| 82 opened_ = (pp_error == PP_OK); | 117 opened_ = (pp_error == PP_OK); |
| 83 root_url_ = root; | 118 root_url_ = root; |
| 84 reply_context_.params.set_result(pp_error); | 119 reply_context_.params.set_result(pp_error); |
| 85 host()->SendReply(reply_context_, | 120 host()->SendReply(reply_context_, |
| 86 PpapiPluginMsg_FileSystem_OpenReply()); | 121 PpapiPluginMsg_FileSystem_OpenReply()); |
| 87 reply_context_ = ppapi::host::ReplyMessageContext(); | 122 reply_context_ = ppapi::host::ReplyMessageContext(); |
| 88 } | 123 } |
| 89 | 124 |
| 90 int32_t PepperFileSystemHost::OnHostMsgOpen( | 125 int32_t PepperFileSystemHost::OnHostMsgOpen( |
| 91 ppapi::host::HostMessageContext* context, | 126 ppapi::host::HostMessageContext* context, |
| 92 int64_t expected_size) { | 127 int64_t expected_size) { |
| 93 // Not allow multiple opens. | 128 // Not allow multiple opens. |
| 94 if (called_open_) | 129 if (called_open_) |
| 95 return PP_ERROR_INPROGRESS; | 130 return PP_ERROR_INPROGRESS; |
|
yzshen1
2013/05/02 23:22:01
This is a little bit wired. It returns INPROGRESS
| |
| 96 called_open_ = true; | 131 called_open_ = true; |
| 97 | 132 |
| 98 fileapi::FileSystemType file_system_type; | 133 fileapi::FileSystemType file_system_type; |
| 99 switch (type_) { | 134 switch (type_) { |
| 100 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: | 135 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: |
| 101 file_system_type = fileapi::kFileSystemTypeTemporary; | 136 file_system_type = fileapi::kFileSystemTypeTemporary; |
| 102 break; | 137 break; |
| 103 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: | 138 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: |
| 104 file_system_type = fileapi::kFileSystemTypePersistent; | 139 file_system_type = fileapi::kFileSystemTypePersistent; |
| 105 break; | 140 break; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 122 GURL(plugin_instance->container()->element().document().url()). | 157 GURL(plugin_instance->container()->element().document().url()). |
| 123 GetOrigin(), | 158 GetOrigin(), |
| 124 file_system_type, expected_size, true /* create */, | 159 file_system_type, expected_size, true /* create */, |
| 125 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { | 160 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { |
| 126 return PP_ERROR_FAILED; | 161 return PP_ERROR_FAILED; |
| 127 } | 162 } |
| 128 | 163 |
| 129 return PP_OK_COMPLETIONPENDING; | 164 return PP_OK_COMPLETIONPENDING; |
| 130 } | 165 } |
| 131 | 166 |
| 167 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( | |
| 168 ppapi::host::HostMessageContext* context, | |
| 169 const std::string& fsid) { | |
| 170 // sanity check | |
|
yzshen1
2013/05/02 23:22:01
Please use a sentence. (Capital initial and '.' at
victorhsieh
2013/05/03 17:26:58
Done.
| |
| 171 if (!LooksLikeAGuid(fsid)) | |
| 172 return PP_ERROR_BADARGUMENT; | |
| 173 const GURL& url = | |
| 174 renderer_ppapi_host_->GetDocumentURLForInstance(pp_instance()); | |
| 175 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( | |
| 176 url.GetWithEmptyPath(), fsid, "crxfs")); | |
|
yzshen1
2013/05/02 23:22:01
Shall we use url.GetOrigin?
victorhsieh
2013/05/03 17:26:58
Yes, that seems to be a better solution as it elim
| |
| 177 opened_ = true; | |
| 178 return PP_OK; | |
| 179 } | |
| 180 | |
| 132 } // namespace content | 181 } // namespace content |
| OLD | NEW |