1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/mobile/android/base/webapp/Dispatcher.java Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*- 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +package org.mozilla.gecko.webapp; 1.10 + 1.11 +import android.app.Activity; 1.12 +import android.content.Intent; 1.13 +import android.os.Bundle; 1.14 +import android.util.Log; 1.15 + 1.16 +public class Dispatcher extends Activity { 1.17 + private static final String LOGTAG = "GeckoWebappDispatcher"; 1.18 + 1.19 + @Override 1.20 + protected void onCreate(Bundle bundle) { 1.21 + super.onCreate(bundle); 1.22 + 1.23 + Allocator allocator = Allocator.getInstance(getApplicationContext()); 1.24 + 1.25 + if (bundle == null) { 1.26 + bundle = getIntent().getExtras(); 1.27 + } 1.28 + 1.29 + if (bundle == null) { 1.30 + Log.e(LOGTAG, "Passed intent data missing."); 1.31 + return; 1.32 + } 1.33 + 1.34 + String packageName = bundle.getString("packageName"); 1.35 + 1.36 + if (packageName == null) { 1.37 + Log.e(LOGTAG, "Package name data missing."); 1.38 + return; 1.39 + } 1.40 + 1.41 + int index = allocator.getIndexForApp(packageName); 1.42 + boolean isInstalled = index >= 0; 1.43 + if (!isInstalled) { 1.44 + index = allocator.findOrAllocatePackage(packageName); 1.45 + } 1.46 + 1.47 + // Copy the intent, without interfering with it. 1.48 + Intent intent = new Intent(getIntent()); 1.49 + 1.50 + // Only change it's destination. 1.51 + intent.setClassName(getApplicationContext(), getPackageName() + ".WebApps$WebApp" + index); 1.52 + 1.53 + // If and only if we haven't seen this before. 1.54 + intent.putExtra("isInstalled", isInstalled); 1.55 + 1.56 + startActivity(intent); 1.57 + } 1.58 +}