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 |
new file mode 100644 |
index 0000000000000000000000000000000000000000..4f5d208fe464eb3a2f0133d5c270313538d65c97 |
--- /dev/null |
+++ b/content/renderer/pepper/pepper_file_system_host.cc |
@@ -0,0 +1,129 @@ |
+// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "content/renderer/pepper/pepper_file_system_host.h" |
+ |
+#include "base/bind.h" |
+#include "base/callback.h" |
+#include "base/memory/weak_ptr.h" |
yzshen1
2013/04/08 21:05:16
You already include it in the .h file (and line 14
victorhsieh
2013/04/08 23:44:38
Done.
|
+#include "content/common/child_thread.h" |
+#include "content/common/fileapi/file_system_dispatcher.h" |
+#include "content/public/renderer/renderer_ppapi_host.h" |
+#include "content/renderer/pepper/null_file_system_callback_dispatcher.h" |
+#include "googleurl/src/gurl.h" |
+#include "ppapi/c/pp_errors.h" |
+#include "ppapi/host/dispatch_host_message.h" |
+#include "ppapi/host/ppapi_host.h" |
+#include "ppapi/proxy/ppapi_messages.h" |
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
+#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/plugins/ppapi/ppapi_plugin_instance.h" |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { |
+ public: |
+ explicit PlatformCallbackAdaptor( |
+ const base::WeakPtr<PepperFileSystemHost>& weak_host) |
+ : weak_host_(weak_host) {} |
yzshen1
2013/04/08 21:05:16
wrong indent.
victorhsieh
2013/04/08 23:44:38
Done.
|
+ |
+ virtual ~PlatformCallbackAdaptor() {} |
+ |
+ virtual void DidOpenFileSystem(const std::string& name_unused, |
yzshen1
2013/04/08 21:05:16
Please use /* */ around unused parameters otherwis
victorhsieh
2013/04/08 23:44:38
Done.
|
+ const GURL& root) OVERRIDE { |
+ if (weak_host_) |
+ weak_host_->OpenFileSystemReply(PP_OK, root.spec()); |
+ } |
+ |
+ virtual void DidFail(int pp_error) OVERRIDE { |
+ if (weak_host_) |
+ weak_host_->OpenFileSystemReply(pp_error, ""); |
+ } |
+ |
+ private: |
+ base::WeakPtr<PepperFileSystemHost> weak_host_; |
+}; |
+ |
+} // namespace |
+ |
+PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, |
+ PP_Instance instance, |
+ PP_Resource resource, |
+ PP_FileSystemType type) |
+ : ResourceHost(host->GetPpapiHost(), instance, resource), |
+ renderer_ppapi_host_(host), |
+ weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
+ type_(type), |
+ called_open_(false) { |
yzshen1
2013/04/08 21:05:16
You should init opened_
victorhsieh
2013/04/08 23:44:38
Done.
|
+} |
+ |
+PepperFileSystemHost::~PepperFileSystemHost() { |
+} |
+ |
+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) |
+ IPC_END_MESSAGE_MAP() |
+ return PP_ERROR_FAILED; |
+} |
+ |
+void PepperFileSystemHost::OpenFileSystemReply(int pp_error, |
+ const std::string& root) { |
+ opened_ = (pp_error == PP_OK); |
+ root_url_ = root; |
+ reply_context_.params.set_result(pp_error); |
+ host()->SendReply(reply_context_, |
yzshen1
2013/04/08 21:05:16
Please reset reply_context_.
victorhsieh
2013/04/08 23:44:38
Done.
|
+ PpapiPluginMsg_FileSystem_OpenReply(root_url_)); |
+} |
+ |
+int32_t PepperFileSystemHost::OnHostMsgOpen( |
+ ppapi::host::HostMessageContext* context, |
+ int64_t expected_size) { |
+ // Not allow multiple opens. |
+ if (called_open_) |
+ return PP_ERROR_INPROGRESS; |
+ called_open_ = true; |
+ |
+ fileapi::FileSystemType file_system_type; |
+ switch (type_) { |
+ case PP_FILESYSTEMTYPE_LOCALTEMPORARY: |
+ file_system_type = fileapi::kFileSystemTypeTemporary; |
+ break; |
+ case PP_FILESYSTEMTYPE_LOCALPERSISTENT: |
+ file_system_type = fileapi::kFileSystemTypePersistent; |
+ break; |
+ case PP_FILESYSTEMTYPE_EXTERNAL: |
+ file_system_type = fileapi::kFileSystemTypeExternal; |
+ break; |
+ default: |
+ return PP_ERROR_FAILED; |
+ } |
+ |
+ webkit::ppapi::PluginInstance* plugin_instance = |
+ renderer_ppapi_host_->GetPluginInstance(pp_instance()); |
+ if (!plugin_instance) |
+ return PP_ERROR_FAILED; |
+ |
+ FileSystemDispatcher* file_system_dispatcher = |
+ ChildThread::current()->file_system_dispatcher(); |
+ reply_context_ = context->MakeReplyMessageContext(); |
+ if (!file_system_dispatcher->OpenFileSystem( |
+ GURL(plugin_instance->container()->element().document().url()). |
+ GetOrigin(), |
+ file_system_type, expected_size, true /* create */, |
+ new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { |
+ return PP_ERROR_FAILED; |
+ } |
+ |
+ return PP_OK_COMPLETIONPENDING; |
+} |
+ |
+} // namespace content |