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/renderer_ppapi_host.h" | 11 #include "content/public/renderer/renderer_ppapi_host.h" |
12 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" | 12 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" |
13 #include "ppapi/c/pp_errors.h" | 13 #include "ppapi/c/pp_errors.h" |
14 #include "ppapi/host/dispatch_host_message.h" | 14 #include "ppapi/host/dispatch_host_message.h" |
15 #include "ppapi/host/ppapi_host.h" | 15 #include "ppapi/host/ppapi_host.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
17 #include "ppapi/shared_impl/file_type_conversion.h" | 17 #include "ppapi/shared_impl/file_type_conversion.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
22 #include "webkit/fileapi/file_system_util.h" | |
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 | 26 |
26 namespace { | 27 namespace { |
27 | 28 |
28 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { | 29 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { |
29 public: | 30 public: |
30 explicit PlatformCallbackAdaptor( | 31 explicit PlatformCallbackAdaptor( |
31 const base::WeakPtr<PepperFileSystemHost>& weak_host) | 32 const base::WeakPtr<PepperFileSystemHost>& weak_host) |
(...skipping 11 matching lines...) Expand all Loading... | |
43 if (weak_host_) { | 44 if (weak_host_) { |
44 weak_host_->OpenFileSystemReply( | 45 weak_host_->OpenFileSystemReply( |
45 ppapi::PlatformFileErrorToPepperError(platform_error), GURL()); | 46 ppapi::PlatformFileErrorToPepperError(platform_error), GURL()); |
46 } | 47 } |
47 } | 48 } |
48 | 49 |
49 private: | 50 private: |
50 base::WeakPtr<PepperFileSystemHost> weak_host_; | 51 base::WeakPtr<PepperFileSystemHost> weak_host_; |
51 }; | 52 }; |
52 | 53 |
54 bool LooksLikeAGuid(const std::string& fsid) { | |
55 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.
| |
56 if (fsid.size() != kExpectedFsIdSize) | |
57 return false; | |
58 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { | |
59 if (('A' <= *it && *it <= 'F') || | |
60 ('0' <= *it && *it <= '9')) | |
61 continue; | |
62 return false; | |
63 } | |
64 return true; | |
65 } | |
66 | |
53 } // namespace | 67 } // namespace |
54 | 68 |
55 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, | 69 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, |
56 PP_Instance instance, | 70 PP_Instance instance, |
57 PP_Resource resource, | 71 PP_Resource resource, |
58 PP_FileSystemType type) | 72 PP_FileSystemType type) |
59 : ResourceHost(host->GetPpapiHost(), instance, resource), | 73 : ResourceHost(host->GetPpapiHost(), instance, resource), |
60 renderer_ppapi_host_(host), | 74 renderer_ppapi_host_(host), |
61 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 75 weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
62 type_(type), | 76 type_(type), |
63 opened_(false), | 77 opened_(false), |
64 called_open_(false) { | 78 called_open_(false) { |
79 ppapi::host::FileSystemRegistry::GetInstance()->Register(pp_instance(), | |
80 pp_resource(), | |
81 this); | |
65 } | 82 } |
66 | 83 |
67 PepperFileSystemHost::~PepperFileSystemHost() { | 84 PepperFileSystemHost::~PepperFileSystemHost() { |
85 ppapi::host::FileSystemRegistry::GetInstance()->Unregister(pp_instance(), | |
86 pp_resource()); | |
68 } | 87 } |
69 | 88 |
70 int32_t PepperFileSystemHost::OnResourceMessageReceived( | 89 int32_t PepperFileSystemHost::OnResourceMessageReceived( |
71 const IPC::Message& msg, | 90 const IPC::Message& msg, |
72 ppapi::host::HostMessageContext* context) { | 91 ppapi::host::HostMessageContext* context) { |
73 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) | 92 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) |
74 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileSystem_Open, | 93 PPAPI_DISPATCH_HOST_RESOURCE_CALL( |
75 OnHostMsgOpen) | 94 PpapiHostMsg_FileSystem_Open, |
95 OnHostMsgOpen) | |
96 PPAPI_DISPATCH_HOST_RESOURCE_CALL( | |
97 PpapiHostMsg_FileSystem_InitIsolatedFileSystem, | |
98 OnHostMsgInitIsolatedFileSystem) | |
76 IPC_END_MESSAGE_MAP() | 99 IPC_END_MESSAGE_MAP() |
77 return PP_ERROR_FAILED; | 100 return PP_ERROR_FAILED; |
78 } | 101 } |
79 | 102 |
103 PP_FileSystemType PepperFileSystemHost::GetType() const { | |
104 return type_; | |
105 } | |
106 | |
107 bool PepperFileSystemHost::IsOpened() const { | |
108 return opened_; | |
109 } | |
110 | |
111 const GURL& PepperFileSystemHost::GetRootUrl() const { | |
112 return root_url_; | |
113 } | |
114 | |
80 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, | 115 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, |
81 const GURL& root) { | 116 const GURL& root) { |
82 opened_ = (pp_error == PP_OK); | 117 opened_ = (pp_error == PP_OK); |
83 root_url_ = root; | 118 root_url_ = root; |
84 reply_context_.params.set_result(pp_error); | 119 reply_context_.params.set_result(pp_error); |
85 host()->SendReply(reply_context_, | 120 host()->SendReply(reply_context_, |
86 PpapiPluginMsg_FileSystem_OpenReply()); | 121 PpapiPluginMsg_FileSystem_OpenReply()); |
87 reply_context_ = ppapi::host::ReplyMessageContext(); | 122 reply_context_ = ppapi::host::ReplyMessageContext(); |
88 } | 123 } |
89 | 124 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 GURL(plugin_instance->container()->element().document().url()). | 157 GURL(plugin_instance->container()->element().document().url()). |
123 GetOrigin(), | 158 GetOrigin(), |
124 file_system_type, expected_size, true /* create */, | 159 file_system_type, expected_size, true /* create */, |
125 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { | 160 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { |
126 return PP_ERROR_FAILED; | 161 return PP_ERROR_FAILED; |
127 } | 162 } |
128 | 163 |
129 return PP_OK_COMPLETIONPENDING; | 164 return PP_OK_COMPLETIONPENDING; |
130 } | 165 } |
131 | 166 |
167 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( | |
168 ppapi::host::HostMessageContext* context, | |
169 const std::string& fsid) { | |
170 // sanity check | |
171 if (!LooksLikeAGuid(fsid)) | |
172 return PP_ERROR_BADARGUMENT; | |
173 const GURL& url = | |
174 renderer_ppapi_host_->GetDocumentURLForInstance(pp_instance()); | |
175 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( | |
176 url.GetWithEmptyPath(), fsid, "crxfs")); | |
177 opened_ = true; | |
178 return PP_OK; | |
179 } | |
180 | |
132 } // namespace content | 181 } // namespace content |
OLD | NEW |