Skip to content

Instantly share code, notes, and snippets.

@maks
Last active March 27, 2017 17:08
Show Gist options
  • Save maks/5544588 to your computer and use it in GitHub Desktop.
Save maks/5544588 to your computer and use it in GitHub Desktop.
Firefox Webview R&D

Basics

  • need to create install.rdf and bootstrap.js as per
  • BUG When testing on a android device beware of this bug which prevents installing the extension xpi from sdcard.

Open fennec with url via Intent:

private void goFF(String url) {
    String FFurl = ((url!= null) && !url.equalsIgnoreCase("")) ? url : "http://manichord.com/";
    Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_DEFAULT);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.setComponent(new ComponentName("org.mozilla.firefox_beta", "org.mozilla.firefox_beta.App"));
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse(FFurl));
    startActivity(intent);
}

Modifying stock Firefox to work as a webview aka Opensign-view

Building Firefox for Android (aka Fennec)

Hg Sidebar

Firefox is stored in Hg (mercurial). So some useful Hg commands:

hg pull && hg update #to get the latest code
hg status # same as git
hg diff # same as git 
hg revert --all ## DISCARD all changes since last commit

Java side activity

Firefoxes android app manifest is in mobile/android/base/AndroidManifest.xml.in

The important part of the manifest is that it points to the App class to be launched for all its intents, which is just a place-holder subclass of BrowserApp which is where all the functionality is implemented.

But there is also WebApp which again just subclasses WebAppImpl which implements the features needed for Firefoxes new packaged installable apps from the Firefox Marketplace.

There are also a bunch of extra activities (eg. awesomebar, settings) and services (eg. password provider, notification provider, etc) that we probably need to strip-out down the track.

Custom Activity

  • So we implement our own subclass on GeckoApp (OpensignApp.java)
  • We add it to AndroidManifest.xml attached to the intent Action au.com.sct.opensign.FFWEBVIEW the url should be the Intents data attribute.

Bugs

Notes

References

Useful Moz links

Add-ons SDK

The add-ons SDK is (hopefully) a newer and nicer more high-level way to develop firefox extensions.

Mobile add-ons docs

NOTE: make sure you are using the latest stable SDK to match the latest version of Firefox for Android otherwise you may get errors trying to run your add-on xpi using cfx tool or the generated xpi may have strange errors with globals not being defined in content script scope, etc.

Communication between content scripts and normal html pages in Add-on SDK based extensions

This is documented here

Implementing HTTP Authenticated Proxies

Purpose

Need to be able to authenticate with a http proxy using basic auth without showing any UI to the user, the proxy-hostname/username/password all need to come from settings via opensign agent.

src code

The code for handling 407s (Proxy Authentication) is in netwerk/protocol/http/nsHttpChannel.cpp with the Authentication bit being the interface in: netwerk/protocol/http/nsIHttpChannelAuthProvider.idl and implementation in: netwerk/protocol/http/nsHttpChannelAuthProvider.cpp

But for our purposes, we want to have a non-interactive AuthProvider implementation...

SetProxyCredentials() in line 1312 of nsHttpChannelAuthProvider.cpp seems to be what actually puts the auth header fields into the request.

Now how to get proxy username, password into there?

Using FF Prefs

mobile prefs in: mobile/android/app/mobile.js

something like this might work via using prefs:

static const char kAllowProxies[] = "network.automatic-ntlm-auth.allow-proxies";
...
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
    if (!prefs)
        return;

    if (isProxyAuth) {
        bool val;
        if (NS_FAILED(prefs->GetBoolPref(kAllowProxies, &val)))
            val = false;
        LOG(("Default credentials allowed for proxy: %d\n", val));
        return val;
    }

Now how does Java code set Firefox prefs?

Testing

Once we actually have something working in FF this should be a simple way to test it: http://stackoverflow.com/questions/724599/setting-up-an-apache-proxy-with-authentication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment