blob: 1ff62600008df65bd3fa5fe895470df5d5eacb99 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2012 The Chromium Authors
[email protected]92ad3f72011-09-02 03:06:472// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
[email protected]c59f771b2011-08-25 01:07:444
5// The portable representation of an instance and root scriptable object.
6// The PPAPI version of the plugin instantiates a subclass of this class.
7
mseaborn45df3da2015-01-29 19:39:228#ifndef COMPONENTS_NACL_RENDERER_PLUGIN_PLUGIN_H_
9#define COMPONENTS_NACL_RENDERER_PLUGIN_PLUGIN_H_
[email protected]c59f771b2011-08-25 01:07:4410
avi26062922015-12-26 00:14:1811#include <stdint.h>
[email protected]c59f771b2011-08-25 01:07:4412#include <stdio.h>
[email protected]c98851c72011-09-08 18:06:4413
dcheng24f43a5e92016-04-22 18:29:0914#include <memory>
[email protected]c59f771b2011-08-25 01:07:4415#include <string>
[email protected]c59f771b2011-08-25 01:07:4416
mseaborn45df3da2015-01-29 19:39:2217#include "components/nacl/renderer/plugin/nacl_subprocess.h"
18#include "components/nacl/renderer/plugin/pnacl_coordinator.h"
19#include "components/nacl/renderer/plugin/service_runtime.h"
mseaborn3cf62d92015-02-10 21:20:0120#include "components/nacl/renderer/ppb_nacl_private.h"
[email protected]5feb6cd2014-02-12 22:41:1321#include "ppapi/cpp/instance.h"
[email protected]45649492014-01-24 20:49:3422#include "ppapi/cpp/private/uma_private.h"
[email protected]c59f771b2011-08-25 01:07:4423#include "ppapi/cpp/url_loader.h"
24#include "ppapi/cpp/var.h"
[email protected]e8f07ac2012-01-03 17:43:3625#include "ppapi/cpp/view.h"
[email protected]b7a490e2014-07-23 16:58:1526#include "ppapi/utility/completion_callback_factory.h"
27
[email protected]c59f771b2011-08-25 01:07:4428namespace pp {
[email protected]557c3002014-03-27 07:39:1029class CompletionCallback;
[email protected]c59f771b2011-08-25 01:07:4430class URLLoader;
[email protected]c59f771b2011-08-25 01:07:4431}
32
[email protected]c59f771b2011-08-25 01:07:4433namespace plugin {
34
35class ErrorInfo;
[email protected]c59f771b2011-08-25 01:07:4436
[email protected]5e64f6382014-06-30 16:18:5337const PP_NaClFileInfo kInvalidNaClFileInfo = {
38 PP_kInvalidFileHandle,
39 0, // token_lo
40 0, // token_hi
41};
42
[email protected]5feb6cd2014-02-12 22:41:1343class Plugin : public pp::Instance {
[email protected]c59f771b2011-08-25 01:07:4444 public:
[email protected]2a292cf42014-04-29 20:12:4345 explicit Plugin(PP_Instance instance);
[email protected]c59f771b2011-08-25 01:07:4446
Peter Boström9f667c382021-10-01 20:09:3147 Plugin(const Plugin&) = delete;
48 Plugin& operator=(const Plugin&) = delete;
49
[email protected]c59f771b2011-08-25 01:07:4450 // ----- Methods inherited from pp::Instance:
51
52 // Initializes this plugin with <embed/object ...> tag attribute count |argc|,
53 // names |argn| and values |argn|. Returns false on failure.
54 // Gets called by the browser right after New().
mseaborna202e2832015-01-26 17:59:3755 bool Init(uint32_t argc, const char* argn[], const char* argv[]) override;
[email protected]c59f771b2011-08-25 01:07:4456
[email protected]7522077b2013-01-17 23:39:4057 // Handles document load, when the plugin is a MIME type handler.
mseaborna202e2832015-01-26 17:59:3758 bool HandleDocumentLoad(const pp::URLLoader& url_loader) override;
[email protected]c59f771b2011-08-25 01:07:4459
[email protected]c59f771b2011-08-25 01:07:4460 // Load support.
[email protected]c59f771b2011-08-25 01:07:4461 //
62 // Starts NaCl module but does not wait until low-level
[email protected]2efbb642014-05-28 22:43:1763 // initialization (e.g. ld.so dynamic loading of manifest files) is
[email protected]c59f771b2011-08-25 01:07:4464 // done. The module will become ready later, asynchronously. Other
65 // event handlers should block until the module is ready before
66 // trying to communicate with it, i.e., until nacl_ready_state is
[email protected]7522077b2013-01-17 23:39:4067 // DONE.
[email protected]c59f771b2011-08-25 01:07:4468 //
69 // NB: currently we do not time out, so if the untrusted code
70 // does not signal that it is ready, then we will deadlock the main
71 // thread of the renderer on this subsequent event delivery. We
72 // should include a time-out at which point we declare the
73 // nacl_ready_state to be done, and let the normal crash detection
74 // mechanism(s) take over.
jvounga26ccdf2015-05-12 15:19:3175 // This function takes over ownership of the file_info.
[email protected]2efbb642014-05-28 22:43:1776 void LoadNaClModule(PP_NaClFileInfo file_info,
mseaborn6e975772015-01-23 04:39:1577 PP_NaClAppProcessType process_type);
[email protected]c59f771b2011-08-25 01:07:4478
[email protected]c59f771b2011-08-25 01:07:4479 // Load support.
[email protected]5e64f6382014-06-30 16:18:5380 // A helper SRPC NaCl module can be loaded given a PP_NaClFileInfo.
[email protected]c59f771b2011-08-25 01:07:4481 // Does not update nacl_module_origin().
jvounga26ccdf2015-05-12 15:19:3182 // Uses the given NaClSubprocess to contain the new SelLdr process.
83 // The given callback is called when the loading is complete.
84 // This function takes over ownership of the file_info.
85 void LoadHelperNaClModule(const std::string& helper_url,
86 PP_NaClFileInfo file_info,
87 NaClSubprocess* subprocess_to_init,
88 pp::CompletionCallback callback);
[email protected]c59f771b2011-08-25 01:07:4489
[email protected]c59f771b2011-08-25 01:07:4490 // Report an error that was encountered while loading a module.
91 void ReportLoadError(const ErrorInfo& error_info);
[email protected]c59f771b2011-08-25 01:07:4492
[email protected]c59f771b2011-08-25 01:07:4493 private:
[email protected]c59f771b2011-08-25 01:07:4494 // The browser will invoke the destructor via the pp::Instance
95 // pointer to this object, not from base's Delete().
mseaborna202e2832015-01-26 17:59:3796 ~Plugin() override;
[email protected]c59f771b2011-08-25 01:07:4497
[email protected]c59f771b2011-08-25 01:07:4498 // Shuts down socket connection, service runtime, and receive thread,
[email protected]828ba9522012-01-30 23:11:0299 // in this order, for the main nacl subprocess.
[email protected]c59f771b2011-08-25 01:07:44100 void ShutDownSubprocesses();
101
[email protected]c59f771b2011-08-25 01:07:44102 // Callback used when getting the URL for the .nexe file. If the URL loading
103 // is successful, the file descriptor is opened and can be passed to sel_ldr
104 // with the sandbox on.
105 void NexeFileDidOpen(int32_t pp_error);
[email protected]c59f771b2011-08-25 01:07:44106
107 // Callback used when a .nexe is translated from bitcode. If the translation
108 // is successful, the file descriptor is opened and can be passed to sel_ldr
109 // with the sandbox on.
110 void BitcodeDidTranslate(int32_t pp_error);
[email protected]c59f771b2011-08-25 01:07:44111
112 // NaCl ISA selection manifest file support. The manifest file is specified
113 // using the "nacl" attribute in the <embed> tag. First, the manifest URL (or
114 // data: URI) is fetched, then the JSON is parsed. Once a valid .nexe is
115 // chosen for the sandbox ISA, any current service runtime is shut down, the
116 // .nexe is loaded and run.
117
[email protected]c59f771b2011-08-25 01:07:44118 // Callback used when getting the manifest file as a local file descriptor.
119 void NaClManifestFileDidOpen(int32_t pp_error);
120
121 // Processes the JSON manifest string and starts loading the nexe.
Justin TerAvest82f0d052014-09-10 20:02:03122 void ProcessNaClManifest(const std::string& manifest_json);
[email protected]c59f771b2011-08-25 01:07:44123
[email protected]828ba9522012-01-30 23:11:02124 // Keep track of the NaCl module subprocess that was spun up in the plugin.
[email protected]c59f771b2011-08-25 01:07:44125 NaClSubprocess main_subprocess_;
[email protected]c59f771b2011-08-25 01:07:44126
[email protected]c59f771b2011-08-25 01:07:44127 pp::CompletionCallbackFactory<Plugin> callback_factory_;
128
dcheng24f43a5e92016-04-22 18:29:09129 std::unique_ptr<PnaclCoordinator> pnacl_coordinator_;
[email protected]c59f771b2011-08-25 01:07:44130
[email protected]0554b5d2013-11-27 18:39:19131 int exit_status_;
[email protected]17b5a8172012-06-22 21:09:09132
[email protected]2efbb642014-05-28 22:43:17133 PP_NaClFileInfo nexe_file_info_;
[email protected]728a9632014-05-16 20:18:20134
[email protected]45649492014-01-24 20:49:34135 pp::UMAPrivate uma_interface_;
[email protected]c59f771b2011-08-25 01:07:44136};
137
138} // namespace plugin
139
mseaborn45df3da2015-01-29 19:39:22140#endif // COMPONENTS_NACL_RENDERER_PLUGIN_PLUGIN_H_