1 // Copyright (c) 2012 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.
5 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h"
7 #include "native_client/src/include/portability_io.h"
8 #include "native_client/src/shared/platform/nacl_check.h"
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
12 #include "ppapi/native_client/src/trusted/plugin/utility.h"
18 static const char kPnaclBaseUrl
[] = "chrome://pnacl-translator/";
20 nacl::string
GetFullUrl(const nacl::string
& partial_url
) {
21 return nacl::string(kPnaclBaseUrl
) + GetNaClInterface()->GetSandboxArch() +
27 PnaclResources::PnaclResources(Plugin
* plugin
)
29 llc_file_info_
= kInvalidNaClFileInfo
;
30 ld_file_info_
= kInvalidNaClFileInfo
;
33 PnaclResources::~PnaclResources() {
34 if (llc_file_info_
.handle
!= PP_kInvalidFileHandle
)
35 CloseFileHandle(llc_file_info_
.handle
);
36 if (ld_file_info_
.handle
!= PP_kInvalidFileHandle
)
37 CloseFileHandle(ld_file_info_
.handle
);
40 bool PnaclResources::ReadResourceInfo() {
41 PP_Var pp_llc_tool_name_var
;
42 PP_Var pp_ld_tool_name_var
;
43 if (!plugin_
->nacl_interface()->GetPnaclResourceInfo(
44 plugin_
->pp_instance(),
45 &pp_llc_tool_name_var
,
46 &pp_ld_tool_name_var
)) {
49 pp::Var
llc_tool_name(pp::PASS_REF
, pp_llc_tool_name_var
);
50 pp::Var
ld_tool_name(pp::PASS_REF
, pp_ld_tool_name_var
);
51 llc_tool_name_
= GetFullUrl(llc_tool_name
.AsString());
52 ld_tool_name_
= GetFullUrl(ld_tool_name
.AsString());
56 PP_NaClFileInfo
PnaclResources::TakeLlcFileInfo() {
57 PP_NaClFileInfo to_return
= llc_file_info_
;
58 llc_file_info_
= kInvalidNaClFileInfo
;
62 PP_NaClFileInfo
PnaclResources::TakeLdFileInfo() {
63 PP_NaClFileInfo to_return
= ld_file_info_
;
64 ld_file_info_
= kInvalidNaClFileInfo
;
68 bool PnaclResources::StartLoad() {
69 PLUGIN_PRINTF(("PnaclResources::StartLoad\n"));
71 // Do a blocking load of each of the resources.
72 plugin_
->nacl_interface()->GetReadExecPnaclFd(llc_tool_name_
.c_str(),
74 plugin_
->nacl_interface()->GetReadExecPnaclFd(ld_tool_name_
.c_str(),
76 return (llc_file_info_
.handle
!= PP_kInvalidFileHandle
&&
77 ld_file_info_
.handle
!= PP_kInvalidFileHandle
);