GearyWebExtension: Add support for sending messages from JS to client

Define a vala-backed JS class in the extension and make that available
to pages when they are registered. Add some helper JS to PageState for
defining message sending functions. Listen for these in
Components.WebView and dispatch to the registered callback for it.
This commit is contained in:
Michael Gratton 2020-08-28 09:49:46 +10:00 committed by Michael James Gratton
parent db69807836
commit 6162785d99
3 changed files with 127 additions and 0 deletions

View file

@ -200,3 +200,12 @@ PageState.prototype = {
throw this.testResult;
}
};
let MessageSender = function(name) {
return function() {
// Since typeof(arguments) == 'object', convert to an array so
// that Components.WebView.MessageCallback callbacks get
// arrays or tuples rather than dicts as arguments
_GearyWebExtension.send(name, Array.from(arguments));
};
};