| 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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 /// | 237 /// |
| 238 /// @return true if the data was handled, false otherwise. | 238 /// @return true if the data was handled, false otherwise. |
| 239 virtual bool HandleDocumentLoad(const URLLoader& url_loader); | 239 virtual bool HandleDocumentLoad(const URLLoader& url_loader); |
| 240 | 240 |
| 241 /// HandleMessage() is a function that the browser calls when PostMessage() | 241 /// HandleMessage() is a function that the browser calls when PostMessage() |
| 242 /// is invoked on the DOM element for the instance in JavaScript. Note | 242 /// is invoked on the DOM element for the instance in JavaScript. Note |
| 243 /// that PostMessage() in the JavaScript interface is asynchronous, meaning | 243 /// that PostMessage() in the JavaScript interface is asynchronous, meaning |
| 244 /// JavaScript execution will not be blocked while HandleMessage() is | 244 /// JavaScript execution will not be blocked while HandleMessage() is |
| 245 /// processing the message. | 245 /// processing the message. |
| 246 /// | 246 /// |
| 247 /// When converting JavaScript arrays, any object properties whose name |
| 248 /// is not an array index are ignored. When passing arrays and objects, the |
| 249 /// entire reference graph will be converted and transferred. If the reference |
| 250 /// graph has cycles, the message will not be sent and an error will be logged |
| 251 /// to the console. |
| 252 /// |
| 247 /// <strong>Example:</strong> | 253 /// <strong>Example:</strong> |
| 248 /// | 254 /// |
| 249 /// The following JavaScript code invokes <code>HandleMessage</code>, passing | 255 /// The following JavaScript code invokes <code>HandleMessage</code>, passing |
| 250 /// the instance on which it was invoked, with <code>message</code> being a | 256 /// the instance on which it was invoked, with <code>message</code> being a |
| 251 /// string <code>Var</code> containing "Hello world!" | 257 /// string <code>Var</code> containing "Hello world!" |
| 252 /// | 258 /// |
| 253 /// @code{.html} | 259 /// @code{.html} |
| 254 /// | 260 /// |
| 255 /// <body> | 261 /// <body> |
| 256 /// <object id="plugin" | 262 /// <object id="plugin" |
| 257 /// type="application/x-ppapi-postMessage-example"/> | 263 /// type="application/x-ppapi-postMessage-example"/> |
| 258 /// <script type="text/javascript"> | 264 /// <script type="text/javascript"> |
| 259 /// document.getElementById('plugin').postMessage("Hello world!"); | 265 /// document.getElementById('plugin').postMessage("Hello world!"); |
| 260 /// </script> | 266 /// </script> |
| 261 /// </body> | 267 /// </body> |
| 262 /// | 268 /// |
| 263 /// @endcode | 269 /// @endcode |
| 264 /// | 270 /// |
| 265 /// Refer to PostMessage() for sending messages to JavaScript. | 271 /// Refer to PostMessage() for sending messages to JavaScript. |
| 266 /// | 272 /// |
| 267 /// @param[in] message A <code>Var</code> containing the data sent from | 273 /// @param[in] message A <code>Var</code> which has been converted from a |
| 268 /// JavaScript. Message can have an int32_t, double, bool, or string value | 274 /// JavaScript value. JavaScript array/object types are supported from Chrome |
| 269 /// (objects are not supported). | 275 /// M29 onward. All JavaScript values are copied when passing them to the |
| 276 /// plugin. |
| 270 virtual void HandleMessage(const Var& message); | 277 virtual void HandleMessage(const Var& message); |
| 271 | 278 |
| 272 /// @} | 279 /// @} |
| 273 | 280 |
| 274 /// @{ | 281 /// @{ |
| 275 /// @name PPB_Instance methods for querying the browser: | 282 /// @name PPB_Instance methods for querying the browser: |
| 276 | 283 |
| 277 /// BindGraphics() binds the given graphics as the current display surface. | 284 /// BindGraphics() binds the given graphics as the current display surface. |
| 278 /// The contents of this device is what will be displayed in the instance's | 285 /// The contents of this device is what will be displayed in the instance's |
| 279 /// area on the web page. The device must be a 2D or a 3D device. | 286 /// area on the web page. The device must be a 2D or a 3D device. |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 /// The instance then invokes PostMessage() as follows: | 453 /// The instance then invokes PostMessage() as follows: |
| 447 /// | 454 /// |
| 448 /// @code | 455 /// @code |
| 449 /// | 456 /// |
| 450 /// PostMessage(pp::Var("Hello world!")); | 457 /// PostMessage(pp::Var("Hello world!")); |
| 451 /// | 458 /// |
| 452 /// @endcode | 459 /// @endcode |
| 453 /// | 460 /// |
| 454 /// The browser will pop-up an alert saying "Hello world!" | 461 /// The browser will pop-up an alert saying "Hello world!" |
| 455 /// | 462 /// |
| 463 /// When passing array or dictionary <code>PP_Var</code>s, the entire |
| 464 /// reference graph will be converted and transferred. If the reference graph |
| 465 /// has cycles, the message will not be sent and an error will be logged to |
| 466 /// the console. |
| 467 /// |
| 456 /// Listeners for message events in JavaScript code will receive an object | 468 /// Listeners for message events in JavaScript code will receive an object |
| 457 /// conforming to the HTML 5 <code>MessageEvent</code> interface. | 469 /// conforming to the HTML 5 <code>MessageEvent</code> interface. |
| 458 /// Specifically, the value of message will be contained as a property called | 470 /// Specifically, the value of message will be contained as a property called |
| 459 /// data in the received <code>MessageEvent</code>. | 471 /// data in the received <code>MessageEvent</code>. |
| 460 /// | 472 /// |
| 461 /// This messaging system is similar to the system used for listening for | 473 /// This messaging system is similar to the system used for listening for |
| 462 /// messages from Web Workers. Refer to | 474 /// messages from Web Workers. Refer to |
| 463 /// <code>http://www.whatwg.org/specs/web-workers/current-work/</code> for | 475 /// <code>http://www.whatwg.org/specs/web-workers/current-work/</code> for |
| 464 /// further information. | 476 /// further information. |
| 465 /// | 477 /// |
| 466 /// Refer to HandleMessage() for receiving events from JavaScript. | 478 /// Refer to HandleMessage() for receiving events from JavaScript. |
| 467 /// | 479 /// |
| 468 /// @param[in] message A <code>Var</code> containing the data to be sent to | 480 /// @param[in] message A <code>Var</code> containing the data to be sent to |
| 469 /// JavaScript. Message can have a numeric, boolean, or string value; arrays | 481 /// JavaScript. Message can have a numeric, boolean, or string value. |
| 470 /// and dictionaries are not yet supported. Ref-counted var types are copied, | 482 /// Array/Dictionary types are supported from Chrome M29 onward. |
| 471 /// and are therefore not shared between the instance and the browser. | 483 /// All var types are copied when passing them to JavaScript. |
| 472 void PostMessage(const Var& message); | 484 void PostMessage(const Var& message); |
| 473 | 485 |
| 474 /// @} | 486 /// @} |
| 475 | 487 |
| 476 /// @{ | 488 /// @{ |
| 477 /// @name PPB_Console methods for logging to the console: | 489 /// @name PPB_Console methods for logging to the console: |
| 478 | 490 |
| 479 /// Logs the given message to the JavaScript console associated with the | 491 /// Logs the given message to the JavaScript console associated with the |
| 480 /// given plugin instance with the given logging level. The name of the plugin | 492 /// given plugin instance with the given logging level. The name of the plugin |
| 481 /// issuing the log message will be automatically prepended to the message. | 493 /// issuing the log message will be automatically prepended to the message. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 private: | 569 private: |
| 558 PP_Instance pp_instance_; | 570 PP_Instance pp_instance_; |
| 559 | 571 |
| 560 typedef std::map<std::string, void*> InterfaceNameToObjectMap; | 572 typedef std::map<std::string, void*> InterfaceNameToObjectMap; |
| 561 InterfaceNameToObjectMap interface_name_to_objects_; | 573 InterfaceNameToObjectMap interface_name_to_objects_; |
| 562 }; | 574 }; |
| 563 | 575 |
| 564 } // namespace pp | 576 } // namespace pp |
| 565 | 577 |
| 566 #endif // PPAPI_CPP_INSTANCE_H_ | 578 #endif // PPAPI_CPP_INSTANCE_H_ |
| OLD | NEW |