Hi Gabriel,

On Thu, Jun 30, 2016 at 9:16 AM, Gabriel Ivașcu <ivascu.gabrie...@gmail.com>
wrote:

> Hi,
>
> I'm writing again because, after looking at the WebChannel-related
> code, it seems to me that this is rather Mozilla-specific code and not
> so easily usable in other contexts.
>

This is only partially true.  See below.


>
> WebChannel.jsm [0] seems to be a JavaScript module that depends on
> other modules and those depend on other modules, winding up to some
> IDL files.
>
> Is there a way to import these modules in specific context other than
> Mozilla/Firefox or does the whole code need to be rewritten?
>

The "whole code need[s] to be rewritten", but it's really not as bad as it
looks.  The WebChannel stuff is just some browser-level abstraction around
a simple event passing model, and in fact you can opt out of it entirely
(at least for a while).  There's an example of doing the dance in a WebView
in the iOS repository.  You can start digging into the code at

https://github.com/mozilla/firefox-ios/blob/5238e873e77e9ad3e699f926d12f61ccafabdc11/Account/FirefoxAccountConfiguration.swift#L95

and

https://github.com/mozilla/firefox-ios/blob/5238e873e77e9ad3e699f926d12f61ccafabdc11/FxAClient/Frontend/SignIn/FxASignIn.js

and

https://github.com/mozilla/firefox-ios/blob/e8f885d0f169f55dd466838a09ba0a440b6bc83c/FxAClient/Frontend/SignIn/FxAContentViewController.swift#L20
.

The first link includes `service=sync&context=fx_ios_v1`; that'll ensure
the accounts service sends you the messages over postMessage.  The second
link shows how to inject the message listener into the WebView context, so
you can react to the messages.  The third link shows what we do with those
messages -- the important one is "login", which includes all the tokens
you'll need to talk to the auth server to get keys, etc.

This postMessage interface has been cleaned up and regularized into the
WebChannel interface, but the underlying mechanism is almost identical.
The browser bits are just an abstraction on top of that since we want to
use the same approach for many browser <-> content interactions.

Yours,
Nick
_______________________________________________
Sync-dev mailing list
Sync-dev@mozilla.org
https://mail.mozilla.org/listinfo/sync-dev

Reply via email to