mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-31 22:25:30 +00:00
114 lines
4.1 KiB
Java
114 lines
4.1 KiB
Java
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#filter substitution
|
|
package @ANDROID_PACKAGE_NAME@;
|
|
|
|
import android.content.Intent;
|
|
import android.net.Uri;
|
|
import android.os.Bundle;
|
|
import android.os.SystemClock;
|
|
import android.util.Log;
|
|
import android.view.MenuItem;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.mozilla.gecko.GeckoApp;
|
|
import org.mozilla.gecko.GeckoAppShell;
|
|
import org.mozilla.gecko.GeckoEvent;
|
|
import org.mozilla.gecko.WebAppAllocator;
|
|
|
|
/*
|
|
* This is a stub activity, meant to just install the marketplace WebApp
|
|
* and then launch it
|
|
*/
|
|
public class MarketplaceApp extends WebApp {
|
|
private static final String LOGTAG = "GeckoMarketplaceApp";
|
|
public static final String MARKETPLACE_HOST = "marketplace.mozilla.org";
|
|
public static final String MARKETPLACE_URI = "https://marketplace.mozilla.org";
|
|
|
|
@Override
|
|
public void onCreate(Bundle savedInstanceState)
|
|
{
|
|
super.onCreate(savedInstanceState);
|
|
|
|
// Check that the uri being requested is a marketplace uri
|
|
String passedUri = null;
|
|
String uri = getURIFromIntent(getIntent());
|
|
if (uri != null && uri.length() > 0) {
|
|
passedUri = uri;
|
|
}
|
|
|
|
if (passedUri != null)
|
|
handleMarketplaceLink(passedUri);
|
|
}
|
|
|
|
// Use the default profile in order to ensure this is installed in the Fennec
|
|
// webapp registry. The marketplace WEBapp will have its own profile
|
|
@Override
|
|
protected String getDefaultProfileName() {
|
|
return "default";
|
|
}
|
|
|
|
@Override
|
|
protected void onNewIntent(Intent intent) {
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onNewIntent");
|
|
|
|
if (checkLaunchState(LaunchState.GeckoExiting)) {
|
|
// We're exiting and shouldn't try to do anything else just incase
|
|
// we're hung for some reason we'll force the process to exit
|
|
System.exit(0);
|
|
return;
|
|
}
|
|
|
|
// if we were previously OOM killed, we can end up here when launching
|
|
// from external shortcuts, so set this as the intent for initialization
|
|
if (!mInitialized) {
|
|
setIntent(intent);
|
|
return;
|
|
}
|
|
|
|
final String action = intent.getAction();
|
|
if (Intent.ACTION_VIEW.equals(action)) {
|
|
String uri = intent.getDataString();
|
|
if (Uri.parse(uri).getHost().equals(MARKETPLACE_HOST)) {
|
|
handleMarketplaceLink(uri);
|
|
return;
|
|
}
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(uri));
|
|
Log.i(LOGTAG,"onNewIntent: " + uri);
|
|
}
|
|
}
|
|
|
|
// All marketplace links from the system will come to the receiver first. It will determine if the
|
|
// marketplace app is installed. If the marketplace is not installed it will install it and send the link
|
|
// to the marketplace app
|
|
private void handleMarketplaceLink(final String url) {
|
|
// see if the marketplace app is registered, if its not, install it
|
|
int index = WebAppAllocator.getInstance(this).getIndexForApp(MARKETPLACE_URI);
|
|
if (index < 0) {
|
|
// If the app isn't installed, we send gecko a message to install it and then launch it with this url
|
|
JSONObject args = new JSONObject();
|
|
try {
|
|
args.put("url", url);
|
|
} catch (Exception e) {
|
|
Log.e(LOGTAG, "error building JSON arguments");
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("WebApps:InstallMarketplace", args.toString()));
|
|
} else {
|
|
// otherwise just launch the webapp with this url
|
|
Intent webappIntent = GeckoAppShell.getWebAppIntent(index, url);
|
|
if (webappIntent == null) {
|
|
Log.i(LOGTAG, "bounce launch");
|
|
return;
|
|
}
|
|
Log.i(LOGTAG, "Open " + url + " in marketplace app");
|
|
startActivity(webappIntent);
|
|
}
|
|
}
|
|
};
|
|
|