Index: content/renderer/pepper/pepper_file_system_host.cc |
diff --git a/content/renderer/pepper/pepper_file_system_host.cc b/content/renderer/pepper/pepper_file_system_host.cc |
index 58e7f2c728106111ecc2d09da5908be0503a05be..39a7f138e063d93d6550002b5b9fc25f135864a7 100644 |
--- a/content/renderer/pepper/pepper_file_system_host.cc |
+++ b/content/renderer/pepper/pepper_file_system_host.cc |
@@ -19,6 +19,7 @@ |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
#include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
+#include "webkit/fileapi/file_system_util.h" |
#include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
namespace content { |
@@ -50,6 +51,19 @@ class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { |
base::WeakPtr<PepperFileSystemHost> weak_host_; |
}; |
+bool LooksLikeAGuid(const std::string& fsid) { |
+ const int kExpectedFsIdSize = 32; |
palmer
2013/05/02 21:30:09
std::string::size returns std::string::size_type,
victorhsieh
2013/05/03 17:26:58
Done.
|
+ if (fsid.size() != kExpectedFsIdSize) |
+ return false; |
+ for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { |
+ if (('A' <= *it && *it <= 'F') || |
+ ('0' <= *it && *it <= '9')) |
+ continue; |
+ return false; |
+ } |
+ return true; |
+} |
+ |
} // namespace |
PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, |
@@ -62,21 +76,42 @@ PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, |
type_(type), |
opened_(false), |
called_open_(false) { |
+ ppapi::host::FileSystemRegistry::GetInstance()->Register(pp_instance(), |
+ pp_resource(), |
+ this); |
} |
PepperFileSystemHost::~PepperFileSystemHost() { |
+ ppapi::host::FileSystemRegistry::GetInstance()->Unregister(pp_instance(), |
+ pp_resource()); |
} |
int32_t PepperFileSystemHost::OnResourceMessageReceived( |
const IPC::Message& msg, |
ppapi::host::HostMessageContext* context) { |
IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) |
- PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileSystem_Open, |
- OnHostMsgOpen) |
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
+ PpapiHostMsg_FileSystem_Open, |
+ OnHostMsgOpen) |
+ PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
+ PpapiHostMsg_FileSystem_InitIsolatedFileSystem, |
+ OnHostMsgInitIsolatedFileSystem) |
IPC_END_MESSAGE_MAP() |
return PP_ERROR_FAILED; |
} |
+PP_FileSystemType PepperFileSystemHost::GetType() const { |
+ return type_; |
+} |
+ |
+bool PepperFileSystemHost::IsOpened() const { |
+ return opened_; |
+} |
+ |
+const GURL& PepperFileSystemHost::GetRootUrl() const { |
+ return root_url_; |
+} |
+ |
void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, |
const GURL& root) { |
opened_ = (pp_error == PP_OK); |
@@ -129,4 +164,18 @@ int32_t PepperFileSystemHost::OnHostMsgOpen( |
return PP_OK_COMPLETIONPENDING; |
} |
+int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( |
+ ppapi::host::HostMessageContext* context, |
+ const std::string& fsid) { |
+ // sanity check |
+ if (!LooksLikeAGuid(fsid)) |
+ return PP_ERROR_BADARGUMENT; |
+ const GURL& url = |
+ renderer_ppapi_host_->GetDocumentURLForInstance(pp_instance()); |
+ root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( |
+ url.GetWithEmptyPath(), fsid, "crxfs")); |
+ opened_ = true; |
+ return PP_OK; |
+} |
+ |
} // namespace content |