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