blob: 4902a753d071556155a3cd98aaab2a015fbeca17 [file] [log] [blame]
[email protected]c6420f082013-09-18 22:42:411// 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
Ryan Hamilton7f3bd3d2022-04-23 00:07:399#include "base/strings/escape.h"
[email protected]c6420f082013-09-18 22:42:4110#include "ppapi/c/pp_errors.h"
11#include "ppapi/host/ppapi_host.h"
12#include "ppapi/shared_impl/file_ref_util.h"
13
14namespace content {
15
16PepperFileRefRendererHost::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
34PepperFileRefRendererHost::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]ad63b5c2014-04-11 21:12:3646PepperFileRefRendererHost::~PepperFileRefRendererHost() {}
[email protected]c6420f082013-09-18 22:42:4147
48PP_FileSystemType PepperFileRefRendererHost::GetFileSystemType() const {
49 return file_system_type_;
50}
51
52GURL 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 Hamilton7f3bd3d2022-04-23 00:07:3959 base::EscapePath(internal_path_.substr(1)));
[email protected]c6420f082013-09-18 22:42:4160 }
61 return GURL();
62}
63
64base::FilePath PepperFileRefRendererHost::GetExternalFilePath() const {
65 if (file_system_type_ != PP_FILESYSTEMTYPE_EXTERNAL)
66 return base::FilePath();
67 return external_path_;
68}
69
70int32_t PepperFileRefRendererHost::OnResourceMessageReceived(
[email protected]ad63b5c2014-04-11 21:12:3671 const IPC::Message& msg,
72 ppapi::host::HostMessageContext* context) {
[email protected]c6420f082013-09-18 22:42:4173 // We don't handle any messages from the plugin in this host.
74 NOTREACHED();
75 return PP_ERROR_FAILED;
76}
77
[email protected]ad63b5c2014-04-11 21:12:3678bool PepperFileRefRendererHost::IsFileRefHost() { return true; }
[email protected]c6420f082013-09-18 22:42:4179
80} // namespace content