OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/pepper/pepper_file_system_host.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/callback.h" | |
9 #include "content/common/child_thread.h" | |
10 #include "content/common/fileapi/file_system_dispatcher.h" | |
11 #include "content/public/renderer/renderer_ppapi_host.h" | |
12 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" | |
13 #include "ppapi/c/pp_errors.h" | |
14 #include "ppapi/host/dispatch_host_message.h" | |
15 #include "ppapi/host/ppapi_host.h" | |
16 #include "ppapi/proxy/ppapi_messages.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | |
21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
22 | |
23 namespace content { | |
24 | |
25 namespace { | |
26 | |
27 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { | |
28 public: | |
29 explicit PlatformCallbackAdaptor( | |
30 const base::WeakPtr<PepperFileSystemHost>& weak_host) | |
31 : weak_host_(weak_host) {} | |
32 | |
33 virtual ~PlatformCallbackAdaptor() {} | |
34 | |
35 virtual void DidOpenFileSystem(const std::string& /* unused */, | |
36 const GURL& root) OVERRIDE { | |
37 if (weak_host_) | |
38 weak_host_->OpenFileSystemReply(PP_OK, root); | |
39 } | |
40 | |
41 virtual void DidFail(int32_t pp_error) OVERRIDE { | |
yzshen1
2013/04/09 17:25:42
Please see my comment about DidFail() elsewhere.
victorhsieh
2013/04/09 18:02:45
Done.
| |
42 if (weak_host_) | |
43 weak_host_->OpenFileSystemReply(pp_error, GURL()); | |
44 } | |
45 | |
46 private: | |
47 base::WeakPtr<PepperFileSystemHost> weak_host_; | |
48 }; | |
49 | |
50 } // namespace | |
51 | |
52 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, | |
53 PP_Instance instance, | |
54 PP_Resource resource, | |
55 PP_FileSystemType type) | |
56 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
57 renderer_ppapi_host_(host), | |
58 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
59 type_(type), | |
60 opened_(false), | |
61 called_open_(false) { | |
62 } | |
63 | |
64 PepperFileSystemHost::~PepperFileSystemHost() { | |
65 } | |
66 | |
67 int32_t PepperFileSystemHost::OnResourceMessageReceived( | |
68 const IPC::Message& msg, | |
69 ppapi::host::HostMessageContext* context) { | |
70 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) | |
71 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileSystem_Open, | |
72 OnHostMsgOpen) | |
73 IPC_END_MESSAGE_MAP() | |
74 return PP_ERROR_FAILED; | |
75 } | |
76 | |
77 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, | |
78 const GURL& root) { | |
79 opened_ = (pp_error == PP_OK); | |
80 root_url_ = root; | |
81 reply_context_.params.set_result(pp_error); | |
82 host()->SendReply(reply_context_, | |
83 PpapiPluginMsg_FileSystem_OpenReply(root_url_.spec())); | |
84 reply_context_ = ppapi::host::ReplyMessageContext(); | |
85 } | |
86 | |
87 int32_t PepperFileSystemHost::OnHostMsgOpen( | |
88 ppapi::host::HostMessageContext* context, | |
89 int64_t expected_size) { | |
90 // Not allow multiple opens. | |
91 if (called_open_) | |
92 return PP_ERROR_INPROGRESS; | |
93 called_open_ = true; | |
94 | |
95 fileapi::FileSystemType file_system_type; | |
96 switch (type_) { | |
97 case PP_FILESYSTEMTYPE_LOCALTEMPORARY: | |
98 file_system_type = fileapi::kFileSystemTypeTemporary; | |
99 break; | |
100 case PP_FILESYSTEMTYPE_LOCALPERSISTENT: | |
101 file_system_type = fileapi::kFileSystemTypePersistent; | |
102 break; | |
103 case PP_FILESYSTEMTYPE_EXTERNAL: | |
104 file_system_type = fileapi::kFileSystemTypeExternal; | |
105 break; | |
106 default: | |
107 return PP_ERROR_FAILED; | |
108 } | |
109 | |
110 webkit::ppapi::PluginInstance* plugin_instance = | |
111 renderer_ppapi_host_->GetPluginInstance(pp_instance()); | |
112 if (!plugin_instance) | |
113 return PP_ERROR_FAILED; | |
114 | |
115 FileSystemDispatcher* file_system_dispatcher = | |
116 ChildThread::current()->file_system_dispatcher(); | |
117 reply_context_ = context->MakeReplyMessageContext(); | |
118 if (!file_system_dispatcher->OpenFileSystem( | |
119 GURL(plugin_instance->container()->element().document().url()). | |
120 GetOrigin(), | |
121 file_system_type, expected_size, true /* create */, | |
122 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { | |
123 return PP_ERROR_FAILED; | |
124 } | |
125 | |
126 return PP_OK_COMPLETIONPENDING; | |
127 } | |
128 | |
129 } // namespace content | |
OLD | NEW |