| OLD | NEW |
| 1 // -*- c++ -*- | 1 // -*- c++ -*- |
| 2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 // Use of this source code is governed by a BSD-style license that can be | 3 // Use of this source code is governed by a BSD-style license that can be |
| 4 // found in the LICENSE file. | 4 // found in the LICENSE file. |
| 5 | 5 |
| 6 // The portable representation of an instance and root scriptable object. | 6 // The portable representation of an instance and root scriptable object. |
| 7 // The PPAPI version of the plugin instantiates a subclass of this class. | 7 // The PPAPI version of the plugin instantiates a subclass of this class. |
| 8 | 8 |
| 9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ | 9 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ |
| 10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ | 10 #define NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ |
| 11 | 11 |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 | 13 |
| 14 #include <map> | 14 #include <map> |
| 15 #include <queue> | 15 #include <queue> |
| 16 #include <set> | 16 #include <set> |
| 17 #include <string> | 17 #include <string> |
| 18 #include <vector> | 18 #include <vector> |
| 19 | 19 |
| 20 #include "native_client/src/include/nacl_macros.h" | 20 #include "native_client/src/include/nacl_macros.h" |
| 21 #include "native_client/src/include/nacl_scoped_ptr.h" | 21 #include "native_client/src/include/nacl_scoped_ptr.h" |
| 22 #include "native_client/src/include/nacl_string.h" | 22 #include "native_client/src/include/nacl_string.h" |
| 23 #include "native_client/src/trusted/plugin/file_downloader.h" | 23 #include "native_client/src/trusted/plugin/file_downloader.h" |
| 24 #include "native_client/src/trusted/plugin/method_map.h" | |
| 25 #include "native_client/src/trusted/plugin/nacl_subprocess.h" | 24 #include "native_client/src/trusted/plugin/nacl_subprocess.h" |
| 26 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" | 25 #include "native_client/src/trusted/plugin/pnacl_coordinator.h" |
| 27 #include "native_client/src/trusted/plugin/service_runtime.h" | 26 #include "native_client/src/trusted/plugin/service_runtime.h" |
| 28 #include "native_client/src/trusted/plugin/utility.h" | 27 #include "native_client/src/trusted/plugin/utility.h" |
| 29 | 28 |
| 30 #include "ppapi/cpp/private/var_private.h" | 29 #include "ppapi/cpp/private/var_private.h" |
| 31 // for pp::VarPrivate | 30 // for pp::VarPrivate |
| 32 #include "ppapi/cpp/private/instance_private.h" | 31 #include "ppapi/cpp/private/instance_private.h" |
| 33 #include "ppapi/cpp/rect.h" | 32 #include "ppapi/cpp/rect.h" |
| 34 #include "ppapi/cpp/url_loader.h" | 33 #include "ppapi/cpp/url_loader.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 56 namespace ppapi_proxy { | 55 namespace ppapi_proxy { |
| 57 class BrowserPpp; | 56 class BrowserPpp; |
| 58 } | 57 } |
| 59 | 58 |
| 60 namespace plugin { | 59 namespace plugin { |
| 61 | 60 |
| 62 class ErrorInfo; | 61 class ErrorInfo; |
| 63 class Manifest; | 62 class Manifest; |
| 64 class PnaclCoordinator; | 63 class PnaclCoordinator; |
| 65 class ProgressEvent; | 64 class ProgressEvent; |
| 66 class ScriptableHandle; | 65 class ScriptablePlugin; |
| 67 | |
| 68 typedef enum { | |
| 69 METHOD_CALL = 0, | |
| 70 PROPERTY_GET, | |
| 71 PROPERTY_SET | |
| 72 } CallType; | |
| 73 | |
| 74 | 66 |
| 75 class Plugin : public pp::InstancePrivate { | 67 class Plugin : public pp::InstancePrivate { |
| 76 public: | 68 public: |
| 77 // Factory method for creation. | 69 // Factory method for creation. |
| 78 static Plugin* New(PP_Instance instance); | 70 static Plugin* New(PP_Instance instance); |
| 79 | 71 |
| 80 // ----- Methods inherited from pp::Instance: | 72 // ----- Methods inherited from pp::Instance: |
| 81 | 73 |
| 82 // Initializes this plugin with <embed/object ...> tag attribute count |argc|, | 74 // Initializes this plugin with <embed/object ...> tag attribute count |argc|, |
| 83 // names |argn| and values |argn|. Returns false on failure. | 75 // names |argn| and values |argn|. Returns false on failure. |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 }; | 155 }; |
| 164 // Report successful loading of a module. | 156 // Report successful loading of a module. |
| 165 void ReportLoadSuccess(LengthComputable length_computable, | 157 void ReportLoadSuccess(LengthComputable length_computable, |
| 166 uint64_t loaded_bytes, | 158 uint64_t loaded_bytes, |
| 167 uint64_t total_bytes); | 159 uint64_t total_bytes); |
| 168 // Report an error that was encountered while loading a module. | 160 // Report an error that was encountered while loading a module. |
| 169 void ReportLoadError(const ErrorInfo& error_info); | 161 void ReportLoadError(const ErrorInfo& error_info); |
| 170 // Report loading a module was aborted, typically due to user action. | 162 // Report loading a module was aborted, typically due to user action. |
| 171 void ReportLoadAbort(); | 163 void ReportLoadAbort(); |
| 172 | 164 |
| 165 // Write a text string on the JavaScript console. |
| 166 void AddToConsole(const nacl::string& text); |
| 167 |
| 173 // Dispatch a JavaScript event to indicate a key step in loading. | 168 // Dispatch a JavaScript event to indicate a key step in loading. |
| 174 // |event_type| is a character string indicating which type of progress | 169 // |event_type| is a character string indicating which type of progress |
| 175 // event (loadstart, progress, error, abort, load, loadend). Events are | 170 // event (loadstart, progress, error, abort, load, loadend). Events are |
| 176 // enqueued on the JavaScript event loop, which then calls back through | 171 // enqueued on the JavaScript event loop, which then calls back through |
| 177 // DispatchProgressEvent. | 172 // DispatchProgressEvent. |
| 178 void EnqueueProgressEvent(const char* event_type); | 173 void EnqueueProgressEvent(const char* event_type); |
| 179 void EnqueueProgressEvent(const char* event_type, | 174 void EnqueueProgressEvent(const char* event_type, |
| 180 const nacl::string& url, | 175 const nacl::string& url, |
| 181 LengthComputable length_computable, | 176 LengthComputable length_computable, |
| 182 uint64_t loaded_bytes, | 177 uint64_t loaded_bytes, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 195 void ReportSelLdrLoadStatus(int status); | 190 void ReportSelLdrLoadStatus(int status); |
| 196 | 191 |
| 197 // Report nexe death after load to JS and shut down the proxy. | 192 // Report nexe death after load to JS and shut down the proxy. |
| 198 void ReportDeadNexe(); | 193 void ReportDeadNexe(); |
| 199 | 194 |
| 200 // The embed/object tag argument list. | 195 // The embed/object tag argument list. |
| 201 int argc() const { return argc_; } | 196 int argc() const { return argc_; } |
| 202 char** argn() const { return argn_; } | 197 char** argn() const { return argn_; } |
| 203 char** argv() const { return argv_; } | 198 char** argv() const { return argv_; } |
| 204 | 199 |
| 205 BrowserInterface* browser_interface() const { return browser_interface_; } | |
| 206 Plugin* plugin() const { return const_cast<Plugin*>(this); } | 200 Plugin* plugin() const { return const_cast<Plugin*>(this); } |
| 207 | 201 |
| 208 // URL resolution support. | 202 // URL resolution support. |
| 209 // plugin_base_url is the URL used for resolving relative URLs used in | 203 // plugin_base_url is the URL used for resolving relative URLs used in |
| 210 // src="...". | 204 // src="...". |
| 211 nacl::string plugin_base_url() const { return plugin_base_url_; } | 205 nacl::string plugin_base_url() const { return plugin_base_url_; } |
| 212 void set_plugin_base_url(nacl::string url) { plugin_base_url_ = url; } | 206 void set_plugin_base_url(nacl::string url) { plugin_base_url_ = url; } |
| 213 // manifest_base_url is the URL used for resolving relative URLs mentioned | 207 // manifest_base_url is the URL used for resolving relative URLs mentioned |
| 214 // in manifest files. If the manifest is a data URI, this is an empty string. | 208 // in manifest files. If the manifest is a data URI, this is an empty string. |
| 215 nacl::string manifest_base_url() const { return manifest_base_url_; } | 209 nacl::string manifest_base_url() const { return manifest_base_url_; } |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 // NB: this is currently invoked from the main thread. If we ever | 249 // NB: this is currently invoked from the main thread. If we ever |
| 256 // move it off the main thread (eliminate the possibility of a | 250 // move it off the main thread (eliminate the possibility of a |
| 257 // malicious nexe that isn't linked against / doesn't use our | 251 // malicious nexe that isn't linked against / doesn't use our |
| 258 // ppapi_proxy code that blocks the main thread on the RPCs used | 252 // ppapi_proxy code that blocks the main thread on the RPCs used |
| 259 // here), then we will need to take care to ensure that the error | 253 // here), then we will need to take care to ensure that the error |
| 260 // and crash reporting state machine (see NexeDidCrash comment) | 254 // and crash reporting state machine (see NexeDidCrash comment) |
| 261 // continues to work. | 255 // continues to work. |
| 262 bool StartProxiedExecution(NaClSrpcChannel* srpc_channel, | 256 bool StartProxiedExecution(NaClSrpcChannel* srpc_channel, |
| 263 ErrorInfo* error_info); | 257 ErrorInfo* error_info); |
| 264 | 258 |
| 265 // Determines whether experimental APIs are usable. | 259 // Support for property getting. |
| 266 static bool ExperimentalJavaScriptApisAreEnabled(); | 260 typedef void (Plugin::* PropertyGetter)(NaClSrpcArg* prop_value); |
| 267 | 261 void AddPropertyGet(const nacl::string& prop_name, PropertyGetter getter); |
| 268 // Methods for method and property dispatch. | 262 bool HasProperty(const nacl::string& prop_name); |
| 269 bool InitParams(uintptr_t method_id, CallType call_type, SrpcParams* params); | 263 bool GetProperty(const nacl::string& prop_name, NaClSrpcArg* prop_value); |
| 270 bool HasMethod(uintptr_t method_id, CallType call_type); | 264 // The supported property getters. |
| 271 bool Invoke(uintptr_t method_id, CallType call_type, SrpcParams* params); | 265 void GetExitStatus(NaClSrpcArg* prop_value); |
| 272 std::vector<uintptr_t>* GetPropertyIdentifiers() { | 266 void GetLastError(NaClSrpcArg* prop_value); |
| 273 return property_get_methods_.Keys(); | 267 void GetReadyStateProperty(NaClSrpcArg* prop_value); |
| 274 } | |
| 275 | 268 |
| 276 // The size returned when a file download operation is unable to determine | 269 // The size returned when a file download operation is unable to determine |
| 277 // the size of the file to load. W3C ProgressEvents specify that unknown | 270 // the size of the file to load. W3C ProgressEvents specify that unknown |
| 278 // sizes return 0. | 271 // sizes return 0. |
| 279 static const uint64_t kUnknownBytes = 0; | 272 static const uint64_t kUnknownBytes = 0; |
| 280 | 273 |
| 281 // Getter for PPAPI proxy interface. | 274 // Getter for PPAPI proxy interface. |
| 282 ppapi_proxy::BrowserPpp* ppapi_proxy() const { return ppapi_proxy_; } | 275 ppapi_proxy::BrowserPpp* ppapi_proxy() const { return ppapi_proxy_; } |
| 283 | 276 |
| 284 // Called back by CallOnMainThread. Dispatches the first enqueued progress | 277 // Called back by CallOnMainThread. Dispatches the first enqueued progress |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 #ifndef HACK_FOR_MACOS_HANG_REMOVED | 323 #ifndef HACK_FOR_MACOS_HANG_REMOVED |
| 331 void XYZZY(const nacl::string& url, pp::VarPrivate js_callback); | 324 void XYZZY(const nacl::string& url, pp::VarPrivate js_callback); |
| 332 #endif // HACK_FOR_MACOS_HANG_REMOVED | 325 #endif // HACK_FOR_MACOS_HANG_REMOVED |
| 333 // Prevent construction and destruction from outside the class: | 326 // Prevent construction and destruction from outside the class: |
| 334 // must use factory New() method instead. | 327 // must use factory New() method instead. |
| 335 explicit Plugin(PP_Instance instance); | 328 explicit Plugin(PP_Instance instance); |
| 336 // The browser will invoke the destructor via the pp::Instance | 329 // The browser will invoke the destructor via the pp::Instance |
| 337 // pointer to this object, not from base's Delete(). | 330 // pointer to this object, not from base's Delete(). |
| 338 ~Plugin(); | 331 ~Plugin(); |
| 339 | 332 |
| 340 bool Init(BrowserInterface* browser_interface, | 333 bool Init(int argc, char* argn[], char* argv[]); |
| 341 int argc, | |
| 342 char* argn[], | |
| 343 char* argv[]); | |
| 344 void LoadMethods(); | |
| 345 // Shuts down socket connection, service runtime, and receive thread, | 334 // Shuts down socket connection, service runtime, and receive thread, |
| 346 // in this order, for the main nacl subprocess. | 335 // in this order, for the main nacl subprocess. |
| 347 void ShutDownSubprocesses(); | 336 void ShutDownSubprocesses(); |
| 348 | 337 |
| 349 ScriptableHandle* scriptable_handle() const { return scriptable_handle_; } | 338 ScriptablePlugin* scriptable_plugin() const { return scriptable_plugin_; } |
| 350 void set_scriptable_handle(ScriptableHandle* scriptable_handle) { | 339 void set_scriptable_plugin(ScriptablePlugin* scriptable_plugin) { |
| 351 scriptable_handle_ = scriptable_handle; | 340 scriptable_plugin_ = scriptable_plugin; |
| 352 } | 341 } |
| 353 | 342 |
| 354 // Access the service runtime for the main NaCl subprocess. | 343 // Access the service runtime for the main NaCl subprocess. |
| 355 ServiceRuntime* main_service_runtime() const { | 344 ServiceRuntime* main_service_runtime() const { |
| 356 return main_subprocess_.service_runtime(); | 345 return main_subprocess_.service_runtime(); |
| 357 } | 346 } |
| 358 | 347 |
| 359 // Setting the properties and methods exported. | |
| 360 void AddPropertyGet(RpcFunction function_ptr, | |
| 361 const char* name, | |
| 362 const char* outs); | |
| 363 | |
| 364 // Help load a nacl module, from the file specified in wrapper. | 348 // Help load a nacl module, from the file specified in wrapper. |
| 365 // This will fully initialize the |subprocess| if the load was successful. | 349 // This will fully initialize the |subprocess| if the load was successful. |
| 366 bool LoadNaClModuleCommon(nacl::DescWrapper* wrapper, | 350 bool LoadNaClModuleCommon(nacl::DescWrapper* wrapper, |
| 367 NaClSubprocess* subprocess, | 351 NaClSubprocess* subprocess, |
| 368 const Manifest* manifest, | 352 const Manifest* manifest, |
| 369 bool should_report_uma, | 353 bool should_report_uma, |
| 370 ErrorInfo* error_info, | 354 ErrorInfo* error_info, |
| 371 pp::CompletionCallback init_done_cb, | 355 pp::CompletionCallback init_done_cb, |
| 372 pp::CompletionCallback crash_cb); | 356 pp::CompletionCallback crash_cb); |
| 373 bool StartSrpcServices(NaClSubprocess* subprocess, ErrorInfo* error_info); | |
| 374 bool StartSrpcServicesCommon(NaClSubprocess* subprocess, | |
| 375 ErrorInfo* error_info); | |
| 376 bool StartJSObjectProxy(NaClSubprocess* subprocess, ErrorInfo* error_info); | |
| 377 | |
| 378 MethodInfo* GetMethodInfo(uintptr_t method_id, CallType call_type); | |
| 379 | 357 |
| 380 // Callback used when getting the URL for the .nexe file. If the URL loading | 358 // Callback used when getting the URL for the .nexe file. If the URL loading |
| 381 // is successful, the file descriptor is opened and can be passed to sel_ldr | 359 // is successful, the file descriptor is opened and can be passed to sel_ldr |
| 382 // with the sandbox on. | 360 // with the sandbox on. |
| 383 void NexeFileDidOpen(int32_t pp_error); | 361 void NexeFileDidOpen(int32_t pp_error); |
| 384 void NexeFileDidOpenContinuation(int32_t pp_error); | 362 void NexeFileDidOpenContinuation(int32_t pp_error); |
| 385 | 363 |
| 386 // Callback used when the reverse channel closes. This is an | 364 // Callback used when the reverse channel closes. This is an |
| 387 // asynchronous event that might turn into a JavaScript error or | 365 // asynchronous event that might turn into a JavaScript error or |
| 388 // crash event -- this is controlled by the two state variables | 366 // crash event -- this is controlled by the two state variables |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 bool NexeIsContentHandler() const; | 425 bool NexeIsContentHandler() const; |
| 448 | 426 |
| 449 // Callback used when loading a URL for SRPC-based StreamAsFile(). | 427 // Callback used when loading a URL for SRPC-based StreamAsFile(). |
| 450 void UrlDidOpenForStreamAsFile(int32_t pp_error, | 428 void UrlDidOpenForStreamAsFile(int32_t pp_error, |
| 451 FileDownloader*& url_downloader, | 429 FileDownloader*& url_downloader, |
| 452 PP_CompletionCallback pp_callback); | 430 PP_CompletionCallback pp_callback); |
| 453 | 431 |
| 454 // Shuts down the proxy for PPAPI nexes. | 432 // Shuts down the proxy for PPAPI nexes. |
| 455 void ShutdownProxy(); // Nexe shutdown + proxy deletion. | 433 void ShutdownProxy(); // Nexe shutdown + proxy deletion. |
| 456 | 434 |
| 457 BrowserInterface* browser_interface_; | 435 ScriptablePlugin* scriptable_plugin_; |
| 458 ScriptableHandle* scriptable_handle_; | |
| 459 | 436 |
| 460 int argc_; | 437 int argc_; |
| 461 char** argn_; | 438 char** argn_; |
| 462 char** argv_; | 439 char** argv_; |
| 463 | 440 |
| 464 // Keep track of the NaCl module subprocess that was spun up in the plugin. | 441 // Keep track of the NaCl module subprocess that was spun up in the plugin. |
| 465 NaClSubprocess main_subprocess_; | 442 NaClSubprocess main_subprocess_; |
| 466 | 443 |
| 467 nacl::string plugin_base_url_; | 444 nacl::string plugin_base_url_; |
| 468 nacl::string manifest_base_url_; | 445 nacl::string manifest_base_url_; |
| 469 nacl::string manifest_url_; | 446 nacl::string manifest_url_; |
| 470 ReadyState nacl_ready_state_; | 447 ReadyState nacl_ready_state_; |
| 471 bool nexe_error_reported_; // error or crash reported | 448 bool nexe_error_reported_; // error or crash reported |
| 472 | 449 |
| 473 nacl::DescWrapperFactory* wrapper_factory_; | 450 nacl::DescWrapperFactory* wrapper_factory_; |
| 474 | 451 |
| 475 MethodMap property_get_methods_; | 452 std::map<nacl::string, PropertyGetter> property_getters_; |
| 476 | 453 |
| 477 // File download support. |nexe_downloader_| can be opened with a specific | 454 // File download support. |nexe_downloader_| can be opened with a specific |
| 478 // callback to run when the file has been downloaded and is opened for | 455 // callback to run when the file has been downloaded and is opened for |
| 479 // reading. We use one downloader for all URL downloads to prevent issuing | 456 // reading. We use one downloader for all URL downloads to prevent issuing |
| 480 // multiple GETs that might arrive out of order. For example, this will | 457 // multiple GETs that might arrive out of order. For example, this will |
| 481 // prevent a GET of a NaCl manifest while a .nexe GET is pending. Note that | 458 // prevent a GET of a NaCl manifest while a .nexe GET is pending. Note that |
| 482 // this will also prevent simultaneous handling of multiple .nexes on a page. | 459 // this will also prevent simultaneous handling of multiple .nexes on a page. |
| 483 FileDownloader nexe_downloader_; | 460 FileDownloader nexe_downloader_; |
| 484 pp::CompletionCallbackFactory<Plugin> callback_factory_; | 461 pp::CompletionCallbackFactory<Plugin> callback_factory_; |
| 485 | 462 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 // in UpdateDownloadProgress to map a url loader back to the URL being | 530 // in UpdateDownloadProgress to map a url loader back to the URL being |
| 554 // downloaded. | 531 // downloaded. |
| 555 const FileDownloader* FindFileDownloader(PP_Resource url_loader) const; | 532 const FileDownloader* FindFileDownloader(PP_Resource url_loader) const; |
| 556 | 533 |
| 557 int64_t time_of_last_progress_event_; | 534 int64_t time_of_last_progress_event_; |
| 558 }; | 535 }; |
| 559 | 536 |
| 560 } // namespace plugin | 537 } // namespace plugin |
| 561 | 538 |
| 562 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ | 539 #endif // NATIVE_CLIENT_SRC_TRUSTED_PLUGIN_PLUGIN_H_ |
| OLD | NEW |