Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef PPAPI_CPP_INSTANCE_H_ | 5 #ifndef PPAPI_CPP_INSTANCE_H_ |
| 6 #define PPAPI_CPP_INSTANCE_H_ | 6 #define PPAPI_CPP_INSTANCE_H_ |
| 7 | 7 |
| 8 /// @file | 8 /// @file |
| 9 /// This file defines the C++ wrapper for an instance. | 9 /// This file defines the C++ wrapper for an instance. |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 struct PP_InputEvent; | 26 struct PP_InputEvent; |
| 27 | 27 |
| 28 /// The C++ interface to the Pepper API. | 28 /// The C++ interface to the Pepper API. |
| 29 namespace pp { | 29 namespace pp { |
| 30 | 30 |
| 31 class Compositor; | 31 class Compositor; |
| 32 class Graphics2D; | 32 class Graphics2D; |
| 33 class Graphics3D; | 33 class Graphics3D; |
| 34 class InputEvent; | 34 class InputEvent; |
| 35 class InstanceHandle; | 35 class InstanceHandle; |
| 36 class MessageHandler; | |
| 37 class MessageLoop; | |
| 36 class Rect; | 38 class Rect; |
| 37 class URLLoader; | 39 class URLLoader; |
| 38 class Var; | 40 class Var; |
| 39 | 41 |
| 40 class Instance { | 42 class Instance { |
| 41 public: | 43 public: |
| 42 /// Default constructor. Construction of an instance should only be done in | 44 /// Default constructor. Construction of an instance should only be done in |
| 43 /// response to a browser request in <code>Module::CreateInstance</code>. | 45 /// response to a browser request in <code>Module::CreateInstance</code>. |
| 44 /// Otherwise, the instance will lack the proper bookkeeping in the browser | 46 /// Otherwise, the instance will lack the proper bookkeeping in the browser |
| 45 /// and in the C++ wrapper. | 47 /// and in the C++ wrapper. |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 /// further information. | 490 /// further information. |
| 489 /// | 491 /// |
| 490 /// Refer to HandleMessage() for receiving events from JavaScript. | 492 /// Refer to HandleMessage() for receiving events from JavaScript. |
| 491 /// | 493 /// |
| 492 /// @param[in] message A <code>Var</code> containing the data to be sent to | 494 /// @param[in] message A <code>Var</code> containing the data to be sent to |
| 493 /// JavaScript. Message can have a numeric, boolean, or string value. | 495 /// JavaScript. Message can have a numeric, boolean, or string value. |
| 494 /// Array/Dictionary types are supported from Chrome M29 onward. | 496 /// Array/Dictionary types are supported from Chrome M29 onward. |
| 495 /// All var types are copied when passing them to JavaScript. | 497 /// All var types are copied when passing them to JavaScript. |
| 496 void PostMessage(const Var& message); | 498 void PostMessage(const Var& message); |
| 497 | 499 |
| 500 /// Dev-Channel Only | |
| 501 /// | |
| 502 /// Registers a handler for receiving messages from JavaScript. If a handler | |
| 503 /// is registered this way, it will replace the Instance's HandleMessage | |
| 504 /// method, and all messages sent from JavaScript via postMessage and | |
| 505 /// postMessageAndAwaitResponse will be dispatched to <code>handler</code>. | |
|
bbudge
2014/09/18 12:41:17
s/handler/message_handler
| |
| 506 /// | |
| 507 /// The function calls will be dispatched via <code>message_loop</code>. This | |
| 508 /// means that the functions will be invoked on the thread to which | |
| 509 /// <code>message_loop</code> is attached, when <code>message_loop</code> is | |
| 510 /// run. It is illegal to pass the main thread message loop; | |
| 511 /// RegisterMessageHandler will return PP_ERROR_WRONG_THREAD in that case. | |
| 512 /// If you quit <code>message_loop</code> before calling Unregister(), | |
| 513 /// the browser will not be able to call functions in the plugin's message | |
| 514 /// handler any more. That could mean missing some messages or could cause a | |
| 515 /// leak if you depend on Destroy() to free hander data. So you should, | |
| 516 /// whenever possible, Unregister() the handler prior to quitting its event | |
| 517 /// loop. | |
| 518 /// | |
| 519 /// Attempting to register a message handler when one is already registered | |
| 520 /// will cause the current MessageHandler to be unregistered and replaced. In | |
| 521 /// that case, no messages will be sent to the "default" message handler | |
| 522 /// (pp::Instance::HandleMessage()). Messages will stop arriving at the prior | |
| 523 /// message handler and will begin to be dispatched at the new message | |
| 524 /// handler. | |
| 525 /// | |
| 526 /// @param[in] handler The plugin-provided object for handling messages. The | |
|
bbudge
2014/09/18 12:41:17
s/handler/message_handler
| |
| 527 /// instance does not take ownership of the pointer; it is up to the plugin to | |
| 528 /// ensure that |message_handler| lives until its WasUnregistered() function | |
| 529 /// is invoked. | |
| 530 /// @param[in] message_loop Represents the message loop on which | |
| 531 /// MessageHandler's functions should be invoked. | |
| 532 /// @return PP_OK on success, or an error from pp_errors.h. | |
| 533 int32_t RegisterMessageHandler(MessageHandler* message_handler, | |
| 534 const MessageLoop& message_loop); | |
| 535 | |
| 536 /// Unregisters the current message handler for this instance if one is | |
| 537 /// registered. After this call, the message handler (if one was | |
| 538 /// registered) will have "WasUnregistered" called on it and will receive no | |
| 539 /// further messages after that point. After that point, all messages sent | |
|
bbudge
2014/09/18 12:41:17
nit: I would eliminate the first "after that point
| |
| 540 /// from JavaScript using postMessage() will be dispatched to | |
| 541 /// pp::Instance::HandleMessage() on the main thread. Attempts to call | |
| 542 /// postMessageAndAwaitResponse() from JavaScript after that point will fail. | |
| 543 /// | |
| 544 /// Attempting to unregister a message handler when none is registered has no | |
| 545 /// effect. | |
| 546 void UnregisterMessageHandler(); | |
| 547 | |
| 498 /// @} | 548 /// @} |
| 499 | 549 |
| 500 /// @{ | 550 /// @{ |
| 501 /// @name PPB_Console methods for logging to the console: | 551 /// @name PPB_Console methods for logging to the console: |
| 502 | 552 |
| 503 /// Logs the given message to the JavaScript console associated with the | 553 /// Logs the given message to the JavaScript console associated with the |
| 504 /// given plugin instance with the given logging level. The name of the plugin | 554 /// given plugin instance with the given logging level. The name of the plugin |
| 505 /// issuing the log message will be automatically prepended to the message. | 555 /// issuing the log message will be automatically prepended to the message. |
| 506 /// The value may be any type of Var. | 556 /// The value may be any type of Var. |
| 507 void LogToConsole(PP_LogLevel level, const Var& value); | 557 void LogToConsole(PP_LogLevel level, const Var& value); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 581 private: | 631 private: |
| 582 PP_Instance pp_instance_; | 632 PP_Instance pp_instance_; |
| 583 | 633 |
| 584 typedef std::map<std::string, void*> InterfaceNameToObjectMap; | 634 typedef std::map<std::string, void*> InterfaceNameToObjectMap; |
| 585 InterfaceNameToObjectMap interface_name_to_objects_; | 635 InterfaceNameToObjectMap interface_name_to_objects_; |
| 586 }; | 636 }; |
| 587 | 637 |
| 588 } // namespace pp | 638 } // namespace pp |
| 589 | 639 |
| 590 #endif // PPAPI_CPP_INSTANCE_H_ | 640 #endif // PPAPI_CPP_INSTANCE_H_ |
| OLD | NEW |