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 "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.
| |
10 #include "content/common/child_thread.h" | |
11 #include "content/common/fileapi/file_system_dispatcher.h" | |
12 #include "content/public/renderer/renderer_ppapi_host.h" | |
13 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" | |
14 #include "googleurl/src/gurl.h" | |
15 #include "ppapi/c/pp_errors.h" | |
16 #include "ppapi/host/dispatch_host_message.h" | |
17 #include "ppapi/host/ppapi_host.h" | |
18 #include "ppapi/proxy/ppapi_messages.h" | |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | |
23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | |
24 | |
25 namespace content { | |
26 | |
27 namespace { | |
28 | |
29 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { | |
30 public: | |
31 explicit PlatformCallbackAdaptor( | |
32 const base::WeakPtr<PepperFileSystemHost>& weak_host) | |
33 : weak_host_(weak_host) {} | |
yzshen1
2013/04/08 21:05:16
wrong indent.
victorhsieh
2013/04/08 23:44:38
Done.
| |
34 | |
35 virtual ~PlatformCallbackAdaptor() {} | |
36 | |
37 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.
| |
38 const GURL& root) OVERRIDE { | |
39 if (weak_host_) | |
40 weak_host_->OpenFileSystemReply(PP_OK, root.spec()); | |
41 } | |
42 | |
43 virtual void DidFail(int pp_error) OVERRIDE { | |
44 if (weak_host_) | |
45 weak_host_->OpenFileSystemReply(pp_error, ""); | |
46 } | |
47 | |
48 private: | |
49 base::WeakPtr<PepperFileSystemHost> weak_host_; | |
50 }; | |
51 | |
52 } // namespace | |
53 | |
54 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, | |
55 PP_Instance instance, | |
56 PP_Resource resource, | |
57 PP_FileSystemType type) | |
58 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
59 renderer_ppapi_host_(host), | |
60 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
61 type_(type), | |
62 called_open_(false) { | |
yzshen1
2013/04/08 21:05:16
You should init opened_
victorhsieh
2013/04/08 23:44:38
Done.
| |
63 } | |
64 | |
65 PepperFileSystemHost::~PepperFileSystemHost() { | |
66 } | |
67 | |
68 int32_t PepperFileSystemHost::OnResourceMessageReceived( | |
69 const IPC::Message& msg, | |
70 ppapi::host::HostMessageContext* context) { | |
71 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) | |
72 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileSystem_Open, | |
73 OnHostMsgOpen) | |
74 IPC_END_MESSAGE_MAP() | |
75 return PP_ERROR_FAILED; | |
76 } | |
77 | |
78 void PepperFileSystemHost::OpenFileSystemReply(int pp_error, | |
79 const std::string& root) { | |
80 opened_ = (pp_error == PP_OK); | |
81 root_url_ = root; | |
82 reply_context_.params.set_result(pp_error); | |
83 host()->SendReply(reply_context_, | |
yzshen1
2013/04/08 21:05:16
Please reset reply_context_.
victorhsieh
2013/04/08 23:44:38
Done.
| |
84 PpapiPluginMsg_FileSystem_OpenReply(root_url_)); | |
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 |