| 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/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 12 #include "content/public/renderer/renderer_ppapi_host.h" | 12 #include "content/public/renderer/renderer_ppapi_host.h" |
| 13 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" | |
| 14 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
| 15 #include "ppapi/host/dispatch_host_message.h" | 14 #include "ppapi/host/dispatch_host_message.h" |
| 16 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
| 17 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
| 18 #include "ppapi/shared_impl/file_type_conversion.h" | 17 #include "ppapi/shared_impl/file_type_conversion.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 24 #include "webkit/fileapi/file_system_util.h" | 23 #include "webkit/fileapi/file_system_util.h" |
| 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 26 | 25 |
| 27 namespace content { | 26 namespace content { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 31 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { | |
| 32 public: | |
| 33 explicit PlatformCallbackAdaptor( | |
| 34 const base::WeakPtr<PepperFileSystemHost>& weak_host) | |
| 35 : weak_host_(weak_host) {} | |
| 36 | |
| 37 virtual ~PlatformCallbackAdaptor() {} | |
| 38 | |
| 39 virtual void DidOpenFileSystem(const std::string& /* unused */, | |
| 40 const GURL& root) OVERRIDE { | |
| 41 if (weak_host_) | |
| 42 weak_host_->OpenFileSystemReply(PP_OK, root); | |
| 43 } | |
| 44 | |
| 45 virtual void DidFail(base::PlatformFileError platform_error) OVERRIDE { | |
| 46 if (weak_host_) { | |
| 47 weak_host_->OpenFileSystemReply( | |
| 48 ppapi::PlatformFileErrorToPepperError(platform_error), GURL()); | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 private: | |
| 53 base::WeakPtr<PepperFileSystemHost> weak_host_; | |
| 54 }; | |
| 55 | |
| 56 bool LooksLikeAGuid(const std::string& fsid) { | 30 bool LooksLikeAGuid(const std::string& fsid) { |
| 57 const size_t kExpectedFsIdSize = 32; | 31 const size_t kExpectedFsIdSize = 32; |
| 58 if (fsid.size() != kExpectedFsIdSize) | 32 if (fsid.size() != kExpectedFsIdSize) |
| 59 return false; | 33 return false; |
| 60 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { | 34 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { |
| 61 if (('A' <= *it && *it <= 'F') || | 35 if (('A' <= *it && *it <= 'F') || |
| 62 ('0' <= *it && *it <= '9')) | 36 ('0' <= *it && *it <= '9')) |
| 63 continue; | 37 continue; |
| 64 return false; | 38 return false; |
| 65 } | 39 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 90 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 64 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
| 91 PpapiHostMsg_FileSystem_Open, | 65 PpapiHostMsg_FileSystem_Open, |
| 92 OnHostMsgOpen) | 66 OnHostMsgOpen) |
| 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | 67 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
| 94 PpapiHostMsg_FileSystem_InitIsolatedFileSystem, | 68 PpapiHostMsg_FileSystem_InitIsolatedFileSystem, |
| 95 OnHostMsgInitIsolatedFileSystem) | 69 OnHostMsgInitIsolatedFileSystem) |
| 96 IPC_END_MESSAGE_MAP() | 70 IPC_END_MESSAGE_MAP() |
| 97 return PP_ERROR_FAILED; | 71 return PP_ERROR_FAILED; |
| 98 } | 72 } |
| 99 | 73 |
| 100 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, | 74 void PepperFileSystemHost::DidOpenFileSystem( |
| 101 const GURL& root) { | 75 const std::string& /* name_unused */, |
| 102 opened_ = (pp_error == PP_OK); | 76 const GURL& root) { |
| 77 opened_ = true; |
| 103 root_url_ = root; | 78 root_url_ = root; |
| 104 reply_context_.params.set_result(pp_error); | 79 reply_context_.params.set_result(PP_OK); |
| 105 host()->SendReply(reply_context_, | 80 host()->SendReply(reply_context_, PpapiPluginMsg_FileSystem_OpenReply()); |
| 106 PpapiPluginMsg_FileSystem_OpenReply()); | |
| 107 reply_context_ = ppapi::host::ReplyMessageContext(); | 81 reply_context_ = ppapi::host::ReplyMessageContext(); |
| 108 } | 82 } |
| 109 | 83 |
| 84 void PepperFileSystemHost::DidFailOpenFileSystem( |
| 85 base::PlatformFileError error) { |
| 86 int32 pp_error = ppapi::PlatformFileErrorToPepperError(error); |
| 87 opened_ = (pp_error == PP_OK); |
| 88 reply_context_.params.set_result(pp_error); |
| 89 host()->SendReply(reply_context_, PpapiPluginMsg_FileSystem_OpenReply()); |
| 90 reply_context_ = ppapi::host::ReplyMessageContext(); |
| 91 } |
| 92 |
| 110 int32_t PepperFileSystemHost::OnHostMsgOpen( | 93 int32_t PepperFileSystemHost::OnHostMsgOpen( |
| 111 ppapi::host::HostMessageContext* context, | 94 ppapi::host::HostMessageContext* context, |
| 112 int64_t expected_size) { | 95 int64_t expected_size) { |
| 113 // Not allow multiple opens. | 96 // Not allow multiple opens. |
| 114 if (called_open_) | 97 if (called_open_) |
| 115 return PP_ERROR_INPROGRESS; | 98 return PP_ERROR_INPROGRESS; |
| 116 called_open_ = true; | 99 called_open_ = true; |
| 117 | 100 |
| 118 fileapi::FileSystemType file_system_type; | 101 fileapi::FileSystemType file_system_type; |
| 119 switch (type_) { | 102 switch (type_) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 135 if (!plugin_instance) | 118 if (!plugin_instance) |
| 136 return PP_ERROR_FAILED; | 119 return PP_ERROR_FAILED; |
| 137 | 120 |
| 138 FileSystemDispatcher* file_system_dispatcher = | 121 FileSystemDispatcher* file_system_dispatcher = |
| 139 ChildThread::current()->file_system_dispatcher(); | 122 ChildThread::current()->file_system_dispatcher(); |
| 140 reply_context_ = context->MakeReplyMessageContext(); | 123 reply_context_ = context->MakeReplyMessageContext(); |
| 141 if (!file_system_dispatcher->OpenFileSystem( | 124 if (!file_system_dispatcher->OpenFileSystem( |
| 142 GURL(plugin_instance->container()->element().document().url()). | 125 GURL(plugin_instance->container()->element().document().url()). |
| 143 GetOrigin(), | 126 GetOrigin(), |
| 144 file_system_type, expected_size, true /* create */, | 127 file_system_type, expected_size, true /* create */, |
| 145 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { | 128 base::Bind(&PepperFileSystemHost::DidOpenFileSystem, |
| 129 weak_factory_.GetWeakPtr()), |
| 130 base::Bind(&PepperFileSystemHost::DidFailOpenFileSystem, |
| 131 weak_factory_.GetWeakPtr()))) { |
| 146 return PP_ERROR_FAILED; | 132 return PP_ERROR_FAILED; |
| 147 } | 133 } |
| 148 | 134 |
| 149 return PP_OK_COMPLETIONPENDING; | 135 return PP_OK_COMPLETIONPENDING; |
| 150 } | 136 } |
| 151 | 137 |
| 152 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( | 138 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( |
| 153 ppapi::host::HostMessageContext* context, | 139 ppapi::host::HostMessageContext* context, |
| 154 const std::string& fsid) { | 140 const std::string& fsid) { |
| 155 // Do a sanity check. | 141 // Do a sanity check. |
| 156 if (!LooksLikeAGuid(fsid)) | 142 if (!LooksLikeAGuid(fsid)) |
| 157 return PP_ERROR_BADARGUMENT; | 143 return PP_ERROR_BADARGUMENT; |
| 158 RenderView* view = | 144 RenderView* view = |
| 159 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()); | 145 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()); |
| 160 if (!view) | 146 if (!view) |
| 161 return PP_ERROR_FAILED; | 147 return PP_ERROR_FAILED; |
| 162 const GURL& url = view->GetWebView()->mainFrame()->document().url(); | 148 const GURL& url = view->GetWebView()->mainFrame()->document().url(); |
| 163 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( | 149 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( |
| 164 url.GetOrigin(), fsid, "crxfs")); | 150 url.GetOrigin(), fsid, "crxfs")); |
| 165 opened_ = true; | 151 opened_ = true; |
| 166 return PP_OK; | 152 return PP_OK; |
| 167 } | 153 } |
| 168 | 154 |
| 169 } // namespace content | 155 } // namespace content |
| OLD | NEW |