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 | |
| 19 namespace content { | |
| 20 | |
| 21 PepperFileRefRendererHost::PepperFileRefRendererHost( | |
| 22 RendererPpapiHost* host, | |
| 23 PP_Instance instance, | |
| 24 PP_Resource resource, | |
| 25 PP_Resource file_system, | |
| 26 const std::string& internal_path) | |
| 27 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
| 28 file_system_type_(PP_FILESYSTEMTYPE_INVALID), | |
| 29 internal_path_(internal_path) { | |
| 30 ResourceHost* fs_host = host->GetPpapiHost()->GetResourceHost(file_system); | |
| 31 if (fs_host && fs_host->IsFileSystemHost()) { | |
| 32 fs_host_ = base::AsWeakPtr(static_cast<PepperFileSystemHost*>(fs_host)); | |
| 33 file_system_type_ = fs_host_->GetType(); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 | |
| 38 PepperFileRefRendererHost::PepperFileRefRendererHost( | |
| 39 RendererPpapiHost* host, | |
| 40 PP_Instance instance, | |
| 41 PP_Resource resource, | |
| 42 const base::FilePath& external_path) | |
| 43 : ResourceHost(host->GetPpapiHost(), instance, resource), | |
| 44 file_system_type_(PP_FILESYSTEMTYPE_EXTERNAL), | |
| 45 external_path_(external_path) { | |
| 46 } | |
| 47 | |
| 48 PepperFileRefRendererHost::~PepperFileRefRendererHost() { | |
| 49 } | |
| 50 | |
| 51 PP_FileSystemType PepperFileRefRendererHost::GetFileSystemType() const { | |
| 52 return file_system_type_; | |
| 53 } | |
| 54 | |
| 55 std::string PepperFileRefRendererHost::GetFileSystemURLSpec() const { | |
| 56 if (fs_host_.get() && fs_host_->IsOpened() && | |
| 57 fs_host_->GetRootUrl().is_valid()) { | |
| 58 return fs_host_->GetRootUrl().Resolve( | |
| 59 net::EscapePath(internal_path_.substr(1))).spec(); | |
|
dmichael (off chromium)
2013/09/03 22:34:50
the subtsr(1) looks slightly magical. I guess you'
teravest
2013/09/04 14:46:25
Added a check and a comment. Also added checks for
| |
| 60 } | |
| 61 return std::string(); | |
| 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( | |
| 71 const IPC::Message& msg, | |
| 72 ppapi::host::HostMessageContext* context) { | |
| 73 // We don't handle any messages from the plugin in this host. | |
| 74 return PP_ERROR_FAILED; | |
|
dmichael (off chromium)
2013/09/03 22:34:50
NOTREACHED() also? To catch mistakes in debug buil
teravest
2013/09/04 14:46:25
Done.
| |
| 75 } | |
| 76 | |
| 77 bool PepperFileRefRendererHost::IsFileRefHost() { | |
| 78 return true; | |
| 79 } | |
| 80 | |
| 81 } // namespace content | |
| OLD | NEW |