Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Side by Side Diff: content/renderer/pepper/pepper_file_system_host.cc

Issue 14188019: CRX FileSystem Pepper private API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 size_t kExpectedFsIdSize = 32;
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) {
65 } 79 }
66 80
67 PepperFileSystemHost::~PepperFileSystemHost() { 81 PepperFileSystemHost::~PepperFileSystemHost() {
68 } 82 }
69 83
70 int32_t PepperFileSystemHost::OnResourceMessageReceived( 84 int32_t PepperFileSystemHost::OnResourceMessageReceived(
71 const IPC::Message& msg, 85 const IPC::Message& msg,
72 ppapi::host::HostMessageContext* context) { 86 ppapi::host::HostMessageContext* context) {
73 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) 87 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg)
74 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileSystem_Open, 88 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
75 OnHostMsgOpen) 89 PpapiHostMsg_FileSystem_Open,
90 OnHostMsgOpen)
91 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
92 PpapiHostMsg_FileSystem_InitIsolatedFileSystem,
93 OnHostMsgInitIsolatedFileSystem)
76 IPC_END_MESSAGE_MAP() 94 IPC_END_MESSAGE_MAP()
77 return PP_ERROR_FAILED; 95 return PP_ERROR_FAILED;
78 } 96 }
79 97
80 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, 98 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error,
81 const GURL& root) { 99 const GURL& root) {
82 opened_ = (pp_error == PP_OK); 100 opened_ = (pp_error == PP_OK);
83 root_url_ = root; 101 root_url_ = root;
84 reply_context_.params.set_result(pp_error); 102 reply_context_.params.set_result(pp_error);
85 host()->SendReply(reply_context_, 103 host()->SendReply(reply_context_,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 GURL(plugin_instance->container()->element().document().url()). 140 GURL(plugin_instance->container()->element().document().url()).
123 GetOrigin(), 141 GetOrigin(),
124 file_system_type, expected_size, true /* create */, 142 file_system_type, expected_size, true /* create */,
125 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { 143 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) {
126 return PP_ERROR_FAILED; 144 return PP_ERROR_FAILED;
127 } 145 }
128 146
129 return PP_OK_COMPLETIONPENDING; 147 return PP_OK_COMPLETIONPENDING;
130 } 148 }
131 149
150 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem(
151 ppapi::host::HostMessageContext* context,
152 const std::string& fsid) {
153 // Do a sanity check.
154 if (!LooksLikeAGuid(fsid))
155 return PP_ERROR_BADARGUMENT;
156 const GURL& url =
157 renderer_ppapi_host_->GetDocumentURLForInstance(pp_instance());
158 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString(
159 url.GetOrigin(), fsid, "crxfs"));
160 opened_ = true;
161 return PP_OK;
162 }
163
132 } // namespace content 164 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698