Commit 2a292cf4 authored by teravest@chromium.org's avatar teravest@chromium.org

Trusted plugin: Miscellaneous cleanup.

This removes some unnecessary code in the trusted plugin. I broke this out to
its own change while fixing up other things.

BUG=239656
R=dmichael@chromium.org

Review URL: https://codereview.chromium.org/260053008

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266945 0039d316-1c4b-4281-b951-d872f2087c98
parent 3b167405
...@@ -72,7 +72,7 @@ pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) { ...@@ -72,7 +72,7 @@ pp::Instance* ModulePpapi::CreateInstance(PP_Instance pp_instance) {
MODULE_PRINTF(("ModulePpapi::CreateInstance (pp_instance=%" NACL_PRId32 MODULE_PRINTF(("ModulePpapi::CreateInstance (pp_instance=%" NACL_PRId32
")\n", ")\n",
pp_instance)); pp_instance));
Plugin* plugin = Plugin::New(pp_instance); Plugin* plugin = new Plugin(pp_instance);
MODULE_PRINTF(("ModulePpapi::CreateInstance (return %p)\n", MODULE_PRINTF(("ModulePpapi::CreateInstance (return %p)\n",
static_cast<void* >(plugin))); static_cast<void* >(plugin)));
return plugin; return plugin;
......
...@@ -354,23 +354,12 @@ NaClSubprocess* Plugin::LoadHelperNaClModule(const nacl::string& helper_url, ...@@ -354,23 +354,12 @@ NaClSubprocess* Plugin::LoadHelperNaClModule(const nacl::string& helper_url,
return nacl_subprocess.release(); return nacl_subprocess.release();
} }
Plugin* Plugin::New(PP_Instance pp_instance) {
PLUGIN_PRINTF(("Plugin::New (pp_instance=%" NACL_PRId32 ")\n", pp_instance));
Plugin* plugin = new Plugin(pp_instance);
PLUGIN_PRINTF(("Plugin::New (plugin=%p)\n", static_cast<void*>(plugin)));
return plugin;
}
// All failures of this function will show up as "Missing Plugin-in", so // All failures of this function will show up as "Missing Plugin-in", so
// there is no need to log to JS console that there was an initialization // there is no need to log to JS console that there was an initialization
// failure. Note that module loading functions will log their own errors. // failure. Note that module loading functions will log their own errors.
bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) { bool Plugin::Init(uint32_t argc, const char* argn[], const char* argv[]) {
PLUGIN_PRINTF(("Plugin::Init (argc=%" NACL_PRIu32 ")\n", argc)); PLUGIN_PRINTF(("Plugin::Init (argc=%" NACL_PRIu32 ")\n", argc));
nacl_interface_->InitializePlugin(pp_instance(), argc, argn, argv); nacl_interface_->InitializePlugin(pp_instance(), argc, argn, argv);
url_util_ = pp::URLUtil_Dev::Get();
if (url_util_ == NULL)
return false;
wrapper_factory_ = new nacl::DescWrapperFactory(); wrapper_factory_ = new nacl::DescWrapperFactory();
pp::Var manifest_url(pp::PASS_REF, nacl_interface_->GetManifestURLArgument( pp::Var manifest_url(pp::PASS_REF, nacl_interface_->GetManifestURLArgument(
pp_instance())); pp_instance()));
...@@ -654,15 +643,13 @@ void Plugin::NaClManifestFileDidOpen(int32_t pp_error) { ...@@ -654,15 +643,13 @@ void Plugin::NaClManifestFileDidOpen(int32_t pp_error) {
void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) { void Plugin::ProcessNaClManifest(const nacl::string& manifest_json) {
HistogramSizeKB("NaCl.Perf.Size.Manifest", HistogramSizeKB("NaCl.Perf.Size.Manifest",
static_cast<int32_t>(manifest_json.length() / 1024)); static_cast<int32_t>(manifest_json.length() / 1024));
ErrorInfo error_info; if (!SetManifestObject(manifest_json))
if (!SetManifestObject(manifest_json, &error_info)) {
ReportLoadError(error_info);
return; return;
}
nacl::string program_url; nacl::string program_url;
PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2}; PP_PNaClOptions pnacl_options = {PP_FALSE, PP_FALSE, 2};
bool uses_nonsfi_mode; bool uses_nonsfi_mode;
ErrorInfo error_info;
if (manifest_->GetProgramURL( if (manifest_->GetProgramURL(
&program_url, &pnacl_options, &uses_nonsfi_mode, &error_info)) { &program_url, &pnacl_options, &uses_nonsfi_mode, &error_info)) {
// TODO(teravest): Make ProcessNaClManifest take responsibility for more of // TODO(teravest): Make ProcessNaClManifest take responsibility for more of
...@@ -742,12 +729,11 @@ void Plugin::RequestNaClManifest(const nacl::string& url) { ...@@ -742,12 +729,11 @@ void Plugin::RequestNaClManifest(const nacl::string& url) {
} }
bool Plugin::SetManifestObject(const nacl::string& manifest_json, bool Plugin::SetManifestObject(const nacl::string& manifest_json) {
ErrorInfo* error_info) {
PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n", PLUGIN_PRINTF(("Plugin::SetManifestObject(): manifest_json='%s'.\n",
manifest_json.c_str())); manifest_json.c_str()));
if (error_info == NULL) ErrorInfo error_info;
return false;
// Determine whether lookups should use portable (i.e., pnacl versions) // Determine whether lookups should use portable (i.e., pnacl versions)
// rather than platform-specific files. // rather than platform-specific files.
bool is_pnacl = nacl_interface_->IsPNaCl(pp_instance()); bool is_pnacl = nacl_interface_->IsPNaCl(pp_instance());
...@@ -760,12 +746,13 @@ bool Plugin::SetManifestObject(const nacl::string& manifest_json, ...@@ -760,12 +746,13 @@ bool Plugin::SetManifestObject(const nacl::string& manifest_json,
manifest_base_url_str.c_str()); manifest_base_url_str.c_str());
const char* sandbox_isa = nacl_interface_->GetSandboxArch(); const char* sandbox_isa = nacl_interface_->GetSandboxArch();
nacl::scoped_ptr<JsonManifest> json_manifest( nacl::scoped_ptr<JsonManifest> json_manifest(
new JsonManifest(url_util_, new JsonManifest(pp::URLUtil_Dev::Get(),
manifest_base_url_str, manifest_base_url_str,
(is_pnacl ? kPortableArch : sandbox_isa), (is_pnacl ? kPortableArch : sandbox_isa),
nonsfi_mode_enabled, nonsfi_mode_enabled,
pnacl_debug)); pnacl_debug));
if (!json_manifest->Init(manifest_json, error_info)) { if (!json_manifest->Init(manifest_json, &error_info)) {
ReportLoadError(error_info);
return false; return false;
} }
manifest_.reset(json_manifest.release()); manifest_.reset(json_manifest.release());
...@@ -790,9 +777,8 @@ void Plugin::UrlDidOpenForStreamAsFile( ...@@ -790,9 +777,8 @@ void Plugin::UrlDidOpenForStreamAsFile(
} else if (info->get_desc() > NACL_NO_FILE_DESC) { } else if (info->get_desc() > NACL_NO_FILE_DESC) {
std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it = std::map<nacl::string, NaClFileInfoAutoCloser*>::iterator it =
url_file_info_map_.find(url_downloader->url()); url_file_info_map_.find(url_downloader->url());
if (it != url_file_info_map_.end()) { if (it != url_file_info_map_.end())
delete it->second; delete it->second;
}
url_file_info_map_[url_downloader->url()] = info; url_file_info_map_[url_downloader->url()] = info;
callback.Run(PP_OK); callback.Run(PP_OK);
} else { } else {
...@@ -974,8 +960,9 @@ bool Plugin::OpenURLFast(const nacl::string& url, ...@@ -974,8 +960,9 @@ bool Plugin::OpenURLFast(const nacl::string& url,
} }
bool Plugin::DocumentCanRequest(const std::string& url) { bool Plugin::DocumentCanRequest(const std::string& url) {
CHECK(url_util_ != NULL); CHECK(pp::Module::Get()->core()->IsMainThread());
return url_util_->DocumentCanRequest(this, pp::Var(url)); CHECK(pp::URLUtil_Dev::Get() != NULL);
return pp::URLUtil_Dev::Get()->DocumentCanRequest(this, pp::Var(url));
} }
void Plugin::set_exit_status(int exit_status) { void Plugin::set_exit_status(int exit_status) {
......
...@@ -52,8 +52,7 @@ class Manifest; ...@@ -52,8 +52,7 @@ class Manifest;
class Plugin : public pp::Instance { class Plugin : public pp::Instance {
public: public:
// Factory method for creation. explicit Plugin(PP_Instance instance);
static Plugin* New(PP_Instance instance);
// ----- Methods inherited from pp::Instance: // ----- Methods inherited from pp::Instance:
...@@ -166,7 +165,6 @@ class Plugin : public pp::Instance { ...@@ -166,7 +165,6 @@ class Plugin : public pp::Instance {
bool DocumentCanRequest(const std::string& url); bool DocumentCanRequest(const std::string& url);
Manifest const* manifest() const { return manifest_.get(); } Manifest const* manifest() const { return manifest_.get(); }
const pp::URLUtil_Dev* url_util() const { return url_util_; }
// set_exit_status may be called off the main thread. // set_exit_status may be called off the main thread.
void set_exit_status(int exit_status); void set_exit_status(int exit_status);
...@@ -176,9 +174,6 @@ class Plugin : public pp::Instance { ...@@ -176,9 +174,6 @@ class Plugin : public pp::Instance {
private: private:
NACL_DISALLOW_COPY_AND_ASSIGN(Plugin); NACL_DISALLOW_COPY_AND_ASSIGN(Plugin);
// Prevent construction and destruction from outside the class:
// must use factory New() method instead.
explicit Plugin(PP_Instance instance);
// The browser will invoke the destructor via the pp::Instance // The browser will invoke the destructor via the pp::Instance
// pointer to this object, not from base's Delete(). // pointer to this object, not from base's Delete().
~Plugin(); ~Plugin();
...@@ -274,8 +269,7 @@ class Plugin : public pp::Instance { ...@@ -274,8 +269,7 @@ class Plugin : public pp::Instance {
// On success, |true| is returned and |manifest_| is updated to // On success, |true| is returned and |manifest_| is updated to
// contain a Manifest that is used by SelectNexeURLFromManifest. // contain a Manifest that is used by SelectNexeURLFromManifest.
// On failure, |false| is returned, and |manifest_| is unchanged. // On failure, |false| is returned, and |manifest_| is unchanged.
bool SetManifestObject(const nacl::string& manifest_json, bool SetManifestObject(const nacl::string& manifest_json);
ErrorInfo* error_info);
// Logs timing information to a UMA histogram, and also logs the same timing // Logs timing information to a UMA histogram, and also logs the same timing
// information divided by the size of the nexe to another histogram. // information divided by the size of the nexe to another histogram.
...@@ -314,8 +308,6 @@ class Plugin : public pp::Instance { ...@@ -314,8 +308,6 @@ class Plugin : public pp::Instance {
// The manifest dictionary. Used for looking up resources to be loaded. // The manifest dictionary. Used for looking up resources to be loaded.
nacl::scoped_ptr<Manifest> manifest_; nacl::scoped_ptr<Manifest> manifest_;
// URL processing interface for use in looking up resources in manifests.
const pp::URLUtil_Dev* url_util_;
// Keep track of the FileDownloaders created to fetch urls. // Keep track of the FileDownloaders created to fetch urls.
std::set<FileDownloader*> url_downloaders_; std::set<FileDownloader*> url_downloaders_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment