Support Mojo typemaps to IDL dictionaries |
|||||||||||||
Issue descriptionThere are many cases in Blink were we pass parameters that comes from script in the form of an autogenerated class (defined in WebIDL as a dictionary) to a Mojo method. An example of this is the USB::requestDevice() method which takes an array of USBDeviceFilter objects and passes them to the device::usb::ChooserService::GetPermission() method. The definitions of USBDeviceFilter in USBDeviceFilter.idl and device::usb::DeviceFilter in device_manager.mojom are effectively identical and it would be useful if they could be typemapped together. Unfortunately typemapping a Mojo struct to an IDL dictionary is not possible because the autogenerated Blink object is garbage collected and the Mojo code generator is unaware of the requirements of garbage collected objects, such as storing pointers to them in Persistent wrappers when they are fields of a non-GCed object or storing them in WTF::HeapVector instead of WTF::Vector.
,
Mar 9 2017
Adding haraken@ for an opinion on the best way to handle Mojo structs holding GCed objects. I think I was incorrect to suggest mapping to WTF::HeapVector<Foo>. WTF::Vector<Persistent<Foo>> is the correct option because it does not require the containing object to be traced.
,
Mar 9 2017
I also remember now my objection to typemapping to Persistent<Foo>. I makes sense for struct members but not for Mojo function signatures, which should use raw pointers.
,
Mar 9 2017
Vectors of Persistents are pretty high overhead. In this case this is just about taking inputs to an IPC, so mojo shouldn't need to store anything into a Persistent just serialize the data down into the pipe? It's only return values that would require vending GC'ed objects. If we're going to support that I think I'd prefer we just made the entire return value GC'ed and used HeapVector, etc.
,
Mar 9 2017
Due to the way WebIDL works yes, we essentially only need to support the Blink to Mojo mapping path since data passing the other direction is usually in an IDL defined interface, not a dictionary. However since Mojo represents method calls as structs passed over a pipe we do need a way to have a valid struct containing a GCed object, at least temporarily. It would be nice if Persistent<HeapVector<Foo>> were valid. Maybe it is?
,
Mar 10 2017
We have PersistentHeapVector :D https://cs.chromium.org/search/?q=persistentheapvector&sq=package:chromium&type=cs Just to confirm: The vectors are guaranteed to be released in a finite time period, right? Otherwise, the persistent handle will cause memory leaks.
,
Mar 10 2017
So for some examples:
The signature for the GetPermission() method defined in chooser_service.mojom we would be,
void GetPermission(WTF::HeapVector<blink::USBDeviceFilter> device_filters,
const GetPermissionCallback& callback);
The EnumerationOptions struct defined in device_manager.mojom would be (simplified),
class EnumerationOptions {
public:
WTF::Optional<WTF::PersistentHeapVector<blink::USBDeviceFilter>> filters;
private:
DISALLOW_COPY_AND_ASSIGN(EnumerationOptions);
};
The signature of the ControlTransferIn() method defined in device.mojom would be,
void ControlTransferIn(blink::USBControlTransferParameters* params, uint32_t length,
uint32_t timeout, const ControlTransferInCallback& callback);
,
Mar 10 2017
,
Mar 14 2017
After discussing this with yzshen@ and rockot@ we agree that this work is worthwhile but there is no current owner. To implement this we need to add two features to the bindings generator: 1. Allow an annotation on a type mapping (such as [gc]) to select a different variant configuration than the default for that subsystem. 2. Allow a variant to define separate types to be used for struct members and function signatures. This way the blink_gc variant could use raw pointers and Heap* collections for function signatures and Persistent<> fields and PersistentHeap* collections for struct fields.
,
Mar 14 2017
,
Mar 15 2017
,
Mar 15 2017
,
Mar 23 2017
,
Jul 8 2017
,
Jul 10 2017
Allowing a variant to specify separate types for struct members and method signatures would also allow the Chromium variant to accept base::StringPiece in function arguments which may reduce some copying of strings. A note for bugs marked as blocked on this issue: A workaround is to use an old-style mojo::TypeConverter specialization instead of a typemap.
,
Jul 18 2017
,
Dec 21 2017
Closing this as there is now consensus on taking a different approach, and it has been documented here: https://chromium.googlesource.com/chromium/src/+/master/docs/security/mojo.md#do-not-write-one_off-functions-to-convert-to_from-mojo-types
,
Nov 19
I was discussing with Ken the best way to typemap some IndexedDB mojom types to Blink GC'd types like IDBKeyRange which is based on ScriptWrappable. After discussing, Ken pointed out this FR and said this might be worth re-opening, so marking it Untriaged for review.
,
Nov 19
peria, could you take a look? You've looked at IDLDictionary recently.
,
Nov 21
Yes, if I can help you from WebIDL bindings' point. |
|||||||||||||
►
Sign in to add a comment |
|||||||||||||
Comment 1 by yzshen@chromium.org
, Mar 9 2017