mobile/android/base/webapp/Dispatcher.java

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:82916fe66a1e
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 package org.mozilla.gecko.webapp;
7
8 import android.app.Activity;
9 import android.content.Intent;
10 import android.os.Bundle;
11 import android.util.Log;
12
13 public class Dispatcher extends Activity {
14 private static final String LOGTAG = "GeckoWebappDispatcher";
15
16 @Override
17 protected void onCreate(Bundle bundle) {
18 super.onCreate(bundle);
19
20 Allocator allocator = Allocator.getInstance(getApplicationContext());
21
22 if (bundle == null) {
23 bundle = getIntent().getExtras();
24 }
25
26 if (bundle == null) {
27 Log.e(LOGTAG, "Passed intent data missing.");
28 return;
29 }
30
31 String packageName = bundle.getString("packageName");
32
33 if (packageName == null) {
34 Log.e(LOGTAG, "Package name data missing.");
35 return;
36 }
37
38 int index = allocator.getIndexForApp(packageName);
39 boolean isInstalled = index >= 0;
40 if (!isInstalled) {
41 index = allocator.findOrAllocatePackage(packageName);
42 }
43
44 // Copy the intent, without interfering with it.
45 Intent intent = new Intent(getIntent());
46
47 // Only change it's destination.
48 intent.setClassName(getApplicationContext(), getPackageName() + ".WebApps$WebApp" + index);
49
50 // If and only if we haven't seen this before.
51 intent.putExtra("isInstalled", isInstalled);
52
53 startActivity(intent);
54 }
55 }

mercurial