| 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/child/child_thread.h" | 9 #include "content/child/child_thread.h" |
| 10 #include "content/child/fileapi/file_system_dispatcher.h" | 10 #include "content/child/fileapi/file_system_dispatcher.h" |
| 11 #include "content/public/renderer/render_view.h" | 11 #include "content/public/renderer/render_view.h" |
| 12 #include "content/public/renderer/renderer_ppapi_host.h" | 12 #include "content/public/renderer/renderer_ppapi_host.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/public/web/WebDocument.h" | 18 #include "third_party/WebKit/public/web/WebDocument.h" |
| 19 #include "third_party/WebKit/public/web/WebElement.h" | 19 #include "third_party/WebKit/public/web/WebElement.h" |
| 20 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
| 21 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 21 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
| 22 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
| 23 #include "webkit/common/fileapi/file_system_util.h" | 23 #include "webkit/common/fileapi/file_system_util.h" |
| 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 24 #include "webkit/plugins/ppapi/ppapi_plugin_instance_impl.h" |
| 25 | 25 |
| 26 namespace content { | 26 namespace content { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 bool LooksLikeAGuid(const std::string& fsid) { | 30 bool LooksLikeAGuid(const std::string& fsid) { |
| 31 const size_t kExpectedFsIdSize = 32; | 31 const size_t kExpectedFsIdSize = 32; |
| 32 if (fsid.size() != kExpectedFsIdSize) | 32 if (fsid.size() != kExpectedFsIdSize) |
| 33 return false; | 33 return false; |
| 34 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { | 34 for (std::string::const_iterator it = fsid.begin(); it != fsid.end(); ++it) { |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 webkit::ppapi::PluginInstance* plugin_instance = | 120 webkit::ppapi::PluginInstance* plugin_instance = |
| 121 renderer_ppapi_host_->GetPluginInstance(pp_instance()); | 121 renderer_ppapi_host_->GetPluginInstance(pp_instance()); |
| 122 if (!plugin_instance) | 122 if (!plugin_instance) |
| 123 return PP_ERROR_FAILED; | 123 return PP_ERROR_FAILED; |
| 124 | 124 |
| 125 FileSystemDispatcher* file_system_dispatcher = | 125 FileSystemDispatcher* file_system_dispatcher = |
| 126 ChildThread::current()->file_system_dispatcher(); | 126 ChildThread::current()->file_system_dispatcher(); |
| 127 reply_context_ = context->MakeReplyMessageContext(); | 127 reply_context_ = context->MakeReplyMessageContext(); |
| 128 file_system_dispatcher->OpenFileSystem( | 128 file_system_dispatcher->OpenFileSystem( |
| 129 GURL(plugin_instance->container()->element().document().url()). | 129 GURL(plugin_instance->GetContainer()->element().document().url()). |
| 130 GetOrigin(), | 130 GetOrigin(), |
| 131 file_system_type, expected_size, true /* create */, | 131 file_system_type, expected_size, true /* create */, |
| 132 base::Bind(&PepperFileSystemHost::DidOpenFileSystem, | 132 base::Bind(&PepperFileSystemHost::DidOpenFileSystem, |
| 133 weak_factory_.GetWeakPtr()), | 133 weak_factory_.GetWeakPtr()), |
| 134 base::Bind(&PepperFileSystemHost::DidFailOpenFileSystem, | 134 base::Bind(&PepperFileSystemHost::DidFailOpenFileSystem, |
| 135 weak_factory_.GetWeakPtr())); | 135 weak_factory_.GetWeakPtr())); |
| 136 return PP_OK_COMPLETIONPENDING; | 136 return PP_OK_COMPLETIONPENDING; |
| 137 } | 137 } |
| 138 | 138 |
| 139 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( | 139 int32_t PepperFileSystemHost::OnHostMsgInitIsolatedFileSystem( |
| 140 ppapi::host::HostMessageContext* context, | 140 ppapi::host::HostMessageContext* context, |
| 141 const std::string& fsid) { | 141 const std::string& fsid) { |
| 142 called_open_ = true; | 142 called_open_ = true; |
| 143 // Do a sanity check. | 143 // Do a sanity check. |
| 144 if (!LooksLikeAGuid(fsid)) | 144 if (!LooksLikeAGuid(fsid)) |
| 145 return PP_ERROR_BADARGUMENT; | 145 return PP_ERROR_BADARGUMENT; |
| 146 RenderView* view = | 146 RenderView* view = |
| 147 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()); | 147 renderer_ppapi_host_->GetRenderViewForInstance(pp_instance()); |
| 148 if (!view) | 148 if (!view) |
| 149 return PP_ERROR_FAILED; | 149 return PP_ERROR_FAILED; |
| 150 const GURL& url = view->GetWebView()->mainFrame()->document().url(); | 150 const GURL& url = view->GetWebView()->mainFrame()->document().url(); |
| 151 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( | 151 root_url_ = GURL(fileapi::GetIsolatedFileSystemRootURIString( |
| 152 url.GetOrigin(), fsid, "crxfs")); | 152 url.GetOrigin(), fsid, "crxfs")); |
| 153 opened_ = true; | 153 opened_ = true; |
| 154 return PP_OK; | 154 return PP_OK; |
| 155 } | 155 } |
| 156 | 156 |
| 157 } // namespace content | 157 } // namespace content |
| OLD | NEW |