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

Side by Side Diff: ppapi/native_client/src/trusted/plugin/plugin.h

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

Powered by Google App Engine
This is Rietveld 408576698