Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 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 | |
Ryan Hamilton | 7f3bd3d | 2022-04-23 00:07:39 | [diff] [blame] | 9 | #include "base/strings/escape.h" |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 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()) { |
David Bertoni | 9b272c4 | 2024-01-23 16:52:37 | [diff] [blame] | 29 | fs_host_ = static_cast<PepperFileSystemHost*>(fs_host)->AsWeakPtr(); |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 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 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 46 | PepperFileRefRendererHost::~PepperFileRefRendererHost() {} |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 47 | |
| 48 | PP_FileSystemType PepperFileRefRendererHost::GetFileSystemType() const { |
| 49 | return file_system_type_; |
| 50 | } |
| 51 | |
| 52 | GURL PepperFileRefRendererHost::GetFileSystemURL() const { |
| 53 | if (fs_host_.get() && fs_host_->IsOpened() && |
| 54 | fs_host_->GetRootUrl().is_valid()) { |
| 55 | CHECK(!internal_path_.empty() && internal_path_[0] == '/'); |
| 56 | // We strip off the leading slash when passing the URL to Resolve(). |
| 57 | // Internal paths are required to be absolute, so we can require this. |
| 58 | return fs_host_->GetRootUrl().Resolve( |
Ryan Hamilton | 7f3bd3d | 2022-04-23 00:07:39 | [diff] [blame] | 59 | base::EscapePath(internal_path_.substr(1))); |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 60 | } |
| 61 | return GURL(); |
| 62 | } |
| 63 | |
| 64 | base::FilePath PepperFileRefRendererHost::GetExternalFilePath() const { |
| 65 | if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL) |
| 66 | return base::FilePath(); |
| 67 | return external_path_; |
| 68 | } |
| 69 | |
| 70 | int32_t PepperFileRefRendererHost::OnResourceMessageReceived( |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 71 | const IPC::Message& msg, |
| 72 | ppapi::host::HostMessageContext* context) { |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 73 | // We don't handle any messages from the plugin in this host. |
Peter Boström | fc7ddc18 | 2024-10-31 19:37:21 | [diff] [blame] | 74 | NOTREACHED(); |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 75 | } |
| 76 | |
[email protected] | ad63b5c | 2014-04-11 21:12:36 | [diff] [blame] | 77 | bool PepperFileRefRendererHost::IsFileRefHost() { return true; } |
[email protected] | c6420f08 | 2013-09-18 22:42:41 | [diff] [blame] | 78 | |
| 79 | } // namespace content |