IPDL Changes: Refcounted Types

Earlier this week, bug 1443954
<https://bugzilla.mozilla.org/show_bug.cgi?id=1443954> landed, which
improved support in IPDL for reference counted types, making it safer and
more ergonomic to directly use reference counted types (such as nsIURI,
nsIPrincipal, nsIInputStream, etc.) in IPDL protocols.

To declare a dependency on a refcounted type in IPDL, use the `using
refcounted` statement, for example:

using refcounted class nsIInputStream from "mozilla/ipc/IPCStreamUtils.h";

The type can then be referenced by their name. These types are passed by
raw pointer when used as an input, and passed by reference-to-RefPtr when
used as an output.

To implement ParamTraits (or IPDLParamTraits
for a refcounted type, specialize on the bare type:

struct ParamTraits<nsIPrincipal>
  static void Write(Message* aMsg, nsIPrincipal* aParam);
  static bool Read(const Message* aMsg, PickleIterator* aIter,
RefPtr<nsIPrincipal>* aResult);

These types may also be used within IPDL unions and IPDL structs. Please
prefer using these refcounted types directly over wrapper types like
`IPC::Principal` when possible.

- Nika
4/13/2018 5:50:32 PM
mozilla.dev.platform 6290 articles. 0 followers. Post Follow

0 Replies

Similar Articles

[PageSpeed] 39