Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 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_ref_renderer_host.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "content/public/renderer/renderer_ppapi_host.h" | |
| 11 #include "net/base/escape.h" | |
| 12 #include "ppapi/c/pp_errors.h" | |
| 13 #include "ppapi/c/pp_file_info.h" | |
| 14 #include "ppapi/c/pp_instance.h" | |
| 15 #include "ppapi/c/pp_resource.h" | |
| 16 #include "ppapi/host/ppapi_host.h" | |
| 17 #include "ppapi/host/resource_host.h" | |
| 18 #include "ppapi/shared_impl/file_ref_util.h" | |
| 19 | |
| 20 namespace content { | |
| 21 | |
| 22 PepperFileRefRendererHost::PepperFileRefRendererHost( | |
| 23 RendererPpapiHost* host, | |
| 24 PP_Instance instance, | |
| 25 PP_Resource resource, | |
| 26 PP_Resource file_system, | |
| 27 const std::string& internal_path) | |
| 28 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
| 29 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | |
| 30 internal_path_(internal_path) { | |
| 31 if (!ppapi::IsValidInternalPath(internal_path)) | |
| 32 return; | |
| 33 ResourceHost* fs_host = host->GetPpapiHost()->GetResourceHost(file_system); | |
| 34 if (fs_host && fs_host->IsFileSystemHost()) { | |
| 35 fs_host_ = base::AsWeakPtr(static_cast<PepperFileSystemHost*>(fs_host)); | |
| 36 file_system_type_ = fs_host_->GetType(); | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 | |
| 41 PepperFileRefRendererHost::PepperFileRefRendererHost( | |
| 42 RendererPpapiHost* host, | |
| 43 PP_Instance instance, | |
| 44 PP_Resource resource, | |
| 45 const base::FilePath& external_path) | |
| 46 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
| 47 file_system_type_(PP_FILESYSTEMTYPE_EXTERNAL), | |
| 48 external_path_(external_path) { | |
| 49 if (!ppapi::IsValidExternalPath(external_path)) | |
| 50 file_system_type_ = PP_FILESYSTEMTYPE_INVALID; | |
| 51 } | |
| 52 | |
| 53 PepperFileRefRendererHost::~PepperFileRefRendererHost() { | |
| 54 } | |
| 55 | |
| 56 PP_FileSystemType PepperFileRefRendererHost::GetFileSystemType() const { | |
| 57 return file_system_type_; | |
| 58 } | |
| 59 | |
| 60 GURL PepperFileRefRendererHost::GetFileSystemURL() const { | |
| 61 if (fs_host_.get() && fs_host_->IsOpened() && | |
| 62 fs_host_->GetRootUrl().is_valid()) { | |
| 63 CHECK(internal_path_[0] == '/'); | |
|
dmichael (off chromium)
2013/09/04 17:23:54
I guess I meant a CHECK that the size is >= 1. Rig
| |
| 64 // We strip off the leading slash when passing the URL to Resolve(). | |
| 65 // Internal paths are required to be absolute, so we can require this. | |
| 66 return fs_host_->GetRootUrl().Resolve( | |
| 67 net::EscapePath(internal_path_.substr(1))); | |
| 68 } | |
| 69 return GURL(); | |
| 70 } | |
| 71 | |
| 72 base::FilePath PepperFileRefRendererHost::GetExternalFilePath() const { | |
| 73 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) | |
| 74 return base::FilePath(); | |
| 75 return external_path_; | |
| 76 } | |
| 77 | |
| 78 int32_t PepperFileRefRendererHost::OnResourceMessageReceived( | |
| 79 const IPC::Message& msg, | |
| 80 ppapi::host::HostMessageContext* context) { | |
| 81 // We don't handle any messages from the plugin in this host. | |
| 82 NOTREACHED(); | |
| 83 return PP_ERROR_FAILED; | |
| 84 } | |
| 85 | |
| 86 bool PepperFileRefRendererHost::IsFileRefHost() { | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 } // namespace content | |
| OLD | NEW |