2011-11-18 10:28:17 -08:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* 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/. */
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-01-31 14:13:33 -08:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2012-04-27 13:04:47 -07:00
|
|
|
import org.mozilla.gecko.gfx.CairoImage;
|
|
|
|
import org.mozilla.gecko.gfx.BufferedCairoImage;
|
2011-11-23 11:07:47 -08:00
|
|
|
import org.mozilla.gecko.gfx.FloatSize;
|
2012-02-02 23:30:41 -08:00
|
|
|
import org.mozilla.gecko.gfx.GeckoLayerClient;
|
2011-11-18 10:28:17 -08:00
|
|
|
import org.mozilla.gecko.gfx.IntSize;
|
2012-01-31 06:40:58 -08:00
|
|
|
import org.mozilla.gecko.gfx.Layer;
|
2011-11-18 10:28:17 -08:00
|
|
|
import org.mozilla.gecko.gfx.LayerController;
|
|
|
|
import org.mozilla.gecko.gfx.LayerView;
|
2012-04-27 13:04:47 -07:00
|
|
|
import org.mozilla.gecko.gfx.PluginLayer;
|
2011-11-18 10:28:17 -08:00
|
|
|
import org.mozilla.gecko.gfx.RectUtils;
|
2012-01-31 06:40:58 -08:00
|
|
|
import org.mozilla.gecko.gfx.SurfaceTextureLayer;
|
2011-11-23 11:07:29 -08:00
|
|
|
import org.mozilla.gecko.gfx.ViewportMetrics;
|
2012-03-02 11:31:27 -08:00
|
|
|
import org.mozilla.gecko.gfx.ImmutableViewportMetrics;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
import java.io.*;
|
|
|
|
import java.util.*;
|
2012-01-04 17:28:04 -08:00
|
|
|
import java.util.regex.Pattern;
|
|
|
|
import java.util.regex.Matcher;
|
2011-11-18 10:28:17 -08:00
|
|
|
import java.util.zip.*;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.nio.*;
|
|
|
|
import java.nio.channels.FileChannel;
|
|
|
|
import java.util.concurrent.*;
|
|
|
|
import java.lang.reflect.*;
|
2011-11-23 00:43:08 -08:00
|
|
|
import java.net.*;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
import org.json.*;
|
|
|
|
|
|
|
|
import android.os.*;
|
|
|
|
import android.app.*;
|
|
|
|
import android.text.*;
|
2012-03-18 09:15:56 -07:00
|
|
|
import android.text.format.Time;
|
2011-11-18 10:28:17 -08:00
|
|
|
import android.view.*;
|
|
|
|
import android.view.inputmethod.*;
|
|
|
|
import android.view.ViewGroup.LayoutParams;
|
|
|
|
import android.content.*;
|
|
|
|
import android.content.res.*;
|
|
|
|
import android.graphics.*;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.widget.*;
|
|
|
|
import android.hardware.*;
|
|
|
|
import android.location.*;
|
2012-04-27 10:35:47 -07:00
|
|
|
import android.view.accessibility.AccessibilityManager;
|
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
import android.util.*;
|
|
|
|
import android.net.*;
|
|
|
|
import android.database.*;
|
|
|
|
import android.database.sqlite.*;
|
|
|
|
import android.provider.*;
|
|
|
|
import android.content.pm.*;
|
|
|
|
import android.content.pm.PackageManager.*;
|
|
|
|
import dalvik.system.*;
|
|
|
|
|
|
|
|
abstract public class GeckoApp
|
2012-04-03 11:58:01 -07:00
|
|
|
extends GeckoActivity
|
|
|
|
implements GeckoEventListener, SensorEventListener, LocationListener,
|
2012-06-10 16:44:50 -07:00
|
|
|
GeckoApplication.ApplicationLifecycleCallbacks,
|
2012-06-12 22:47:52 -07:00
|
|
|
Tabs.OnTabsChangedListener
|
2012-06-11 15:18:40 -07:00
|
|
|
{
|
2011-11-18 10:28:17 -08:00
|
|
|
private static final String LOGTAG = "GeckoApp";
|
|
|
|
|
2012-01-24 06:03:28 -08:00
|
|
|
public static enum StartupMode {
|
|
|
|
NORMAL,
|
|
|
|
NEW_VERSION,
|
|
|
|
NEW_PROFILE
|
|
|
|
}
|
|
|
|
|
2011-11-29 19:54:07 -08:00
|
|
|
public static final String ACTION_ALERT_CLICK = "org.mozilla.gecko.ACTION_ALERT_CLICK";
|
|
|
|
public static final String ACTION_ALERT_CLEAR = "org.mozilla.gecko.ACTION_ALERT_CLEAR";
|
|
|
|
public static final String ACTION_WEBAPP = "org.mozilla.gecko.WEBAPP";
|
|
|
|
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
|
|
|
|
public static final String ACTION_BOOKMARK = "org.mozilla.gecko.BOOKMARK";
|
2012-01-09 23:50:56 -08:00
|
|
|
public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD";
|
2012-01-24 20:32:12 -08:00
|
|
|
public static final String ACTION_UPDATE = "org.mozilla.gecko.UPDATE";
|
2012-03-08 10:25:44 -08:00
|
|
|
public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW";
|
2012-03-14 15:48:22 -07:00
|
|
|
public static final String SAVED_STATE_TITLE = "title";
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-24 06:03:28 -08:00
|
|
|
StartupMode mStartupMode = null;
|
2012-06-12 22:47:52 -07:00
|
|
|
protected LinearLayout mMainLayout;
|
|
|
|
protected RelativeLayout mGeckoLayout;
|
2012-06-11 15:18:40 -07:00
|
|
|
public View getView() { return mGeckoLayout; }
|
2011-11-18 10:28:17 -08:00
|
|
|
public static SurfaceView cameraView;
|
|
|
|
public static GeckoApp mAppContext;
|
2012-01-26 09:17:33 -08:00
|
|
|
public static boolean mDOMFullScreen = false;
|
2012-06-11 15:18:40 -07:00
|
|
|
protected MenuPanel mMenuPanel;
|
2011-11-18 10:28:17 -08:00
|
|
|
public static Menu sMenu;
|
2012-01-03 21:47:48 -08:00
|
|
|
private static GeckoThread sGeckoThread = null;
|
2012-04-13 12:31:16 -07:00
|
|
|
public Handler mMainHandler;
|
2012-02-25 20:22:40 -08:00
|
|
|
private GeckoProfile mProfile;
|
2012-01-27 17:28:47 -08:00
|
|
|
public static boolean sIsGeckoReady = false;
|
2012-01-27 11:19:13 -08:00
|
|
|
public static int mOrientation;
|
2011-11-29 20:58:39 -08:00
|
|
|
|
2012-04-02 13:50:03 -07:00
|
|
|
private GeckoConnectivityReceiver mConnectivityReceiver;
|
2012-04-04 17:31:19 -07:00
|
|
|
private GeckoBatteryManager mBatteryReceiver;
|
2011-11-22 12:48:22 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public static DoorHangerPopup mDoorHangerPopup;
|
2012-03-06 11:56:41 -08:00
|
|
|
public static FormAssistPopup mFormAssistPopup;
|
2012-06-10 16:44:50 -07:00
|
|
|
public TabsPanel mTabsPanel;
|
2011-11-18 10:28:17 -08:00
|
|
|
public Favicons mFavicons;
|
2011-11-22 12:48:22 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
private static LayerController mLayerController;
|
2012-02-02 23:30:41 -08:00
|
|
|
private static GeckoLayerClient mLayerClient;
|
2011-12-02 15:41:14 -08:00
|
|
|
private static AbsoluteLayout mPluginContainer;
|
2012-05-30 13:26:13 -07:00
|
|
|
private static FindInPageBar mFindInPageBar;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
private FullScreenHolder mFullScreenPluginContainer;
|
2012-05-30 09:10:49 -07:00
|
|
|
private View mFullScreenPluginView;
|
|
|
|
|
2012-06-06 19:39:01 -07:00
|
|
|
private HashMap<String, PowerManager.WakeLock> mWakeLocks = new HashMap<String, PowerManager.WakeLock>();
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
protected int mRestoreMode = GeckoAppShell.RESTORE_NONE;
|
2012-02-14 13:30:15 -08:00
|
|
|
private boolean mInitialized = false;
|
|
|
|
|
2012-06-02 23:07:03 -07:00
|
|
|
static Vector<MenuItem> sAddonMenuItems = new Vector<MenuItem>();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2011-11-21 22:56:55 -08:00
|
|
|
public enum LaunchState {Launching, WaitForDebugger,
|
2011-11-18 10:28:17 -08:00
|
|
|
Launched, GeckoRunning, GeckoExiting};
|
|
|
|
private static LaunchState sLaunchState = LaunchState.Launching;
|
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
private ActivityResultHandlerMap mActivityResultHandlerMap = new ActivityResultHandlerMap();
|
|
|
|
private FilePickerResultHandlerSync mFilePickerResultHandlerSync = new FilePickerResultHandlerSync();
|
|
|
|
private AwesomebarResultHandler mAwesomebarResultHandler = new AwesomebarResultHandler();
|
|
|
|
private CameraImageResultHandler mCameraImageResultHandler = new CameraImageResultHandler();
|
|
|
|
private CameraVideoResultHandler mCameraVideoResultHandler = new CameraVideoResultHandler();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public static boolean checkLaunchState(LaunchState checkState) {
|
|
|
|
synchronized(sLaunchState) {
|
|
|
|
return sLaunchState == checkState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setLaunchState(LaunchState setState) {
|
|
|
|
synchronized(sLaunchState) {
|
|
|
|
sLaunchState = setState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if mLaunchState is equal to checkState this sets mLaunchState to setState
|
|
|
|
// and return true. Otherwise we return false.
|
|
|
|
static boolean checkAndSetLaunchState(LaunchState checkState, LaunchState setState) {
|
|
|
|
synchronized(sLaunchState) {
|
|
|
|
if (sLaunchState != checkState)
|
|
|
|
return false;
|
|
|
|
sLaunchState = setState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void toggleChrome(final Boolean aShow) { }
|
|
|
|
|
|
|
|
void focusChrome() { }
|
|
|
|
|
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
|
|
|
switch(msg) {
|
|
|
|
case LOCATION_CHANGE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
hidePlugins(tab);
|
|
|
|
updatePopups(tab);
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case LOAD_ERROR:
|
|
|
|
case START:
|
|
|
|
case STOP:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case UNSELECTED:
|
|
|
|
case CLOSED:
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
updatePopups(tab);
|
|
|
|
hidePlugins(tab);
|
|
|
|
break;
|
|
|
|
case ADDED:
|
|
|
|
case SELECTED:
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
updatePopups(tab);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void refreshChrome() { }
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public static final String PLUGIN_ACTION = "android.webkit.PLUGIN";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A plugin that wish to be loaded in the WebView must provide this permission
|
|
|
|
* in their AndroidManifest.xml.
|
|
|
|
*/
|
|
|
|
public static final String PLUGIN_PERMISSION = "android.webkit.permission.PLUGIN";
|
|
|
|
|
|
|
|
private static final String PLUGIN_SYSTEM_LIB = "/system/lib/plugins/";
|
|
|
|
|
|
|
|
private static final String PLUGIN_TYPE = "type";
|
|
|
|
private static final String TYPE_NATIVE = "native";
|
|
|
|
public ArrayList<PackageInfo> mPackageInfoCache = new ArrayList<PackageInfo>();
|
|
|
|
|
|
|
|
String[] getPluginDirectories() {
|
2012-05-03 14:14:05 -07:00
|
|
|
|
2012-06-05 11:52:48 -07:00
|
|
|
// An awful hack to detect Tegra devices. Easiest way to do it without spinning up a EGL context.
|
|
|
|
boolean isTegra = (new File("/system/lib/hw/gralloc.tegra.so")).exists();
|
|
|
|
if (isTegra) {
|
|
|
|
// disable Flash on pre-HC Tegra (bug 703056)
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
Log.w(LOGTAG, "Blocking plugins because of Tegra 2 + Gingerbread bug (bug 703056)");
|
2012-05-03 14:14:05 -07:00
|
|
|
return new String[0];
|
2012-06-05 11:52:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// disable Flash on Tegra ICS with CM9 and other custom firmware (bug 736421)
|
|
|
|
File vfile = new File("/proc/version");
|
|
|
|
FileReader vreader = null;
|
|
|
|
try {
|
|
|
|
if (vfile.canRead()) {
|
|
|
|
vreader = new FileReader(vfile);
|
|
|
|
String version = new BufferedReader(vreader).readLine();
|
|
|
|
if (version.indexOf("CM9") != -1 ||
|
|
|
|
version.indexOf("cyanogen") != -1 ||
|
|
|
|
version.indexOf("Nova") != -1)
|
|
|
|
{
|
|
|
|
Log.w(LOGTAG, "Blocking plugins because of Tegra 2 + unofficial ICS bug (bug 736421)");
|
|
|
|
return new String[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (IOException ex) {
|
|
|
|
// nothing
|
|
|
|
} finally {
|
|
|
|
try {
|
|
|
|
if (vreader != null) {
|
|
|
|
vreader.close();
|
|
|
|
}
|
|
|
|
} catch (IOException ex) {
|
|
|
|
// nothing
|
|
|
|
}
|
|
|
|
}
|
2012-05-03 14:14:05 -07:00
|
|
|
}
|
|
|
|
|
2012-01-31 06:40:58 -08:00
|
|
|
// we don't support Honeycomb
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB &&
|
2012-01-31 22:29:09 -08:00
|
|
|
Build.VERSION.SDK_INT < 14 /*Build.VERSION_CODES.ICE_CREAM_SANDWICH*/ )
|
2012-06-05 11:52:48 -07:00
|
|
|
{
|
|
|
|
Log.w(LOGTAG, "Blocking plugins because of Honeycomb");
|
2011-12-12 13:47:37 -08:00
|
|
|
return new String[0];
|
2012-06-05 11:52:48 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-13 11:08:39 -08:00
|
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - start of getPluginDirectories");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
ArrayList<String> directories = new ArrayList<String>();
|
2012-01-24 09:16:48 -08:00
|
|
|
PackageManager pm = mAppContext.getPackageManager();
|
2011-11-18 10:28:17 -08:00
|
|
|
List<ResolveInfo> plugins = pm.queryIntentServices(new Intent(PLUGIN_ACTION),
|
|
|
|
PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
|
|
|
|
|
|
|
|
synchronized(mPackageInfoCache) {
|
|
|
|
|
|
|
|
// clear the list of existing packageInfo objects
|
|
|
|
mPackageInfoCache.clear();
|
|
|
|
|
|
|
|
|
|
|
|
for (ResolveInfo info : plugins) {
|
|
|
|
|
|
|
|
// retrieve the plugin's service information
|
|
|
|
ServiceInfo serviceInfo = info.serviceInfo;
|
|
|
|
if (serviceInfo == null) {
|
|
|
|
Log.w(LOGTAG, "Ignore bad plugin");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-11-24 03:29:15 -08:00
|
|
|
// Blacklist HTC's flash lite.
|
|
|
|
// See bug #704516 - We're not quite sure what Flash Lite does,
|
|
|
|
// but loading it causes Flash to give errors and fail to draw.
|
|
|
|
if (serviceInfo.packageName.equals("com.htc.flashliteplugin")) {
|
|
|
|
Log.w(LOGTAG, "Skipping HTC's flash lite plugin");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName);
|
|
|
|
|
|
|
|
|
|
|
|
// retrieve information from the plugin's manifest
|
|
|
|
PackageInfo pkgInfo;
|
|
|
|
try {
|
|
|
|
pkgInfo = pm.getPackageInfo(serviceInfo.packageName,
|
|
|
|
PackageManager.GET_PERMISSIONS
|
|
|
|
| PackageManager.GET_SIGNATURES);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (pkgInfo == null) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Could not load package information.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* find the location of the plugin's shared library. The default
|
|
|
|
* is to assume the app is either a user installed app or an
|
|
|
|
* updated system app. In both of these cases the library is
|
|
|
|
* stored in the app's data directory.
|
|
|
|
*/
|
|
|
|
String directory = pkgInfo.applicationInfo.dataDir + "/lib";
|
|
|
|
final int appFlags = pkgInfo.applicationInfo.flags;
|
|
|
|
final int updatedSystemFlags = ApplicationInfo.FLAG_SYSTEM |
|
|
|
|
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP;
|
|
|
|
// preloaded system app with no user updates
|
|
|
|
if ((appFlags & updatedSystemFlags) == ApplicationInfo.FLAG_SYSTEM) {
|
|
|
|
directory = PLUGIN_SYSTEM_LIB + pkgInfo.packageName;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the plugin has the required permissions
|
|
|
|
String permissions[] = pkgInfo.requestedPermissions;
|
|
|
|
if (permissions == null) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
boolean permissionOk = false;
|
|
|
|
for (String permit : permissions) {
|
|
|
|
if (PLUGIN_PERMISSION.equals(permit)) {
|
|
|
|
permissionOk = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!permissionOk) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Does not have required permission (2).");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check to ensure the plugin is properly signed
|
|
|
|
Signature signatures[] = pkgInfo.signatures;
|
|
|
|
if (signatures == null) {
|
|
|
|
Log.w(LOGTAG, "Loading plugin: " + serviceInfo.packageName + ". Not signed.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// determine the type of plugin from the manifest
|
|
|
|
if (serviceInfo.metaData == null) {
|
|
|
|
Log.e(LOGTAG, "The plugin '" + serviceInfo.name + "' has no type defined");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
String pluginType = serviceInfo.metaData.getString(PLUGIN_TYPE);
|
|
|
|
if (!TYPE_NATIVE.equals(pluginType)) {
|
|
|
|
Log.e(LOGTAG, "Unrecognized plugin type: " + pluginType);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
Class<?> cls = getPluginClass(serviceInfo.packageName, serviceInfo.name);
|
|
|
|
|
|
|
|
//TODO implement any requirements of the plugin class here!
|
|
|
|
boolean classFound = true;
|
|
|
|
|
|
|
|
if (!classFound) {
|
|
|
|
Log.e(LOGTAG, "The plugin's class' " + serviceInfo.name + "' does not extend the appropriate class.");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
Log.e(LOGTAG, "Can't find plugin: " + serviceInfo.packageName);
|
|
|
|
continue;
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
Log.e(LOGTAG, "Can't find plugin's class: " + serviceInfo.name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if all checks have passed then make the plugin available
|
|
|
|
mPackageInfoCache.add(pkgInfo);
|
|
|
|
directories.add(directory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String [] result = directories.toArray(new String[directories.size()]);
|
2012-01-13 11:08:39 -08:00
|
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - end of getPluginDirectories");
|
2011-11-18 10:28:17 -08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
String getPluginPackage(String pluginLib) {
|
|
|
|
|
|
|
|
if (pluginLib == null || pluginLib.length() == 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
synchronized(mPackageInfoCache) {
|
|
|
|
for (PackageInfo pkgInfo : mPackageInfoCache) {
|
|
|
|
if (pluginLib.contains(pkgInfo.packageName)) {
|
|
|
|
return pkgInfo.packageName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
Class<?> getPluginClass(String packageName, String className)
|
|
|
|
throws NameNotFoundException, ClassNotFoundException {
|
2012-01-24 09:16:48 -08:00
|
|
|
Context pluginContext = mAppContext.createPackageContext(packageName,
|
2011-11-18 10:28:17 -08:00
|
|
|
Context.CONTEXT_INCLUDE_CODE |
|
|
|
|
Context.CONTEXT_IGNORE_SECURITY);
|
|
|
|
ClassLoader pluginCL = pluginContext.getClassLoader();
|
|
|
|
return pluginCL.loadClass(className);
|
|
|
|
}
|
|
|
|
|
2012-06-02 23:07:03 -07:00
|
|
|
private void addAddonMenuItem(final int id, final String label, final String icon) {
|
|
|
|
if (sMenu == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
final MenuItem item = sMenu.add(Menu.NONE, id, Menu.NONE, label);
|
|
|
|
|
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
Log.i(LOGTAG, "menu item clicked");
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked", Integer.toString(id)));
|
|
|
|
((Activity) GeckoApp.mAppContext).closeOptionsMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (icon != null) {
|
|
|
|
if (icon.startsWith("data")) {
|
|
|
|
byte[] raw = GeckoAppShell.decodeBase64(icon.substring(22), GeckoAppShell.BASE64_DEFAULT);
|
|
|
|
Bitmap bitmap = BitmapFactory.decodeByteArray(raw, 0, raw.length);
|
|
|
|
BitmapDrawable drawable = new BitmapDrawable(bitmap);
|
|
|
|
item.setIcon(drawable);
|
|
|
|
}
|
|
|
|
else if (icon.startsWith("jar:") || icon.startsWith("file://")) {
|
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
URL url = new URL(icon);
|
|
|
|
InputStream is = (InputStream) url.getContent();
|
|
|
|
Drawable drawable = Drawable.createFromStream(is, "src");
|
|
|
|
item.setIcon(drawable);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "Unable to set icon", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sAddonMenuItems.add(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void removeAddonMenuItem(int id) {
|
|
|
|
for (MenuItem item : sAddonMenuItems) {
|
|
|
|
if (item.getItemId() == id) {
|
|
|
|
sAddonMenuItems.remove(item);
|
|
|
|
|
|
|
|
if (sMenu == null)
|
|
|
|
break;
|
|
|
|
|
|
|
|
MenuItem menuItem = sMenu.findItem(id);
|
|
|
|
if (menuItem != null)
|
|
|
|
sMenu.removeItem(id);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-25 12:47:51 -07:00
|
|
|
@Override
|
|
|
|
public void invalidateOptionsMenu() {
|
|
|
|
if (sMenu == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
onPrepareOptionsMenu(sMenu);
|
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
super.invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public boolean onCreateOptionsMenu(Menu menu)
|
|
|
|
{
|
|
|
|
sMenu = menu;
|
2012-05-31 16:01:50 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
MenuInflater inflater = getMenuInflater();
|
2012-05-31 16:01:50 -07:00
|
|
|
inflater.inflate(R.menu.gecko_menu, sMenu);
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPrepareOptionsMenu(Menu aMenu)
|
|
|
|
{
|
2011-12-01 17:27:11 -08:00
|
|
|
if (!sIsGeckoReady)
|
2011-12-20 08:33:25 -08:00
|
|
|
aMenu.findItem(R.id.settings).setEnabled(false);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
MenuItem bookmark = aMenu.findItem(R.id.bookmark);
|
|
|
|
MenuItem forward = aMenu.findItem(R.id.forward);
|
2011-11-22 16:44:58 -08:00
|
|
|
MenuItem share = aMenu.findItem(R.id.share);
|
2011-12-13 16:23:35 -08:00
|
|
|
MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf);
|
2012-01-23 13:47:48 -08:00
|
|
|
MenuItem charEncoding = aMenu.findItem(R.id.char_encoding);
|
2012-05-30 13:26:13 -07:00
|
|
|
MenuItem findInPage = aMenu.findItem(R.id.find_in_page);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-05 13:20:04 -08:00
|
|
|
if (tab == null || tab.getURL() == null) {
|
2011-11-18 10:28:17 -08:00
|
|
|
bookmark.setEnabled(false);
|
|
|
|
forward.setEnabled(false);
|
2011-11-22 16:44:58 -08:00
|
|
|
share.setEnabled(false);
|
2011-12-13 16:23:35 -08:00
|
|
|
saveAsPDF.setEnabled(false);
|
2012-05-30 13:26:13 -07:00
|
|
|
findInPage.setEnabled(false);
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
2012-05-30 13:26:13 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
bookmark.setEnabled(true);
|
|
|
|
bookmark.setCheckable(true);
|
|
|
|
|
|
|
|
if (tab.isBookmark()) {
|
|
|
|
bookmark.setChecked(true);
|
|
|
|
bookmark.setIcon(R.drawable.ic_menu_bookmark_remove);
|
|
|
|
} else {
|
|
|
|
bookmark.setChecked(false);
|
|
|
|
bookmark.setIcon(R.drawable.ic_menu_bookmark_add);
|
|
|
|
}
|
|
|
|
|
|
|
|
forward.setEnabled(tab.canDoForward());
|
|
|
|
|
2012-03-22 13:02:06 -07:00
|
|
|
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
|
2011-11-22 16:44:58 -08:00
|
|
|
String scheme = Uri.parse(tab.getURL()).getScheme();
|
2012-03-05 13:20:04 -08:00
|
|
|
share.setEnabled(!(scheme.equals("about") || scheme.equals("chrome") ||
|
2012-03-22 13:02:06 -07:00
|
|
|
scheme.equals("file") || scheme.equals("resource")));
|
2011-12-13 16:23:35 -08:00
|
|
|
|
|
|
|
// Disable save as PDF for about:home and xul pages
|
|
|
|
saveAsPDF.setEnabled(!(tab.getURL().equals("about:home") ||
|
|
|
|
tab.getContentType().equals("application/vnd.mozilla.xul+xml")));
|
2011-11-22 16:44:58 -08:00
|
|
|
|
2012-05-30 13:26:13 -07:00
|
|
|
// Disable find in page for about:home, since it won't work on Java content
|
|
|
|
if (!tab.getURL().equals("about:home"))
|
|
|
|
findInPage.setEnabled(true);
|
|
|
|
|
2012-01-23 13:47:48 -08:00
|
|
|
charEncoding.setVisible(GeckoPreferences.getCharEncodingState());
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
@Override
|
|
|
|
public MenuInflater getMenuInflater() {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
return new GeckoMenuInflater(mAppContext);
|
|
|
|
else
|
|
|
|
return super.getMenuInflater();
|
|
|
|
}
|
|
|
|
|
|
|
|
public View getMenuPanel() {
|
|
|
|
return mMenuPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
// MenuPanel holds the scrollable Menu
|
|
|
|
public static class MenuPanel extends ScrollView {
|
|
|
|
public MenuPanel(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
if (getChildCount() == 0) {
|
|
|
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int restrictedHeightSpec;
|
|
|
|
int childHeight = getChildAt(0).getHeight();
|
|
|
|
|
|
|
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
|
|
((Activity) GeckoApp.mAppContext).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
|
|
|
|
|
|
// heightPixels changes during rotation.
|
|
|
|
int preferredHeight = (int) (0.75 * metrics.heightPixels);
|
|
|
|
restrictedHeightSpec = MeasureSpec.makeMeasureSpec(childHeight <= preferredHeight ? childHeight : preferredHeight, MeasureSpec.EXACTLY);
|
|
|
|
|
|
|
|
super.onMeasure(widthMeasureSpec, restrictedHeightSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View onCreatePanelView(int featureId) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL) {
|
|
|
|
if (mMenuPanel == null) {
|
|
|
|
mMenuPanel = new MenuPanel(mAppContext, null);
|
|
|
|
} else {
|
|
|
|
// Prepare the panel everytime before showing the menu.
|
|
|
|
onPreparePanel(featureId, mMenuPanel, sMenu);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mMenuPanel;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onCreatePanelView(featureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onCreatePanelMenu(int featureId, Menu menu) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL) {
|
|
|
|
if (mMenuPanel == null) {
|
|
|
|
mMenuPanel = (MenuPanel) onCreatePanelView(featureId);
|
|
|
|
}
|
|
|
|
|
|
|
|
GeckoMenu gMenu = new GeckoMenu(mAppContext, null);
|
|
|
|
menu = gMenu;
|
|
|
|
mMenuPanel.addView(gMenu);
|
|
|
|
|
|
|
|
return onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onCreatePanelMenu(featureId, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreparePanel(int featureId, View view, Menu menu) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL)
|
|
|
|
return onPrepareOptionsMenu(menu);
|
|
|
|
|
|
|
|
return super.onPreparePanel(featureId, view, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuOpened(int featureId, Menu menu) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL) {
|
|
|
|
if (sMenu == null) {
|
|
|
|
onCreatePanelMenu(featureId, menu);
|
|
|
|
onPreparePanel(featureId, mMenuPanel, sMenu);
|
|
|
|
}
|
|
|
|
|
2012-06-05 10:24:52 -07:00
|
|
|
// Scroll custom menu to the top
|
|
|
|
if (mMenuPanel != null)
|
|
|
|
mMenuPanel.scrollTo(0, 0);
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onMenuOpened(featureId, menu);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
Tab tab = null;
|
|
|
|
Intent intent = null;
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.quit:
|
2011-11-23 23:04:26 -08:00
|
|
|
synchronized(sLaunchState) {
|
|
|
|
if (sLaunchState == LaunchState.GeckoRunning)
|
|
|
|
GeckoAppShell.notifyGeckoOfEvent(
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoEvent.createBroadcastEvent("Browser:Quit", null));
|
2011-11-23 23:04:26 -08:00
|
|
|
else
|
|
|
|
System.exit(0);
|
|
|
|
sLaunchState = LaunchState.GeckoExiting;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
2011-11-18 14:49:15 -08:00
|
|
|
case R.id.bookmark:
|
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
if (item.isChecked()) {
|
|
|
|
tab.removeBookmark();
|
|
|
|
Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
|
|
|
|
item.setIcon(R.drawable.ic_menu_bookmark_add);
|
|
|
|
} else {
|
|
|
|
tab.addBookmark();
|
|
|
|
Toast.makeText(this, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
|
|
|
|
item.setIcon(R.drawable.ic_menu_bookmark_remove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.share:
|
2012-06-10 16:44:50 -07:00
|
|
|
shareCurrentUrl();
|
2011-11-18 14:49:15 -08:00
|
|
|
return true;
|
|
|
|
case R.id.reload:
|
2012-05-04 12:52:13 -07:00
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.doReload();
|
2011-11-18 14:49:15 -08:00
|
|
|
return true;
|
|
|
|
case R.id.forward:
|
2012-05-04 12:52:13 -07:00
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.doForward();
|
2011-11-18 14:49:15 -08:00
|
|
|
return true;
|
|
|
|
case R.id.save_as_pdf:
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
|
2011-11-18 14:49:15 -08:00
|
|
|
return true;
|
2011-12-20 08:33:25 -08:00
|
|
|
case R.id.settings:
|
2011-11-18 14:49:15 -08:00
|
|
|
intent = new Intent(this, GeckoPreferences.class);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
2011-12-17 13:50:09 -08:00
|
|
|
case R.id.site_settings:
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Get", null));
|
2011-12-17 13:50:09 -08:00
|
|
|
return true;
|
2011-11-18 14:49:15 -08:00
|
|
|
case R.id.addons:
|
2012-01-03 10:57:24 -08:00
|
|
|
loadUrlInTab("about:addons");
|
2011-11-18 14:49:15 -08:00
|
|
|
return true;
|
2012-01-06 06:34:34 -08:00
|
|
|
case R.id.downloads:
|
2012-04-04 10:12:44 -07:00
|
|
|
loadUrlInTab("about:downloads");
|
2012-01-06 06:34:34 -08:00
|
|
|
return true;
|
2012-01-23 13:47:48 -08:00
|
|
|
case R.id.char_encoding:
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
|
2012-01-23 13:47:48 -08:00
|
|
|
return true;
|
2012-05-30 13:26:13 -07:00
|
|
|
case R.id.find_in_page:
|
|
|
|
mFindInPageBar.show();
|
|
|
|
return true;
|
2011-11-18 14:49:15 -08:00
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
private void shareCurrentUrl() {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
String url = tab.getURL();
|
|
|
|
if (url == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GeckoAppShell.openUriExternal(url, "text/plain", "", "",
|
|
|
|
Intent.ACTION_SEND, tab.getTitle());
|
|
|
|
}
|
|
|
|
|
2011-11-29 19:54:07 -08:00
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
2011-12-12 10:50:35 -08:00
|
|
|
|
2011-11-29 19:54:07 -08:00
|
|
|
if (outState == null)
|
|
|
|
outState = new Bundle();
|
2011-12-12 10:50:35 -08:00
|
|
|
|
2012-04-16 11:56:56 -07:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
outState.putString(SAVED_STATE_TITLE, tab.getDisplayTitle());
|
2012-03-14 15:48:22 -07:00
|
|
|
}
|
2011-11-29 19:54:07 -08:00
|
|
|
|
2012-05-23 18:53:39 -07:00
|
|
|
public DisplayMetrics getDisplayMetrics() {
|
|
|
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
|
|
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
|
|
return metrics;
|
|
|
|
}
|
|
|
|
|
2012-04-01 12:17:32 -07:00
|
|
|
void getAndProcessThumbnailForTab(final Tab tab) {
|
2012-03-14 15:48:22 -07:00
|
|
|
boolean isSelectedTab = Tabs.getInstance().isSelectedTab(tab);
|
|
|
|
final Bitmap bitmap = isSelectedTab ? mLayerClient.getBitmap() : null;
|
|
|
|
|
2012-05-03 16:29:59 -07:00
|
|
|
if ("about:home".equals(tab.getURL())) {
|
|
|
|
tab.updateThumbnail(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-14 15:48:22 -07:00
|
|
|
if (bitmap != null) {
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
|
|
|
|
processThumbnail(tab, bitmap, bos.toByteArray());
|
|
|
|
} else {
|
|
|
|
if (tab.getState() == Tab.STATE_DELAYED) {
|
|
|
|
byte[] thumbnail = BrowserDB.getThumbnailForUrl(getContentResolver(), tab.getURL());
|
|
|
|
if (thumbnail != null)
|
|
|
|
processThumbnail(tab, null, thumbnail);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-01 12:17:32 -07:00
|
|
|
int dw = tab.getThumbnailWidth();
|
|
|
|
int dh = tab.getThumbnailHeight();
|
2012-06-05 19:55:18 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createScreenshotEvent(tab.getId(), 0, 0, 0, 0, 0, 0, dw, dh, GeckoAppShell.SCREENSHOT_THUMBNAIL));
|
2012-03-14 15:48:22 -07:00
|
|
|
}
|
2012-01-16 19:23:04 -08:00
|
|
|
}
|
2012-01-13 10:10:13 -08:00
|
|
|
|
|
|
|
void processThumbnail(Tab thumbnailTab, Bitmap bitmap, byte[] compressed) {
|
2012-03-14 15:48:22 -07:00
|
|
|
if (Tabs.getInstance().isSelectedTab(thumbnailTab)) {
|
2012-02-03 22:48:26 -08:00
|
|
|
if (compressed == null) {
|
|
|
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
|
bitmap.compress(Bitmap.CompressFormat.PNG, 0, bos);
|
|
|
|
compressed = bos.toByteArray();
|
|
|
|
}
|
|
|
|
}
|
2012-02-21 21:12:14 -08:00
|
|
|
|
2012-01-16 19:23:04 -08:00
|
|
|
try {
|
|
|
|
if (bitmap == null)
|
|
|
|
bitmap = BitmapFactory.decodeByteArray(compressed, 0, compressed.length);
|
|
|
|
thumbnailTab.updateThumbnail(bitmap);
|
|
|
|
} catch (OutOfMemoryError ome) {
|
|
|
|
Log.w(LOGTAG, "decoding byte array ran out of memory", ome);
|
|
|
|
}
|
2012-01-13 10:10:13 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void updatePopups(final Tab tab) {
|
|
|
|
mDoorHangerPopup.updatePopup();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void addDoorHanger(String message, String value, JSONArray buttons, Tab tab, JSONObject options) {
|
|
|
|
mDoorHangerPopup.addDoorHanger(message, value, buttons, tab, options, null);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-13 16:23:35 -08:00
|
|
|
void handleLocationChange(final int tabId, final String uri,
|
2012-04-23 14:35:50 -07:00
|
|
|
final String documentURI, final String contentType,
|
|
|
|
final boolean sameDocument) {
|
2011-11-18 10:28:17 -08:00
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
2011-12-02 08:12:43 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
tab.updateURL(uri);
|
2011-12-13 16:23:35 -08:00
|
|
|
tab.setDocumentURI(documentURI);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-04-23 14:35:50 -07:00
|
|
|
tab.setContentType(contentType);
|
2012-05-29 14:10:48 -07:00
|
|
|
tab.clearFavicon();
|
2012-05-02 09:07:58 -07:00
|
|
|
tab.updateIdentityData(null);
|
2012-06-02 11:23:45 -07:00
|
|
|
tab.setReaderEnabled(false);
|
2011-11-18 10:28:17 -08:00
|
|
|
tab.removeTransientDoorHangers();
|
2012-05-18 08:24:27 -07:00
|
|
|
tab.setAllowZoom(true);
|
|
|
|
tab.setDefaultZoom(0);
|
2012-05-18 08:24:27 -07:00
|
|
|
tab.setMinZoom(0);
|
|
|
|
tab.setMaxZoom(0);
|
2012-01-24 16:31:33 -08:00
|
|
|
tab.setHasTouchListeners(false);
|
2012-04-23 10:29:14 -07:00
|
|
|
tab.setCheckerboardColor(Color.WHITE);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-06-11 15:18:40 -07:00
|
|
|
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOCATION_CHANGE);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-02 09:07:58 -07:00
|
|
|
void handleSecurityChange(final int tabId, final JSONObject identityData) {
|
2011-11-18 10:28:17 -08:00
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
2012-05-02 09:07:58 -07:00
|
|
|
tab.updateIdentityData(identityData);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-06-02 11:23:45 -07:00
|
|
|
void handleReaderEnabled(final int tabId) {
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tab.setReaderEnabled(true);
|
|
|
|
}
|
|
|
|
|
2011-12-16 11:32:32 -08:00
|
|
|
void handleLoadError(final int tabId, final String uri, final String title) {
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
2012-06-12 09:53:44 -07:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
// When a load error occurs, the URLBar can get corrupt so we reset it
|
2012-06-12 09:53:44 -07:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-06-11 15:18:40 -07:00
|
|
|
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOAD_ERROR);
|
2012-05-02 13:55:27 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void handlePageShow(final int tabId) { }
|
2012-02-14 09:50:55 -08:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
private String getDefaultProfileName() {
|
|
|
|
return "default";
|
2012-02-14 09:50:55 -08:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void handleClearHistory() { }
|
2012-04-04 12:29:31 -07:00
|
|
|
|
2012-01-24 06:03:28 -08:00
|
|
|
public StartupMode getStartupMode() {
|
|
|
|
// This function might touch the disk and should not
|
|
|
|
// be called from UI's main thread.
|
|
|
|
|
|
|
|
synchronized(this) {
|
|
|
|
if (mStartupMode != null)
|
|
|
|
return mStartupMode;
|
|
|
|
|
|
|
|
String packageName = getPackageName();
|
|
|
|
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
|
|
|
|
// This key should be profile-dependent. For now, we're simply hardcoding
|
|
|
|
// the "default" profile here.
|
2012-06-11 15:18:40 -07:00
|
|
|
String profileName = getDefaultProfileName();
|
|
|
|
if (profileName == null)
|
|
|
|
profileName = "default";
|
|
|
|
String keyName = packageName + "." + profileName + ".startup_version";
|
2012-01-24 06:03:28 -08:00
|
|
|
String appVersion = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
PackageInfo pkgInfo = getPackageManager().getPackageInfo(packageName, 0);
|
|
|
|
appVersion = pkgInfo.versionName;
|
|
|
|
} catch(NameNotFoundException nnfe) {
|
|
|
|
// If, for some reason, we can't fetch the app version
|
|
|
|
// we fallback to NORMAL startup mode.
|
|
|
|
mStartupMode = StartupMode.NORMAL;
|
|
|
|
return mStartupMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
String startupVersion = settings.getString(keyName, null);
|
|
|
|
if (startupVersion == null) {
|
|
|
|
mStartupMode = StartupMode.NEW_PROFILE;
|
|
|
|
} else {
|
|
|
|
if (startupVersion.equals(appVersion))
|
|
|
|
mStartupMode = StartupMode.NORMAL;
|
|
|
|
else
|
|
|
|
mStartupMode = StartupMode.NEW_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mStartupMode != StartupMode.NORMAL)
|
|
|
|
settings.edit().putString(keyName, appVersion).commit();
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "Startup mode: " + mStartupMode);
|
|
|
|
|
|
|
|
return mStartupMode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void addTab() { }
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
public void showLocalTabs() { }
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
public void showRemoteTabs() { }
|
2012-06-07 21:47:22 -07:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
private void showTabs(TabsPanel.Panel panel) { }
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
public void hideTabs() { }
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
public boolean areTabsShown() { return false; }
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
Log.i(LOGTAG, "Got message: " + event);
|
|
|
|
try {
|
|
|
|
if (event.equals("Menu:Add")) {
|
2012-06-02 23:07:03 -07:00
|
|
|
final String label = message.getString("name");
|
|
|
|
final int id = message.getInt("id");
|
|
|
|
String iconRes = null;
|
2011-11-18 10:28:17 -08:00
|
|
|
try { // icon is optional
|
2012-06-02 23:07:03 -07:00
|
|
|
iconRes = message.getString("icon");
|
2011-11-18 10:28:17 -08:00
|
|
|
} catch (Exception ex) { }
|
2012-06-02 23:07:03 -07:00
|
|
|
final String icon = iconRes;
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
addAddonMenuItem(id, label, icon);
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("Menu:Remove")) {
|
2012-06-02 23:07:03 -07:00
|
|
|
final int id = message.getInt("id");
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
removeAddonMenuItem(id);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-06-02 23:07:03 -07:00
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("Toast:Show")) {
|
|
|
|
final String msg = message.getString("message");
|
|
|
|
final String duration = message.getString("duration");
|
|
|
|
handleShowToast(msg, duration);
|
|
|
|
} else if (event.equals("DOMContentLoaded")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
2012-02-28 16:17:58 -08:00
|
|
|
final String backgroundColor = message.getString("bgColor");
|
2012-05-02 13:55:27 -07:00
|
|
|
handleContentLoaded(tabId);
|
2012-04-23 10:29:14 -07:00
|
|
|
Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (backgroundColor != null) {
|
|
|
|
tab.setCheckerboardColor(backgroundColor);
|
|
|
|
} else {
|
|
|
|
// Default to white if no color is given
|
|
|
|
tab.setCheckerboardColor(Color.WHITE);
|
2012-02-28 16:17:58 -08:00
|
|
|
}
|
2012-04-23 10:29:14 -07:00
|
|
|
|
|
|
|
// Sync up the LayerController and the tab if the tab's
|
|
|
|
// currently displayed.
|
|
|
|
if (getLayerController() != null && Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
getLayerController().setCheckerboardColor(tab.getCheckerboardColor());
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("DOMTitleChanged")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
|
|
|
final String title = message.getString("title");
|
|
|
|
handleTitleChanged(tabId, title);
|
|
|
|
Log.i(LOGTAG, "title - " + title);
|
|
|
|
} else if (event.equals("DOMLinkAdded")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
|
|
|
final String rel = message.getString("rel");
|
|
|
|
final String href = message.getString("href");
|
2012-05-29 14:10:48 -07:00
|
|
|
final int size = message.getInt("size");
|
|
|
|
Log.i(LOGTAG, "link rel - " + rel + ", href - " + href + ", size - " + size);
|
|
|
|
handleLinkAdded(tabId, rel, href, size);
|
2011-12-30 11:48:21 -08:00
|
|
|
} else if (event.equals("DOMWindowClose")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
|
|
|
handleWindowClose(tabId);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("log")) {
|
|
|
|
// generic log listener
|
|
|
|
final String msg = message.getString("msg");
|
|
|
|
Log.i(LOGTAG, "Log: " + msg);
|
|
|
|
} else if (event.equals("Content:LocationChange")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
|
|
|
final String uri = message.getString("uri");
|
2011-12-13 16:23:35 -08:00
|
|
|
final String documentURI = message.getString("documentURI");
|
|
|
|
final String contentType = message.getString("contentType");
|
2012-04-23 14:35:50 -07:00
|
|
|
final boolean sameDocument = message.getBoolean("sameDocument");
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.i(LOGTAG, "URI - " + uri);
|
2012-04-23 14:35:50 -07:00
|
|
|
handleLocationChange(tabId, uri, documentURI, contentType, sameDocument);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("Content:SecurityChange")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
2012-05-02 09:07:58 -07:00
|
|
|
final JSONObject identity = message.getJSONObject("identity");
|
|
|
|
Log.i(LOGTAG, "Security Mode - " + identity.getString("mode"));
|
|
|
|
handleSecurityChange(tabId, identity);
|
2012-06-02 11:23:45 -07:00
|
|
|
} else if (event.equals("Content:ReaderEnabled")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
|
|
|
handleReaderEnabled(tabId);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("Content:StateChange")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
2012-04-23 07:34:14 -07:00
|
|
|
final String uri = message.getString("uri");
|
2012-03-07 13:58:31 -08:00
|
|
|
final boolean success = message.getBoolean("success");
|
2011-11-18 10:28:17 -08:00
|
|
|
int state = message.getInt("state");
|
|
|
|
Log.i(LOGTAG, "State - " + state);
|
2011-12-21 13:34:02 -08:00
|
|
|
if ((state & GeckoAppShell.WPL_STATE_IS_NETWORK) != 0) {
|
2011-11-18 10:28:17 -08:00
|
|
|
if ((state & GeckoAppShell.WPL_STATE_START) != 0) {
|
|
|
|
Log.i(LOGTAG, "Got a document start");
|
2012-01-19 11:44:16 -08:00
|
|
|
final boolean showProgress = message.getBoolean("showProgress");
|
2012-04-23 07:34:14 -07:00
|
|
|
handleDocumentStart(tabId, showProgress, uri);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if ((state & GeckoAppShell.WPL_STATE_STOP) != 0) {
|
|
|
|
Log.i(LOGTAG, "Got a document stop");
|
2012-05-07 16:54:52 -07:00
|
|
|
handleDocumentStop(tabId, success, uri);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
2011-12-16 11:32:32 -08:00
|
|
|
} else if (event.equals("Content:LoadError")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
|
|
|
final String uri = message.getString("uri");
|
|
|
|
final String title = message.getString("title");
|
|
|
|
handleLoadError(tabId, uri, title);
|
2012-05-02 13:55:27 -07:00
|
|
|
} else if (event.equals("Content:PageShow")) {
|
|
|
|
final int tabId = message.getInt("tabID");
|
|
|
|
handlePageShow(tabId);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("Doorhanger:Add")) {
|
|
|
|
handleDoorHanger(message);
|
|
|
|
} else if (event.equals("Doorhanger:Remove")) {
|
|
|
|
handleDoorHangerRemove(message);
|
2011-12-01 17:27:11 -08:00
|
|
|
} else if (event.equals("Gecko:Ready")) {
|
|
|
|
sIsGeckoReady = true;
|
2011-11-18 10:28:17 -08:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (sMenu != null)
|
2011-12-20 08:33:25 -08:00
|
|
|
sMenu.findItem(R.id.settings).setEnabled(true);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
2011-11-23 23:04:26 -08:00
|
|
|
setLaunchState(GeckoApp.LaunchState.GeckoRunning);
|
|
|
|
GeckoAppShell.sendPendingEventsToGecko();
|
2012-03-14 15:48:22 -07:00
|
|
|
connectGeckoLayerClient();
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("ToggleChrome:Hide")) {
|
2012-06-11 15:18:40 -07:00
|
|
|
toggleChrome(false);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("ToggleChrome:Show")) {
|
2012-06-11 15:18:40 -07:00
|
|
|
toggleChrome(true);
|
2012-03-07 16:24:38 -08:00
|
|
|
} else if (event.equals("ToggleChrome:Focus")) {
|
2012-06-11 15:18:40 -07:00
|
|
|
focusChrome();
|
2012-01-26 09:17:33 -08:00
|
|
|
} else if (event.equals("DOMFullScreen:Start")) {
|
|
|
|
mDOMFullScreen = true;
|
|
|
|
} else if (event.equals("DOMFullScreen:Stop")) {
|
|
|
|
mDOMFullScreen = false;
|
2011-12-17 13:50:09 -08:00
|
|
|
} else if (event.equals("Permissions:Data")) {
|
|
|
|
String host = message.getString("host");
|
|
|
|
JSONArray permissions = message.getJSONArray("permissions");
|
|
|
|
showSiteSettingsDialog(host, permissions);
|
2012-01-23 13:47:48 -08:00
|
|
|
} else if (event.equals("CharEncoding:Data")) {
|
|
|
|
final JSONArray charsets = message.getJSONArray("charsets");
|
|
|
|
int selected = message.getInt("selected");
|
|
|
|
|
|
|
|
final int len = charsets.length();
|
|
|
|
final String[] titleArray = new String[len];
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
JSONObject charset = charsets.getJSONObject(i);
|
|
|
|
titleArray[i] = charset.getString("title");
|
|
|
|
}
|
|
|
|
|
|
|
|
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
dialogBuilder.setSingleChoiceItems(titleArray, selected, new AlertDialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
try {
|
|
|
|
JSONObject charset = charsets.getJSONObject(which);
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Set", charset.getString("code")));
|
2012-01-23 13:47:48 -08:00
|
|
|
dialog.dismiss();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error parsing json", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
dialogBuilder.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("CharEncoding:State")) {
|
|
|
|
final boolean visible = message.getString("visible").equals("true");
|
|
|
|
GeckoPreferences.setCharEncodingState(visible);
|
2012-05-22 18:32:32 -07:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (sMenu != null)
|
2012-01-23 13:47:48 -08:00
|
|
|
sMenu.findItem(R.id.char_encoding).setVisible(visible);
|
2012-05-22 18:32:32 -07:00
|
|
|
}
|
|
|
|
});
|
2012-01-24 20:32:12 -08:00
|
|
|
} else if (event.equals("Update:Restart")) {
|
|
|
|
doRestart("org.mozilla.gecko.restart_update");
|
2012-05-18 08:24:27 -07:00
|
|
|
} else if (event.equals("Tab:ViewportMetadata")) {
|
|
|
|
int tabId = message.getInt("tabID");
|
|
|
|
Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
tab.setAllowZoom(message.getBoolean("allowZoom"));
|
|
|
|
tab.setDefaultZoom((float) message.getDouble("defaultZoom"));
|
2012-05-18 08:24:27 -07:00
|
|
|
tab.setMinZoom((float) message.getDouble("minZoom"));
|
|
|
|
tab.setMaxZoom((float) message.getDouble("maxZoom"));
|
2012-05-18 08:24:27 -07:00
|
|
|
// Sync up the LayerController and the tab if the tab's currently displayed.
|
|
|
|
LayerController controller = getLayerController();
|
|
|
|
if (controller != null && Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
controller.setAllowZoom(tab.getAllowZoom());
|
|
|
|
controller.setDefaultZoom(tab.getDefaultZoom());
|
2012-05-18 08:24:27 -07:00
|
|
|
controller.setMinZoom(tab.getMinZoom());
|
|
|
|
controller.setMaxZoom(tab.getMaxZoom());
|
2012-05-18 08:24:27 -07:00
|
|
|
}
|
2012-01-30 20:47:23 -08:00
|
|
|
} else if (event.equals("Tab:HasTouchListener")) {
|
|
|
|
int tabId = message.getInt("tabID");
|
2012-05-22 18:32:32 -07:00
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
2012-01-30 20:47:23 -08:00
|
|
|
tab.setHasTouchListeners(true);
|
2012-05-22 18:32:32 -07:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab))
|
2012-04-07 00:09:26 -07:00
|
|
|
mLayerController.getView().getTouchEventHandler().setWaitForTouchListeners(true);
|
2012-05-22 18:32:32 -07:00
|
|
|
}
|
|
|
|
});
|
2012-02-14 09:50:55 -08:00
|
|
|
} else if (event.equals("Session:StatePurged")) {
|
2012-06-11 15:18:40 -07:00
|
|
|
onStatePurged();
|
2012-02-21 21:11:50 -08:00
|
|
|
} else if (event.equals("Bookmark:Insert")) {
|
|
|
|
final String url = message.getString("url");
|
|
|
|
final String title = message.getString("title");
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Toast.makeText(GeckoApp.mAppContext, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
|
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
BrowserDB.addBookmark(GeckoApp.mAppContext.getContentResolver(), title, url);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-03-09 15:06:50 -08:00
|
|
|
} else if (event.equals("Accessibility:Event")) {
|
2012-04-27 10:35:47 -07:00
|
|
|
final AccessibilityEvent accEvent = AccessibilityEvent.obtain(message.getInt("eventType"));
|
|
|
|
accEvent.setClassName(LayerView.class.getName());
|
|
|
|
accEvent.setPackageName(mAppContext.getPackageName());
|
2012-03-09 15:06:50 -08:00
|
|
|
|
|
|
|
final JSONArray text = message.getJSONArray("text");
|
2012-04-27 10:35:47 -07:00
|
|
|
for (int i = 0; i < text.length(); i++)
|
|
|
|
accEvent.getText().add(text.getString(i));
|
|
|
|
|
|
|
|
accEvent.setContentDescription(message.optString("description"));
|
|
|
|
accEvent.setEnabled(message.optBoolean("enabled", true));
|
|
|
|
accEvent.setChecked(message.optBoolean("checked"));
|
|
|
|
accEvent.setPassword(message.optBoolean("password"));
|
|
|
|
accEvent.setAddedCount(message.optInt("addedCount"));
|
|
|
|
accEvent.setRemovedCount(message.optInt("removedCount"));
|
|
|
|
accEvent.setFromIndex(message.optInt("fromIndex"));
|
|
|
|
accEvent.setItemCount(message.optInt("itemCount"));
|
|
|
|
accEvent.setCurrentItemIndex(message.optInt("currentItemIndex"));
|
|
|
|
accEvent.setBeforeText(message.optString("beforeText"));
|
|
|
|
|
2012-03-09 15:06:50 -08:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-04-27 10:35:47 -07:00
|
|
|
AccessibilityManager accessibilityManager =
|
|
|
|
(AccessibilityManager) mAppContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
|
|
|
|
accessibilityManager.sendAccessibilityEvent(accEvent);
|
2012-03-09 15:06:50 -08:00
|
|
|
}
|
|
|
|
});
|
2012-05-10 10:33:12 -07:00
|
|
|
} else if (event.equals("Accessibility:Ready")) {
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
JSONObject ret = new JSONObject();
|
|
|
|
AccessibilityManager accessibilityManager =
|
|
|
|
(AccessibilityManager) mAppContext.getSystemService(Context.ACCESSIBILITY_SERVICE);
|
|
|
|
try {
|
|
|
|
ret.put("enabled", accessibilityManager.isEnabled());
|
|
|
|
// XXX: A placeholder for future explore by touch support.
|
|
|
|
ret.put("exploreByTouch", false);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
Log.e(LOGTAG, "Error building JSON arguments for Accessibility:Ready:", ex);
|
|
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Accessibility:Settings",
|
|
|
|
ret.toString()));
|
|
|
|
}
|
|
|
|
});
|
2012-06-06 13:52:14 -07:00
|
|
|
} else if (event.equals("Shortcut:Remove")) {
|
|
|
|
final String url = message.getString("url");
|
|
|
|
final String title = message.getString("title");
|
2012-06-06 14:45:41 -07:00
|
|
|
final String type = message.getString("shortcutType");
|
2012-06-06 13:52:14 -07:00
|
|
|
GeckoAppShell.removeShortcut(title, url, type);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2011-11-23 11:07:29 -08:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void onStatePurged() { }
|
2011-11-28 22:38:35 -08:00
|
|
|
|
2011-12-17 13:50:09 -08:00
|
|
|
/**
|
|
|
|
* @param aPermissions
|
|
|
|
* Array of JSON objects to represent site permissions.
|
|
|
|
* Example: { type: "offline-app", setting: "Store Offline Data: Allow" }
|
|
|
|
*/
|
|
|
|
private void showSiteSettingsDialog(String aHost, JSONArray aPermissions) {
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
|
|
|
|
|
|
|
View customTitleView = getLayoutInflater().inflate(R.layout.site_setting_title, null);
|
|
|
|
((TextView) customTitleView.findViewById(R.id.title)).setText(R.string.site_settings_title);
|
|
|
|
((TextView) customTitleView.findViewById(R.id.host)).setText(aHost);
|
|
|
|
builder.setCustomTitle(customTitleView);
|
|
|
|
|
|
|
|
// If there are no permissions to clear, show the user a message about that.
|
|
|
|
// In the future, we want to disable the menu item if there are no permissions to clear.
|
|
|
|
if (aPermissions.length() == 0) {
|
|
|
|
builder.setMessage(R.string.site_settings_no_settings);
|
|
|
|
} else {
|
|
|
|
// Eventually we should use a list adapter and custom checkable list items
|
|
|
|
// to make a two-line UI to match the mock-ups
|
|
|
|
CharSequence[] items = new CharSequence[aPermissions.length()];
|
|
|
|
boolean[] states = new boolean[aPermissions.length()];
|
|
|
|
for (int i = 0; i < aPermissions.length(); i++) {
|
|
|
|
try {
|
|
|
|
items[i] = aPermissions.getJSONObject(i).
|
|
|
|
getString("setting");
|
|
|
|
// Make all the items checked by default
|
|
|
|
states[i] = true;
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.i(LOGTAG, "JSONException: " + e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
builder.setMultiChoiceItems(items, states, new DialogInterface.OnMultiChoiceClickListener(){
|
|
|
|
public void onClick(DialogInterface dialog, int item, boolean state) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setPositiveButton(R.string.site_settings_clear, new DialogInterface.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
ListView listView = ((AlertDialog) dialog).getListView();
|
|
|
|
SparseBooleanArray checkedItemPositions = listView.getCheckedItemPositions();
|
|
|
|
|
|
|
|
// An array of the indices of the permissions we want to clear
|
|
|
|
JSONArray permissionsToClear = new JSONArray();
|
|
|
|
for (int i = 0; i < checkedItemPositions.size(); i++) {
|
|
|
|
boolean checked = checkedItemPositions.get(i);
|
|
|
|
if (checked)
|
|
|
|
permissionsToClear.put(i);
|
|
|
|
}
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Clear", permissionsToClear.toString()));
|
2011-12-17 13:50:09 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
builder.setNegativeButton(R.string.site_settings_cancel, new DialogInterface.OnClickListener(){
|
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
dialog.cancel();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
builder.create().show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
void handleDoorHanger(JSONObject geckoObject) throws JSONException {
|
|
|
|
final String message = geckoObject.getString("message");
|
|
|
|
final String value = geckoObject.getString("value");
|
|
|
|
final JSONArray buttons = geckoObject.getJSONArray("buttons");
|
|
|
|
final int tabId = geckoObject.getInt("tabID");
|
|
|
|
final JSONObject options = geckoObject.getJSONObject("options");
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "DoorHanger received for tab " + tabId + ", msg:" + message);
|
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Tab tab = Tabs.getInstance().getTab(tabId);
|
2012-02-21 21:12:22 -08:00
|
|
|
if (tab != null)
|
2012-06-11 15:18:40 -07:00
|
|
|
addDoorHanger(message, value, buttons, tab, options);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleDoorHangerRemove(JSONObject geckoObject) throws JSONException {
|
|
|
|
final String value = geckoObject.getString("value");
|
|
|
|
final int tabId = geckoObject.getInt("tabID");
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "Doorhanger:Remove received for tab " + tabId);
|
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
tab.removeDoorHanger(value);
|
2012-06-11 15:18:40 -07:00
|
|
|
updatePopups(tab);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-04-23 07:34:14 -07:00
|
|
|
void handleDocumentStart(int tabId, final boolean showProgress, String uri) {
|
2011-11-18 10:28:17 -08:00
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
2012-04-27 10:52:21 -07:00
|
|
|
tab.setState("about:home".equals(uri) ? Tab.STATE_SUCCESS : Tab.STATE_LOADING);
|
2012-05-02 09:07:58 -07:00
|
|
|
tab.updateIdentityData(null);
|
2012-06-02 11:23:45 -07:00
|
|
|
tab.setReaderEnabled(false);
|
2012-04-24 12:13:36 -07:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab))
|
|
|
|
getLayerController().getView().getRenderer().resetCheckerboard();
|
2011-11-18 10:28:17 -08:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-06-11 15:18:40 -07:00
|
|
|
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.START, showProgress);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-07 16:54:52 -07:00
|
|
|
void handleDocumentStop(int tabId, boolean success, final String uri) {
|
2011-11-18 10:28:17 -08:00
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
2012-03-07 13:58:31 -08:00
|
|
|
tab.setState(success ? Tab.STATE_SUCCESS : Tab.STATE_ERROR);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-02-29 09:09:43 -08:00
|
|
|
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.STOP);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
2012-04-03 17:08:28 -07:00
|
|
|
GeckoAppShell.getHandler().postDelayed(new Runnable() {
|
|
|
|
public void run() {
|
2012-05-07 16:54:52 -07:00
|
|
|
if (!uri.equals(tab.getURL()))
|
|
|
|
return;
|
|
|
|
|
2012-04-03 17:08:28 -07:00
|
|
|
getAndProcessThumbnailForTab(tab);
|
2012-04-24 12:13:36 -07:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createStartPaintListentingEvent(tab.getId()));
|
|
|
|
GeckoAppShell.screenshotWholePage(tab);
|
|
|
|
}
|
|
|
|
|
2012-04-03 17:08:28 -07:00
|
|
|
}
|
|
|
|
}, 500);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleShowToast(final String message, final String duration) {
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Toast toast;
|
|
|
|
if (duration.equals("long"))
|
|
|
|
toast = Toast.makeText(mAppContext, message, Toast.LENGTH_LONG);
|
|
|
|
else
|
|
|
|
toast = Toast.makeText(mAppContext, message, Toast.LENGTH_SHORT);
|
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-02 13:55:27 -07:00
|
|
|
void handleContentLoaded(int tabId) {
|
2011-11-18 10:28:17 -08:00
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
2012-05-17 14:35:33 -07:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.LOADED);
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
void handleTitleChanged(int tabId, String title) {
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tab.updateTitle(title);
|
|
|
|
}
|
|
|
|
|
2012-05-29 14:10:48 -07:00
|
|
|
void handleLinkAdded(final int tabId, String rel, final String href, int size) {
|
|
|
|
if (rel.indexOf("[icon]") == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
tab.updateFaviconURL(href, size);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-30 11:48:21 -08:00
|
|
|
void handleWindowClose(final int tabId) {
|
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getTab(tabId);
|
|
|
|
tabs.closeTab(tab);
|
|
|
|
}
|
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
private void addFullScreenPluginView(View view) {
|
2012-05-30 09:10:49 -07:00
|
|
|
if (mFullScreenPluginView != null) {
|
|
|
|
Log.w(LOGTAG, "Already have a fullscreen plugin view");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setFullScreen(true);
|
|
|
|
|
|
|
|
view.setWillNotDraw(false);
|
|
|
|
if (view instanceof SurfaceView) {
|
|
|
|
((SurfaceView) view).setZOrderOnTop(true);
|
|
|
|
}
|
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
mFullScreenPluginContainer = new FullScreenHolder(this);
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
|
|
Gravity.CENTER);
|
|
|
|
mFullScreenPluginContainer.addView(view, layoutParams);
|
|
|
|
|
|
|
|
|
|
|
|
FrameLayout decor = (FrameLayout)getWindow().getDecorView();
|
|
|
|
decor.addView(mFullScreenPluginContainer, layoutParams);
|
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
mFullScreenPluginView = view;
|
|
|
|
}
|
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
void addPluginView(final View view, final Rect rect, final boolean isFullScreen) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-01-31 06:30:47 -08:00
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
if (isFullScreen) {
|
2012-06-06 19:39:36 -07:00
|
|
|
addFullScreenPluginView(view);
|
2012-05-30 09:10:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
PluginLayer layer = (PluginLayer) tab.getPluginLayer(view);
|
|
|
|
if (layer == null) {
|
|
|
|
layer = new PluginLayer(view, rect, mLayerController.getView().getRenderer().getMaxTextureSize());
|
|
|
|
tab.addPluginLayer(view, layer);
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
2012-04-27 13:04:47 -07:00
|
|
|
layer.reset(rect);
|
|
|
|
layer.setVisible(true);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-05-11 07:54:51 -07:00
|
|
|
|
|
|
|
mLayerController.getView().addLayer(layer);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
private void removeFullScreenPluginView(View view) {
|
|
|
|
if (mFullScreenPluginView == null) {
|
|
|
|
Log.w(LOGTAG, "Don't have a fullscreen plugin view");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFullScreenPluginView != view) {
|
|
|
|
Log.w(LOGTAG, "Passed view is not the current full screen view");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
mFullScreenPluginContainer.removeView(mFullScreenPluginView);
|
2012-05-30 09:10:49 -07:00
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
// We need do do this on the next iteration in order to avoid
|
|
|
|
// a deadlock, see comment below in FullScreenHolder
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mLayerController.getView().setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
FrameLayout decor = (FrameLayout)getWindow().getDecorView();
|
|
|
|
decor.removeView(mFullScreenPluginContainer);
|
2012-05-30 09:10:49 -07:00
|
|
|
|
|
|
|
mFullScreenPluginView = null;
|
2012-06-06 19:39:36 -07:00
|
|
|
|
|
|
|
GeckoScreenOrientationListener.getInstance().unlockScreenOrientation();
|
|
|
|
setFullScreen(false);
|
2012-05-30 09:10:49 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void removePluginView(final View view, final boolean isFullScreen) {
|
2011-11-18 10:28:17 -08:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-04-27 13:04:47 -07:00
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
2012-01-31 06:30:47 -08:00
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
if (isFullScreen) {
|
|
|
|
removeFullScreenPluginView(view);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
PluginLayer layer = (PluginLayer) tab.removePluginLayer(view);
|
|
|
|
if (layer != null) {
|
|
|
|
layer.destroy();
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:40:58 -08:00
|
|
|
public Surface createSurface() {
|
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
if (tab == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
SurfaceTextureLayer layer = SurfaceTextureLayer.create();
|
|
|
|
if (layer == null)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
Surface surface = layer.getSurface();
|
|
|
|
tab.addPluginLayer(surface, layer);
|
|
|
|
return surface;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void destroySurface(Surface surface) {
|
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
2012-02-15 12:34:31 -08:00
|
|
|
Layer layer = tab.removePluginLayer(surface);
|
|
|
|
hidePluginLayer(layer);
|
2012-01-31 06:40:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void showSurface(Surface surface, int x, int y,
|
2012-04-27 13:04:47 -07:00
|
|
|
int w, int h, boolean inverted, boolean blend) {
|
2012-01-31 06:40:58 -08:00
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
LayerView layerView = mLayerController.getView();
|
|
|
|
SurfaceTextureLayer layer = (SurfaceTextureLayer)tab.getPluginLayer(surface);
|
|
|
|
if (layer == null)
|
|
|
|
return;
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
layer.update(new Rect(x, y, x + w, y + h), inverted, blend);
|
2012-01-31 06:40:58 -08:00
|
|
|
layerView.addLayer(layer);
|
|
|
|
|
|
|
|
// FIXME: shouldn't be necessary, layer will request
|
|
|
|
// one when it gets first frame
|
|
|
|
layerView.requestRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void hidePluginLayer(Layer layer) {
|
|
|
|
LayerView layerView = mLayerController.getView();
|
|
|
|
layerView.removeLayer(layer);
|
|
|
|
layerView.requestRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showPluginLayer(Layer layer) {
|
|
|
|
LayerView layerView = mLayerController.getView();
|
|
|
|
layerView.addLayer(layer);
|
|
|
|
layerView.requestRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideSurface(Surface surface) {
|
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Layer layer = tab.getPluginLayer(surface);
|
|
|
|
if (layer == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
hidePluginLayer(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void requestRender() {
|
|
|
|
mLayerController.getView().requestRender();
|
|
|
|
}
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
public void hidePlugins() {
|
2012-01-31 06:30:47 -08:00
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
hidePlugins(tab);
|
2012-01-31 06:30:47 -08:00
|
|
|
}
|
2012-04-27 13:04:47 -07:00
|
|
|
|
|
|
|
public void hidePlugins(Tab tab) {
|
|
|
|
for (Layer layer : tab.getPluginLayers()) {
|
|
|
|
if (layer instanceof PluginLayer) {
|
|
|
|
((PluginLayer) layer).setVisible(false);
|
2012-01-31 06:40:58 -08:00
|
|
|
}
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
hidePluginLayer(layer);
|
2012-01-31 06:40:58 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
requestRender();
|
2012-01-31 06:30:47 -08:00
|
|
|
}
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
public void showPlugins() {
|
2012-01-31 06:30:47 -08:00
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
showPlugins(tab);
|
2012-01-31 06:30:47 -08:00
|
|
|
}
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
public void showPlugins(Tab tab) {
|
|
|
|
for (Layer layer : tab.getPluginLayers()) {
|
|
|
|
showPluginLayer(layer);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
if (layer instanceof PluginLayer) {
|
|
|
|
((PluginLayer) layer).setVisible(true);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
2012-04-27 13:04:47 -07:00
|
|
|
|
|
|
|
requestRender();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setFullScreen(final boolean fullscreen) {
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
// Hide/show the system notification bar
|
2012-02-15 16:14:02 -08:00
|
|
|
Window window = getWindow();
|
|
|
|
window.setFlags(fullscreen ?
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN : 0,
|
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
|
|
2012-02-16 14:22:27 -08:00
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
window.getDecorView().setSystemUiVisibility(fullscreen ? 1 : 0);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-05-24 15:22:47 -07:00
|
|
|
public boolean isTablet() {
|
|
|
|
DisplayMetrics metrics = new DisplayMetrics();
|
|
|
|
getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
|
|
|
|
|
|
// Checking for sw600dp for 7" tablet.
|
|
|
|
if (((metrics.widthPixels / metrics.density) >= 600) &&
|
|
|
|
((metrics.heightPixels / metrics.density) >= 600))
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
/** Called when the activity is first created. */
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2012-03-07 11:19:05 -08:00
|
|
|
GeckoAppShell.registerGlobalExceptionHandler();
|
|
|
|
|
2012-01-27 17:28:30 -08:00
|
|
|
mAppContext = this;
|
|
|
|
|
2012-05-16 15:28:28 -07:00
|
|
|
// Check to see if the activity is restarted after configuration change.
|
|
|
|
if (getLastNonConfigurationInstance() != null) {
|
|
|
|
// Restart the application as a safe way to handle the configuration change.
|
|
|
|
doRestart();
|
|
|
|
System.exit(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-12 17:15:38 -08:00
|
|
|
// StrictMode is set by defaults resource flag |enableStrictMode|.
|
|
|
|
if (getResources().getBoolean(R.bool.enableStrictMode)) {
|
|
|
|
enableStrictMode();
|
|
|
|
}
|
2011-12-12 17:15:23 -08:00
|
|
|
|
2012-03-08 10:25:44 -08:00
|
|
|
GeckoAppShell.loadMozGlue();
|
2012-06-04 07:58:54 -07:00
|
|
|
sGeckoThread = new GeckoThread();
|
|
|
|
String uri = getURIFromIntent(getIntent());
|
|
|
|
if (uri != null && uri.length() > 0 && !uri.equals("about:home"))
|
|
|
|
sGeckoThread.start();
|
|
|
|
|
2012-04-13 12:31:16 -07:00
|
|
|
mMainHandler = new Handler();
|
2012-01-13 11:08:39 -08:00
|
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onCreate");
|
2012-01-03 21:47:48 -08:00
|
|
|
|
2012-03-23 12:00:17 -07:00
|
|
|
LayoutInflater.from(this).setFactory(GeckoViewsFactory.getInstance());
|
|
|
|
|
2012-02-14 13:30:15 -08:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
|
|
|
mOrientation = getResources().getConfiguration().orientation;
|
|
|
|
|
|
|
|
setContentView(R.layout.gecko_app);
|
|
|
|
|
|
|
|
// setup gecko layout
|
|
|
|
mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
|
|
|
|
mMainLayout = (LinearLayout) findViewById(R.id.main_layout);
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
// setup tabs panel
|
|
|
|
mTabsPanel = (TabsPanel) findViewById(R.id.tabs_panel);
|
|
|
|
|
2012-04-16 11:56:56 -07:00
|
|
|
if (savedInstanceState != null) {
|
2012-05-14 14:48:04 -07:00
|
|
|
mRestoreMode = GeckoAppShell.RESTORE_OOM;
|
2012-04-16 11:56:56 -07:00
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
((GeckoApplication) getApplication()).addApplicationLifecycleCallbacks(this);
|
2012-02-14 13:30:15 -08:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void initializeChrome(String uri, Boolean isExternalURL) { }
|
|
|
|
|
2012-02-14 13:30:15 -08:00
|
|
|
private void initialize() {
|
|
|
|
mInitialized = true;
|
|
|
|
|
2012-05-25 12:47:51 -07:00
|
|
|
invalidateOptionsMenu();
|
2012-05-24 15:47:49 -07:00
|
|
|
|
2012-01-03 21:47:48 -08:00
|
|
|
Intent intent = getIntent();
|
2012-03-07 10:36:38 -08:00
|
|
|
String action = intent.getAction();
|
2012-01-04 17:28:04 -08:00
|
|
|
String args = intent.getStringExtra("args");
|
|
|
|
if (args != null && args.contains("-profile")) {
|
|
|
|
Pattern p = Pattern.compile("(?:-profile\\s*)(\\w*)(\\s*)");
|
|
|
|
Matcher m = p.matcher(args);
|
|
|
|
if (m.find()) {
|
2012-02-25 20:22:40 -08:00
|
|
|
mProfile = GeckoProfile.get(this, m.group(1));
|
2012-01-04 17:28:04 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-07 10:36:38 -08:00
|
|
|
if (ACTION_UPDATE.equals(action) || args != null && args.contains("-alert update-app")) {
|
2012-01-24 20:32:12 -08:00
|
|
|
Log.i(LOGTAG,"onCreate: Update request");
|
|
|
|
checkAndLaunchUpdate();
|
|
|
|
}
|
|
|
|
|
2012-01-27 17:33:02 -08:00
|
|
|
String passedUri = null;
|
2012-01-28 09:24:51 -08:00
|
|
|
String uri = getURIFromIntent(intent);
|
2012-04-16 11:56:56 -07:00
|
|
|
if (uri != null && uri.length() > 0) {
|
|
|
|
passedUri = uri;
|
|
|
|
}
|
2011-12-12 09:57:04 -08:00
|
|
|
|
2012-05-14 14:48:04 -07:00
|
|
|
if (mRestoreMode == GeckoAppShell.RESTORE_NONE && getProfile().shouldRestoreSession())
|
|
|
|
mRestoreMode = GeckoAppShell.RESTORE_CRASH;
|
2012-04-23 07:47:46 -07:00
|
|
|
|
|
|
|
boolean isExternalURL = passedUri != null && !passedUri.equals("about:home");
|
2012-06-11 15:18:40 -07:00
|
|
|
initializeChrome(uri, isExternalURL);
|
2012-04-23 07:47:46 -07:00
|
|
|
|
2012-04-17 13:01:28 -07:00
|
|
|
// Start migrating as early as possible, can do this in
|
|
|
|
// parallel with Gecko load.
|
|
|
|
checkMigrateProfile();
|
|
|
|
|
2012-01-09 23:50:56 -08:00
|
|
|
Uri data = intent.getData();
|
|
|
|
if (data != null && "http".equals(data.getScheme()) &&
|
|
|
|
isHostOnPrefetchWhitelist(data.getHost())) {
|
|
|
|
Intent copy = new Intent(intent);
|
|
|
|
copy.setAction(ACTION_LOAD);
|
|
|
|
GeckoAppShell.getHandler().post(new RedirectorRunnable(copy));
|
|
|
|
// We're going to handle this uri with the redirector, so setting
|
|
|
|
// the action to MAIN and clearing the uri data prevents us from
|
|
|
|
// loading it twice
|
|
|
|
intent.setAction(Intent.ACTION_MAIN);
|
|
|
|
intent.setData(null);
|
2012-03-16 09:29:37 -07:00
|
|
|
passedUri = "about:empty";
|
2012-01-09 23:50:56 -08:00
|
|
|
}
|
|
|
|
|
2012-06-04 07:58:54 -07:00
|
|
|
sGeckoThread.init(intent, passedUri, mRestoreMode);
|
2012-03-07 10:36:38 -08:00
|
|
|
if (!ACTION_DEBUG.equals(action) &&
|
|
|
|
checkAndSetLaunchState(LaunchState.Launching, LaunchState.Launched)) {
|
2012-06-04 07:58:54 -07:00
|
|
|
sGeckoThread.reallyStart();
|
2012-03-07 10:36:38 -08:00
|
|
|
} else if (ACTION_DEBUG.equals(action) &&
|
|
|
|
checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) {
|
|
|
|
mMainHandler.postDelayed(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Log.i(LOGTAG, "Launching from debug intent after 5s wait");
|
|
|
|
setLaunchState(LaunchState.Launching);
|
2012-06-04 07:58:54 -07:00
|
|
|
sGeckoThread.reallyStart();
|
2012-03-07 10:36:38 -08:00
|
|
|
}
|
|
|
|
}, 1000 * 5 /* 5 seconds */);
|
|
|
|
Log.i(LOGTAG, "Intent : ACTION_DEBUG - waiting 5s before launching");
|
|
|
|
}
|
2012-01-03 21:47:48 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
mFavicons = new Favicons(this);
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
Tabs.getInstance().setContentResolver(getContentResolver());
|
|
|
|
Tabs.getInstance().registerOnTabsChangedListener(this);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
if (cameraView == null) {
|
|
|
|
cameraView = new SurfaceView(this);
|
|
|
|
cameraView.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLayerController == null) {
|
|
|
|
/*
|
2012-02-22 11:45:44 -08:00
|
|
|
* Create a layer client, but don't hook it up to the layer controller yet.
|
2011-11-18 10:28:17 -08:00
|
|
|
*/
|
2012-02-22 11:45:44 -08:00
|
|
|
mLayerClient = new GeckoLayerClient(this);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Hook a placeholder layer client up to the layer controller so that the user can pan
|
|
|
|
* and zoom a cached screenshot of the previous page. This call will return null if
|
|
|
|
* there is no cached screenshot; in that case, we have no choice but to display a
|
|
|
|
* checkerboard.
|
|
|
|
*
|
|
|
|
* TODO: Fall back to a built-in screenshot of the Fennec Start page for a nice first-
|
|
|
|
* run experience, perhaps?
|
|
|
|
*/
|
|
|
|
mLayerController = new LayerController(this);
|
2012-03-22 15:07:00 -07:00
|
|
|
View v = mLayerController.getView();
|
|
|
|
|
2012-04-01 12:17:32 -07:00
|
|
|
// Instead of flickering the checkerboard, show a white screen until Gecko paints
|
|
|
|
v.setBackgroundColor(Color.WHITE);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-22 15:07:00 -07:00
|
|
|
mGeckoLayout.addView(v, 0);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-02 15:41:14 -08:00
|
|
|
mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);
|
2012-05-30 13:26:13 -07:00
|
|
|
mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
|
2011-12-02 15:41:14 -08:00
|
|
|
|
2012-02-14 13:30:15 -08:00
|
|
|
mDoorHangerPopup = new DoorHangerPopup(this);
|
2012-03-06 11:56:41 -08:00
|
|
|
mFormAssistPopup = (FormAssistPopup) findViewById(R.id.form_assist_popup);
|
2012-02-14 13:30:15 -08:00
|
|
|
|
2012-01-13 11:08:39 -08:00
|
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - UI almost up");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
//register for events
|
|
|
|
GeckoAppShell.registerGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
|
2011-12-30 11:48:21 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("log", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext);
|
2012-06-02 11:23:45 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Content:ReaderEnabled", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Content:StateChange", GeckoApp.mAppContext);
|
2011-12-16 11:32:32 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Content:LoadError", GeckoApp.mAppContext);
|
2012-05-02 13:55:27 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Content:PageShow", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Doorhanger:Remove", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
|
2012-01-26 09:17:33 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Start", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("DOMFullScreen:Stop", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
|
2012-03-07 16:24:38 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("ToggleChrome:Focus", GeckoApp.mAppContext);
|
2011-12-17 13:50:09 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
|
2012-01-23 13:47:48 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.registerGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext);
|
2012-01-24 20:32:12 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Update:Restart", GeckoApp.mAppContext);
|
2012-01-30 20:47:23 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext);
|
2012-05-18 08:24:27 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Tab:ViewportMetadata", GeckoApp.mAppContext);
|
2012-02-14 09:50:55 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
|
2012-02-21 21:11:50 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);
|
2012-03-09 15:06:50 -08:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Accessibility:Event", GeckoApp.mAppContext);
|
2012-05-10 10:33:12 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Accessibility:Ready", GeckoApp.mAppContext);
|
2012-06-06 13:52:14 -07:00
|
|
|
GeckoAppShell.registerGeckoEventListener("Shortcut:Remove", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() != null) {
|
2012-01-24 08:06:47 -08:00
|
|
|
SmsManager.getInstance().start();
|
2012-01-17 10:38:04 -08:00
|
|
|
}
|
2012-01-17 10:52:17 -08:00
|
|
|
|
2012-04-04 17:31:19 -07:00
|
|
|
mBatteryReceiver = new GeckoBatteryManager();
|
|
|
|
mBatteryReceiver.registerFor(mAppContext);
|
|
|
|
|
2012-04-04 17:29:30 -07:00
|
|
|
mConnectivityReceiver = new GeckoConnectivityReceiver();
|
|
|
|
mConnectivityReceiver.registerFor(mAppContext);
|
|
|
|
|
2012-01-16 09:17:34 -08:00
|
|
|
GeckoNetworkManager.getInstance().init();
|
2012-04-04 17:29:30 -07:00
|
|
|
GeckoNetworkManager.getInstance().start();
|
|
|
|
|
|
|
|
GeckoScreenOrientationListener.getInstance().start();
|
2012-01-17 10:40:39 -08:00
|
|
|
|
2011-12-14 09:35:58 -08:00
|
|
|
final GeckoApp self = this;
|
2012-01-24 08:06:47 -08:00
|
|
|
|
2012-01-03 10:50:44 -08:00
|
|
|
GeckoAppShell.getHandler().postDelayed(new Runnable() {
|
2011-12-14 09:35:58 -08:00
|
|
|
public void run() {
|
2012-01-13 11:08:39 -08:00
|
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - pre checkLaunchState");
|
2012-04-17 13:01:28 -07:00
|
|
|
// Sync settings need Gecko to be loaded, so
|
|
|
|
// no hurry in starting this.
|
|
|
|
checkMigrateSync();
|
2011-12-14 09:35:58 -08:00
|
|
|
|
|
|
|
/*
|
|
|
|
XXXX see bug 635342
|
|
|
|
We want to disable this code if possible. It is about 145ms in runtime
|
|
|
|
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
String localeCode = settings.getString(getPackageName() + ".locale", "");
|
|
|
|
if (localeCode != null && localeCode.length() > 0)
|
|
|
|
GeckoAppShell.setSelectedLocale(localeCode);
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!checkLaunchState(LaunchState.Launched)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 50);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-02-25 20:22:40 -08:00
|
|
|
public GeckoProfile getProfile() {
|
|
|
|
// fall back to default profile if we didn't load a specific one
|
|
|
|
if (mProfile == null) {
|
|
|
|
mProfile = GeckoProfile.get(this);
|
|
|
|
}
|
|
|
|
return mProfile;
|
|
|
|
}
|
|
|
|
|
2011-12-12 17:15:23 -08:00
|
|
|
/**
|
|
|
|
* Enable Android StrictMode checks (for supported OS versions).
|
|
|
|
* http://developer.android.com/reference/android/os/StrictMode.html
|
|
|
|
*/
|
|
|
|
private void enableStrictMode()
|
|
|
|
{
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
|
|
|
.detectAll()
|
|
|
|
.penaltyLog()
|
|
|
|
.build());
|
|
|
|
|
|
|
|
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
|
|
|
.detectAll()
|
|
|
|
.penaltyLog()
|
|
|
|
.build());
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void enableCameraView() {
|
|
|
|
// Some phones (eg. nexus S) need at least a 8x16 preview size
|
|
|
|
mMainLayout.addView(cameraView, new AbsoluteLayout.LayoutParams(8, 16, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
public void disableCameraView() {
|
|
|
|
mMainLayout.removeView(cameraView);
|
|
|
|
}
|
|
|
|
|
2012-01-09 23:50:56 -08:00
|
|
|
abstract public String getDefaultUAString();
|
|
|
|
abstract public String getUAStringForHost(String host);
|
|
|
|
|
|
|
|
class RedirectorRunnable implements Runnable {
|
|
|
|
Intent mIntent;
|
|
|
|
RedirectorRunnable(Intent intent) {
|
|
|
|
mIntent = intent;
|
|
|
|
}
|
|
|
|
public void run() {
|
|
|
|
HttpURLConnection connection = null;
|
|
|
|
try {
|
|
|
|
// this class should only be initialized with an intent with non-null data
|
|
|
|
URL url = new URL(mIntent.getData().toString());
|
|
|
|
// data url should have an http scheme
|
|
|
|
connection = (HttpURLConnection) url.openConnection();
|
|
|
|
connection.setRequestProperty("User-Agent", getUAStringForHost(url.getHost()));
|
|
|
|
connection.setInstanceFollowRedirects(false);
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
connection.connect();
|
|
|
|
int code = connection.getResponseCode();
|
|
|
|
if (code >= 300 && code < 400) {
|
|
|
|
String location = connection.getHeaderField("Location");
|
|
|
|
Uri data;
|
|
|
|
if (location != null &&
|
|
|
|
(data = Uri.parse(location)) != null &&
|
|
|
|
!"about".equals(data.getScheme()) &&
|
|
|
|
!"chrome".equals(data.getScheme())) {
|
|
|
|
mIntent.setData(data);
|
|
|
|
} else {
|
|
|
|
mIntent.putExtra("prefetched", 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mIntent.putExtra("prefetched", 1);
|
|
|
|
}
|
|
|
|
} catch (IOException ioe) {
|
|
|
|
Log.i(LOGTAG, "exception trying to pre-fetch redirected url", ioe);
|
|
|
|
mIntent.putExtra("prefetched", 1);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "unexpected exception, passing url directly to Gecko but we should explicitly catch this", e);
|
|
|
|
mIntent.putExtra("prefetched", 1);
|
|
|
|
} finally {
|
|
|
|
if (connection != null)
|
|
|
|
connection.disconnect();
|
|
|
|
}
|
|
|
|
mMainHandler.postAtFrontOfQueue(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
onNewIntent(mIntent);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private final String kPrefetchWhiteListArray[] = new String[] {
|
|
|
|
"t.co",
|
|
|
|
"bit.ly",
|
|
|
|
"moz.la",
|
|
|
|
"aje.me",
|
|
|
|
"facebook.com",
|
|
|
|
"goo.gl",
|
|
|
|
"tinyurl.com"
|
|
|
|
};
|
|
|
|
|
|
|
|
private final CopyOnWriteArrayList<String> kPrefetchWhiteList =
|
|
|
|
new CopyOnWriteArrayList<String>(kPrefetchWhiteListArray);
|
|
|
|
|
|
|
|
private boolean isHostOnPrefetchWhitelist(String host) {
|
|
|
|
return kPrefetchWhiteList.contains(host);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
2012-01-13 11:08:39 -08:00
|
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onNewIntent");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2012-01-09 23:50:56 -08:00
|
|
|
|
2012-02-29 15:56:53 -08:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2012-03-07 17:59:27 -08:00
|
|
|
// don't perform any actions if launching from recent apps
|
|
|
|
if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0)
|
|
|
|
return;
|
|
|
|
|
2012-01-09 23:50:56 -08:00
|
|
|
if (checkLaunchState(LaunchState.Launched)) {
|
|
|
|
Uri data = intent.getData();
|
|
|
|
Bundle bundle = intent.getExtras();
|
|
|
|
// if the intent has data (i.e. a URI to be opened) and the scheme
|
|
|
|
// is either http, we'll prefetch it, which means warming
|
|
|
|
// up the radio and DNS cache by connecting and parsing the redirect
|
|
|
|
// if the return code is between 300 and 400
|
|
|
|
if (data != null &&
|
|
|
|
"http".equals(data.getScheme()) &&
|
|
|
|
(bundle == null || bundle.getInt("prefetched", 0) != 1) &&
|
|
|
|
isHostOnPrefetchWhitelist(data.getHost())) {
|
|
|
|
GeckoAppShell.getHandler().post(new RedirectorRunnable(intent));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
final String action = intent.getAction();
|
|
|
|
|
|
|
|
if (Intent.ACTION_MAIN.equals(action)) {
|
|
|
|
Log.i(LOGTAG, "Intent : ACTION_MAIN");
|
2012-04-13 19:45:25 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(""));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-01-09 23:50:56 -08:00
|
|
|
else if (ACTION_LOAD.equals(action)) {
|
|
|
|
String uri = intent.getDataString();
|
2012-06-10 16:44:50 -07:00
|
|
|
loadUrl(uri, AwesomeBar.Target.CURRENT_TAB);
|
2012-01-09 23:50:56 -08:00
|
|
|
Log.i(LOGTAG,"onNewIntent: " + uri);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
else if (Intent.ACTION_VIEW.equals(action)) {
|
|
|
|
String uri = intent.getDataString();
|
2012-04-13 19:45:25 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(uri));
|
2011-11-23 00:43:08 -08:00
|
|
|
Log.i(LOGTAG,"onNewIntent: " + uri);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
else if (ACTION_WEBAPP.equals(action)) {
|
2012-01-28 09:24:51 -08:00
|
|
|
String uri = getURIFromIntent(intent);
|
2012-04-13 19:45:25 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createWebappLoadEvent(uri));
|
2011-11-18 10:28:17 -08:00
|
|
|
Log.i(LOGTAG,"Intent : WEBAPP - " + uri);
|
|
|
|
}
|
|
|
|
else if (ACTION_BOOKMARK.equals(action)) {
|
2012-01-28 09:24:51 -08:00
|
|
|
String uri = getURIFromIntent(intent);
|
2012-04-13 19:45:25 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBookmarkLoadEvent(uri));
|
2012-01-28 09:24:51 -08:00
|
|
|
Log.i(LOGTAG,"Intent : BOOKMARK - " + uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handles getting a uri from and intent in a way that is backwards
|
|
|
|
* compatable with our previous implementations
|
|
|
|
*/
|
|
|
|
private String getURIFromIntent(Intent intent) {
|
|
|
|
String uri = intent.getDataString();
|
|
|
|
if (uri != null)
|
|
|
|
return uri;
|
|
|
|
|
|
|
|
final String action = intent.getAction();
|
|
|
|
if (ACTION_WEBAPP.equals(action) || ACTION_BOOKMARK.equals(action)) {
|
|
|
|
uri = intent.getStringExtra("args");
|
|
|
|
if (uri != null && uri.startsWith("--url=")) {
|
|
|
|
uri.replace("--url=", "");
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-01-28 09:24:51 -08:00
|
|
|
return uri;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume()
|
|
|
|
{
|
|
|
|
Log.i(LOGTAG, "resume");
|
2012-02-15 12:34:31 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// After an onPause, the activity is back in the foreground.
|
|
|
|
// Undo whatever we did in onPause.
|
|
|
|
super.onResume();
|
|
|
|
|
2012-05-07 16:17:08 -07:00
|
|
|
SiteIdentityPopup.getInstance().dismiss();
|
2012-05-02 09:07:58 -07:00
|
|
|
|
2012-01-30 15:10:16 -08:00
|
|
|
int newOrientation = getResources().getConfiguration().orientation;
|
|
|
|
|
|
|
|
if (mOrientation != newOrientation) {
|
|
|
|
mOrientation = newOrientation;
|
2012-06-11 15:18:40 -07:00
|
|
|
refreshChrome();
|
2012-01-30 15:10:16 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-04-13 12:31:16 -07:00
|
|
|
@Override
|
|
|
|
public void onWindowFocusChanged(boolean hasFocus) {
|
|
|
|
super.onWindowFocusChanged(hasFocus);
|
|
|
|
|
|
|
|
if (!mInitialized && hasFocus)
|
|
|
|
initialize();
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public void onStop()
|
|
|
|
{
|
|
|
|
Log.i(LOGTAG, "stop");
|
|
|
|
// We're about to be stopped, potentially in preparation for
|
|
|
|
// being destroyed. We're killable after this point -- as I
|
|
|
|
// understand it, in extreme cases the process can be terminated
|
|
|
|
// without going through onDestroy.
|
|
|
|
//
|
|
|
|
// We might also get an onRestart after this; not sure what
|
|
|
|
// that would mean for Gecko if we were to kill it here.
|
|
|
|
// Instead, what we should do here is save prefs, session,
|
|
|
|
// etc., and generally mark the profile as 'clean', and then
|
|
|
|
// dirty it again if we get an onResume.
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createStoppingEvent(isApplicationInBackground()));
|
2011-11-18 10:28:17 -08:00
|
|
|
super.onStop();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onRestart()
|
|
|
|
{
|
|
|
|
Log.i(LOGTAG, "restart");
|
|
|
|
super.onRestart();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart()
|
|
|
|
{
|
2012-01-13 11:08:39 -08:00
|
|
|
Log.w(LOGTAG, "zerdatime " + SystemClock.uptimeMillis() + " - onStart");
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
Log.i(LOGTAG, "start");
|
2012-04-03 11:58:01 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createStartEvent(isApplicationInBackground()));
|
2011-11-18 10:28:17 -08:00
|
|
|
super.onStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy()
|
|
|
|
{
|
|
|
|
Log.i(LOGTAG, "destroy");
|
|
|
|
|
|
|
|
// Tell Gecko to shutting down; we'll end up calling System.exit()
|
|
|
|
// in onXreExit.
|
|
|
|
if (isFinishing())
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createShutdownEvent());
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("DOMContentLoaded", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("DOMTitleChanged", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("DOMLinkAdded", GeckoApp.mAppContext);
|
2011-12-30 11:48:21 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("DOMWindowClose", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("log", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Content:LocationChange", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Content:SecurityChange", GeckoApp.mAppContext);
|
2012-06-02 11:23:45 -07:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Content:ReaderEnabled", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Content:StateChange", GeckoApp.mAppContext);
|
2011-12-16 11:32:32 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Content:LoadError", GeckoApp.mAppContext);
|
2012-05-02 13:55:27 -07:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Content:PageShow", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("onCameraCapture", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Doorhanger:Add", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Menu:Add", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Menu:Remove", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Gecko:Ready", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
|
2012-03-07 16:24:38 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("ToggleChrome:Focus", GeckoApp.mAppContext);
|
2011-12-17 13:50:09 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
|
2012-01-23 13:47:48 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("CharEncoding:Data", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("CharEncoding:State", GeckoApp.mAppContext);
|
2012-01-30 20:47:23 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Tab:HasTouchListener", GeckoApp.mAppContext);
|
2012-02-14 09:50:55 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Session:StatePurged", GeckoApp.mAppContext);
|
2012-02-21 21:11:50 -08:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Bookmark:Insert", GeckoApp.mAppContext);
|
2012-05-10 10:33:12 -07:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Accessibility:Event", GeckoApp.mAppContext);
|
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Accessibility:Ready", GeckoApp.mAppContext);
|
2012-06-06 13:52:14 -07:00
|
|
|
GeckoAppShell.unregisterGeckoEventListener("Shortcut:Remove", GeckoApp.mAppContext);
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-04-30 13:17:29 -07:00
|
|
|
if (mFavicons != null)
|
|
|
|
mFavicons.close();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-01-17 10:38:04 -08:00
|
|
|
if (SmsManager.getInstance() != null) {
|
2012-01-24 08:06:47 -08:00
|
|
|
SmsManager.getInstance().stop();
|
|
|
|
if (isFinishing())
|
|
|
|
SmsManager.getInstance().shutdown();
|
2012-01-17 10:38:04 -08:00
|
|
|
}
|
2012-01-17 10:52:17 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
super.onDestroy();
|
2011-11-22 12:48:22 -08:00
|
|
|
|
2012-04-30 13:17:29 -07:00
|
|
|
if (mBatteryReceiver != null)
|
|
|
|
mBatteryReceiver.unregisterFor(mAppContext);
|
2012-03-08 15:48:44 -08:00
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
((GeckoApplication) getApplication()).removeApplicationLifecycleCallbacks(this);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-11-28 22:38:35 -08:00
|
|
|
@Override
|
|
|
|
public void onContentChanged() {
|
|
|
|
super.onContentChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
2011-12-21 00:03:34 -08:00
|
|
|
public void onConfigurationChanged(Configuration newConfig)
|
2011-11-18 10:28:17 -08:00
|
|
|
{
|
|
|
|
Log.i(LOGTAG, "configuration changed");
|
2011-12-06 16:44:08 -08:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
super.onConfigurationChanged(newConfig);
|
2011-12-21 00:03:34 -08:00
|
|
|
|
|
|
|
if (mOrientation != newConfig.orientation) {
|
|
|
|
mOrientation = newConfig.orientation;
|
2012-04-28 12:46:03 -07:00
|
|
|
if (mFormAssistPopup != null)
|
|
|
|
mFormAssistPopup.hide();
|
2012-05-07 16:17:08 -07:00
|
|
|
SiteIdentityPopup.getInstance().dismiss();
|
2012-06-11 15:18:40 -07:00
|
|
|
refreshChrome();
|
2011-12-21 00:03:34 -08:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onLowMemory()
|
|
|
|
{
|
|
|
|
Log.e(LOGTAG, "low memory");
|
|
|
|
if (checkLaunchState(LaunchState.GeckoRunning))
|
|
|
|
GeckoAppShell.onLowMemory();
|
|
|
|
super.onLowMemory();
|
2012-04-26 12:47:59 -07:00
|
|
|
GeckoAppShell.geckoEventSync();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-04-03 11:58:01 -07:00
|
|
|
@Override
|
|
|
|
public void onApplicationPause() {
|
|
|
|
Log.i(LOGTAG, "application paused");
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createPauseEvent(true));
|
2012-04-04 17:29:30 -07:00
|
|
|
|
2012-04-23 13:58:14 -07:00
|
|
|
if (mConnectivityReceiver != null)
|
|
|
|
mConnectivityReceiver.unregisterFor(mAppContext);
|
2012-04-04 17:29:30 -07:00
|
|
|
GeckoNetworkManager.getInstance().stop();
|
|
|
|
GeckoScreenOrientationListener.getInstance().stop();
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onApplicationResume() {
|
|
|
|
Log.i(LOGTAG, "application resumed");
|
|
|
|
if (checkLaunchState(LaunchState.GeckoRunning))
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createResumeEvent(true));
|
2012-04-04 17:29:30 -07:00
|
|
|
|
2012-04-23 13:58:14 -07:00
|
|
|
if (mConnectivityReceiver != null)
|
|
|
|
mConnectivityReceiver.registerFor(mAppContext);
|
2012-04-04 17:29:30 -07:00
|
|
|
GeckoNetworkManager.getInstance().start();
|
|
|
|
GeckoScreenOrientationListener.getInstance().start();
|
2012-04-03 11:58:01 -07:00
|
|
|
}
|
|
|
|
|
2012-05-16 15:28:28 -07:00
|
|
|
@Override
|
|
|
|
public Object onRetainNonConfigurationInstance() {
|
|
|
|
// Send a non-null value so that we can restart the application,
|
|
|
|
// when activity restarts due to configuration change.
|
|
|
|
return new Boolean(true);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
abstract public String getPackageName();
|
|
|
|
abstract public String getContentProcessName();
|
|
|
|
|
|
|
|
public void addEnvToIntent(Intent intent) {
|
|
|
|
Map<String,String> envMap = System.getenv();
|
|
|
|
Set<Map.Entry<String,String>> envSet = envMap.entrySet();
|
|
|
|
Iterator<Map.Entry<String,String>> envIter = envSet.iterator();
|
|
|
|
int c = 0;
|
|
|
|
while (envIter.hasNext()) {
|
|
|
|
Map.Entry<String,String> entry = envIter.next();
|
|
|
|
intent.putExtra("env" + c, entry.getKey() + "="
|
|
|
|
+ entry.getValue());
|
|
|
|
c++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void doRestart() {
|
2012-01-24 20:32:12 -08:00
|
|
|
doRestart("org.mozilla.gecko.restart");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void doRestart(String action) {
|
|
|
|
Log.i(LOGTAG, "doRestart(\"" + action + "\")");
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
|
|
|
Intent intent = new Intent(action);
|
|
|
|
intent.setClassName(getPackageName(),
|
|
|
|
getPackageName() + ".Restarter");
|
|
|
|
/* TODO: addEnvToIntent(intent); */
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
|
|
|
|
Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
|
|
|
Log.i(LOGTAG, intent.toString());
|
|
|
|
GeckoAppShell.killAnyZombies();
|
|
|
|
startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "error doing restart", e);
|
|
|
|
}
|
|
|
|
finish();
|
|
|
|
// Give the restart process time to start before we die
|
|
|
|
GeckoAppShell.waitForAnotherGeckoProc();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleNotification(String action, String alertName, String alertCookie) {
|
|
|
|
GeckoAppShell.handleNotification(action, alertName, alertCookie);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void checkAndLaunchUpdate() {
|
|
|
|
Log.i(LOGTAG, "Checking for an update");
|
|
|
|
|
|
|
|
int statusCode = 8; // UNEXPECTED_ERROR
|
|
|
|
File baseUpdateDir = null;
|
|
|
|
if (Build.VERSION.SDK_INT >= 8)
|
|
|
|
baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS);
|
|
|
|
else
|
|
|
|
baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download");
|
|
|
|
|
|
|
|
File updateDir = new File(new File(baseUpdateDir, "updates"),"0");
|
|
|
|
|
|
|
|
File updateFile = new File(updateDir, "update.apk");
|
|
|
|
File statusFile = new File(updateDir, "update.status");
|
|
|
|
|
|
|
|
if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!updateFile.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Log.i(LOGTAG, "Update is available!");
|
|
|
|
|
|
|
|
// Launch APK
|
|
|
|
File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk");
|
|
|
|
try {
|
|
|
|
if (updateFile.renameTo(updateFileToRun)) {
|
|
|
|
String amCmd = "/system/bin/am start -a android.intent.action.VIEW " +
|
|
|
|
"-n com.android.packageinstaller/.PackageInstallerActivity -d file://" +
|
|
|
|
updateFileToRun.getPath();
|
|
|
|
Log.i(LOGTAG, amCmd);
|
|
|
|
Runtime.getRuntime().exec(amCmd);
|
|
|
|
statusCode = 0; // OK
|
|
|
|
} else {
|
|
|
|
Log.i(LOGTAG, "Cannot rename the update file!");
|
|
|
|
statusCode = 7; // WRITE_ERROR
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "error launching installer to update", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the status file
|
|
|
|
String status = statusCode == 0 ? "succeeded\n" : "failed: "+ statusCode + "\n";
|
|
|
|
|
|
|
|
OutputStream outStream;
|
|
|
|
try {
|
|
|
|
byte[] buf = status.getBytes("UTF-8");
|
|
|
|
outStream = new FileOutputStream(statusFile);
|
|
|
|
outStream.write(buf, 0, buf.length);
|
|
|
|
outStream.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "error writing status file", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statusCode == 0)
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String readUpdateStatus(File statusFile) {
|
|
|
|
String status = "";
|
|
|
|
try {
|
|
|
|
BufferedReader reader = new BufferedReader(new FileReader(statusFile));
|
|
|
|
status = reader.readLine();
|
|
|
|
reader.close();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.i(LOGTAG, "error reading update status", e);
|
|
|
|
}
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2011-12-19 13:56:11 -08:00
|
|
|
private void checkMigrateProfile() {
|
2012-04-17 13:01:28 -07:00
|
|
|
final File profileDir = getProfile().getDir();
|
|
|
|
final long currentTime = SystemClock.uptimeMillis();
|
2012-02-10 14:01:44 -08:00
|
|
|
|
2011-12-19 13:56:11 -08:00
|
|
|
if (profileDir != null) {
|
2012-01-19 12:19:56 -08:00
|
|
|
final GeckoApp app = GeckoApp.mAppContext;
|
2012-04-04 12:29:31 -07:00
|
|
|
|
2012-04-19 07:41:52 -07:00
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
Log.i(LOGTAG, "Checking profile migration in: " + profileDir.getAbsolutePath());
|
|
|
|
|
2012-05-08 15:51:07 -07:00
|
|
|
ProfileMigrator profileMigrator = new ProfileMigrator(app);
|
2012-04-04 12:29:31 -07:00
|
|
|
|
2012-04-19 07:41:52 -07:00
|
|
|
// Do a migration run on the first start after an upgrade.
|
|
|
|
if (!profileMigrator.hasMigrationRun()) {
|
2012-04-19 13:07:39 -07:00
|
|
|
// Show the "Setting up Fennec" screen if this takes
|
|
|
|
// a while.
|
2012-04-19 07:41:52 -07:00
|
|
|
final SetupScreen setupScreen = new SetupScreen(app);
|
|
|
|
|
2012-04-19 13:07:39 -07:00
|
|
|
final Runnable startCallback = new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
setupScreen.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
final Runnable stopCallback = new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
GeckoApp.mAppContext.runOnUiThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
setupScreen.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
2012-04-04 12:29:31 -07:00
|
|
|
|
2012-04-19 13:07:39 -07:00
|
|
|
profileMigrator.setLongOperationCallbacks(startCallback,
|
|
|
|
stopCallback);
|
2012-05-08 15:51:07 -07:00
|
|
|
profileMigrator.launchPlaces(profileDir);
|
2012-04-17 13:01:28 -07:00
|
|
|
|
|
|
|
long timeDiff = SystemClock.uptimeMillis() - currentTime;
|
|
|
|
Log.i(LOGTAG, "Profile migration took " + timeDiff + " ms");
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
finishProfileMigration();
|
2012-04-17 13:01:28 -07:00
|
|
|
}
|
2012-04-19 07:41:52 -07:00
|
|
|
}}
|
|
|
|
);
|
2012-04-17 13:01:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
protected void finishProfileMigration() {
|
|
|
|
}
|
|
|
|
|
2012-04-17 13:01:28 -07:00
|
|
|
private void checkMigrateSync() {
|
|
|
|
final File profileDir = getProfile().getDir();
|
|
|
|
if (profileDir != null) {
|
|
|
|
final GeckoApp app = GeckoApp.mAppContext;
|
2012-05-08 15:51:07 -07:00
|
|
|
ProfileMigrator profileMigrator = new ProfileMigrator(app);
|
2012-04-17 13:01:28 -07:00
|
|
|
if (!profileMigrator.hasSyncMigrated()) {
|
|
|
|
Log.i(LOGTAG, "Checking Sync settings in: " + profileDir.getAbsolutePath());
|
|
|
|
profileMigrator.launchSyncPrefs();
|
2012-04-04 12:29:31 -07:00
|
|
|
}
|
2011-12-19 13:56:11 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-18 09:15:56 -07:00
|
|
|
/**
|
|
|
|
* The FilePickerPromptRunnable has to be called to show an intent-like
|
|
|
|
* context menu UI using the PromptService.
|
|
|
|
*/
|
|
|
|
private class FilePickerPromptRunnable implements Runnable {
|
|
|
|
public FilePickerPromptRunnable(String aTitle, PromptService.PromptListItem[] aItems) {
|
|
|
|
super();
|
|
|
|
mTitle = aTitle;
|
|
|
|
mItems = aItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
GeckoAppShell.getPromptService().Show(mTitle, "", null, mItems, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String mTitle;
|
|
|
|
private PromptService.PromptListItem[] mItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
private int addIntentActivitiesToList(Intent intent, ArrayList<PromptService.PromptListItem> items, ArrayList<Intent> aIntents) {
|
|
|
|
PackageManager pm = mAppContext.getPackageManager();
|
|
|
|
final List<ResolveInfo> lri =
|
|
|
|
pm.queryIntentActivityOptions(GeckoApp.mAppContext.getComponentName(), null, intent, 0);
|
|
|
|
|
|
|
|
if (lri == null) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i<lri.size(); i++) {
|
|
|
|
final ResolveInfo ri = lri.get(i);
|
|
|
|
Intent rintent = new Intent(intent);
|
|
|
|
rintent.setComponent(new ComponentName(
|
|
|
|
ri.activityInfo.applicationInfo.packageName,
|
|
|
|
ri.activityInfo.name));
|
|
|
|
|
|
|
|
PromptService.PromptListItem item = new PromptService.PromptListItem(ri.loadLabel(pm).toString());
|
|
|
|
item.icon = ri.loadIcon(pm);
|
|
|
|
items.add(item);
|
|
|
|
aIntents.add(rintent);
|
|
|
|
}
|
|
|
|
|
|
|
|
return lri.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
private int AddFilePickingActivities(ArrayList<PromptService.PromptListItem> aItems, String aType, ArrayList<Intent> aIntents) {
|
Backout 7e28d1a2c648, 330b210f503d, 2421d39e0ab3, aa978ffa44bc, 38a71ae7e06d, b94319584a7a, 7e8278f5e814, 0b4e3c7608ab, 329c07609ca8, 0d61a0d8dba4, Due to Ts regression on Android
2012-03-17 18:51:39 -07:00
|
|
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
2012-03-18 09:15:56 -07:00
|
|
|
intent.setType(aType);
|
Backout 7e28d1a2c648, 330b210f503d, 2421d39e0ab3, aa978ffa44bc, 38a71ae7e06d, b94319584a7a, 7e8278f5e814, 0b4e3c7608ab, 329c07609ca8, 0d61a0d8dba4, Due to Ts regression on Android
2012-03-17 18:51:39 -07:00
|
|
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
2012-03-18 09:15:56 -07:00
|
|
|
|
|
|
|
return addIntentActivitiesToList(intent, aItems, aIntents);
|
|
|
|
}
|
|
|
|
|
|
|
|
static private String generateImageName() {
|
|
|
|
Time now = new Time();
|
|
|
|
now.setToNow();
|
|
|
|
return now.format("%Y-%m-%d %H.%M.%S") + ".jpg";
|
|
|
|
}
|
|
|
|
|
|
|
|
private PromptService.PromptListItem[] getItemsAndIntentsForFilePicker(String aMimeType, ArrayList<Intent> aIntents) {
|
|
|
|
ArrayList<PromptService.PromptListItem> items = new ArrayList<PromptService.PromptListItem>();
|
|
|
|
|
|
|
|
if (aMimeType.equals("audio/*")) {
|
|
|
|
if (AddFilePickingActivities(items, "audio/*", aIntents) <= 0) {
|
|
|
|
AddFilePickingActivities(items, "*/*", aIntents);
|
|
|
|
}
|
|
|
|
} else if (aMimeType.equals("image/*")) {
|
|
|
|
mImageFilePath = generateImageName();
|
|
|
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT,
|
|
|
|
Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
|
|
|
|
mImageFilePath)));
|
|
|
|
addIntentActivitiesToList(intent, items, aIntents);
|
|
|
|
|
|
|
|
if (AddFilePickingActivities(items, "image/*", aIntents) <= 0) {
|
|
|
|
AddFilePickingActivities(items, "*/*", aIntents);
|
|
|
|
}
|
|
|
|
} else if (aMimeType.equals("video/*")) {
|
|
|
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
|
|
|
|
addIntentActivitiesToList(intent, items, aIntents);
|
|
|
|
|
|
|
|
if (AddFilePickingActivities(items, "video/*", aIntents) <= 0) {
|
|
|
|
AddFilePickingActivities(items, "*/*", aIntents);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mImageFilePath = generateImageName();
|
|
|
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
|
|
|
intent.putExtra(MediaStore.EXTRA_OUTPUT,
|
|
|
|
Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
|
|
|
|
mImageFilePath)));
|
|
|
|
addIntentActivitiesToList(intent, items, aIntents);
|
|
|
|
|
|
|
|
intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
|
|
|
|
addIntentActivitiesToList(intent, items, aIntents);
|
|
|
|
|
|
|
|
AddFilePickingActivities(items, "*/*", aIntents);
|
|
|
|
}
|
|
|
|
|
|
|
|
return items.toArray(new PromptService.PromptListItem[] {});
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getFilePickerTitle(String aMimeType) {
|
|
|
|
if (aMimeType.equals("audio/*")) {
|
|
|
|
return getString(R.string.filepicker_audio_title);
|
|
|
|
} else if (aMimeType.equals("image/*")) {
|
|
|
|
return getString(R.string.filepicker_image_title);
|
|
|
|
} else if (aMimeType.equals("video/*")) {
|
|
|
|
return getString(R.string.filepicker_video_title);
|
|
|
|
} else {
|
|
|
|
return getString(R.string.filepicker_title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-14 11:35:47 -07:00
|
|
|
private Intent getFilePickerIntent(String aMimeType) {
|
2012-03-18 09:15:56 -07:00
|
|
|
ArrayList<Intent> intents = new ArrayList<Intent>();
|
|
|
|
PromptService.PromptListItem[] items = getItemsAndIntentsForFilePicker(aMimeType, intents);
|
|
|
|
|
2012-03-14 11:35:47 -07:00
|
|
|
if (intents.size() == 0) {
|
|
|
|
Log.i(LOGTAG, "no activities for the file picker!");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (intents.size() == 1)
|
|
|
|
return intents.get(0);
|
|
|
|
|
2012-03-18 09:15:56 -07:00
|
|
|
GeckoAppShell.getHandler().post(new FilePickerPromptRunnable(getFilePickerTitle(aMimeType), items));
|
|
|
|
|
|
|
|
String promptServiceResult = "";
|
|
|
|
try {
|
|
|
|
promptServiceResult = PromptService.waitForReturn();
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Log.e(LOGTAG, "showing prompt failed: ", e);
|
2012-03-14 11:35:47 -07:00
|
|
|
return null;
|
2012-03-18 09:15:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int itemId = -1;
|
|
|
|
try {
|
|
|
|
itemId = new JSONObject(promptServiceResult).getInt("button");
|
|
|
|
|
|
|
|
if (itemId == -1) {
|
2012-03-14 11:35:47 -07:00
|
|
|
return null;
|
2012-03-18 09:15:56 -07:00
|
|
|
}
|
|
|
|
} catch (org.json.JSONException e) {
|
|
|
|
Log.e(LOGTAG, "result from promptservice was invalid: ", e);
|
2012-03-14 11:35:47 -07:00
|
|
|
return null;
|
2012-03-18 09:15:56 -07:00
|
|
|
}
|
|
|
|
|
2012-03-14 11:35:47 -07:00
|
|
|
return intents.get(itemId);
|
|
|
|
}
|
|
|
|
|
|
|
|
private String mImageFilePath = "";
|
|
|
|
private SynchronousQueue<String> mFilePickerResult = new SynchronousQueue<String>();
|
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
public boolean showFilePicker(String aMimeType, ActivityResultHandler handler) {
|
|
|
|
Intent intent = getFilePickerIntent(aMimeType);
|
|
|
|
|
|
|
|
if (intent == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
startActivityForResult(intent, mActivityResultHandlerMap.put(handler));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-03-14 11:35:47 -07:00
|
|
|
public String showFilePicker(String aMimeType) {
|
|
|
|
Intent intent = getFilePickerIntent(aMimeType);
|
|
|
|
|
|
|
|
if (intent == null) {
|
|
|
|
return "";
|
|
|
|
}
|
2012-03-18 09:15:56 -07:00
|
|
|
|
|
|
|
if (intent.getAction().equals(android.provider.MediaStore.ACTION_IMAGE_CAPTURE)) {
|
2012-04-04 22:50:06 -07:00
|
|
|
startActivityForResult(intent, mActivityResultHandlerMap.put(mCameraImageResultHandler));
|
2012-03-18 09:15:56 -07:00
|
|
|
} else if (intent.getAction().equals(android.provider.MediaStore.ACTION_VIDEO_CAPTURE)) {
|
2012-04-04 22:50:06 -07:00
|
|
|
startActivityForResult(intent, mActivityResultHandlerMap.put(mCameraVideoResultHandler));
|
2012-03-18 09:15:56 -07:00
|
|
|
} else if (intent.getAction().equals(Intent.ACTION_GET_CONTENT)) {
|
2012-04-04 22:50:06 -07:00
|
|
|
startActivityForResult(intent, mActivityResultHandlerMap.put(mFilePickerResultHandlerSync));
|
2012-03-18 09:15:56 -07:00
|
|
|
} else {
|
|
|
|
Log.e(LOGTAG, "We should not get an intent with another action!");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
String filePickerResult = "";
|
|
|
|
|
|
|
|
try {
|
|
|
|
while (null == (filePickerResult = mFilePickerResult.poll(1, TimeUnit.MILLISECONDS))) {
|
|
|
|
GeckoAppShell.processNextNativeEvent();
|
|
|
|
}
|
|
|
|
} catch (InterruptedException e) {
|
2012-03-18 09:15:56 -07:00
|
|
|
Log.e(LOGTAG, "showing file picker failed: ", e);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return filePickerResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onSearchRequested() {
|
2012-06-10 16:44:50 -07:00
|
|
|
return showAwesomebar(AwesomeBar.Target.CURRENT_TAB);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
public boolean showAwesomebar(AwesomeBar.Target aTarget) {
|
|
|
|
return showAwesomebar(aTarget, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean showAwesomebar(AwesomeBar.Target aTarget, String aUrl) {
|
2011-11-18 10:28:17 -08:00
|
|
|
Intent intent = new Intent(getBaseContext(), AwesomeBar.class);
|
|
|
|
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_NO_HISTORY);
|
2012-06-10 16:44:50 -07:00
|
|
|
intent.putExtra(AwesomeBar.TARGET_KEY, aTarget.name());
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
// if we were passed in a url, show it
|
|
|
|
if (aUrl != null && !TextUtils.isEmpty(aUrl)) {
|
|
|
|
intent.putExtra(AwesomeBar.CURRENT_URL_KEY, aUrl);
|
|
|
|
} else if (aTarget == AwesomeBar.Target.CURRENT_TAB) {
|
|
|
|
// otherwise, if we're editing the current tab, show its url
|
2011-11-18 10:28:17 -08:00
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
2012-06-10 16:44:50 -07:00
|
|
|
|
|
|
|
aUrl = tab.getURL();
|
|
|
|
if (aUrl != null) {
|
|
|
|
intent.putExtra(AwesomeBar.CURRENT_URL_KEY, aUrl);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
startActivityForResult(intent, mActivityResultHandlerMap.put(mAwesomebarResultHandler));
|
2011-11-18 10:28:17 -08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2012-06-11 15:18:40 -07:00
|
|
|
if (mTabsPanel != null && mTabsPanel.isShown()) {
|
2012-06-10 16:44:50 -07:00
|
|
|
mTabsPanel.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
if (mDoorHangerPopup.isShowing()) {
|
|
|
|
mDoorHangerPopup.dismiss();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
if (mFullScreenPluginView != null) {
|
2012-06-11 10:50:59 -07:00
|
|
|
GeckoAppShell.onFullScreenPluginHidden(mFullScreenPluginView);
|
|
|
|
removeFullScreenPluginView(mFullScreenPluginView);
|
2012-05-30 09:10:49 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-07 16:17:08 -07:00
|
|
|
SiteIdentityPopup identityPopup = SiteIdentityPopup.getInstance();
|
|
|
|
if (identityPopup.isShowing()) {
|
|
|
|
identityPopup.dismiss();
|
2012-05-02 09:07:58 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-01-26 09:17:33 -08:00
|
|
|
if (mDOMFullScreen) {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FullScreen:Exit", null));
|
2011-11-18 10:28:17 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-19 10:44:52 -08:00
|
|
|
Tabs tabs = Tabs.getInstance();
|
|
|
|
Tab tab = tabs.getSelectedTab();
|
|
|
|
if (tab == null) {
|
2011-11-18 10:28:17 -08:00
|
|
|
moveTaskToBack(true);
|
2011-12-19 10:44:52 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tab.doBack())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (tab.isExternal()) {
|
|
|
|
moveTaskToBack(true);
|
|
|
|
tabs.closeTab(tab);
|
|
|
|
return;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2011-12-19 10:44:52 -08:00
|
|
|
|
|
|
|
int parentId = tab.getParentId();
|
|
|
|
Tab parent = tabs.getTab(parentId);
|
|
|
|
if (parent != null) {
|
|
|
|
// The back button should always return to the parent (not a sibling).
|
|
|
|
tabs.closeTab(tab, parent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
moveTaskToBack(true);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int kCaptureIndex = 0;
|
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
public interface ActivityResultHandler {
|
|
|
|
public void onActivityResult(int resultCode, Intent data);
|
|
|
|
}
|
|
|
|
|
|
|
|
class ActivityResultHandlerMap {
|
|
|
|
private Map<Integer, ActivityResultHandler> mMap = new HashMap<Integer, ActivityResultHandler>();
|
|
|
|
private int mCounter = 0;
|
|
|
|
|
|
|
|
synchronized int put(ActivityResultHandler handler) {
|
|
|
|
mMap.put(mCounter, handler);
|
|
|
|
return mCounter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
synchronized ActivityResultHandler getAndRemove(int i) {
|
|
|
|
return mMap.remove(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
protected void onActivityResult(int requestCode, int resultCode,
|
|
|
|
Intent data) {
|
2012-04-04 22:50:06 -07:00
|
|
|
ActivityResultHandler handler = mActivityResultHandlerMap.getAndRemove(requestCode);
|
|
|
|
if (handler != null)
|
|
|
|
handler.onActivityResult(resultCode, data);
|
|
|
|
else
|
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static abstract class FilePickerResultHandler implements ActivityResultHandler {
|
|
|
|
String handleActivityResult(int resultCode, Intent data) {
|
2012-05-29 08:09:50 -07:00
|
|
|
if (data == null || resultCode != RESULT_OK)
|
2012-04-16 15:53:00 -07:00
|
|
|
return "";
|
2012-04-04 22:50:06 -07:00
|
|
|
Uri uri = data.getData();
|
2012-06-10 16:44:50 -07:00
|
|
|
if (uri == null)
|
|
|
|
return "";
|
2012-04-16 15:53:00 -07:00
|
|
|
if ("file".equals(uri.getScheme())) {
|
|
|
|
String path = uri.getPath();
|
|
|
|
return path == null ? "" : path;
|
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
try {
|
|
|
|
ContentResolver cr = GeckoApp.mAppContext.getContentResolver();
|
|
|
|
Cursor cursor = cr.query(uri, new String[] { OpenableColumns.DISPLAY_NAME },
|
|
|
|
null, null, null);
|
|
|
|
String name = null;
|
|
|
|
if (cursor != null) {
|
|
|
|
try {
|
|
|
|
if (cursor.moveToNext()) {
|
|
|
|
name = cursor.getString(0);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
} finally {
|
|
|
|
cursor.close();
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
String fileName = "tmp_";
|
|
|
|
String fileExt = null;
|
|
|
|
int period;
|
|
|
|
if (name == null || (period = name.lastIndexOf('.')) == -1) {
|
|
|
|
String mimeType = cr.getType(uri);
|
|
|
|
fileExt = "." + GeckoAppShell.getExtensionFromMimeType(mimeType);
|
|
|
|
} else {
|
|
|
|
fileExt = name.substring(period);
|
|
|
|
fileName = name.substring(0, period);
|
|
|
|
}
|
|
|
|
File file = File.createTempFile(fileName, fileExt, GeckoAppShell.getGREDir(GeckoApp.mAppContext));
|
|
|
|
FileOutputStream fos = new FileOutputStream(file);
|
|
|
|
InputStream is = cr.openInputStream(uri);
|
|
|
|
byte[] buf = new byte[4096];
|
|
|
|
int len = is.read(buf);
|
|
|
|
while (len != -1) {
|
|
|
|
fos.write(buf, 0, len);
|
|
|
|
len = is.read(buf);
|
|
|
|
}
|
|
|
|
fos.close();
|
2012-04-16 15:53:00 -07:00
|
|
|
String path = file.getAbsolutePath();
|
|
|
|
return path == null ? "" : path;
|
2012-04-04 22:50:06 -07:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "showing file picker", e);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-04-16 15:53:00 -07:00
|
|
|
return "";
|
2012-04-04 22:50:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class FilePickerResultHandlerSync extends FilePickerResultHandler {
|
|
|
|
public void onActivityResult(int resultCode, Intent data) {
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
2012-04-04 22:50:06 -07:00
|
|
|
mFilePickerResult.put(handleActivityResult(resultCode, data));
|
2011-11-18 10:28:17 -08:00
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Log.i(LOGTAG, "error returning file picker result", e);
|
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class AwesomebarResultHandler implements ActivityResultHandler {
|
|
|
|
public void onActivityResult(int resultCode, Intent data) {
|
2011-11-18 10:28:17 -08:00
|
|
|
if (data != null) {
|
|
|
|
String url = data.getStringExtra(AwesomeBar.URL_KEY);
|
2012-06-10 16:44:50 -07:00
|
|
|
AwesomeBar.Target target = AwesomeBar.Target.valueOf(data.getStringExtra(AwesomeBar.TARGET_KEY));
|
2011-12-07 17:52:07 -08:00
|
|
|
String searchEngine = data.getStringExtra(AwesomeBar.SEARCH_KEY);
|
2012-02-22 18:26:04 -08:00
|
|
|
boolean userEntered = data.getBooleanExtra(AwesomeBar.USER_ENTERED_KEY, false);
|
2011-12-16 11:32:32 -08:00
|
|
|
if (url != null && url.length() > 0)
|
2012-06-10 16:44:50 -07:00
|
|
|
loadRequest(url, target, searchEngine, userEntered);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class CameraImageResultHandler implements ActivityResultHandler {
|
2012-06-10 16:44:50 -07:00
|
|
|
public void onActivityResult(int resultCode, Intent data) {
|
2012-03-18 09:15:56 -07:00
|
|
|
try {
|
|
|
|
if (resultCode != Activity.RESULT_OK) {
|
|
|
|
mFilePickerResult.put("");
|
2012-04-04 22:50:06 -07:00
|
|
|
return;
|
2012-03-18 09:15:56 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-03-18 09:15:56 -07:00
|
|
|
File file = new File(Environment.getExternalStorageDirectory(), mImageFilePath);
|
|
|
|
mImageFilePath = "";
|
|
|
|
mFilePickerResult.put(file.getAbsolutePath());
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Log.i(LOGTAG, "error returning file picker result", e);
|
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
}
|
|
|
|
}
|
2012-03-16 14:44:00 -07:00
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
class CameraVideoResultHandler implements ActivityResultHandler {
|
|
|
|
public void onActivityResult(int resultCode, Intent data) {
|
2012-03-18 09:15:56 -07:00
|
|
|
try {
|
|
|
|
if (data == null || resultCode != Activity.RESULT_OK) {
|
|
|
|
mFilePickerResult.put("");
|
2012-04-04 22:50:06 -07:00
|
|
|
return;
|
2012-03-18 09:15:56 -07:00
|
|
|
}
|
Backout 7e28d1a2c648, 330b210f503d, 2421d39e0ab3, aa978ffa44bc, 38a71ae7e06d, b94319584a7a, 7e8278f5e814, 0b4e3c7608ab, 329c07609ca8, 0d61a0d8dba4, Due to Ts regression on Android
2012-03-17 18:51:39 -07:00
|
|
|
|
2012-03-18 09:15:56 -07:00
|
|
|
Cursor cursor = managedQuery(data.getData(),
|
|
|
|
new String[] { MediaStore.Video.Media.DATA },
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
cursor.moveToFirst();
|
|
|
|
mFilePickerResult.put(cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA)));
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
Log.i(LOGTAG, "error returning file picker result", e);
|
|
|
|
}
|
|
|
|
|
2012-04-04 22:50:06 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-07 17:52:07 -08:00
|
|
|
// If searchEngine is provided, url will be used as the search query.
|
|
|
|
// Otherwise, the url is loaded.
|
2012-06-11 15:18:40 -07:00
|
|
|
protected void loadRequest(String url, AwesomeBar.Target target, String searchEngine, boolean userEntered) {
|
2012-06-10 16:44:50 -07:00
|
|
|
Log.d(LOGTAG, target.name());
|
2011-12-07 17:52:07 -08:00
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("url", url);
|
|
|
|
args.put("engine", searchEngine);
|
2012-02-22 18:26:04 -08:00
|
|
|
args.put("userEntered", userEntered);
|
2011-12-07 17:52:07 -08:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "error building JSON arguments");
|
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
|
|
|
|
if (target == AwesomeBar.Target.NEW_TAB) {
|
2012-03-12 12:48:55 -07:00
|
|
|
Log.d(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add");
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString()));
|
2011-11-18 10:28:17 -08:00
|
|
|
} else {
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Load", args.toString()));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 07:59:50 -07:00
|
|
|
public void loadUrl(String url) {
|
|
|
|
loadRequest(url, AwesomeBar.Target.CURRENT_TAB, null, false);
|
|
|
|
}
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
public void loadUrl(String url, AwesomeBar.Target target) {
|
|
|
|
loadRequest(url, target, null, false);
|
2011-12-07 17:52:07 -08:00
|
|
|
}
|
|
|
|
|
2011-12-19 10:44:52 -08:00
|
|
|
/**
|
2012-01-03 10:57:24 -08:00
|
|
|
* Open the url as a new tab, and mark the selected tab as its "parent".
|
|
|
|
* If the url is already open in a tab, the existing tab is selected.
|
2011-12-19 10:44:52 -08:00
|
|
|
* Use this for tabs opened by the browser chrome, so users can press the
|
|
|
|
* "Back" button to return to the previous tab.
|
|
|
|
*/
|
2012-01-03 10:57:24 -08:00
|
|
|
public void loadUrlInTab(String url) {
|
|
|
|
ArrayList<Tab> tabs = Tabs.getInstance().getTabsInOrder();
|
|
|
|
if (tabs != null) {
|
|
|
|
Iterator<Tab> tabsIter = tabs.iterator();
|
|
|
|
while (tabsIter.hasNext()) {
|
|
|
|
Tab tab = tabsIter.next();
|
|
|
|
if (url.equals(tab.getURL())) {
|
2012-01-25 14:18:47 -08:00
|
|
|
Tabs.getInstance().selectTab(tab.getId());
|
2012-01-03 10:57:24 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-19 10:44:52 -08:00
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("url", url);
|
2012-01-24 09:15:52 -08:00
|
|
|
args.put("parentId", Tabs.getInstance().getSelectedTab().getId());
|
2011-12-19 10:44:52 -08:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "error building JSON arguments");
|
|
|
|
}
|
2012-01-24 09:16:18 -08:00
|
|
|
Log.i(LOGTAG, "Sending message to Gecko: " + SystemClock.uptimeMillis() + " - Tab:Add");
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Add", args.toString()));
|
2011-12-19 10:44:52 -08:00
|
|
|
}
|
|
|
|
|
2012-03-22 10:35:19 -07:00
|
|
|
/* This method is referenced by Robocop via reflection. */
|
2012-02-02 23:30:41 -08:00
|
|
|
public GeckoLayerClient getLayerClient() { return mLayerClient; }
|
2011-11-18 10:28:17 -08:00
|
|
|
public LayerController getLayerController() { return mLayerController; }
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
public AbsoluteLayout getPluginContainer() { return mPluginContainer; }
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
// accelerometer
|
2012-03-20 23:36:17 -07:00
|
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
public void onSensorChanged(SensorEvent event)
|
|
|
|
{
|
2012-02-08 23:18:27 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createSensorEvent(event));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// geolocation
|
|
|
|
public void onLocationChanged(Location location)
|
|
|
|
{
|
|
|
|
Log.w(LOGTAG, "onLocationChanged "+location);
|
2012-03-08 22:16:25 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createLocationEvent(location));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void onProviderDisabled(String provider)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onProviderEnabled(String provider)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onStatusChanged(String provider, int status, Bundle extras)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-06-06 19:39:01 -07:00
|
|
|
// Called when a Gecko Hal WakeLock is changed
|
|
|
|
public void notifyWakeLockChanged(String topic, String state) {
|
|
|
|
PowerManager.WakeLock wl = mWakeLocks.get(topic);
|
|
|
|
if (state.equals("locked-foreground") && wl == null) {
|
|
|
|
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
|
|
|
|
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, topic);
|
|
|
|
wl.acquire();
|
|
|
|
mWakeLocks.put(topic, wl);
|
|
|
|
} else if (!state.equals("locked-foreground") && wl != null) {
|
|
|
|
wl.release();
|
|
|
|
mWakeLocks.remove(topic);
|
|
|
|
}
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
private void connectGeckoLayerClient() {
|
|
|
|
LayerController layerController = getLayerController();
|
2012-02-02 23:30:41 -08:00
|
|
|
layerController.setLayerClient(mLayerClient);
|
2012-04-04 08:55:40 -07:00
|
|
|
|
2012-04-07 00:09:26 -07:00
|
|
|
layerController.getView().getTouchEventHandler().setOnTouchListener(new View.OnTouchListener() {
|
2012-04-04 08:55:40 -07:00
|
|
|
public boolean onTouch(View view, MotionEvent event) {
|
|
|
|
if (event == null)
|
|
|
|
return true;
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createMotionEvent(event));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-05-02 04:15:07 -07:00
|
|
|
|
|
|
|
public boolean linkerExtract() {
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-06 19:39:36 -07:00
|
|
|
|
|
|
|
private class FullScreenHolder extends FrameLayout {
|
|
|
|
|
|
|
|
public FullScreenHolder(Context ctx) {
|
|
|
|
super(ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addView(View view, int index) {
|
|
|
|
/**
|
|
|
|
* This normally gets called when Flash adds a separate SurfaceView
|
|
|
|
* for the video. It is unhappy if we have the LayerView underneath
|
|
|
|
* it for some reason so we need to hide that. Hiding the LayerView causes
|
|
|
|
* its surface to be destroyed, which causes a pause composition
|
|
|
|
* event to be sent to Gecko. We synchronously wait for that to be
|
|
|
|
* processed. Simultaneously, however, Flash is waiting on a mutex so
|
|
|
|
* the post() below is an attempt to avoid a deadlock.
|
|
|
|
*/
|
|
|
|
super.addView(view, index);
|
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
mLayerController.getView().setVisibility(View.INVISIBLE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The methods below are simply copied from what Android WebKit does.
|
|
|
|
* It wasn't ever called in my testing, but might as well
|
|
|
|
* keep it in case it is for some reason. The methods
|
|
|
|
* all return true because we don't want any events
|
|
|
|
* leaking out from the fullscreen view.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
|
if (event.isSystem()) {
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
|
|
|
mFullScreenPluginView.onKeyDown(keyCode, event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
|
if (event.isSystem()) {
|
|
|
|
return super.onKeyUp(keyCode, event);
|
|
|
|
}
|
|
|
|
mFullScreenPluginView.onKeyUp(keyCode, event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTrackballEvent(MotionEvent event) {
|
|
|
|
mFullScreenPluginView.onTrackballEvent(event);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-06-10 16:44:50 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onContextItemSelected(MenuItem item) {
|
|
|
|
switch(item.getItemId()) {
|
|
|
|
case R.id.pasteandgo: {
|
|
|
|
String text = GeckoAppShell.getClipboardText();
|
|
|
|
if (text != null && !TextUtils.isEmpty(text)) {
|
|
|
|
loadUrl(text, AwesomeBar.Target.CURRENT_TAB);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.paste: {
|
|
|
|
String text = GeckoAppShell.getClipboardText();
|
|
|
|
if (text != null && !TextUtils.isEmpty(text)) {
|
|
|
|
showAwesomebar(AwesomeBar.Target.CURRENT_TAB, text);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.share: {
|
|
|
|
shareCurrentUrl();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.copyurl: {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
String url = tab.getURL();
|
|
|
|
if (url != null) {
|
|
|
|
GeckoAppShell.setClipboardText(url);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
case R.id.add_to_launcher: {
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
String url = tab.getURL();
|
|
|
|
String title = tab.getTitle();
|
|
|
|
BitmapDrawable favicon = (BitmapDrawable)(tab.getFavicon());
|
|
|
|
if (url != null && title != null) {
|
|
|
|
GeckoAppShell.createShortcut(title, url, favicon == null ? null : favicon.getBitmap(), "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-02 13:55:27 -07:00
|
|
|
}
|