michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.webapp; michael@0: michael@0: import android.app.Activity; michael@0: import android.content.Intent; michael@0: import android.os.Bundle; michael@0: import android.util.Log; michael@0: michael@0: public class Dispatcher extends Activity { michael@0: private static final String LOGTAG = "GeckoWebappDispatcher"; michael@0: michael@0: @Override michael@0: protected void onCreate(Bundle bundle) { michael@0: super.onCreate(bundle); michael@0: michael@0: Allocator allocator = Allocator.getInstance(getApplicationContext()); michael@0: michael@0: if (bundle == null) { michael@0: bundle = getIntent().getExtras(); michael@0: } michael@0: michael@0: if (bundle == null) { michael@0: Log.e(LOGTAG, "Passed intent data missing."); michael@0: return; michael@0: } michael@0: michael@0: String packageName = bundle.getString("packageName"); michael@0: michael@0: if (packageName == null) { michael@0: Log.e(LOGTAG, "Package name data missing."); michael@0: return; michael@0: } michael@0: michael@0: int index = allocator.getIndexForApp(packageName); michael@0: boolean isInstalled = index >= 0; michael@0: if (!isInstalled) { michael@0: index = allocator.findOrAllocatePackage(packageName); michael@0: } michael@0: michael@0: // Copy the intent, without interfering with it. michael@0: Intent intent = new Intent(getIntent()); michael@0: michael@0: // Only change it's destination. michael@0: intent.setClassName(getApplicationContext(), getPackageName() + ".WebApps$WebApp" + index); michael@0: michael@0: // If and only if we haven't seen this before. michael@0: intent.putExtra("isInstalled", isInstalled); michael@0: michael@0: startActivity(intent); michael@0: } michael@0: }