plugin.h revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// -*- c++ -*- 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The portable representation of an instance and root scriptable object. 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The PPAPI version of the plugin instantiates a subclass of this class. 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stdio.h> 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map> 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <queue> 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <set> 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "native_client/src/include/nacl_macros.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "native_client/src/include/nacl_scoped_ptr.h" 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "native_client/src/include/nacl_string.h" 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "native_client/src/trusted/validator/nacl_file_info.h" 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/c/private/ppb_nacl_private.h" 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/cpp/instance.h" 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ppapi/cpp/private/uma_private.h" 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/url_loader.h" 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/var.h" 295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ppapi/cpp/view.h" 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 31ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ppapi/native_client/src/trusted/plugin/file_downloader.h" 32ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ppapi/native_client/src/trusted/plugin/nacl_subprocess.h" 33ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ppapi/native_client/src/trusted/plugin/pnacl_coordinator.h" 34ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ppapi/native_client/src/trusted/plugin/service_runtime.h" 35ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch#include "ppapi/native_client/src/trusted/plugin/utility.h" 36ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace nacl { 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DescWrapper; 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class DescWrapperFactory; 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace nacl 415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace pp { 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLLoader; 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLUtil_Dev; 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace ppapi_proxy { 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserPpp; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace plugin { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ErrorInfo; 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Manifest; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Plugin : public pp::Instance { 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Factory method for creation. 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static Plugin* New(PP_Instance instance); 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ----- Methods inherited from pp::Instance: 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Initializes this plugin with <embed/object ...> tag attribute count |argc|, 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // names |argn| and values |argn|. Returns false on failure. 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Gets called by the browser right after New(). 665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]); 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Handles document load, when the plugin is a MIME type handler. 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual bool HandleDocumentLoad(const pp::URLLoader& url_loader); 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // ----- Plugin interface support. 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Load support. 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NaCl module can be loaded given a DescWrapper. 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Starts NaCl module but does not wait until low-level 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // initialization (e.g., ld.so dynamic loading of manifest files) is 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // done. The module will become ready later, asynchronously. Other 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // event handlers should block until the module is ready before 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // trying to communicate with it, i.e., until nacl_ready_state is 812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // DONE. 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NB: currently we do not time out, so if the untrusted code 845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // does not signal that it is ready, then we will deadlock the main 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // thread of the renderer on this subsequent event delivery. We 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // should include a time-out at which point we declare the 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // nacl_ready_state to be done, and let the normal crash detection 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // mechanism(s) take over. 895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // 905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Updates nacl_module_origin() and nacl_module_url(). 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void LoadNaClModule(nacl::DescWrapper* wrapper, 92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool enable_dyncode_syscalls, 937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool enable_exception_handling, 943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool enable_crash_throttling, 957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const pp::CompletionCallback& init_done_cb, 967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const pp::CompletionCallback& crash_cb); 975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Finish hooking interfaces up, after low-level initialization is 995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // complete. 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool LoadNaClModuleContinuationIntern(ErrorInfo* error_info); 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Continuation for starting SRPC/JSProxy services as appropriate. 1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This is invoked as a callback when the NaCl module makes the 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // init_done reverse RPC to tell us that low-level initialization 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // such as ld.so processing is done. That initialization requires 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // that the main thread be free in order to do Pepper 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // main-thread-only operations such as file processing. 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool LoadNaClModuleContinuation(int32_t pp_error); 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Load support. 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A helper SRPC NaCl module can be loaded given a DescWrapper. 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Blocks until the helper module signals initialization is done. 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Does not update nacl_module_origin(). 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns NULL or the NaClSubprocess of the new helper NaCl module. 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NaClSubprocess* LoadHelperNaClModule(nacl::DescWrapper* wrapper, 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const Manifest* manifest, 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ErrorInfo* error_info); 1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns the argument value for the specified key, or NULL if not found. 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string LookupArgument(const std::string& key) const; 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum LengthComputable { 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LENGTH_IS_NOT_COMPUTABLE = 0, 1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LENGTH_IS_COMPUTABLE = 1 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Report successful loading of a module. 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ReportLoadSuccess(LengthComputable length_computable, 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64_t loaded_bytes, 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64_t total_bytes); 1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Report an error that was encountered while loading a module. 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ReportLoadError(const ErrorInfo& error_info); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Report loading a module was aborted, typically due to user action. 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ReportLoadAbort(); 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Write a text string on the JavaScript console. 1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void AddToConsole(const nacl::string& text); 1375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Dispatch a JavaScript event to indicate a key step in loading. 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |event_type| is a character string indicating which type of progress 1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // event (loadstart, progress, error, abort, load, loadend). Events are 1415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // enqueued on the JavaScript event loop, which then calls back through 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // DispatchProgressEvent. 143f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void EnqueueProgressEvent(PP_NaClEventType event_type); 144f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void EnqueueProgressEvent(PP_NaClEventType event_type, 1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const nacl::string& url, 1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LengthComputable length_computable, 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64_t loaded_bytes, 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64_t total_bytes); 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Report the error code that sel_ldr produces when starting a nexe. 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ReportSelLdrLoadStatus(int status); 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Report nexe death after load to JS and shut down the proxy. 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ReportDeadNexe(); 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL resolution support. 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // plugin_base_url is the URL used for resolving relative URLs used in 1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // src="...". 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::string plugin_base_url() const { return plugin_base_url_; } 1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_plugin_base_url(const nacl::string& url) { plugin_base_url_ = url; } 1615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // manifest_base_url is the URL used for resolving relative URLs mentioned 1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in manifest files. If the manifest is a data URI, this is an empty string. 1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::string manifest_base_url() const { return manifest_base_url_; } 1645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_manifest_base_url(const nacl::string& url) { 1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) manifest_base_url_ = url; 1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The state of readiness of the plugin. 1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) enum ReadyState { 1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The trusted plugin begins in this ready state. 1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UNSENT = 0, 1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The manifest file has been requested, but not yet received. 1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) OPENED = 1, 1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This state is unused. 1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) HEADERS_RECEIVED = 2, 1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The manifest file has been received and the nexe successfully requested. 1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) LOADING = 3, 1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The nexe has been loaded and the proxy started, so it is ready for 1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // interaction with the page. 1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DONE = 4 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) }; 1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool nexe_error_reported() const { return nexe_error_reported_; } 1835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void set_nexe_error_reported(bool val) { 1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nexe_error_reported_ = val; 1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::DescWrapperFactory* wrapper_factory() const { return wrapper_factory_; } 1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Requests a NaCl manifest download from a |url| relative to the page origin. 1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void RequestNaClManifest(const nacl::string& url); 1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The size returned when a file download operation is unable to determine 1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // the size of the file to load. W3C ProgressEvents specify that unknown 1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // sizes return 0. 1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const uint64_t kUnknownBytes = 0; 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Called back by CallOnMainThread. Dispatches the first enqueued progress 1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // event. 1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void DispatchProgressEvent(int32_t result); 2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Requests a URL asynchronously resulting in a call to pp_callback with 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // a PP_Error indicating status. On success an open file descriptor 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // corresponding to the url body is recorded for further lookup. 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool StreamAsFile(const nacl::string& url, 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_CompletionCallback pp_callback); 20690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 20790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Returns rich information for a file retrieved by StreamAsFile(). This info 20890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // contains a file descriptor. The caller must take ownership of this 20990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // descriptor. 21090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) struct NaClFileInfo GetFileInfo(const nacl::string& url); 2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // A helper function that gets the scheme type for |url|. Uses URLUtil_Dev 2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // interface which this class has as a member. 2145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) UrlSchemeType GetUrlScheme(const std::string& url); 2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A helper function that indicates if |url| can be requested by the document 2172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // under the same-origin policy. Strictly speaking, it may be possible for the 2182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // document to request the URL using CORS even if this function returns false. 2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool DocumentCanRequest(const std::string& url); 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 221f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void set_last_error_string(const nacl::string& error); 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The MIME type used to instantiate this instance of the NaCl plugin. 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Typically, the MIME type will be application/x-nacl. However, if the NEXE 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is being used as a content type handler for another content type (such as 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // PDF), then this function will return that type. 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const nacl::string& mime_type() const { return mime_type_; } 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The default MIME type for the NaCl plugin. 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static const char* const kNaClMIMEType; 2307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // The MIME type for the plugin when using PNaCl. 2317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static const char* const kPnaclMIMEType; 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Returns true if PPAPI Dev interfaces should be allowed. 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool enable_dev_interfaces() { return enable_dev_interfaces_; } 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Manifest const* manifest() const { return manifest_.get(); } 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const pp::URLUtil_Dev* url_util() const { return url_util_; } 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 238f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int exit_status() const { return exit_status_; } 239f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // set_exit_status may be called off the main thread. 240f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void set_exit_status(int exit_status); 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const PPB_NaCl_Private* nacl_interface() const { return nacl_interface_; } 2435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pp::UMAPrivate& uma_interface() { return uma_interface_; } 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NACL_DISALLOW_COPY_AND_ASSIGN(Plugin); 2475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Prevent construction and destruction from outside the class: 2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // must use factory New() method instead. 2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) explicit Plugin(PP_Instance instance); 2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The browser will invoke the destructor via the pp::Instance 2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // pointer to this object, not from base's Delete(). 2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ~Plugin(); 2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool EarlyInit(int argc, const char* argn[], const char* argv[]); 2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Shuts down socket connection, service runtime, and receive thread, 2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in this order, for the main nacl subprocess. 2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ShutDownSubprocesses(); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Access the service runtime for the main NaCl subprocess. 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ServiceRuntime* main_service_runtime() const { 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return main_subprocess_.service_runtime(); 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Histogram helper functions, internal to Plugin so they can use 2655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // uma_interface_ normally. 2665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramTimeSmall(const std::string& name, int64_t ms); 2675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramTimeMedium(const std::string& name, int64_t ms); 2685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramTimeLarge(const std::string& name, int64_t ms); 2695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramSizeKB(const std::string& name, int32_t sample); 2705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramEnumerate(const std::string& name, 2715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int sample, 2725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int maximum, 2735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int out_of_range_replacement); 2745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramEnumerateOsArch(const std::string& sandbox_isa); 2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramEnumerateLoadStatus(PluginErrorCode error_code, 2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_installed); 2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramEnumerateSelLdrLoadStatus(NaClErrorCode error_code, 2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool is_installed); 2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramEnumerateManifestIsDataURI(bool is_data_uri); 2805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void HistogramHTTPStatusCode(const std::string& name, int status); 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Load a nacl module from the file specified in wrapper. 2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Only to be used from a background (non-main) thread. 2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This will fully initialize the |subprocess| if the load was successful. 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool LoadNaClModuleFromBackgroundThread(nacl::DescWrapper* wrapper, 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NaClSubprocess* subprocess, 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const Manifest* manifest, 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const SelLdrStartParams& params); 2897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 2907dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Start sel_ldr from the main thread, given the start params. 2917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // |pp_error| is set by CallOnMainThread (should be PP_OK). 2927dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch void StartSelLdrOnMainThread(int32_t pp_error, 2937dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ServiceRuntime* service_runtime, 2947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch const SelLdrStartParams& params, 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pp::CompletionCallback callback); 2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Signals that StartSelLdr has finished. 2985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SignalStartSelLdrDone(int32_t pp_error, 2995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool* started, 3005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ServiceRuntime* service_runtime); 3015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void LoadNexeAndStart(int32_t pp_error, 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) nacl::DescWrapper* wrapper, 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ServiceRuntime* service_runtime, 3055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const pp::CompletionCallback& crash_cb); 3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback used when getting the URL for the .nexe file. If the URL loading 3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is successful, the file descriptor is opened and can be passed to sel_ldr 3095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // with the sandbox on. 3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NexeFileDidOpen(int32_t pp_error); 3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NexeFileDidOpenContinuation(int32_t pp_error); 3125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback used when the reverse channel closes. This is an 3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // asynchronous event that might turn into a JavaScript error or 3155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // crash event -- this is controlled by the two state variables 3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // nacl_ready_state_ and nexe_error_reported_: If an error or crash 3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // had already been reported, no additional crash event is 3185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // generated. If no error has been reported but nacl_ready_state_ 3195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is not DONE, then the loadend event has not been reported, and we 3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // enqueue an error event followed by loadend. If nacl_ready_state_ 3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is DONE, then we are in the post-loadend (we need temporal 3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // predicate symbols), and we enqueue a crash event. 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NexeDidCrash(int32_t pp_error); 3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback used when a .nexe is translated from bitcode. If the translation 3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // is successful, the file descriptor is opened and can be passed to sel_ldr 3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // with the sandbox on. 3285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void BitcodeDidTranslate(int32_t pp_error); 3295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void BitcodeDidTranslateContinuation(int32_t pp_error); 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // NaCl ISA selection manifest file support. The manifest file is specified 3325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // using the "nacl" attribute in the <embed> tag. First, the manifest URL (or 3335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // data: URI) is fetched, then the JSON is parsed. Once a valid .nexe is 3345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // chosen for the sandbox ISA, any current service runtime is shut down, the 3355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // .nexe is loaded and run. 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback used when getting the manifest file as a buffer (e.g., data URIs) 3385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NaClManifestBufferReady(int32_t pp_error); 3395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback used when getting the manifest file as a local file descriptor. 3415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void NaClManifestFileDidOpen(int32_t pp_error); 3425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Processes the JSON manifest string and starts loading the nexe. 3445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void ProcessNaClManifest(const nacl::string& manifest_json); 3455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Parses the JSON in |manifest_json| and retains a Manifest in 3475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |manifest_| for use by subsequent resource lookups. 3485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // On success, |true| is returned and |manifest_| is updated to 3495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // contain a Manifest that is used by SelectNexeURLFromManifest. 3505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // On failure, |false| is returned, and |manifest_| is unchanged. 3515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool SetManifestObject(const nacl::string& manifest_json, 3525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ErrorInfo* error_info); 3535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Logs timing information to a UMA histogram, and also logs the same timing 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // information divided by the size of the nexe to another histogram. 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void HistogramStartupTimeSmall(const std::string& name, float dt); 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void HistogramStartupTimeMedium(const std::string& name, float dt); 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // This NEXE is being used as a content type handler rather than directly by 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // an HTML document. 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool NexeIsContentHandler() const; 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback used when loading a URL for SRPC-based StreamAsFile(). 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void UrlDidOpenForStreamAsFile(int32_t pp_error, 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FileDownloader*& url_downloader, 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_CompletionCallback pp_callback); 3675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Copy the main service runtime's most recent NaClLog output to the 3695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // JavaScript console. Valid to use only after a crash, e.g., via a 3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // detail level LOG_FATAL NaClLog entry. If the crash was not due 3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to a LOG_FATAL this method will do nothing. 3725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void CopyCrashLogToJsConsole(); 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 374c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Open an app file by requesting a file descriptor from the browser. This 375c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // method first checks that the url is for an installed file before making the 376c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // request so it won't slow down non-installed file downloads. 377c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool OpenURLFast(const nacl::string& url, FileDownloader* downloader); 378c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 379f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void set_nacl_ready_state(ReadyState state); 380f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 381f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void SetExitStatusOnMainThread(int32_t pp_error, int exit_status); 382f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 3835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::map<std::string, std::string> args_; 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Keep track of the NaCl module subprocess that was spun up in the plugin. 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) NaClSubprocess main_subprocess_; 3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::string plugin_base_url_; 3895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::string manifest_base_url_; 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::string manifest_url_; 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ReadyState nacl_ready_state_; 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool nexe_error_reported_; // error or crash reported 3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::DescWrapperFactory* wrapper_factory_; 3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // File download support. |nexe_downloader_| can be opened with a specific 3975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // callback to run when the file has been downloaded and is opened for 3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // reading. We use one downloader for all URL downloads to prevent issuing 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // multiple GETs that might arrive out of order. For example, this will 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // prevent a GET of a NaCl manifest while a .nexe GET is pending. Note that 4015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // this will also prevent simultaneous handling of multiple .nexes on a page. 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) FileDownloader nexe_downloader_; 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pp::CompletionCallbackFactory<Plugin> callback_factory_; 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::scoped_ptr<PnaclCoordinator> pnacl_coordinator_; 4065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The manifest dictionary. Used for looking up resources to be loaded. 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::scoped_ptr<Manifest> manifest_; 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URL processing interface for use in looking up resources in manifests. 4105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const pp::URLUtil_Dev* url_util_; 4115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // PPAPI Dev interfaces are disabled by default. 4135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool enable_dev_interfaces_; 4145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // A flag indicating if the NaCl executable is being loaded from an installed 4162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // application. This flag is used to bucket UMA statistics more precisely to 4172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // help determine whether nexe loading problems are caused by networking 4182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // issues. (Installed applications will be loaded from disk.) 4192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Unfortunately, the definition of what it means to be part of an installed 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // application is a little murky - for example an installed application can 4212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // register a mime handler that loads NaCl executables into an arbitrary web 4222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // page. As such, the flag actually means "our best guess, based on the URLs 4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // for NaCl resources that we have seen so far". 4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_installed_; 4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If we get a DidChangeView event before the nexe is loaded, we store it and 4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // replay it to nexe after it's loaded. We need to replay when this View 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // resource is non-is_null(). 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pp::View view_to_replay_; 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // If we get a HandleDocumentLoad event before the nexe is loaded, we store 4325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // it and replay it to nexe after it's loaded. We need to replay when this 4335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // URLLoader resource is non-is_null(). 4345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) pp::URLLoader document_load_to_replay_; 4355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) nacl::string mime_type_; 4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Keep track of the FileDownloaders created to fetch urls. 4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<FileDownloader*> url_downloaders_; 4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Keep track of file descriptors opened by StreamAsFile(). 4415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // These are owned by the browser. 4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::map<nacl::string, NaClFileInfoAutoCloser*> url_file_info_map_; 4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Used for NexeFileDidOpenContinuation 4455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t load_start_; 4465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t init_time_; 4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t ready_time_; 4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) size_t nexe_size_; 4505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Callback to receive .nexe and .dso download progress notifications. 4525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static void UpdateDownloadProgress( 4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Instance pp_instance, 4545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) PP_Resource pp_resource, 4555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t bytes_sent, 4565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t total_bytes_to_be_sent, 4575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t bytes_received, 4585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t total_bytes_to_be_received); 4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Finds the file downloader which owns the given URL loader. This is used 4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // in UpdateDownloadProgress to map a url loader back to the URL being 4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // downloaded. 4635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const FileDownloader* FindFileDownloader(PP_Resource url_loader) const; 4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int64_t time_of_last_progress_event_; 466f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int exit_status_; 4675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const PPB_NaCl_Private* nacl_interface_; 4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pp::UMAPrivate uma_interface_; 4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace plugin 4735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ 475