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

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/render_view.h"
11 #include "content/public/renderer/renderer_ppapi_host.h" 12 #include "content/public/renderer/renderer_ppapi_host.h"
12 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h" 13 #include "content/renderer/pepper/null_file_system_callback_dispatcher.h"
13 #include "ppapi/c/pp_errors.h" 14 #include "ppapi/c/pp_errors.h"
14 #include "ppapi/host/dispatch_host_message.h" 15 #include "ppapi/host/dispatch_host_message.h"
15 #include "ppapi/host/ppapi_host.h" 16 #include "ppapi/host/ppapi_host.h"
16 #include "ppapi/proxy/ppapi_messages.h" 17 #include "ppapi/proxy/ppapi_messages.h"
17 #include "ppapi/shared_impl/file_type_conversion.h" 18 #include "ppapi/shared_impl/file_type_conversion.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
24 #include "webkit/fileapi/file_system_util.h"
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 25 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
23 26
24 namespace content { 27 namespace content {
25 28
26 namespace { 29 namespace {
27 30
28 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher { 31 class PlatformCallbackAdaptor : public NullFileSystemCallbackDispatcher {
29 public: 32 public:
30 explicit PlatformCallbackAdaptor( 33 explicit PlatformCallbackAdaptor(
31 const base::WeakPtr<PepperFileSystemHost>& weak_host) 34 const base::WeakPtr<PepperFileSystemHost>& weak_host)
(...skipping 11 matching lines...) Expand all
43 if (weak_host_) { 46 if (weak_host_) {
44 weak_host_->OpenFileSystemReply( 47 weak_host_->OpenFileSystemReply(
45 ppapi::PlatformFileErrorToPepperError(platform_error), GURL()); 48 ppapi::PlatformFileErrorToPepperError(platform_error), GURL());
46 } 49 }
47 } 50 }
48 51
49 private: 52 private:
50 base::WeakPtr<PepperFileSystemHost> weak_host_; 53 base::WeakPtr<PepperFileSystemHost> weak_host_;
51 }; 54 };
52 55
56 bool LooksLikeAGuid(const std::string& fsid) {
57 const size_t kExpectedFsIdSize = 32;
58 if (fsid.size() != kExpectedFsIdSize)
59 return false;
60 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) {
61 if (('A' <= *it && *it <= 'F') ||
62 ('0' <= *it && *it <= '9'))
63 continue;
64 return false;
65 }
66 return true;
67 }
68
53 } // namespace 69 } // namespace
54 70
55 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host, 71 PepperFileSystemHost::PepperFileSystemHost(RendererPpapiHost* host,
56 PP_Instance instance, 72 PP_Instance instance,
57 PP_Resource resource, 73 PP_Resource resource,
58 PP_FileSystemType type) 74 PP_FileSystemType type)
59 : ResourceHost(host->GetPpapiHost(), instance, resource), 75 : ResourceHost(host->GetPpapiHost(), instance, resource),
60 renderer_ppapi_host_(host), 76 renderer_ppapi_host_(host),
61 weak_factory_(this), 77 weak_factory_(this),
62 type_(type), 78 type_(type),
63 opened_(false), 79 opened_(false),
64 called_open_(false) { 80 called_open_(false) {
65 } 81 }
66 82
67 PepperFileSystemHost::~PepperFileSystemHost() { 83 PepperFileSystemHost::~PepperFileSystemHost() {
68 } 84 }
69 85
70 int32_t PepperFileSystemHost::OnResourceMessageReceived( 86 int32_t PepperFileSystemHost::OnResourceMessageReceived(
71 const IPC::Message& msg, 87 const IPC::Message& msg,
72 ppapi::host::HostMessageContext* context) { 88 ppapi::host::HostMessageContext* context) {
73 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg) 89 IPC_BEGIN_MESSAGE_MAP(PepperFileSystemHost, msg)
74 PPAPI_DISPATCH_HOST_RESOURCE_CALL(PpapiHostMsg_FileSystem_Open, 90 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
75 OnHostMsgOpen) 91 PpapiHostMsg_FileSystem_Open,
92 OnHostMsgOpen)
93 PPAPI_DISPATCH_HOST_RESOURCE_CALL(
94 PpapiHostMsg_FileSystem_InitIsolatedFileSystem,
95 OnHostMsgInitIsolatedFileSystem)
76 IPC_END_MESSAGE_MAP() 96 IPC_END_MESSAGE_MAP()
77 return PP_ERROR_FAILED; 97 return PP_ERROR_FAILED;
78 } 98 }
79 99
80 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error, 100 void PepperFileSystemHost::OpenFileSystemReply(int32_t pp_error,
81 const GURL& root) { 101 const GURL& root) {
82 opened_ = (pp_error == PP_OK); 102 opened_ = (pp_error == PP_OK);
83 root_url_ = root; 103 root_url_ = root;
84 reply_context_.params.set_result(pp_error); 104 reply_context_.params.set_result(pp_error);
85 host()->SendReply(reply_context_, 105 host()->SendReply(reply_context_,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 GURL(plugin_instance->container()->element().document().url()). 142 GURL(plugin_instance->container()->element().document().url()).
123 GetOrigin(), 143 GetOrigin(),
124 file_system_type, expected_size, true /* create */, 144 file_system_type, expected_size, true /* create */,
125 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) { 145 new PlatformCallbackAdaptor(weak_factory_.GetWeakPtr()))) {
126 return PP_ERROR_FAILED; 146 return PP_ERROR_FAILED;
127 } 147 }
128 148
129 return PP_OK_COMPLETIONPENDING; 149 return PP_OK_COMPLETIONPENDING;
130 } 150 }
131 151
152 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem(
153 ppapi::host::HostMessageContext* context,
154 const std::string& fsid) {
155 // Do a sanity check.
156 if (!LooksLikeAGuid(fsid))
157 return PP_ERROR_BADARGUMENT;
158 RenderView* view =
159 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance());
160 if (!view)
161 return PP_ERROR_FAILED;
162 const GURL& url = view->GetWebView()->mainFrame()->document().url();
163 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString(
164 url.GetOrigin(), fsid, "crxfs"));
165 opened_ = true;
166 return PP_OK;
167 }
168
132 } // namespace content 169 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_file_system_host.h ('k') | content/renderer/pepper/pepper_in_process_resource_creation.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698