Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: ppapi/native_client/src/trusted/plugin/pnacl_resources.cc

Issue 261143002: Pepper: Remove file_utils from trusted plugin. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h" 5 #include "ppapi/native_client/src/trusted/plugin/pnacl_resources.h"
6 6
7 #include "native_client/src/include/portability_io.h" 7 #include "native_client/src/include/portability_io.h"
8 #include "native_client/src/shared/platform/nacl_check.h" 8 #include "native_client/src/shared/platform/nacl_check.h"
9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h" 9 #include "native_client/src/trusted/desc/nacl_desc_wrapper.h"
10 #include "ppapi/c/pp_errors.h" 10 #include "ppapi/c/pp_errors.h"
11 #include "ppapi/native_client/src/trusted/plugin/file_utils.h"
12 #include "ppapi/native_client/src/trusted/plugin/plugin.h" 11 #include "ppapi/native_client/src/trusted/plugin/plugin.h"
13 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 12 #include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h"
14 #include "ppapi/native_client/src/trusted/plugin/utility.h" 13 #include "ppapi/native_client/src/trusted/plugin/utility.h"
15 #include "third_party/jsoncpp/source/include/json/reader.h" 14 #include "third_party/jsoncpp/source/include/json/reader.h"
16 #include "third_party/jsoncpp/source/include/json/value.h" 15 #include "third_party/jsoncpp/source/include/json/value.h"
17 16
18 namespace plugin { 17 namespace plugin {
19 18
20 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/"; 19 static const char kPnaclBaseUrl[] = "chrome://pnacl-translator/";
21 20
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 PLUGIN_PRINTF(("PnaclResources::ReadResourceInfo\n")); 98 PLUGIN_PRINTF(("PnaclResources::ReadResourceInfo\n"));
100 99
101 nacl::string full_url = PnaclUrls::GetBaseUrl() + resource_info_url; 100 nacl::string full_url = PnaclUrls::GetBaseUrl() + resource_info_url;
102 PLUGIN_PRINTF(("Resolved resources info url: %s\n", full_url.c_str())); 101 PLUGIN_PRINTF(("Resolved resources info url: %s\n", full_url.c_str()));
103 nacl::string resource_info_filename = 102 nacl::string resource_info_filename =
104 PnaclUrls::PnaclComponentURLToFilename(full_url); 103 PnaclUrls::PnaclComponentURLToFilename(full_url);
105 104
106 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n", 105 PLUGIN_PRINTF(("Pnacl-converted resources info url: %s\n",
107 resource_info_filename.c_str())); 106 resource_info_filename.c_str()));
108 107
109 int32_t fd = GetPnaclFD(plugin_, resource_info_filename.c_str()); 108 PP_Var pp_llc_tool_name_var;
110 if (fd < 0) { 109 PP_Var pp_ld_tool_name_var;
111 // File-open failed. Assume this means that the file is 110 if (!plugin_->nacl_interface()->GetPnaclResourceInfo(
112 // not actually installed. 111 plugin_->pp_instance(),
113 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 112 resource_info_filename.c_str(),
114 nacl::string("The Portable Native Client (pnacl) component is not " 113 &pp_llc_tool_name_var,
115 "installed. Please consult chrome://components for more " 114 &pp_ld_tool_name_var)) {
116 "information.")); 115 coordinator_->ExitWithError();
117 return;
118 } 116 }
119 117
120 nacl::string json_buffer; 118 pp::Var llc_tool_name(pp::PASS_REF, pp_llc_tool_name_var);
121 file_utils::StatusCode status = file_utils::SlurpFile(fd, json_buffer); 119 pp::Var ld_tool_name(pp::PASS_REF, pp_ld_tool_name_var);
122 if (status != file_utils::PLUGIN_FILE_SUCCESS) { 120 llc_tool_name_ = llc_tool_name.AsString();
123 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH, 121 ld_tool_name_ = ld_tool_name.AsString();
124 nacl::string("PnaclResources::ReadResourceInfo reading "
125 "failed for: ") + resource_info_filename);
126 return;
127 }
128
129 // Finally, we have the resource info JSON data in json_buffer.
130 PLUGIN_PRINTF(("Resource info JSON data:\n%s\n", json_buffer.c_str()));
131 if (!ParseResourceInfo(json_buffer))
132 return;
133
134 // Done. Queue the completion callback.
135 pp::Core* core = pp::Module::Get()->core(); 122 pp::Core* core = pp::Module::Get()->core();
136 core->CallOnMainThread(0, resource_info_read_cb, PP_OK); 123 core->CallOnMainThread(0, resource_info_read_cb, PP_OK);
137 } 124 }
138 125
139 bool PnaclResources::ParseResourceInfo(const nacl::string& buf) {
140 // Expect the JSON file to contain a top-level object (dictionary).
141 Json::Reader json_reader;
142 Json::Value json_data;
143 if (!json_reader.parse(buf, json_data)) {
144 std::string errmsg = nacl::string("JSON parse error: ") +
145 json_reader.getFormatedErrorMessages();
146 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
147 nacl::string("Parsing resource info failed: ") + errmsg + "\n");
148 return false;
149 }
150
151 if (!json_data.isObject()) {
152 coordinator_->ReportNonPpapiError(PP_NACL_ERROR_PNACL_RESOURCE_FETCH,
153 nacl::string("Parsing resource info failed: "
154 "Malformed JSON dictionary\n"));
155 return false;
156 }
157
158 if (json_data.isMember("pnacl-llc-name")) {
159 Json::Value json_name = json_data["pnacl-llc-name"];
160 if (json_name.isString()) {
161 llc_tool_name_ = json_name.asString();
162 PLUGIN_PRINTF(("Set llc_tool_name=%s\n", llc_tool_name_.c_str()));
163 }
164 }
165
166 if (json_data.isMember("pnacl-ld-name")) {
167 Json::Value json_name = json_data["pnacl-ld-name"];
168 if (json_name.isString()) {
169 ld_tool_name_ = json_name.asString();
170 PLUGIN_PRINTF(("Set ld_tool_name=%s\n", ld_tool_name_.c_str()));
171 }
172 }
173 return true;
174 }
175
176 nacl::string PnaclResources::GetFullUrl( 126 nacl::string PnaclResources::GetFullUrl(
177 const nacl::string& partial_url, const nacl::string& sandbox_arch) const { 127 const nacl::string& partial_url, const nacl::string& sandbox_arch) const {
178 return PnaclUrls::GetBaseUrl() + sandbox_arch + "/" + partial_url; 128 return PnaclUrls::GetBaseUrl() + sandbox_arch + "/" + partial_url;
179 } 129 }
180 130
181 void PnaclResources::StartLoad( 131 void PnaclResources::StartLoad(
182 const pp::CompletionCallback& all_loaded_callback) { 132 const pp::CompletionCallback& all_loaded_callback) {
183 PLUGIN_PRINTF(("PnaclResources::StartLoad\n")); 133 PLUGIN_PRINTF(("PnaclResources::StartLoad\n"));
184 134
185 std::vector<nacl::string> resource_urls; 135 std::vector<nacl::string> resource_urls;
186 resource_urls.push_back(GetLlcUrl()); 136 resource_urls.push_back(llc_tool_name_);
187 resource_urls.push_back(GetLdUrl()); 137 resource_urls.push_back(ld_tool_name_);
188 138
189 PLUGIN_PRINTF(("PnaclResources::StartLoad -- local install of PNaCl.\n")); 139 PLUGIN_PRINTF(("PnaclResources::StartLoad -- local install of PNaCl.\n"));
190 // Do a blocking load of each of the resources. 140 // Do a blocking load of each of the resources.
191 int32_t result = PP_OK; 141 int32_t result = PP_OK;
192 for (size_t i = 0; i < resource_urls.size(); ++i) { 142 for (size_t i = 0; i < resource_urls.size(); ++i) {
193 nacl::string full_url = GetFullUrl( 143 nacl::string full_url = GetFullUrl(
194 resource_urls[i], plugin_->nacl_interface()->GetSandboxArch()); 144 resource_urls[i], plugin_->nacl_interface()->GetSandboxArch());
195 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url); 145 nacl::string filename = PnaclUrls::PnaclComponentURLToFilename(full_url);
196 146
197 int32_t fd = PnaclResources::GetPnaclFD(plugin_, filename.c_str()); 147 int32_t fd = PnaclResources::GetPnaclFD(plugin_, filename.c_str());
(...skipping 12 matching lines...) Expand all
210 resource_wrappers_[resource_urls[i]] = 160 resource_wrappers_[resource_urls[i]] =
211 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY); 161 plugin_->wrapper_factory()->MakeFileDesc(fd, O_RDONLY);
212 } 162 }
213 } 163 }
214 // We're done! Queue the callback. 164 // We're done! Queue the callback.
215 pp::Core* core = pp::Module::Get()->core(); 165 pp::Core* core = pp::Module::Get()->core();
216 core->CallOnMainThread(0, all_loaded_callback, result); 166 core->CallOnMainThread(0, all_loaded_callback, result);
217 } 167 }
218 168
219 } // namespace plugin 169 } // namespace plugin
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698