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;
|
|
|
|
|
2014-02-22 19:53:02 -08:00
|
|
|
import java.io.BufferedOutputStream;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.text.DateFormat;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2012-10-30 13:27:33 -07:00
|
|
|
import org.mozilla.gecko.background.announcements.AnnouncementsBroadcastService;
|
2013-03-06 08:37:04 -08:00
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2013-09-12 07:48:59 -07:00
|
|
|
import org.mozilla.gecko.favicons.Favicons;
|
2013-04-22 18:03:01 -07:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
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.LayerView;
|
2012-04-27 13:04:47 -07:00
|
|
|
import org.mozilla.gecko.gfx.PluginLayer;
|
2014-02-04 19:41:29 -08:00
|
|
|
import org.mozilla.gecko.health.HealthRecorder;
|
2014-02-04 19:41:29 -08:00
|
|
|
import org.mozilla.gecko.health.SessionInformation;
|
2014-02-04 19:41:29 -08:00
|
|
|
import org.mozilla.gecko.health.StubbedHealthRecorder;
|
2014-02-22 19:53:02 -08:00
|
|
|
import org.mozilla.gecko.menu.GeckoMenu;
|
|
|
|
import org.mozilla.gecko.menu.GeckoMenuInflater;
|
|
|
|
import org.mozilla.gecko.menu.MenuPanel;
|
2013-11-11 10:41:16 -08:00
|
|
|
import org.mozilla.gecko.preferences.GeckoPreferences;
|
2014-02-22 19:53:02 -08:00
|
|
|
import org.mozilla.gecko.prompts.PromptService;
|
2013-03-06 08:37:04 -08:00
|
|
|
import org.mozilla.gecko.updater.UpdateService;
|
|
|
|
import org.mozilla.gecko.updater.UpdateServiceHelper;
|
2013-08-02 13:33:30 -07:00
|
|
|
import org.mozilla.gecko.util.ActivityResultHandler;
|
2012-08-02 17:13:40 -07:00
|
|
|
import org.mozilla.gecko.util.GeckoEventListener;
|
2013-04-02 07:04:21 -07:00
|
|
|
import org.mozilla.gecko.util.HardwareUtils;
|
2013-03-15 03:52:52 -07:00
|
|
|
import org.mozilla.gecko.util.ThreadUtils;
|
2013-03-06 08:37:04 -08:00
|
|
|
import org.mozilla.gecko.util.UiAsyncTask;
|
2014-01-24 21:57:13 -08:00
|
|
|
import org.mozilla.gecko.webapp.EventListener;
|
2014-02-22 19:53:02 -08:00
|
|
|
import org.mozilla.gecko.webapp.UninstallListener;
|
2013-07-16 01:33:06 -07:00
|
|
|
import org.mozilla.gecko.widget.ButtonToast;
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.app.Activity;
|
|
|
|
import android.app.AlertDialog;
|
2012-11-23 16:40:07 -08:00
|
|
|
import android.app.Dialog;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.SharedPreferences;
|
2013-07-03 15:24:57 -07:00
|
|
|
import android.content.pm.PackageManager.NameNotFoundException;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.content.res.Configuration;
|
|
|
|
import android.graphics.Bitmap;
|
2012-12-17 09:30:01 -08:00
|
|
|
import android.graphics.BitmapFactory;
|
2013-08-13 08:49:21 -07:00
|
|
|
import android.graphics.RectF;
|
2014-02-22 19:53:02 -08:00
|
|
|
import android.graphics.drawable.Drawable;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.hardware.Sensor;
|
|
|
|
import android.hardware.SensorEvent;
|
|
|
|
import android.hardware.SensorEventListener;
|
|
|
|
import android.location.Location;
|
|
|
|
import android.location.LocationListener;
|
|
|
|
import android.net.Uri;
|
2014-02-22 19:53:02 -08:00
|
|
|
import android.net.wifi.ScanResult;
|
2013-06-04 08:09:54 -07:00
|
|
|
import android.net.wifi.WifiManager;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Handler;
|
|
|
|
import android.os.PowerManager;
|
|
|
|
import android.os.StrictMode;
|
2013-07-11 14:03:12 -07:00
|
|
|
import android.preference.PreferenceManager;
|
2013-06-10 09:17:56 -07:00
|
|
|
import android.provider.ContactsContract;
|
2013-08-02 13:33:30 -07:00
|
|
|
import android.provider.MediaStore.Images.Media;
|
2013-05-30 09:50:45 -07:00
|
|
|
import android.telephony.CellLocation;
|
|
|
|
import android.telephony.NeighboringCellInfo;
|
2014-02-22 19:53:02 -08:00
|
|
|
import android.telephony.PhoneStateListener;
|
2013-05-30 09:50:45 -07:00
|
|
|
import android.telephony.SignalStrength;
|
|
|
|
import android.telephony.TelephonyManager;
|
|
|
|
import android.telephony.gsm.GsmCellLocation;
|
2013-11-21 23:33:28 -08:00
|
|
|
import android.text.TextUtils;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.util.AttributeSet;
|
2012-12-17 09:30:01 -08:00
|
|
|
import android.util.Base64;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.util.Log;
|
|
|
|
import android.util.SparseBooleanArray;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.KeyEvent;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
|
|
|
import android.view.MotionEvent;
|
2013-07-11 08:17:37 -07:00
|
|
|
import android.view.OrientationEventListener;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.SurfaceHolder;
|
|
|
|
import android.view.SurfaceView;
|
2013-06-30 23:01:57 -07:00
|
|
|
import android.view.TextureView;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2014-02-19 09:56:03 -08:00
|
|
|
import android.view.ViewStub;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.Window;
|
|
|
|
import android.view.WindowManager;
|
|
|
|
import android.widget.AbsoluteLayout;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.RelativeLayout;
|
2012-11-23 16:40:07 -08:00
|
|
|
import android.widget.SimpleAdapter;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.Toast;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
public abstract class GeckoApp
|
2014-02-22 19:53:02 -08:00
|
|
|
extends GeckoActivity
|
2013-12-03 15:05:43 -08:00
|
|
|
implements
|
|
|
|
ContextGetter,
|
|
|
|
GeckoAppShell.GeckoInterface,
|
|
|
|
GeckoEventListener,
|
|
|
|
GeckoMenu.Callback,
|
|
|
|
GeckoMenu.MenuPresenter,
|
|
|
|
LocationListener,
|
|
|
|
SensorEventListener,
|
|
|
|
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-10-01 13:57:03 -07:00
|
|
|
private static enum StartupAction {
|
|
|
|
NORMAL, /* normal application start */
|
|
|
|
URL, /* launched with a passed URL */
|
2013-02-01 11:49:08 -08:00
|
|
|
PREFETCH /* launched with a passed URL that we prefetch */
|
2012-10-01 13:57:03 -07:00
|
|
|
}
|
|
|
|
|
2013-11-15 22:59:17 -08:00
|
|
|
public static final String ACTION_ALERT_CALLBACK = "org.mozilla.gecko.ACTION_ALERT_CALLBACK";
|
|
|
|
public static final String ACTION_BOOKMARK = "org.mozilla.gecko.BOOKMARK";
|
|
|
|
public static final String ACTION_DEBUG = "org.mozilla.gecko.DEBUG";
|
|
|
|
public static final String ACTION_LAUNCH_SETTINGS = "org.mozilla.gecko.SETTINGS";
|
|
|
|
public static final String ACTION_LOAD = "org.mozilla.gecko.LOAD";
|
|
|
|
public static final String ACTION_INIT_PW = "org.mozilla.gecko.INIT_PW";
|
|
|
|
public static final String ACTION_WEBAPP_PREFIX = "org.mozilla.gecko.WEBAPP";
|
|
|
|
|
|
|
|
public static final String EXTRA_STATE_BUNDLE = "stateBundle";
|
|
|
|
|
|
|
|
public static final String PREFS_ALLOW_STATE_BUNDLE = "allowStateBundle";
|
|
|
|
public static final String PREFS_CRASHED = "crashed";
|
|
|
|
public static final String PREFS_NAME = "GeckoApp";
|
|
|
|
public static final String PREFS_OOM_EXCEPTION = "OOMException";
|
|
|
|
public static final String PREFS_VERSION_CODE = "versionCode";
|
|
|
|
public static final String PREFS_WAS_STOPPED = "wasStopped";
|
|
|
|
|
|
|
|
public static final String SAVED_STATE_IN_BACKGROUND = "inBackground";
|
2012-10-09 11:26:33 -07:00
|
|
|
public static final String SAVED_STATE_PRIVATE_SESSION = "privateSession";
|
2012-08-21 04:20:26 -07:00
|
|
|
|
2013-05-30 09:50:45 -07:00
|
|
|
static private final String LOCATION_URL = "https://location.services.mozilla.com/v1/submit";
|
|
|
|
|
2013-07-24 15:50:26 -07:00
|
|
|
// Delay before running one-time "cleanup" tasks that may be needed
|
|
|
|
// after a version upgrade.
|
|
|
|
private static final int CLEANUP_DEFERRAL_SECONDS = 15;
|
|
|
|
|
2013-03-07 02:17:32 -08:00
|
|
|
protected RelativeLayout mMainLayout;
|
2012-06-12 22:47:52 -07:00
|
|
|
protected RelativeLayout mGeckoLayout;
|
2012-06-11 15:18:40 -07:00
|
|
|
public View getView() { return mGeckoLayout; }
|
2013-06-30 23:01:57 -07:00
|
|
|
private View mCameraView;
|
2013-07-11 08:17:37 -07:00
|
|
|
private OrientationEventListener mCameraOrientationEventListener;
|
2013-06-04 23:26:11 -07:00
|
|
|
public List<GeckoAppShell.AppStateListener> mAppStateListeners;
|
2013-05-24 09:21:01 -07:00
|
|
|
private static GeckoApp sAppContext;
|
2012-06-11 15:18:40 -07:00
|
|
|
protected MenuPanel mMenuPanel;
|
2012-06-13 13:28:00 -07:00
|
|
|
protected Menu mMenu;
|
2013-07-18 11:43:34 -07:00
|
|
|
protected GeckoProfile mProfile;
|
2012-12-07 10:50:56 -08:00
|
|
|
protected boolean mIsRestoringActivity;
|
2011-11-29 20:58:39 -08:00
|
|
|
|
2013-07-23 13:14:00 -07:00
|
|
|
private ContactService mContactService;
|
2012-06-13 14:12:15 -07:00
|
|
|
private PromptService mPromptService;
|
2012-07-19 13:16:44 -07:00
|
|
|
private TextSelection mTextSelection;
|
2011-11-22 12:48:22 -08:00
|
|
|
|
2012-07-27 23:31:54 -07:00
|
|
|
protected DoorHangerPopup mDoorHangerPopup;
|
|
|
|
protected FormAssistPopup mFormAssistPopup;
|
2013-07-16 01:33:06 -07:00
|
|
|
protected ButtonToast mToast;
|
2011-11-22 12:48:22 -08:00
|
|
|
|
2012-10-12 04:57:07 -07:00
|
|
|
protected LayerView mLayerView;
|
2012-07-13 07:17:03 -07:00
|
|
|
private AbsoluteLayout mPluginContainer;
|
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>();
|
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
protected boolean mShouldRestore;
|
2012-08-22 08:37:14 -07:00
|
|
|
protected boolean mInitialized = false;
|
2012-10-01 13:57:00 -07:00
|
|
|
private Telemetry.Timer mJavaUiStartupTimer;
|
|
|
|
private Telemetry.Timer mGeckoReadyStartupTimer;
|
2012-02-14 13:30:15 -08:00
|
|
|
|
2012-10-09 11:26:33 -07:00
|
|
|
private String mPrivateBrowsingSession;
|
|
|
|
|
2014-02-04 19:41:29 -08:00
|
|
|
private volatile HealthRecorder mHealthRecorder = null;
|
2013-03-07 02:17:32 -08:00
|
|
|
|
2013-05-30 09:50:45 -07:00
|
|
|
private int mSignalStrenth;
|
|
|
|
private PhoneStateListener mPhoneStateListener = null;
|
2014-02-06 20:25:35 -08:00
|
|
|
private boolean mShouldReportGeoData;
|
2013-05-30 09:50:45 -07:00
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
abstract public int getLayout();
|
2012-07-23 13:08:48 -07:00
|
|
|
abstract public boolean hasTabsSideBar();
|
2012-06-18 10:03:03 -07:00
|
|
|
abstract protected String getDefaultProfileName();
|
|
|
|
|
2013-04-09 17:10:47 -07:00
|
|
|
private static final String RESTARTER_ACTION = "org.mozilla.gecko.restart";
|
|
|
|
private static final String RESTARTER_CLASS = "org.mozilla.gecko.Restarter";
|
|
|
|
|
2013-05-16 15:07:44 -07:00
|
|
|
@SuppressWarnings("serial")
|
|
|
|
class SessionRestoreException extends Exception {
|
2013-05-16 15:07:44 -07:00
|
|
|
public SessionRestoreException(Exception e) {
|
|
|
|
super(e);
|
|
|
|
}
|
|
|
|
|
2013-05-16 15:07:44 -07:00
|
|
|
public SessionRestoreException(String message) {
|
|
|
|
super(message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 12:18:01 -08:00
|
|
|
void toggleChrome(final boolean aShow) { }
|
2012-06-11 15:18:40 -07:00
|
|
|
|
|
|
|
void focusChrome() { }
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
@Override
|
2013-05-24 09:21:01 -07:00
|
|
|
public Context getContext() {
|
|
|
|
return sAppContext;
|
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
@Override
|
|
|
|
public SharedPreferences getSharedPreferences() {
|
|
|
|
return GeckoApp.getAppSharedPreferences();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static SharedPreferences getAppSharedPreferences() {
|
|
|
|
return GeckoApp.sAppContext.getSharedPreferences(GeckoApp.PREFS_NAME, 0);
|
|
|
|
}
|
|
|
|
|
2013-05-24 09:21:01 -07:00
|
|
|
public Activity getActivity() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public LocationListener getLocationListener() {
|
2013-05-31 14:32:12 -07:00
|
|
|
if (mShouldReportGeoData && mPhoneStateListener == null) {
|
2013-05-30 09:50:45 -07:00
|
|
|
mPhoneStateListener = new PhoneStateListener() {
|
|
|
|
public void onSignalStrengthsChanged(SignalStrength signalStrength) {
|
|
|
|
setCurrentSignalStrenth(signalStrength);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
|
|
|
|
}
|
2013-05-24 09:21:01 -07:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public SensorEventListener getSensorEventListener() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2013-06-30 23:01:57 -07:00
|
|
|
public View getCameraView() {
|
2013-06-04 23:26:11 -07:00
|
|
|
return mCameraView;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addAppStateListener(GeckoAppShell.AppStateListener listener) {
|
|
|
|
mAppStateListeners.add(listener);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void removeAppStateListener(GeckoAppShell.AppStateListener listener) {
|
|
|
|
mAppStateListeners.remove(listener);
|
2013-05-24 09:21:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public FormAssistPopup getFormAssistPopup() {
|
|
|
|
return mFormAssistPopup;
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
2012-07-06 11:19:19 -07:00
|
|
|
// When a tab is closed, it is always unselected first.
|
|
|
|
// When a tab is unselected, another tab is always selected first.
|
2012-06-11 15:18:40 -07:00
|
|
|
switch(msg) {
|
2012-07-06 11:19:19 -07:00
|
|
|
case UNSELECTED:
|
|
|
|
hidePlugins(tab);
|
|
|
|
break;
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
case LOCATION_CHANGE:
|
2012-07-06 11:19:19 -07:00
|
|
|
// We only care about location change for the selected tab.
|
|
|
|
if (!Tabs.getInstance().isSelectedTab(tab))
|
|
|
|
break;
|
|
|
|
// Fall through...
|
|
|
|
case SELECTED:
|
|
|
|
invalidateOptionsMenu();
|
2013-01-09 11:37:01 -08:00
|
|
|
if (mFormAssistPopup != null)
|
|
|
|
mFormAssistPopup.hide();
|
2012-06-11 15:18:40 -07:00
|
|
|
break;
|
2013-02-26 11:50:04 -08:00
|
|
|
|
|
|
|
case LOADED:
|
|
|
|
// Sync up the layer view and the tab if the tab is
|
|
|
|
// currently displayed.
|
|
|
|
LayerView layerView = mLayerView;
|
|
|
|
if (layerView != null && Tabs.getInstance().isSelectedTab(tab))
|
|
|
|
layerView.setBackgroundColor(tab.getBackgroundColor());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DESKTOP_MODE_CHANGE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab))
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
break;
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void refreshChrome() { }
|
|
|
|
|
2012-05-25 12:47:51 -07:00
|
|
|
@Override
|
|
|
|
public void invalidateOptionsMenu() {
|
2012-06-13 13:28:00 -07:00
|
|
|
if (mMenu == null)
|
2012-05-25 12:47:51 -07:00
|
|
|
return;
|
|
|
|
|
2012-06-13 13:28:00 -07:00
|
|
|
onPrepareOptionsMenu(mMenu);
|
2012-05-25 12:47:51 -07:00
|
|
|
|
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
super.invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
2012-07-26 23:52:41 -07:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
2012-06-13 13:28:00 -07:00
|
|
|
mMenu = menu;
|
2012-05-31 16:01:50 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
MenuInflater inflater = getMenuInflater();
|
2012-07-26 23:52:41 -07:00
|
|
|
inflater.inflate(R.menu.gecko_app_menu, mMenu);
|
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)
|
2013-06-17 17:31:17 -07:00
|
|
|
return new GeckoMenuInflater(this);
|
2012-05-31 16:01:50 -07:00
|
|
|
else
|
|
|
|
return super.getMenuInflater();
|
|
|
|
}
|
|
|
|
|
2012-09-19 10:35:35 -07:00
|
|
|
public MenuPanel getMenuPanel() {
|
2014-02-03 16:19:00 -08:00
|
|
|
if (mMenuPanel == null) {
|
|
|
|
onCreatePanelMenu(Window.FEATURE_OPTIONS_PANEL, null);
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
2012-05-31 16:01:50 -07:00
|
|
|
return mMenuPanel;
|
|
|
|
}
|
|
|
|
|
2012-12-04 13:12:04 -08:00
|
|
|
@Override
|
|
|
|
public boolean onMenuItemSelected(MenuItem item) {
|
|
|
|
return onOptionsItemSelected(item);
|
2012-09-19 10:35:35 -07:00
|
|
|
}
|
|
|
|
|
2012-12-04 13:12:04 -08:00
|
|
|
@Override
|
|
|
|
public void openMenu() {
|
|
|
|
openOptionsMenu();
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
2012-12-04 13:12:04 -08:00
|
|
|
@Override
|
|
|
|
public void showMenu(View menu) {
|
|
|
|
// Hide the menu only if we are showing the MenuPopup.
|
2013-04-02 07:04:21 -07:00
|
|
|
if (!HardwareUtils.hasMenuButton())
|
2012-12-04 13:12:04 -08:00
|
|
|
closeMenu();
|
2012-09-19 10:35:35 -07:00
|
|
|
|
2012-12-04 13:12:04 -08:00
|
|
|
mMenuPanel.removeAllViews();
|
|
|
|
mMenuPanel.addView(menu);
|
2012-09-19 10:35:35 -07:00
|
|
|
|
2012-12-04 13:12:04 -08:00
|
|
|
openOptionsMenu();
|
|
|
|
}
|
2012-09-19 10:35:35 -07:00
|
|
|
|
2012-12-04 13:12:04 -08:00
|
|
|
@Override
|
|
|
|
public void closeMenu() {
|
|
|
|
closeOptionsMenu();
|
2012-09-19 10:35:35 -07:00
|
|
|
}
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
@Override
|
|
|
|
public View onCreatePanelView(int featureId) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL) {
|
|
|
|
if (mMenuPanel == null) {
|
2013-05-24 09:21:01 -07:00
|
|
|
mMenuPanel = new MenuPanel(this, null);
|
2012-05-31 16:01:50 -07:00
|
|
|
} else {
|
|
|
|
// Prepare the panel everytime before showing the menu.
|
2012-06-13 13:28:00 -07:00
|
|
|
onPreparePanel(featureId, mMenuPanel, mMenu);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return mMenuPanel;
|
|
|
|
}
|
2014-02-18 16:09:00 -08:00
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-05-24 09:21:01 -07:00
|
|
|
GeckoMenu gMenu = new GeckoMenu(this, null);
|
2012-12-04 13:12:04 -08:00
|
|
|
gMenu.setCallback(this);
|
|
|
|
gMenu.setMenuPresenter(this);
|
2012-05-31 16:01:50 -07:00
|
|
|
menu = gMenu;
|
|
|
|
mMenuPanel.addView(gMenu);
|
|
|
|
|
|
|
|
return onCreateOptionsMenu(menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onCreatePanelMenu(featureId, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onPreparePanel(int featureId, View view, Menu menu) {
|
2014-02-24 08:44:56 -08:00
|
|
|
if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL)
|
2012-05-31 16:01:50 -07:00
|
|
|
return onPrepareOptionsMenu(menu);
|
|
|
|
|
|
|
|
return super.onPreparePanel(featureId, view, menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onMenuOpened(int featureId, Menu menu) {
|
2012-11-30 09:59:49 -08:00
|
|
|
// exit full-screen mode whenever the menu is opened
|
2013-02-08 07:22:35 -08:00
|
|
|
if (mLayerView != null && mLayerView.isFullScreen()) {
|
2012-11-30 09:59:49 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("FullScreen:Exit", null));
|
|
|
|
}
|
|
|
|
|
2012-05-31 16:01:50 -07:00
|
|
|
if (Build.VERSION.SDK_INT >= 11 && featureId == Window.FEATURE_OPTIONS_PANEL) {
|
2012-06-13 13:28:00 -07:00
|
|
|
if (mMenu == null) {
|
2014-02-03 16:19:00 -08:00
|
|
|
// getMenuPanel() will force the creation of the menu as well
|
|
|
|
MenuPanel panel = getMenuPanel();
|
|
|
|
onPreparePanel(featureId, panel, mMenu);
|
2012-05-31 16:01:50 -07:00
|
|
|
}
|
|
|
|
|
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) {
|
2013-08-13 16:44:00 -07:00
|
|
|
if (item.getItemId() == R.id.quit) {
|
|
|
|
if (GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.GeckoRunning, GeckoThread.LaunchState.GeckoExiting)) {
|
|
|
|
GeckoAppShell.notifyGeckoOfEvent(GeckoEvent.createBroadcastEvent("Browser:Quit", null));
|
|
|
|
} else {
|
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2013-08-13 16:44:00 -07:00
|
|
|
|
|
|
|
return super.onOptionsItemSelected(item);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-09-19 10:35:35 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onOptionsMenuClosed(Menu menu) {
|
2012-12-04 13:12:04 -08:00
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
mMenuPanel.removeAllViews();
|
|
|
|
mMenuPanel.addView((GeckoMenu) mMenu);
|
|
|
|
}
|
2012-09-19 10:35:35 -07:00
|
|
|
}
|
2012-07-24 21:30:46 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
2013-05-29 16:07:12 -07:00
|
|
|
// Handle hardware menu key presses separately so that we can show a custom menu in some cases.
|
|
|
|
if (keyCode == KeyEvent.KEYCODE_MENU) {
|
2012-07-24 21:30:46 -07:00
|
|
|
openOptionsMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.onKeyDown(keyCode, event);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-29 19:54:07 -08:00
|
|
|
protected void onSaveInstanceState(Bundle outState) {
|
|
|
|
super.onSaveInstanceState(outState);
|
2011-12-12 10:50:35 -08:00
|
|
|
|
2014-02-19 09:56:03 -08:00
|
|
|
if (mToast != null) {
|
|
|
|
mToast.onSaveInstanceState(outState);
|
|
|
|
}
|
|
|
|
|
2013-03-26 11:04:20 -07:00
|
|
|
outState.putBoolean(SAVED_STATE_IN_BACKGROUND, isApplicationInBackground());
|
2012-10-09 11:26:33 -07:00
|
|
|
outState.putString(SAVED_STATE_PRIVATE_SESSION, mPrivateBrowsingSession);
|
2012-03-14 15:48:22 -07:00
|
|
|
}
|
2011-11-29 19:54:07 -08:00
|
|
|
|
2012-07-26 15:08:50 -07:00
|
|
|
void handleFaviconRequest(final String url) {
|
2013-03-15 03:52:53 -07:00
|
|
|
(new UiAsyncTask<Void, Void, String>(ThreadUtils.getBackgroundHandler()) {
|
2012-07-26 15:08:50 -07:00
|
|
|
@Override
|
|
|
|
public String doInBackground(Void... params) {
|
2014-01-13 15:08:58 -08:00
|
|
|
return Favicons.getFaviconURLForPageURL(url);
|
2012-07-26 15:08:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(String faviconUrl) {
|
2012-08-31 08:36:38 -07:00
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
|
2012-07-26 15:08:50 -07:00
|
|
|
if (faviconUrl != null) {
|
|
|
|
try {
|
|
|
|
args.put("url", url);
|
|
|
|
args.put("faviconUrl", faviconUrl);
|
|
|
|
} catch (JSONException e) {
|
2012-10-23 09:45:40 -07:00
|
|
|
Log.w(LOGTAG, "Error building JSON favicon arguments.", e);
|
2012-07-26 15:08:50 -07:00
|
|
|
}
|
|
|
|
}
|
2012-08-31 08:36:38 -07:00
|
|
|
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Reader:FaviconReturn", args.toString()));
|
2012-07-26 15:08:50 -07:00
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
|
|
|
|
2012-07-06 09:22:57 -07:00
|
|
|
void handleClearHistory() {
|
|
|
|
BrowserDB.clearHistory(getContentResolver());
|
|
|
|
}
|
2012-04-04 12:29:31 -07:00
|
|
|
|
2013-01-02 13:43:01 -08:00
|
|
|
public void addTab() { }
|
|
|
|
|
|
|
|
public void addPrivateTab() { }
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2012-12-18 17:04:39 -08:00
|
|
|
public void showNormalTabs() { }
|
|
|
|
|
|
|
|
public void showPrivateTabs() { }
|
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-19 13:37:57 -07:00
|
|
|
/**
|
|
|
|
* Close the tab UI indirectly (not as the result of a direct user
|
|
|
|
* action). This does not force the UI to close; for example in Firefox
|
|
|
|
* tablet mode it will remain open unless the user explicitly closes it.
|
|
|
|
*
|
|
|
|
* @return True if the tab UI was hidden.
|
|
|
|
*/
|
|
|
|
public boolean autoHideTabs() { return false; }
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
public boolean areTabsShown() { return false; }
|
2012-06-10 16:44:50 -07:00
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
try {
|
2012-07-26 23:53:48 -07:00
|
|
|
if (event.equals("Toast:Show")) {
|
2011-11-18 10:28:17 -08:00
|
|
|
final String msg = message.getString("message");
|
2013-07-16 01:33:06 -07:00
|
|
|
final JSONObject button = message.optJSONObject("button");
|
|
|
|
if (button != null) {
|
|
|
|
final String label = button.optString("label");
|
|
|
|
final String icon = button.optString("icon");
|
|
|
|
final String id = button.optString("id");
|
|
|
|
showButtonToast(msg, label, icon, id);
|
|
|
|
} else {
|
|
|
|
final String duration = message.getString("duration");
|
|
|
|
showNormalToast(msg, duration);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
} else if (event.equals("log")) {
|
|
|
|
// generic log listener
|
|
|
|
final String msg = message.getString("msg");
|
2012-10-23 09:45:40 -07:00
|
|
|
Log.d(LOGTAG, "Log: " + msg);
|
2012-07-26 15:08:50 -07:00
|
|
|
} else if (event.equals("Reader:FaviconRequest")) {
|
|
|
|
final String url = message.getString("url");
|
|
|
|
handleFaviconRequest(url);
|
2011-12-01 17:27:11 -08:00
|
|
|
} else if (event.equals("Gecko:Ready")) {
|
2012-10-01 13:57:00 -07:00
|
|
|
mGeckoReadyStartupTimer.stop();
|
2013-05-29 21:34:02 -07:00
|
|
|
geckoConnected();
|
2013-06-04 17:16:57 -07:00
|
|
|
|
|
|
|
// This method is already running on the background thread, so we
|
2013-07-02 12:08:09 -07:00
|
|
|
// know that mHealthRecorder will exist. That doesn't stop us being
|
|
|
|
// paranoid.
|
|
|
|
// This method is cheap, so don't spawn a new runnable.
|
2014-02-04 19:41:29 -08:00
|
|
|
final HealthRecorder rec = mHealthRecorder;
|
2013-07-02 12:08:09 -07:00
|
|
|
if (rec != null) {
|
|
|
|
rec.recordGeckoStartupTime(mGeckoReadyStartupTimer.getElapsed());
|
|
|
|
}
|
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")) {
|
2012-11-24 14:32:08 -08:00
|
|
|
// Local ref to layerView for thread safety
|
|
|
|
LayerView layerView = mLayerView;
|
|
|
|
if (layerView != null) {
|
|
|
|
layerView.setFullScreen(true);
|
|
|
|
}
|
2012-01-26 09:17:33 -08:00
|
|
|
} else if (event.equals("DOMFullScreen:Stop")) {
|
2012-11-24 14:32:08 -08:00
|
|
|
// Local ref to layerView for thread safety
|
|
|
|
LayerView layerView = mLayerView;
|
|
|
|
if (layerView != null) {
|
|
|
|
layerView.setFullScreen(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-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");
|
2013-05-24 09:21:01 -07:00
|
|
|
final Context context = this;
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-02-21 21:11:50 -08:00
|
|
|
public void run() {
|
2013-05-24 09:21:01 -07:00
|
|
|
Toast.makeText(context, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-02-21 21:11:50 -08:00
|
|
|
public void run() {
|
2013-06-17 17:31:17 -07:00
|
|
|
BrowserDB.addBookmark(getContentResolver(), title, url);
|
2012-02-21 21:11:50 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2012-03-09 15:06:50 -08:00
|
|
|
} else if (event.equals("Accessibility:Event")) {
|
2012-08-20 15:29:22 -07:00
|
|
|
GeckoAccessibility.sendAccessibilityEvent(message);
|
2012-05-10 10:33:12 -07:00
|
|
|
} else if (event.equals("Accessibility:Ready")) {
|
2013-04-17 14:51:53 -07:00
|
|
|
GeckoAccessibility.updateAccessibilitySettings(this);
|
2012-06-06 13:52:14 -07:00
|
|
|
} else if (event.equals("Shortcut:Remove")) {
|
|
|
|
final String url = message.getString("url");
|
2012-06-18 10:03:03 -07:00
|
|
|
final String origin = message.getString("origin");
|
2012-06-06 13:52:14 -07:00
|
|
|
final String title = message.getString("title");
|
2012-06-06 14:45:41 -07:00
|
|
|
final String type = message.getString("shortcutType");
|
2012-06-18 10:03:03 -07:00
|
|
|
GeckoAppShell.removeShortcut(title, url, origin, type);
|
2012-06-27 09:14:16 -07:00
|
|
|
} else if (event.equals("Share:Text")) {
|
|
|
|
String text = message.getString("text");
|
|
|
|
GeckoAppShell.openUriExternal(text, "text/plain", "", "", Intent.ACTION_SEND, "");
|
2012-07-10 14:25:15 -07:00
|
|
|
} else if (event.equals("Share:Image")) {
|
|
|
|
String src = message.getString("url");
|
|
|
|
String type = message.getString("mime");
|
|
|
|
GeckoAppShell.shareImage(src, type);
|
2013-08-05 14:21:28 -07:00
|
|
|
} else if (event.equals("Image:SetAs")) {
|
2012-12-17 09:30:01 -08:00
|
|
|
String src = message.getString("url");
|
2013-08-02 13:33:30 -07:00
|
|
|
setImageAs(src);
|
2012-07-06 09:22:57 -07:00
|
|
|
} else if (event.equals("Sanitize:ClearHistory")) {
|
|
|
|
handleClearHistory();
|
2012-08-31 06:31:29 -07:00
|
|
|
} else if (event.equals("Update:Check")) {
|
|
|
|
startService(new Intent(UpdateServiceHelper.ACTION_CHECK_FOR_UPDATE, null, this, UpdateService.class));
|
2013-03-13 08:47:38 -07:00
|
|
|
} else if (event.equals("Update:Download")) {
|
|
|
|
startService(new Intent(UpdateServiceHelper.ACTION_DOWNLOAD_UPDATE, null, this, UpdateService.class));
|
|
|
|
} else if (event.equals("Update:Install")) {
|
|
|
|
startService(new Intent(UpdateServiceHelper.ACTION_APPLY_UPDATE, null, this, UpdateService.class));
|
2012-10-09 11:26:33 -07:00
|
|
|
} else if (event.equals("PrivateBrowsing:Data")) {
|
|
|
|
// null strings return "null" (http://code.google.com/p/android/issues/detail?id=13830)
|
|
|
|
if (message.isNull("session")) {
|
|
|
|
mPrivateBrowsingSession = null;
|
|
|
|
} else {
|
|
|
|
mPrivateBrowsingSession = message.getString("session");
|
|
|
|
}
|
2013-06-10 09:17:56 -07:00
|
|
|
} else if (event.equals("Contact:Add")) {
|
|
|
|
if (!message.isNull("email")) {
|
|
|
|
Uri contactUri = Uri.parse(message.getString("email"));
|
|
|
|
Intent i = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, contactUri);
|
|
|
|
startActivity(i);
|
|
|
|
} else if (!message.isNull("phone")) {
|
|
|
|
Uri contactUri = Uri.parse(message.getString("phone"));
|
|
|
|
Intent i = new Intent(ContactsContract.Intents.SHOW_OR_CREATE_CONTACT, contactUri);
|
|
|
|
startActivity(i);
|
|
|
|
} else {
|
|
|
|
// something went wrong.
|
|
|
|
Log.e(LOGTAG, "Received Contact:Add message with no email nor phone number");
|
|
|
|
}
|
2013-08-06 22:13:21 -07:00
|
|
|
} else if (event.equals("Intent:GetHandlers")) {
|
|
|
|
Intent intent = GeckoAppShell.getOpenURIIntent(sAppContext, message.optString("url"),
|
|
|
|
message.optString("mime"), message.optString("action"), message.optString("title"));
|
|
|
|
String[] handlers = GeckoAppShell.getHandlersForIntent(intent);
|
|
|
|
ArrayList<String> appList = new ArrayList<String>(handlers.length);
|
|
|
|
for (int i = 0; i < handlers.length; i++) {
|
|
|
|
appList.add(handlers[i]);
|
|
|
|
}
|
|
|
|
JSONObject handlersJSON = new JSONObject();
|
|
|
|
handlersJSON.put("apps", new JSONArray(appList));
|
2014-02-11 09:16:00 -08:00
|
|
|
EventDispatcher.sendResponse(message, handlersJSON);
|
2013-08-06 22:13:21 -07:00
|
|
|
} else if (event.equals("Intent:Open")) {
|
|
|
|
GeckoAppShell.openUriExternal(message.optString("url"),
|
|
|
|
message.optString("mime"), message.optString("packageName"),
|
|
|
|
message.optString("className"), message.optString("action"), message.optString("title"));
|
2014-02-24 06:57:31 -08:00
|
|
|
} else if (event.equals("Intent:OpenForResult")) {
|
|
|
|
Intent intent = GeckoAppShell.getOpenURIIntent(this,
|
|
|
|
message.optString("url"),
|
|
|
|
message.optString("mime"),
|
|
|
|
message.optString("action"),
|
|
|
|
message.optString("title"));
|
|
|
|
intent.setClassName(message.optString("packageName"), message.optString("className"));
|
|
|
|
|
|
|
|
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
|
|
|
|
|
|
final JSONObject originalMessage = message;
|
|
|
|
ActivityHandlerHelper.startIntentForActivity(this,
|
|
|
|
intent,
|
|
|
|
new ActivityResultHandler() {
|
|
|
|
@Override
|
|
|
|
public void onActivityResult (int resultCode, Intent data) {
|
|
|
|
JSONObject response = new JSONObject();
|
|
|
|
|
|
|
|
try {
|
|
|
|
if (data != null) {
|
|
|
|
response.put("extras", bundleToJSON(data.getExtras()));
|
|
|
|
}
|
|
|
|
response.put("resultCode", resultCode);
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.w(LOGTAG, "Error building JSON response.", e);
|
|
|
|
}
|
|
|
|
|
|
|
|
EventDispatcher.sendResponse(originalMessage, response);
|
|
|
|
}
|
|
|
|
});
|
2013-12-03 15:05:43 -08:00
|
|
|
} else if (event.equals("Locale:Set")) {
|
|
|
|
setLocale(message.getString("locale"));
|
2014-01-31 14:51:24 -08:00
|
|
|
} else if (event.equals("NativeApp:IsDebuggable")) {
|
2014-02-11 09:16:00 -08:00
|
|
|
JSONObject ret = new JSONObject();
|
|
|
|
ret.put("isDebuggable", getIsDebuggable() ? "true" : "false");
|
|
|
|
EventDispatcher.sendResponse(message, ret);
|
2014-01-22 11:56:11 -08:00
|
|
|
} else if (event.equals("SystemUI:Visibility")) {
|
|
|
|
setSystemUiVisible(message.getBoolean("visible"));
|
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.
|
2012-11-23 16:40:07 -08:00
|
|
|
* Example: { type: "offline-app", setting: "Store Offline Data", value: "Allow" }
|
2011-12-17 13:50:09 -08:00
|
|
|
*/
|
|
|
|
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);
|
2012-11-23 16:40:07 -08:00
|
|
|
((TextView) customTitleView.findViewById(R.id.host)).setText(aHost);
|
2011-12-17 13:50:09 -08:00
|
|
|
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 {
|
2012-11-23 16:40:07 -08:00
|
|
|
|
|
|
|
ArrayList <HashMap<String, String>> itemList = new ArrayList <HashMap<String, String>>();
|
2011-12-17 13:50:09 -08:00
|
|
|
for (int i = 0; i < aPermissions.length(); i++) {
|
|
|
|
try {
|
2012-11-23 16:40:07 -08:00
|
|
|
JSONObject permObj = aPermissions.getJSONObject(i);
|
|
|
|
HashMap<String, String> map = new HashMap<String, String>();
|
|
|
|
map.put("setting", permObj.getString("setting"));
|
|
|
|
map.put("value", permObj.getString("value"));
|
|
|
|
itemList.add(map);
|
2011-12-17 13:50:09 -08:00
|
|
|
} catch (JSONException e) {
|
2012-10-23 09:45:40 -07:00
|
|
|
Log.w(LOGTAG, "Exception populating settings items.", e);
|
2011-12-17 13:50:09 -08:00
|
|
|
}
|
|
|
|
}
|
2012-11-23 16:40:07 -08:00
|
|
|
|
|
|
|
// setMultiChoiceItems doesn't support using an adapter, so we're creating a hack with
|
|
|
|
// setSingleChoiceItems and changing the choiceMode below when we create the dialog
|
|
|
|
builder.setSingleChoiceItems(new SimpleAdapter(
|
|
|
|
GeckoApp.this,
|
|
|
|
itemList,
|
|
|
|
R.layout.site_setting_item,
|
|
|
|
new String[] { "setting", "value" },
|
|
|
|
new int[] { R.id.setting, R.id.value }
|
|
|
|
), -1, new DialogInterface.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-11-23 16:40:07 -08:00
|
|
|
public void onClick(DialogInterface dialog, int id) { }
|
|
|
|
});
|
|
|
|
|
2011-12-17 13:50:09 -08:00
|
|
|
builder.setPositiveButton(R.string.site_settings_clear, new DialogInterface.OnClickListener() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-12-17 13:50:09 -08:00
|
|
|
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();
|
2012-11-23 16:40:07 -08:00
|
|
|
for (int i = 0; i < checkedItemPositions.size(); i++)
|
|
|
|
if (checkedItemPositions.get(i))
|
2011-12-17 13:50:09 -08:00
|
|
|
permissionsToClear.put(i);
|
2012-11-23 16:40:07 -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(){
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-12-17 13:50:09 -08:00
|
|
|
public void onClick(DialogInterface dialog, int id) {
|
|
|
|
dialog.cancel();
|
2012-11-23 16:40:07 -08:00
|
|
|
}
|
2011-12-17 13:50:09 -08:00
|
|
|
});
|
|
|
|
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-12-17 13:50:09 -08:00
|
|
|
public void run() {
|
2012-11-23 16:40:07 -08:00
|
|
|
Dialog dialog = builder.create();
|
|
|
|
dialog.show();
|
|
|
|
|
|
|
|
ListView listView = ((AlertDialog) dialog).getListView();
|
|
|
|
if (listView != null) {
|
|
|
|
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
|
|
|
int listSize = listView.getAdapter().getCount();
|
|
|
|
for (int i = 0; i < listSize; i++)
|
|
|
|
listView.setItemChecked(i, true);
|
|
|
|
}
|
2011-12-17 13:50:09 -08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-27 23:31:54 -07:00
|
|
|
public void showToast(final int resId, final int duration) {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-07-27 23:31:54 -07:00
|
|
|
public void run() {
|
2013-06-17 17:31:17 -07:00
|
|
|
Toast.makeText(GeckoApp.this, resId, duration).show();
|
2012-07-27 23:31:54 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-16 01:33:06 -07:00
|
|
|
public void showNormalToast(final String message, final String duration) {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void run() {
|
|
|
|
Toast toast;
|
2013-07-16 01:33:06 -07:00
|
|
|
if (duration.equals("long")) {
|
2013-06-17 17:31:17 -07:00
|
|
|
toast = Toast.makeText(GeckoApp.this, message, Toast.LENGTH_LONG);
|
2013-07-16 01:33:06 -07:00
|
|
|
} else {
|
2013-06-17 17:31:17 -07:00
|
|
|
toast = Toast.makeText(GeckoApp.this, message, Toast.LENGTH_SHORT);
|
2013-07-16 01:33:06 -07:00
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
toast.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-19 09:56:03 -08:00
|
|
|
protected ButtonToast getButtonToast() {
|
|
|
|
if (mToast != null) {
|
|
|
|
return mToast;
|
|
|
|
}
|
|
|
|
|
|
|
|
ViewStub toastStub = (ViewStub) findViewById(R.id.toast_stub);
|
|
|
|
mToast = new ButtonToast(toastStub.inflate());
|
|
|
|
|
|
|
|
return mToast;
|
|
|
|
}
|
|
|
|
|
2013-07-16 01:33:06 -07:00
|
|
|
void showButtonToast(final String message, final String buttonText,
|
|
|
|
final String buttonIcon, final String buttonId) {
|
|
|
|
BitmapUtils.getDrawable(GeckoApp.this, buttonIcon, new BitmapUtils.BitmapLoader() {
|
2014-02-22 09:41:30 -08:00
|
|
|
@Override
|
2013-09-30 07:59:40 -07:00
|
|
|
public void onBitmapFound(final Drawable d) {
|
2014-02-22 09:41:30 -08:00
|
|
|
getButtonToast().show(false, message, buttonText, d, new ButtonToast.ToastListener() {
|
2013-07-16 01:33:06 -07:00
|
|
|
@Override
|
2014-02-22 09:41:30 -08:00
|
|
|
public void onButtonClicked() {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Toast:Click", buttonId));
|
|
|
|
}
|
2013-09-30 07:59:40 -07:00
|
|
|
|
2014-02-22 09:41:30 -08:00
|
|
|
@Override
|
|
|
|
public void onToastHidden(ButtonToast.ReasonHidden reason) {
|
|
|
|
if (reason == ButtonToast.ReasonHidden.TIMEOUT) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Toast:Hidden", buttonId));
|
|
|
|
}
|
2013-07-16 01:33:06 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-24 06:57:31 -08:00
|
|
|
private JSONObject bundleToJSON(Bundle bundle) {
|
|
|
|
JSONObject json = new JSONObject();
|
|
|
|
if (bundle == null) {
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (String key : bundle.keySet()) {
|
|
|
|
try {
|
|
|
|
json.put(key, bundle.get(key));
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.w(LOGTAG, "Error building JSON response.", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return json;
|
|
|
|
}
|
|
|
|
|
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(
|
2012-07-31 15:26:29 -07:00
|
|
|
ViewGroup.LayoutParams.FILL_PARENT,
|
|
|
|
ViewGroup.LayoutParams.FILL_PARENT,
|
2012-06-06 19:39:36 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-08-13 08:49:21 -07:00
|
|
|
public void addPluginView(final View view, final RectF rect, final boolean isFullScreen) {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
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) {
|
2012-08-20 12:43:53 -07:00
|
|
|
layer = new PluginLayer(view, rect, mLayerView.getRenderer().getMaxTextureSize());
|
2012-04-27 13:04:47 -07:00
|
|
|
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
|
|
|
|
2012-08-20 12:43:53 -07:00
|
|
|
mLayerView.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
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-06 19:39:36 -07:00
|
|
|
public void run() {
|
2013-11-21 11:18:40 -08:00
|
|
|
mLayerView.showSurface();
|
2012-06-06 19:39:36 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
FrameLayout decor = (FrameLayout)getWindow().getDecorView();
|
|
|
|
decor.removeView(mFullScreenPluginContainer);
|
2012-10-22 07:51:29 -07:00
|
|
|
|
2012-05-30 09:10:49 -07:00
|
|
|
mFullScreenPluginView = null;
|
2012-06-06 19:39:36 -07:00
|
|
|
|
2014-02-20 09:50:18 -08:00
|
|
|
GeckoScreenOrientation.getInstance().unlock();
|
2012-06-06 19:39:36 -07:00
|
|
|
setFullScreen(false);
|
2012-05-30 09:10:49 -07:00
|
|
|
}
|
|
|
|
|
2013-05-24 09:21:01 -07:00
|
|
|
public void removePluginView(final View view, final boolean isFullScreen) {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
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-12-17 09:30:01 -08:00
|
|
|
|
2013-08-02 13:33:30 -07:00
|
|
|
// This method starts downloading an image synchronously and displays the Chooser activity to set the image as wallpaper.
|
|
|
|
private void setImageAs(final String aSrc) {
|
|
|
|
boolean isDataURI = aSrc.startsWith("data:");
|
|
|
|
Bitmap image = null;
|
|
|
|
InputStream is = null;
|
|
|
|
ByteArrayOutputStream os = null;
|
|
|
|
try {
|
|
|
|
if (isDataURI) {
|
|
|
|
int dataStart = aSrc.indexOf(",");
|
|
|
|
byte[] buf = Base64.decode(aSrc.substring(dataStart+1), Base64.DEFAULT);
|
|
|
|
image = BitmapUtils.decodeByteArray(buf);
|
|
|
|
} else {
|
|
|
|
int byteRead;
|
|
|
|
byte[] buf = new byte[4192];
|
|
|
|
os = new ByteArrayOutputStream();
|
|
|
|
URL url = new URL(aSrc);
|
|
|
|
is = url.openStream();
|
2012-12-17 09:30:01 -08:00
|
|
|
|
2013-08-02 13:33:30 -07:00
|
|
|
// Cannot read from same stream twice. Also, InputStream from
|
|
|
|
// URL does not support reset. So converting to byte array.
|
2012-12-17 09:30:01 -08:00
|
|
|
|
2013-08-02 13:33:30 -07:00
|
|
|
while((byteRead = is.read(buf)) != -1) {
|
|
|
|
os.write(buf, 0, byteRead);
|
2012-12-17 09:30:01 -08:00
|
|
|
}
|
2013-08-02 13:33:30 -07:00
|
|
|
byte[] imgBuffer = os.toByteArray();
|
|
|
|
image = BitmapUtils.decodeByteArray(imgBuffer);
|
|
|
|
}
|
|
|
|
if (image != null) {
|
|
|
|
String path = Media.insertImage(getContentResolver(),image, null, null);
|
|
|
|
final Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
|
|
|
|
intent.addCategory(Intent.CATEGORY_DEFAULT);
|
|
|
|
intent.setData(Uri.parse(path));
|
|
|
|
|
|
|
|
// Removes the image from storage once the chooser activity ends.
|
2014-02-14 12:02:05 -08:00
|
|
|
ActivityHandlerHelper.startIntentForActivity(this,
|
|
|
|
Intent.createChooser(intent, sAppContext.getString(R.string.set_image_chooser_title)),
|
|
|
|
new ActivityResultHandler() {
|
|
|
|
@Override
|
|
|
|
public void onActivityResult (int resultCode, Intent data) {
|
|
|
|
getContentResolver().delete(intent.getData(), null, null);
|
|
|
|
}
|
|
|
|
});
|
2013-08-02 13:33:30 -07:00
|
|
|
} else {
|
|
|
|
Toast.makeText(sAppContext, R.string.set_image_fail, Toast.LENGTH_SHORT).show();
|
|
|
|
}
|
|
|
|
} catch(OutOfMemoryError ome) {
|
|
|
|
Log.e(LOGTAG, "Out of Memory when converting to byte array", ome);
|
|
|
|
} catch(IOException ioe) {
|
|
|
|
Log.e(LOGTAG, "I/O Exception while setting wallpaper", ioe);
|
|
|
|
} finally {
|
|
|
|
if (is != null) {
|
|
|
|
try {
|
|
|
|
is.close();
|
2012-12-17 09:30:01 -08:00
|
|
|
} catch(IOException ioe) {
|
2013-08-02 13:33:30 -07:00
|
|
|
Log.w(LOGTAG, "I/O Exception while closing stream", ioe);
|
2012-12-17 09:30:01 -08:00
|
|
|
}
|
|
|
|
}
|
2013-08-02 13:33:30 -07:00
|
|
|
if (os != null) {
|
|
|
|
try {
|
|
|
|
os.close();
|
|
|
|
} catch(IOException ioe) {
|
|
|
|
Log.w(LOGTAG, "I/O Exception while closing stream", ioe);
|
2012-12-17 09:30:01 -08:00
|
|
|
}
|
|
|
|
}
|
2013-08-02 13:33:30 -07:00
|
|
|
}
|
2012-12-17 09:30:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
private int getBitmapSampleSize(BitmapFactory.Options options, int idealWidth, int idealHeight) {
|
|
|
|
int width = options.outWidth;
|
|
|
|
int height = options.outHeight;
|
|
|
|
int inSampleSize = 1;
|
|
|
|
if (height > idealHeight || width > idealWidth) {
|
|
|
|
if (width > height) {
|
|
|
|
inSampleSize = Math.round((float)height / (float)idealHeight);
|
|
|
|
} else {
|
|
|
|
inSampleSize = Math.round((float)width / (float)idealWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return inSampleSize;
|
|
|
|
}
|
|
|
|
|
2012-01-31 06:40:58 -08:00
|
|
|
private void hidePluginLayer(Layer layer) {
|
2012-08-20 12:43:53 -07:00
|
|
|
LayerView layerView = mLayerView;
|
2012-01-31 06:40:58 -08:00
|
|
|
layerView.removeLayer(layer);
|
|
|
|
layerView.requestRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showPluginLayer(Layer layer) {
|
2012-08-20 12:43:53 -07:00
|
|
|
LayerView layerView = mLayerView;
|
2012-01-31 06:40:58 -08:00
|
|
|
layerView.addLayer(layer);
|
|
|
|
layerView.requestRender();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void requestRender() {
|
2012-08-20 12:43:53 -07:00
|
|
|
mLayerView.requestRender();
|
2012-01-31 06:40:58 -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) {
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-07-09 13:34:44 -07:00
|
|
|
/**
|
|
|
|
* Check and start the Java profiler if MOZ_PROFILER_STARTUP env var is specified
|
|
|
|
**/
|
|
|
|
protected void earlyStartJavaSampler(Intent intent)
|
|
|
|
{
|
|
|
|
String env = intent.getStringExtra("env0");
|
|
|
|
for (int i = 1; env != null; i++) {
|
|
|
|
if (env.startsWith("MOZ_PROFILER_STARTUP=")) {
|
|
|
|
if (!env.endsWith("=")) {
|
|
|
|
GeckoJavaSampler.start(10, 1000);
|
|
|
|
Log.d(LOGTAG, "Profiling Java on startup");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
env = intent.getStringExtra("env" + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-22 10:23:53 -07:00
|
|
|
/**
|
|
|
|
* Called when the activity is first created.
|
|
|
|
*
|
|
|
|
* Here we initialize all of our profile settings, Firefox Health Report,
|
|
|
|
* and other one-shot constructions.
|
|
|
|
**/
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
2012-10-01 11:22:18 -07:00
|
|
|
GeckoAppShell.registerGlobalExceptionHandler();
|
2012-10-01 08:15:28 -07:00
|
|
|
|
2013-03-06 08:37:04 -08:00
|
|
|
// Enable Android Strict Mode for developers' local builds (the "default" channel).
|
2013-04-09 17:10:47 -07:00
|
|
|
if ("default".equals(AppConstants.MOZ_UPDATE_CHANNEL)) {
|
2013-03-06 08:37:04 -08:00
|
|
|
enableStrictMode();
|
|
|
|
}
|
|
|
|
|
2012-10-01 13:57:00 -07:00
|
|
|
// The clock starts...now. Better hurry!
|
2013-12-10 10:41:34 -08:00
|
|
|
mJavaUiStartupTimer = new Telemetry.UptimeTimer("FENNEC_STARTUP_TIME_JAVAUI");
|
|
|
|
mGeckoReadyStartupTimer = new Telemetry.UptimeTimer("FENNEC_STARTUP_TIME_GECKOREADY");
|
2012-10-01 13:57:00 -07:00
|
|
|
|
2013-07-09 13:34:44 -07:00
|
|
|
Intent intent = getIntent();
|
|
|
|
String args = intent.getStringExtra("args");
|
|
|
|
earlyStartJavaSampler(intent);
|
2013-04-16 14:34:46 -07:00
|
|
|
|
2013-07-18 11:43:34 -07:00
|
|
|
if (mProfile == null) {
|
|
|
|
String profileName = null;
|
|
|
|
String profilePath = null;
|
|
|
|
if (args != null) {
|
|
|
|
if (args.contains("-P")) {
|
|
|
|
Pattern p = Pattern.compile("(?:-P\\s*)(\\w*)(\\s*)");
|
|
|
|
Matcher m = p.matcher(args);
|
|
|
|
if (m.find()) {
|
|
|
|
profileName = m.group(1);
|
|
|
|
}
|
2013-04-16 14:34:46 -07:00
|
|
|
}
|
2013-05-22 10:23:53 -07:00
|
|
|
|
2013-07-18 11:43:34 -07:00
|
|
|
if (args.contains("-profile")) {
|
|
|
|
Pattern p = Pattern.compile("(?:-profile\\s*)(\\S*)(\\s*)");
|
|
|
|
Matcher m = p.matcher(args);
|
|
|
|
if (m.find()) {
|
|
|
|
profilePath = m.group(1);
|
|
|
|
}
|
|
|
|
if (profileName == null) {
|
|
|
|
profileName = getDefaultProfileName();
|
|
|
|
if (profileName == null)
|
2014-01-14 21:45:59 -08:00
|
|
|
profileName = GeckoProfile.DEFAULT_PROFILE;
|
2013-07-18 11:43:34 -07:00
|
|
|
}
|
2013-10-23 09:33:56 -07:00
|
|
|
GeckoProfile.sIsUsingCustomProfile = true;
|
2013-04-16 14:34:46 -07:00
|
|
|
}
|
2013-05-22 10:23:53 -07:00
|
|
|
|
2013-07-18 11:43:34 -07:00
|
|
|
if (profileName != null || profilePath != null) {
|
|
|
|
mProfile = GeckoProfile.get(this, profileName, profilePath);
|
|
|
|
}
|
2013-04-16 14:34:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BrowserDB.initialize(getProfile().getName());
|
2013-12-03 15:05:43 -08:00
|
|
|
((GeckoApplication) getApplication()).initialize();
|
2012-10-01 13:57:00 -07:00
|
|
|
|
2013-05-24 09:21:01 -07:00
|
|
|
sAppContext = this;
|
|
|
|
GeckoAppShell.setContextGetter(this);
|
|
|
|
GeckoAppShell.setGeckoInterface(this);
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.setUiThread(Thread.currentThread(), new Handler());
|
2013-03-15 03:52:52 -07:00
|
|
|
|
2013-07-15 12:12:15 -07:00
|
|
|
Tabs.getInstance().attachToContext(this);
|
2013-10-11 16:42:39 -07:00
|
|
|
try {
|
|
|
|
Favicons.attachToContext(this);
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception starting favicon cache. Corrupt resources?", e);
|
|
|
|
}
|
2012-01-27 17:28:30 -08:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
// Did the OS locale change while we were backgrounded? If so,
|
|
|
|
// we need to die so that Gecko will re-init add-ons that touch
|
|
|
|
// the UI.
|
|
|
|
// This is using a sledgehammer to crack a nut, but it'll do for
|
|
|
|
// now.
|
|
|
|
if (LocaleManager.systemLocaleDidChange()) {
|
|
|
|
Log.i(LOGTAG, "System locale changed. Restarting.");
|
2013-12-01 21:53:17 -08:00
|
|
|
doRestart();
|
|
|
|
System.exit(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-08-27 15:03:38 -07:00
|
|
|
if (GeckoThread.isCreated()) {
|
|
|
|
// This happens when the GeckoApp activity is destroyed by Android
|
|
|
|
// without killing the entire application (see Bug 769269).
|
|
|
|
mIsRestoringActivity = true;
|
|
|
|
Telemetry.HistogramAdd("FENNEC_RESTORING_ACTIVITY", 1);
|
|
|
|
}
|
|
|
|
|
2013-05-22 10:23:53 -07:00
|
|
|
// Fix for Bug 830557 on Tegra boards running Froyo.
|
2013-02-04 11:59:14 -08:00
|
|
|
// This fix must be done before doing layout.
|
|
|
|
// Assume the bug is fixed in Gingerbread and up.
|
|
|
|
if (Build.VERSION.SDK_INT < 9) {
|
|
|
|
try {
|
|
|
|
Class<?> inputBindResultClass =
|
|
|
|
Class.forName("com.android.internal.view.InputBindResult");
|
|
|
|
java.lang.reflect.Field creatorField =
|
|
|
|
inputBindResultClass.getField("CREATOR");
|
|
|
|
Log.i(LOGTAG, "froyo startup fix: " + String.valueOf(creatorField.get(null)));
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "froyo startup fix failed", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-15 22:59:17 -08:00
|
|
|
Bundle stateBundle = getIntent().getBundleExtra(EXTRA_STATE_BUNDLE);
|
|
|
|
if (stateBundle != null) {
|
|
|
|
// Use the state bundle if it was given as an intent extra. This is
|
|
|
|
// only intended to be used internally via Robocop, so a boolean
|
|
|
|
// is read from a private shared pref to prevent other apps from
|
|
|
|
// injecting states.
|
|
|
|
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
|
|
|
if (prefs.getBoolean(PREFS_ALLOW_STATE_BUNDLE, false)) {
|
|
|
|
Log.i(LOGTAG, "Restoring state from intent bundle");
|
|
|
|
prefs.edit().remove(PREFS_ALLOW_STATE_BUNDLE).commit();
|
|
|
|
savedInstanceState = stateBundle;
|
|
|
|
}
|
|
|
|
} else if (savedInstanceState != null) {
|
|
|
|
// Bug 896992 - This intent has already been handled; reset the intent.
|
|
|
|
setIntent(new Intent(Intent.ACTION_MAIN));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-02-14 13:30:15 -08:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2014-02-20 09:50:18 -08:00
|
|
|
GeckoScreenOrientation.getInstance().update(getResources().getConfiguration().orientation);
|
2012-02-14 13:30:15 -08:00
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
setContentView(getLayout());
|
2012-02-14 13:30:15 -08:00
|
|
|
|
2013-05-22 10:23:53 -07:00
|
|
|
// Set up Gecko layout.
|
2012-02-14 13:30:15 -08:00
|
|
|
mGeckoLayout = (RelativeLayout) findViewById(R.id.gecko_layout);
|
2013-03-07 02:17:32 -08:00
|
|
|
mMainLayout = (RelativeLayout) findViewById(R.id.main_layout);
|
2012-02-14 13:30:15 -08:00
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
// Determine whether we should restore tabs.
|
|
|
|
mShouldRestore = getSessionRestoreState(savedInstanceState);
|
|
|
|
if (mShouldRestore && savedInstanceState != null) {
|
2012-08-21 04:20:26 -07:00
|
|
|
boolean wasInBackground =
|
|
|
|
savedInstanceState.getBoolean(SAVED_STATE_IN_BACKGROUND, false);
|
|
|
|
|
2012-10-09 08:59:42 -07:00
|
|
|
// Don't log OOM-kills if only one activity was destroyed. (For example
|
|
|
|
// from "Don't keep activities" on ICS)
|
|
|
|
if (!wasInBackground && !mIsRestoringActivity) {
|
2012-10-09 08:59:44 -07:00
|
|
|
Telemetry.HistogramAdd("FENNEC_WAS_KILLED", 1);
|
2012-08-21 04:20:26 -07:00
|
|
|
}
|
2012-10-09 11:26:33 -07:00
|
|
|
|
|
|
|
mPrivateBrowsingSession = savedInstanceState.getString(SAVED_STATE_PRIVATE_SESSION);
|
2012-04-16 11:56:56 -07:00
|
|
|
}
|
|
|
|
|
2013-05-22 10:23:53 -07:00
|
|
|
// Perform background initialization.
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-08-21 04:20:26 -07:00
|
|
|
public void run() {
|
2013-06-04 17:16:57 -07:00
|
|
|
final SharedPreferences prefs = GeckoApp.getAppSharedPreferences();
|
2012-08-21 04:20:26 -07:00
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
// Wait until now to set this, because we'd rather throw an exception than
|
|
|
|
// have a caller of LocaleManager regress startup.
|
|
|
|
LocaleManager.setContextGetter(GeckoApp.this);
|
|
|
|
LocaleManager.initialize();
|
|
|
|
|
2013-06-04 17:16:57 -07:00
|
|
|
SessionInformation previousSession = SessionInformation.fromSharedPrefs(prefs);
|
|
|
|
if (previousSession.wasKilled()) {
|
2012-10-09 08:59:44 -07:00
|
|
|
Telemetry.HistogramAdd("FENNEC_WAS_KILLED", 1);
|
2012-08-21 04:20:26 -07:00
|
|
|
}
|
2013-06-04 17:16:57 -07:00
|
|
|
|
2012-08-21 04:20:26 -07:00
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
editor.putBoolean(GeckoApp.PREFS_OOM_EXCEPTION, false);
|
|
|
|
|
2013-06-04 17:16:57 -07:00
|
|
|
// Put a flag to check if we got a normal `onSaveInstanceState`
|
|
|
|
// on exit, or if we were suddenly killed (crash or native OOM).
|
2012-08-21 04:20:26 -07:00
|
|
|
editor.putBoolean(GeckoApp.PREFS_WAS_STOPPED, false);
|
2013-06-04 17:16:57 -07:00
|
|
|
|
2012-08-21 04:20:26 -07:00
|
|
|
editor.commit();
|
2013-05-22 10:23:53 -07:00
|
|
|
|
|
|
|
// The lifecycle of mHealthRecorder is "shortly after onCreate"
|
|
|
|
// through "onDestroy" -- essentially the same as the lifecycle
|
|
|
|
// of the activity itself.
|
|
|
|
final String profilePath = getProfile().getDir().getAbsolutePath();
|
|
|
|
final EventDispatcher dispatcher = GeckoAppShell.getEventDispatcher();
|
2014-02-04 19:41:29 -08:00
|
|
|
Log.i(LOGTAG, "Creating HealthRecorder.");
|
2013-12-03 15:05:43 -08:00
|
|
|
|
2013-10-16 18:56:27 -07:00
|
|
|
final String osLocale = Locale.getDefault().toString();
|
2013-12-03 15:05:43 -08:00
|
|
|
String appLocale = LocaleManager.getAndApplyPersistedLocale();
|
|
|
|
Log.d(LOGTAG, "OS locale is " + osLocale + ", app locale is " + appLocale);
|
|
|
|
|
|
|
|
if (appLocale == null) {
|
|
|
|
appLocale = osLocale;
|
|
|
|
}
|
2013-10-16 18:56:27 -07:00
|
|
|
|
2014-02-04 19:41:29 -08:00
|
|
|
mHealthRecorder = GeckoApp.this.createHealthRecorder(GeckoApp.this,
|
|
|
|
profilePath,
|
|
|
|
dispatcher,
|
|
|
|
osLocale,
|
|
|
|
appLocale,
|
|
|
|
previousSession);
|
2013-12-03 15:05:43 -08:00
|
|
|
|
|
|
|
final String uiLocale = appLocale;
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GeckoApp.this.onLocaleReady(uiLocale);
|
|
|
|
}
|
|
|
|
});
|
2014-02-06 15:13:27 -08:00
|
|
|
|
|
|
|
// Perform webapp uninstalls as appropiate.
|
|
|
|
if (AppConstants.MOZ_ANDROID_SYNTHAPKS) {
|
|
|
|
UninstallListener.initUninstallPackageScan(getApplicationContext());
|
|
|
|
}
|
2012-08-21 04:20:26 -07:00
|
|
|
}
|
|
|
|
});
|
2013-03-21 13:32:11 -07:00
|
|
|
|
|
|
|
GeckoAppShell.setNotificationClient(makeNotificationClient());
|
2013-11-11 08:17:02 -08:00
|
|
|
NotificationHelper.init(getApplicationContext());
|
2012-02-14 13:30:15 -08:00
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
/**
|
|
|
|
* At this point, the resource system and the rest of the browser are
|
|
|
|
* aware of the locale.
|
|
|
|
*
|
|
|
|
* Now we can display strings!
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public void onLocaleReady(final String locale) {
|
|
|
|
if (!ThreadUtils.isOnUiThread()) {
|
|
|
|
throw new RuntimeException("onLocaleReady must always be called from the UI thread.");
|
|
|
|
}
|
|
|
|
|
|
|
|
// The URL bar hint needs to be populated.
|
|
|
|
TextView urlBar = (TextView) findViewById(R.id.url_bar_title);
|
|
|
|
if (urlBar == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final String hint = getResources().getString(R.string.url_bar_default_text);
|
|
|
|
urlBar.setHint(hint);
|
|
|
|
|
|
|
|
// Allow onConfigurationChanged to take care of the rest.
|
|
|
|
onConfigurationChanged(getResources().getConfiguration());
|
|
|
|
}
|
|
|
|
|
2013-05-16 15:07:43 -07:00
|
|
|
protected void initializeChrome() {
|
2013-12-11 16:28:14 -08:00
|
|
|
mDoorHangerPopup = new DoorHangerPopup(this);
|
2012-10-25 09:55:19 -07:00
|
|
|
mPluginContainer = (AbsoluteLayout) findViewById(R.id.plugin_container);
|
|
|
|
mFormAssistPopup = (FormAssistPopup) findViewById(R.id.form_assist_popup);
|
|
|
|
|
2013-06-04 23:26:11 -07:00
|
|
|
if (mCameraView == null) {
|
2013-06-30 23:01:57 -07:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
|
|
|
mCameraView = new SurfaceView(this);
|
|
|
|
((SurfaceView)mCameraView).getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
|
|
|
|
} else {
|
|
|
|
mCameraView = new TextureView(this);
|
|
|
|
}
|
2012-10-25 09:55:19 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mLayerView == null) {
|
|
|
|
LayerView layerView = (LayerView) findViewById(R.id.layer_view);
|
|
|
|
layerView.initializeView(GeckoAppShell.getEventDispatcher());
|
|
|
|
mLayerView = layerView;
|
2013-06-06 11:05:32 -07:00
|
|
|
GeckoAppShell.setLayerView(layerView);
|
2013-01-25 10:51:41 -08:00
|
|
|
// bind the GeckoEditable instance to the new LayerView
|
2013-03-19 13:54:48 -07:00
|
|
|
GeckoAppShell.notifyIMEContext(GeckoEditableListener.IME_STATE_DISABLED, "", "", "");
|
2012-10-25 09:55:19 -07:00
|
|
|
}
|
2012-08-04 16:34:42 -07:00
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2013-05-16 15:07:43 -07:00
|
|
|
/**
|
|
|
|
* Loads the initial tab at Fennec startup.
|
|
|
|
*
|
|
|
|
* If Fennec was opened with an external URL, that URL will be loaded.
|
|
|
|
* Otherwise, unless there was a session restore, the default URL
|
|
|
|
* (about:home) be loaded.
|
|
|
|
*
|
|
|
|
* @param url External URL to load, or null to load the default URL
|
|
|
|
*/
|
|
|
|
protected void loadStartupTab(String url) {
|
|
|
|
if (url == null) {
|
2013-09-10 11:17:42 -07:00
|
|
|
if (!mShouldRestore) {
|
2013-05-16 15:07:43 -07:00
|
|
|
// Show about:home if we aren't restoring previous session and
|
2013-11-26 19:48:30 -08:00
|
|
|
// there's no external URL.
|
2013-12-17 22:43:30 -08:00
|
|
|
Tabs.getInstance().loadUrl(AboutPages.HOME, Tabs.LOADURL_NEW_TAB);
|
2013-05-16 15:07:43 -07:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If given an external URL, load it
|
2013-07-30 10:26:45 -07:00
|
|
|
int flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED | Tabs.LOADURL_EXTERNAL;
|
2013-05-16 15:07:43 -07:00
|
|
|
Tabs.getInstance().loadUrl(url, flags);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-14 13:30:15 -08:00
|
|
|
private void initialize() {
|
|
|
|
mInitialized = true;
|
|
|
|
|
2012-01-03 21:47:48 -08:00
|
|
|
Intent intent = getIntent();
|
2012-03-07 10:36:38 -08:00
|
|
|
String action = intent.getAction();
|
2012-06-15 09:02:11 -07:00
|
|
|
|
2012-01-27 17:33:02 -08:00
|
|
|
String passedUri = null;
|
2013-11-21 23:33:28 -08:00
|
|
|
final String uri = getURIFromIntent(intent);
|
|
|
|
if (!TextUtils.isEmpty(uri)) {
|
2012-04-16 11:56:56 -07:00
|
|
|
passedUri = uri;
|
|
|
|
}
|
2011-12-12 09:57:04 -08:00
|
|
|
|
2013-11-21 23:33:28 -08:00
|
|
|
final boolean isExternalURL = passedUri != null &&
|
|
|
|
!AboutPages.isAboutHome(passedUri);
|
2012-10-01 13:57:03 -07:00
|
|
|
StartupAction startupAction;
|
|
|
|
if (isExternalURL) {
|
|
|
|
startupAction = StartupAction.URL;
|
|
|
|
} else {
|
|
|
|
startupAction = StartupAction.NORMAL;
|
|
|
|
}
|
|
|
|
|
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();
|
2012-08-27 17:11:42 -07:00
|
|
|
if (data != null && "http".equals(data.getScheme())) {
|
2013-02-01 11:49:08 -08:00
|
|
|
startupAction = StartupAction.PREFETCH;
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new PrefetchRunnable(data.toString()));
|
2012-01-09 23:50:56 -08:00
|
|
|
}
|
|
|
|
|
2012-10-22 12:37:50 -07:00
|
|
|
Tabs.registerOnTabsChangedListener(this);
|
|
|
|
|
2013-08-27 15:03:38 -07:00
|
|
|
initializeChrome();
|
|
|
|
|
2012-10-29 16:34:29 -07:00
|
|
|
// If we are doing a restore, read the session data and send it to Gecko
|
2013-09-10 11:17:42 -07:00
|
|
|
if (!mIsRestoringActivity) {
|
|
|
|
String restoreMessage = null;
|
2013-09-10 11:17:42 -07:00
|
|
|
if (mShouldRestore) {
|
2013-09-10 11:17:42 -07:00
|
|
|
try {
|
|
|
|
// restoreSessionTabs() will create simple tab stubs with the
|
|
|
|
// URL and title for each page, but we also need to restore
|
|
|
|
// session history. restoreSessionTabs() will inject the IDs
|
|
|
|
// of the tab stubs into the JSON data (which holds the session
|
|
|
|
// history). This JSON data is then sent to Gecko so session
|
|
|
|
// history can be restored for each tab.
|
|
|
|
restoreMessage = restoreSessionTabs(isExternalURL);
|
|
|
|
} catch (SessionRestoreException e) {
|
|
|
|
// If restore failed, do a normal startup
|
|
|
|
Log.e(LOGTAG, "An error occurred during restore", e);
|
2013-09-10 11:17:42 -07:00
|
|
|
mShouldRestore = false;
|
2013-09-10 11:17:42 -07:00
|
|
|
}
|
2012-10-29 16:34:29 -07:00
|
|
|
}
|
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Session:Restore", restoreMessage));
|
|
|
|
}
|
2012-11-27 16:35:20 -08:00
|
|
|
|
2013-08-12 16:15:35 -07:00
|
|
|
// External URLs should always be loaded regardless of whether Gecko is
|
|
|
|
// already running.
|
|
|
|
if (isExternalURL) {
|
|
|
|
loadStartupTab(passedUri);
|
|
|
|
} else if (!mIsRestoringActivity) {
|
|
|
|
loadStartupTab(null);
|
2013-05-16 15:07:43 -07:00
|
|
|
}
|
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
// We now have tab stubs from the last session. Any future tabs should
|
|
|
|
// be animated.
|
|
|
|
Tabs.getInstance().notifyListeners(null, Tabs.TabEvents.RESTORED);
|
2012-10-29 16:34:29 -07:00
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
// If we're not restoring, move the session file so it can be read for
|
|
|
|
// the last tabs section.
|
|
|
|
if (!mShouldRestore) {
|
|
|
|
getProfile().moveSessionFile();
|
2012-10-15 10:40:16 -07:00
|
|
|
}
|
|
|
|
|
2012-10-01 13:57:03 -07:00
|
|
|
Telemetry.HistogramAdd("FENNEC_STARTUP_GECKOAPP_ACTION", startupAction.ordinal());
|
|
|
|
|
2013-08-27 15:03:38 -07:00
|
|
|
if (!mIsRestoringActivity) {
|
|
|
|
GeckoThread.setArgs(intent.getStringExtra("args"));
|
|
|
|
GeckoThread.setAction(intent.getAction());
|
|
|
|
GeckoThread.setUri(passedUri);
|
|
|
|
}
|
|
|
|
if (!ACTION_DEBUG.equals(action) &&
|
|
|
|
GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.Launching, GeckoThread.LaunchState.Launched)) {
|
|
|
|
GeckoThread.createAndStart();
|
|
|
|
} else if (ACTION_DEBUG.equals(action) &&
|
|
|
|
GeckoThread.checkAndSetLaunchState(GeckoThread.LaunchState.Launching, GeckoThread.LaunchState.WaitForDebugger)) {
|
|
|
|
ThreadUtils.getUiHandler().postDelayed(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GeckoThread.setLaunchState(GeckoThread.LaunchState.Launching);
|
|
|
|
GeckoThread.createAndStart();
|
|
|
|
}
|
|
|
|
}, 1000 * 5 /* 5 seconds */);
|
|
|
|
}
|
|
|
|
|
2013-06-13 18:58:26 -07:00
|
|
|
// Check if launched from data reporting notification.
|
|
|
|
if (ACTION_LAUNCH_SETTINGS.equals(action)) {
|
2013-06-17 17:31:17 -07:00
|
|
|
Intent settingsIntent = new Intent(GeckoApp.this, GeckoPreferences.class);
|
2013-06-13 18:58:26 -07:00
|
|
|
// Copy extras.
|
|
|
|
settingsIntent.putExtras(intent);
|
|
|
|
startActivity(settingsIntent);
|
|
|
|
}
|
|
|
|
|
2013-06-04 23:26:11 -07:00
|
|
|
//app state callbacks
|
|
|
|
mAppStateListeners = new LinkedList<GeckoAppShell.AppStateListener>();
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
//register for events
|
2012-08-04 00:33:07 -07:00
|
|
|
registerEventListener("log");
|
2013-06-10 09:25:35 -07:00
|
|
|
registerEventListener("Reader:ListCountRequest");
|
2013-10-14 06:58:16 -07:00
|
|
|
registerEventListener("Reader:ListStatusRequest");
|
2013-02-24 20:51:04 -08:00
|
|
|
registerEventListener("Reader:Added");
|
|
|
|
registerEventListener("Reader:Removed");
|
|
|
|
registerEventListener("Reader:Share");
|
2012-08-04 00:33:07 -07:00
|
|
|
registerEventListener("Reader:FaviconRequest");
|
|
|
|
registerEventListener("onCameraCapture");
|
|
|
|
registerEventListener("Gecko:Ready");
|
|
|
|
registerEventListener("Toast:Show");
|
|
|
|
registerEventListener("DOMFullScreen:Start");
|
|
|
|
registerEventListener("DOMFullScreen:Stop");
|
|
|
|
registerEventListener("ToggleChrome:Hide");
|
|
|
|
registerEventListener("ToggleChrome:Show");
|
|
|
|
registerEventListener("ToggleChrome:Focus");
|
|
|
|
registerEventListener("Permissions:Data");
|
|
|
|
registerEventListener("Session:StatePurged");
|
|
|
|
registerEventListener("Bookmark:Insert");
|
|
|
|
registerEventListener("Accessibility:Event");
|
|
|
|
registerEventListener("Accessibility:Ready");
|
|
|
|
registerEventListener("Shortcut:Remove");
|
|
|
|
registerEventListener("Share:Text");
|
|
|
|
registerEventListener("Share:Image");
|
2013-08-05 14:21:28 -07:00
|
|
|
registerEventListener("Image:SetAs");
|
2012-08-04 00:33:07 -07:00
|
|
|
registerEventListener("Sanitize:ClearHistory");
|
2012-08-31 06:31:29 -07:00
|
|
|
registerEventListener("Update:Check");
|
2013-03-13 08:47:38 -07:00
|
|
|
registerEventListener("Update:Download");
|
|
|
|
registerEventListener("Update:Install");
|
2012-10-09 11:26:33 -07:00
|
|
|
registerEventListener("PrivateBrowsing:Data");
|
2013-06-10 09:17:56 -07:00
|
|
|
registerEventListener("Contact:Add");
|
2013-08-06 22:13:21 -07:00
|
|
|
registerEventListener("Intent:Open");
|
2014-02-24 06:57:31 -08:00
|
|
|
registerEventListener("Intent:OpenForResult");
|
2013-08-06 22:13:21 -07:00
|
|
|
registerEventListener("Intent:GetHandlers");
|
2013-12-03 15:05:43 -08:00
|
|
|
registerEventListener("Locale:Set");
|
2014-01-31 14:51:24 -08:00
|
|
|
registerEventListener("NativeApp:IsDebuggable");
|
2014-01-22 11:56:11 -08:00
|
|
|
registerEventListener("SystemUI:Visibility");
|
2014-01-24 21:57:13 -08:00
|
|
|
|
|
|
|
EventListener.registerEvents();
|
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
|
|
|
|
2013-07-23 13:14:00 -07:00
|
|
|
mContactService = new ContactService(GeckoAppShell.getEventDispatcher(), this);
|
|
|
|
|
2013-05-23 15:50:56 -07:00
|
|
|
mPromptService = new PromptService(this);
|
2012-06-13 14:12:15 -07:00
|
|
|
|
2012-07-19 13:16:44 -07:00
|
|
|
mTextSelection = new TextSelection((TextSelectionHandle) findViewById(R.id.start_handle),
|
2012-09-21 10:56:41 -07:00
|
|
|
(TextSelectionHandle) findViewById(R.id.middle_handle),
|
2012-08-02 18:38:45 -07:00
|
|
|
(TextSelectionHandle) findViewById(R.id.end_handle),
|
2012-12-18 22:57:54 -08:00
|
|
|
GeckoAppShell.getEventDispatcher(),
|
|
|
|
this);
|
2012-07-19 13:16:44 -07:00
|
|
|
|
2012-10-15 06:56:42 -07:00
|
|
|
PrefsHelper.getPref("app.update.autodownload", new PrefsHelper.PrefHandlerBase() {
|
|
|
|
@Override public void prefValue(String pref, String value) {
|
|
|
|
UpdateServiceHelper.registerForUpdates(GeckoApp.this, value);
|
|
|
|
}
|
|
|
|
});
|
2012-08-31 06:31:29 -07:00
|
|
|
|
2013-05-31 14:32:12 -07:00
|
|
|
PrefsHelper.getPref("app.geo.reportdata", new PrefsHelper.PrefHandlerBase() {
|
|
|
|
@Override public void prefValue(String pref, int value) {
|
|
|
|
if (value == 1)
|
|
|
|
mShouldReportGeoData = true;
|
|
|
|
else
|
|
|
|
mShouldReportGeoData = false;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-04 17:16:57 -07:00
|
|
|
// Trigger the completion of the telemetry timer that wraps activity startup,
|
|
|
|
// then grab the duration to give to FHR.
|
2012-10-01 13:57:00 -07:00
|
|
|
mJavaUiStartupTimer.stop();
|
2013-06-04 17:16:57 -07:00
|
|
|
final long javaDuration = mJavaUiStartupTimer.getElapsed();
|
2012-10-01 13:57:00 -07:00
|
|
|
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.getBackgroundHandler().postDelayed(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-12-14 09:35:58 -08:00
|
|
|
public void run() {
|
2014-02-04 19:41:29 -08:00
|
|
|
final HealthRecorder rec = mHealthRecorder;
|
2013-07-02 12:08:09 -07:00
|
|
|
if (rec != null) {
|
|
|
|
rec.recordJavaStartupTime(javaDuration);
|
|
|
|
}
|
2013-06-04 17:16:57 -07:00
|
|
|
|
2012-10-30 13:27:33 -07:00
|
|
|
// Record our launch time for the announcements service
|
|
|
|
// to use in assessing inactivity.
|
2013-06-17 17:31:17 -07:00
|
|
|
final Context context = GeckoApp.this;
|
2012-10-30 13:27:33 -07:00
|
|
|
AnnouncementsBroadcastService.recordLastLaunch(context);
|
|
|
|
|
2013-09-19 14:41:04 -07:00
|
|
|
// Kick off our background services. We do this by invoking the broadcast
|
|
|
|
// receiver, which uses the system alarm infrastructure to perform tasks at
|
|
|
|
// intervals.
|
2012-10-30 13:27:33 -07:00
|
|
|
GeckoPreferences.broadcastAnnouncementsPref(context);
|
2013-06-12 16:17:47 -07:00
|
|
|
GeckoPreferences.broadcastHealthReportUploadPref(context);
|
2013-01-23 06:38:57 -08:00
|
|
|
if (!GeckoThread.checkLaunchState(GeckoThread.LaunchState.Launched)) {
|
2011-12-14 09:35:58 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 50);
|
2012-07-13 07:20:34 -07:00
|
|
|
|
|
|
|
if (mIsRestoringActivity) {
|
2013-01-23 06:38:57 -08:00
|
|
|
GeckoThread.setLaunchState(GeckoThread.LaunchState.GeckoRunning);
|
2012-07-13 07:20:34 -07:00
|
|
|
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (selectedTab != null)
|
2012-12-07 10:50:56 -08:00
|
|
|
Tabs.getInstance().notifyListeners(selectedTab, Tabs.TabEvents.SELECTED);
|
2013-05-29 21:34:02 -07:00
|
|
|
geckoConnected();
|
2012-08-20 12:43:53 -07:00
|
|
|
GeckoAppShell.setLayerClient(mLayerView.getLayerClient());
|
2012-07-13 07:20:34 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Viewport:Flush", null));
|
|
|
|
}
|
2013-01-11 01:26:39 -08:00
|
|
|
|
2013-01-22 11:19:35 -08:00
|
|
|
if (ACTION_ALERT_CALLBACK.equals(action)) {
|
2013-03-11 11:59:23 -07:00
|
|
|
processAlertCallback(intent);
|
2013-01-11 01:26:39 -08:00
|
|
|
}
|
2013-05-16 15:07:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private String restoreSessionTabs(final boolean isExternalURL) throws SessionRestoreException {
|
|
|
|
try {
|
|
|
|
String sessionString = getProfile().readSessionFile(false);
|
|
|
|
if (sessionString == null) {
|
|
|
|
throw new SessionRestoreException("Could not read from session file");
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are doing an OOM restore, parse the session data and
|
|
|
|
// stub the restored tabs immediately. This allows the UI to be
|
|
|
|
// updated before Gecko has restored.
|
2013-09-10 11:17:42 -07:00
|
|
|
if (mShouldRestore) {
|
2013-05-16 15:07:44 -07:00
|
|
|
final JSONArray tabs = new JSONArray();
|
|
|
|
SessionParser parser = new SessionParser() {
|
|
|
|
@Override
|
|
|
|
public void onTabRead(SessionTab sessionTab) {
|
|
|
|
JSONObject tabObject = sessionTab.getTabObject();
|
|
|
|
|
|
|
|
int flags = Tabs.LOADURL_NEW_TAB;
|
|
|
|
flags |= ((isExternalURL || !sessionTab.isSelected()) ? Tabs.LOADURL_DELAY_LOAD : 0);
|
|
|
|
flags |= (tabObject.optBoolean("desktopMode") ? Tabs.LOADURL_DESKTOP : 0);
|
|
|
|
flags |= (tabObject.optBoolean("isPrivate") ? Tabs.LOADURL_PRIVATE : 0);
|
|
|
|
|
2013-05-16 15:07:44 -07:00
|
|
|
Tab tab = Tabs.getInstance().loadUrl(sessionTab.getUrl(), flags);
|
|
|
|
tab.updateTitle(sessionTab.getTitle());
|
2013-05-16 15:07:44 -07:00
|
|
|
|
|
|
|
try {
|
|
|
|
tabObject.put("tabId", tab.getId());
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "JSON error", e);
|
|
|
|
}
|
|
|
|
tabs.put(tabObject);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-16 15:07:44 -07:00
|
|
|
if (mPrivateBrowsingSession == null) {
|
|
|
|
parser.parse(sessionString);
|
|
|
|
} else {
|
|
|
|
parser.parse(sessionString, mPrivateBrowsingSession);
|
2013-05-16 15:07:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tabs.length() > 0) {
|
|
|
|
sessionString = new JSONObject().put("windows", new JSONArray().put(new JSONObject().put("tabs", tabs))).toString();
|
|
|
|
} else {
|
|
|
|
throw new SessionRestoreException("No tabs could be read from session file");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSONObject restoreData = new JSONObject();
|
|
|
|
restoreData.put("sessionString", sessionString);
|
|
|
|
return restoreData.toString();
|
|
|
|
|
|
|
|
} catch (JSONException e) {
|
|
|
|
throw new SessionRestoreException(e);
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
/**
|
|
|
|
* Determine whether the session should be restored.
|
|
|
|
*
|
|
|
|
* @param savedInstanceState Saved instance state given to the activity
|
|
|
|
* @return Whether to restore
|
|
|
|
*/
|
|
|
|
protected boolean getSessionRestoreState(Bundle savedInstanceState) {
|
2013-06-04 17:16:57 -07:00
|
|
|
final SharedPreferences prefs = GeckoApp.getAppSharedPreferences();
|
2013-09-10 11:17:42 -07:00
|
|
|
boolean shouldRestore = false;
|
2013-07-03 15:24:57 -07:00
|
|
|
|
|
|
|
final int versionCode = getVersionCode();
|
|
|
|
if (prefs.getInt(PREFS_VERSION_CODE, 0) != versionCode) {
|
2013-08-23 12:32:19 -07:00
|
|
|
// If the version has changed, the user has done an upgrade, so restore
|
|
|
|
// previous tabs.
|
2013-07-03 15:24:57 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
prefs.edit()
|
|
|
|
.putInt(PREFS_VERSION_CODE, versionCode)
|
|
|
|
.commit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
shouldRestore = true;
|
|
|
|
} else if (savedInstanceState != null || getSessionRestorePreference().equals("always") || getRestartFromIntent()) {
|
|
|
|
// We're coming back from a background kill by the OS, the user
|
|
|
|
// has chosen to always restore, or we just restarted.
|
|
|
|
shouldRestore = true;
|
2013-07-03 15:24:57 -07:00
|
|
|
}
|
2012-12-07 10:50:40 -08:00
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
return shouldRestore;
|
|
|
|
}
|
2013-04-18 17:19:10 -07:00
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
private String getSessionRestorePreference() {
|
|
|
|
return PreferenceManager.getDefaultSharedPreferences(this)
|
|
|
|
.getString(GeckoPreferences.PREFS_RESTORE_SESSION, "quit");
|
|
|
|
}
|
2013-07-03 15:24:57 -07:00
|
|
|
|
2013-09-10 11:17:42 -07:00
|
|
|
private boolean getRestartFromIntent() {
|
|
|
|
return getIntent().getBooleanExtra("didRestart", false);
|
2012-11-08 14:49:07 -08:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2013-03-06 08:37:04 -08:00
|
|
|
private void enableStrictMode() {
|
2012-08-14 14:13:52 -07:00
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) {
|
2011-12-12 17:15:23 -08:00
|
|
|
return;
|
2012-08-14 14:13:52 -07:00
|
|
|
}
|
2011-12-12 17:15:23 -08:00
|
|
|
|
2013-03-06 08:37:04 -08:00
|
|
|
Log.d(LOGTAG, "Enabling Android StrictMode");
|
|
|
|
|
2012-08-14 14:13:52 -07:00
|
|
|
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
|
|
|
.detectAll()
|
|
|
|
.penaltyLog()
|
|
|
|
.build());
|
2011-12-12 17:15:23 -08:00
|
|
|
|
|
|
|
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
|
|
|
.detectAll()
|
|
|
|
.penaltyLog()
|
|
|
|
.build());
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
public void enableCameraView() {
|
2013-07-11 08:17:37 -07:00
|
|
|
// Start listening for orientation events
|
|
|
|
mCameraOrientationEventListener = new OrientationEventListener(this) {
|
|
|
|
@Override
|
|
|
|
public void onOrientationChanged(int orientation) {
|
|
|
|
if (mAppStateListeners != null) {
|
|
|
|
for (GeckoAppShell.AppStateListener listener: mAppStateListeners) {
|
|
|
|
listener.onOrientationChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
mCameraOrientationEventListener.enable();
|
|
|
|
|
|
|
|
// Try to make it fully transparent.
|
2013-06-30 23:01:57 -07:00
|
|
|
if (mCameraView instanceof SurfaceView) {
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
|
|
mCameraView.setAlpha(0.0f);
|
|
|
|
}
|
|
|
|
} else if (mCameraView instanceof TextureView) {
|
|
|
|
mCameraView.setAlpha(0.0f);
|
|
|
|
}
|
|
|
|
RelativeLayout mCameraLayout = (RelativeLayout) findViewById(R.id.camera_layout);
|
2011-11-18 10:28:17 -08:00
|
|
|
// Some phones (eg. nexus S) need at least a 8x16 preview size
|
2013-06-30 23:01:57 -07:00
|
|
|
mCameraLayout.addView(mCameraView,
|
|
|
|
new AbsoluteLayout.LayoutParams(8, 16, 0, 0));
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void disableCameraView() {
|
2013-07-11 08:17:37 -07:00
|
|
|
if (mCameraOrientationEventListener != null) {
|
|
|
|
mCameraOrientationEventListener.disable();
|
|
|
|
mCameraOrientationEventListener = null;
|
|
|
|
}
|
2013-06-30 23:01:57 -07:00
|
|
|
RelativeLayout mCameraLayout = (RelativeLayout) findViewById(R.id.camera_layout);
|
|
|
|
mCameraLayout.removeView(mCameraView);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-04-09 17:10:47 -07:00
|
|
|
public String getDefaultUAString() {
|
|
|
|
return HardwareUtils.isTablet() ? AppConstants.USER_AGENT_FENNEC_TABLET :
|
|
|
|
AppConstants.USER_AGENT_FENNEC_MOBILE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getUAStringForHost(String host) {
|
|
|
|
// With our standard UA String, we get a 200 response code and
|
|
|
|
// client-side redirect from t.co. This bot-like UA gives us a
|
|
|
|
// 301 response code
|
|
|
|
if ("t.co".equals(host)) {
|
|
|
|
return AppConstants.USER_AGENT_BOT_LIKE;
|
|
|
|
}
|
|
|
|
return getDefaultUAString();
|
|
|
|
}
|
2012-01-09 23:50:56 -08:00
|
|
|
|
2012-08-27 17:11:42 -07:00
|
|
|
class PrefetchRunnable implements Runnable {
|
2013-02-01 11:49:08 -08:00
|
|
|
private String mPrefetchUrl;
|
2012-08-27 17:11:42 -07:00
|
|
|
|
2013-02-01 11:49:08 -08:00
|
|
|
PrefetchRunnable(String prefetchUrl) {
|
|
|
|
mPrefetchUrl = prefetchUrl;
|
|
|
|
}
|
2012-08-27 17:11:42 -07:00
|
|
|
|
2013-02-01 11:49:08 -08:00
|
|
|
@Override
|
2012-01-09 23:50:56 -08:00
|
|
|
public void run() {
|
2013-02-01 11:49:08 -08:00
|
|
|
HttpURLConnection connection = null;
|
2012-01-09 23:50:56 -08:00
|
|
|
try {
|
2013-02-01 11:49:08 -08:00
|
|
|
URL url = new URL(mPrefetchUrl);
|
2012-01-09 23:50:56 -08:00
|
|
|
// data url should have an http scheme
|
2013-02-01 11:49:08 -08:00
|
|
|
connection = (HttpURLConnection) url.openConnection();
|
|
|
|
connection.setRequestProperty("User-Agent", getUAStringForHost(url.getHost()));
|
|
|
|
connection.setInstanceFollowRedirects(false);
|
|
|
|
connection.setRequestMethod("GET");
|
|
|
|
connection.connect();
|
2012-08-27 17:11:42 -07:00
|
|
|
} catch (Exception e) {
|
2013-02-01 11:49:08 -08:00
|
|
|
Log.e(LOGTAG, "Exception prefetching URL", e);
|
2012-08-27 17:11:42 -07:00
|
|
|
} finally {
|
2013-02-01 11:49:08 -08:00
|
|
|
if (connection != null)
|
|
|
|
connection.disconnect();
|
2012-08-27 17:11:42 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-11 11:59:23 -07:00
|
|
|
private void processAlertCallback(Intent intent) {
|
|
|
|
String alertName = "";
|
|
|
|
String alertCookie = "";
|
|
|
|
Uri data = intent.getData();
|
|
|
|
if (data != null) {
|
|
|
|
alertName = data.getQueryParameter("name");
|
|
|
|
if (alertName == null)
|
|
|
|
alertName = "";
|
|
|
|
alertCookie = data.getQueryParameter("cookie");
|
|
|
|
if (alertCookie == null)
|
|
|
|
alertCookie = "";
|
|
|
|
}
|
|
|
|
handleNotification(ACTION_ALERT_CALLBACK, alertName, alertCookie);
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
2013-01-23 06:38:57 -08:00
|
|
|
if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoExiting)) {
|
2011-11-18 10:28:17 -08:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
final String action = intent.getAction();
|
|
|
|
|
2013-08-12 16:15:35 -07:00
|
|
|
if (ACTION_LOAD.equals(action)) {
|
2012-01-09 23:50:56 -08:00
|
|
|
String uri = intent.getDataString();
|
2012-10-05 14:51:18 -07:00
|
|
|
Tabs.getInstance().loadUrl(uri);
|
2013-03-05 05:05:26 -08:00
|
|
|
} else if (Intent.ACTION_VIEW.equals(action)) {
|
2011-11-18 10:28:17 -08:00
|
|
|
String uri = intent.getDataString();
|
2013-10-01 09:15:44 -07:00
|
|
|
Tabs.getInstance().loadUrl(uri, Tabs.LOADURL_NEW_TAB |
|
|
|
|
Tabs.LOADURL_USER_ENTERED |
|
|
|
|
Tabs.LOADURL_EXTERNAL);
|
2013-03-05 05:05:26 -08:00
|
|
|
} else if (action != null && action.startsWith(ACTION_WEBAPP_PREFIX)) {
|
2014-01-09 10:18:55 -08:00
|
|
|
// A lightweight mechanism for loading a web page as a webapp
|
|
|
|
// without installing the app natively nor registering it in the DOM
|
|
|
|
// application registry.
|
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));
|
2013-03-05 05:05:26 -08:00
|
|
|
} 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));
|
2013-03-05 05:05:26 -08:00
|
|
|
} else if (Intent.ACTION_SEARCH.equals(action)) {
|
2012-10-04 16:57:39 -07:00
|
|
|
String uri = getURIFromIntent(intent);
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createURILoadEvent(uri));
|
2013-03-05 05:05:26 -08:00
|
|
|
} else if (ACTION_ALERT_CALLBACK.equals(action)) {
|
2013-03-11 11:59:23 -07:00
|
|
|
processAlertCallback(intent);
|
2013-07-30 11:45:25 -07:00
|
|
|
} else if (ACTION_LAUNCH_SETTINGS.equals(action)) {
|
2013-06-13 18:58:26 -07:00
|
|
|
// Check if launched from data reporting notification.
|
2013-06-17 17:31:17 -07:00
|
|
|
Intent settingsIntent = new Intent(GeckoApp.this, GeckoPreferences.class);
|
2013-06-13 18:58:26 -07:00
|
|
|
// Copy extras.
|
|
|
|
settingsIntent.putExtras(intent);
|
|
|
|
startActivity(settingsIntent);
|
2012-10-19 11:15:06 -07:00
|
|
|
}
|
2012-01-28 09:24:51 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handles getting a uri from and intent in a way that is backwards
|
|
|
|
* compatable with our previous implementations
|
|
|
|
*/
|
2012-08-22 08:37:14 -07:00
|
|
|
protected String getURIFromIntent(Intent intent) {
|
2012-08-29 08:51:34 -07:00
|
|
|
final String action = intent.getAction();
|
|
|
|
if (ACTION_ALERT_CALLBACK.equals(action))
|
|
|
|
return null;
|
|
|
|
|
2012-01-28 09:24:51 -08:00
|
|
|
String uri = intent.getDataString();
|
|
|
|
if (uri != null)
|
|
|
|
return uri;
|
|
|
|
|
2012-06-28 06:42:32 -07:00
|
|
|
if ((action != null && action.startsWith(ACTION_WEBAPP_PREFIX)) || ACTION_BOOKMARK.equals(action)) {
|
2012-01-28 09:24:51 -08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-02-20 09:50:18 -08:00
|
|
|
protected int getOrientation() {
|
|
|
|
return GeckoScreenOrientation.getInstance().getAndroidOrientation();
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public void onResume()
|
|
|
|
{
|
|
|
|
// After an onPause, the activity is back in the foreground.
|
|
|
|
// Undo whatever we did in onPause.
|
|
|
|
super.onResume();
|
|
|
|
|
2012-01-30 15:10:16 -08:00
|
|
|
int newOrientation = getResources().getConfiguration().orientation;
|
2014-02-20 09:50:18 -08:00
|
|
|
if (GeckoScreenOrientation.getInstance().update(newOrientation)) {
|
2012-06-11 15:18:40 -07:00
|
|
|
refreshChrome();
|
2012-01-30 15:10:16 -08:00
|
|
|
}
|
2012-06-13 12:22:52 -07:00
|
|
|
|
|
|
|
// User may have enabled/disabled accessibility.
|
2013-04-17 14:51:53 -07:00
|
|
|
GeckoAccessibility.updateAccessibilitySettings(this);
|
2012-08-21 04:20:26 -07:00
|
|
|
|
2013-06-04 23:26:11 -07:00
|
|
|
if (mAppStateListeners != null) {
|
2013-06-05 11:52:39 -07:00
|
|
|
for (GeckoAppShell.AppStateListener listener: mAppStateListeners) {
|
2013-06-04 23:26:11 -07:00
|
|
|
listener.onResume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-04 17:16:57 -07:00
|
|
|
// We use two times: a pseudo-unique wall-clock time to identify the
|
|
|
|
// current session across power cycles, and the elapsed realtime to
|
|
|
|
// track the duration of the session.
|
|
|
|
final long now = System.currentTimeMillis();
|
|
|
|
final long realTime = android.os.SystemClock.elapsedRealtime();
|
|
|
|
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-08-21 04:20:26 -07:00
|
|
|
public void run() {
|
2014-02-04 19:41:29 -08:00
|
|
|
// Now construct the new session on HealthRecorder's behalf. We do this here
|
2013-06-04 17:16:57 -07:00
|
|
|
// so it can benefit from a single near-startup prefs commit.
|
|
|
|
SessionInformation currentSession = new SessionInformation(now, realTime);
|
|
|
|
|
|
|
|
SharedPreferences prefs = GeckoApp.getAppSharedPreferences();
|
2012-08-21 04:20:26 -07:00
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
editor.putBoolean(GeckoApp.PREFS_WAS_STOPPED, false);
|
2013-06-04 17:16:57 -07:00
|
|
|
currentSession.recordBegin(editor);
|
2012-08-21 04:20:26 -07:00
|
|
|
editor.commit();
|
2013-06-04 17:16:57 -07:00
|
|
|
|
2014-02-04 19:41:29 -08:00
|
|
|
final HealthRecorder rec = mHealthRecorder;
|
2013-06-04 17:16:57 -07:00
|
|
|
if (rec != null) {
|
|
|
|
rec.setCurrentSession(currentSession);
|
2013-07-02 12:08:09 -07:00
|
|
|
} else {
|
|
|
|
Log.w(LOGTAG, "Can't record session: rec is null.");
|
2013-06-04 17:16:57 -07:00
|
|
|
}
|
2012-08-21 04:20:26 -07: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);
|
|
|
|
|
2013-02-19 11:54:40 -08:00
|
|
|
if (!mInitialized && hasFocus) {
|
2012-04-13 12:31:16 -07:00
|
|
|
initialize();
|
2013-02-19 11:54:40 -08:00
|
|
|
getWindow().setBackgroundDrawable(null);
|
|
|
|
}
|
2012-04-13 12:31:16 -07:00
|
|
|
}
|
|
|
|
|
2012-08-21 04:20:26 -07:00
|
|
|
@Override
|
|
|
|
public void onPause()
|
|
|
|
{
|
2014-02-04 19:41:29 -08:00
|
|
|
final HealthRecorder rec = mHealthRecorder;
|
2013-09-19 14:41:04 -07:00
|
|
|
final Context context = this;
|
2013-06-04 17:16:57 -07:00
|
|
|
|
2012-08-21 04:20:26 -07:00
|
|
|
// In some way it's sad that Android will trigger StrictMode warnings
|
|
|
|
// here as the whole point is to save to disk while the activity is not
|
|
|
|
// interacting with the user.
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-08-21 04:20:26 -07:00
|
|
|
public void run() {
|
2013-06-04 17:16:57 -07:00
|
|
|
SharedPreferences prefs = GeckoApp.getAppSharedPreferences();
|
2012-08-21 04:20:26 -07:00
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
editor.putBoolean(GeckoApp.PREFS_WAS_STOPPED, true);
|
2013-06-04 17:16:57 -07:00
|
|
|
if (rec != null) {
|
|
|
|
rec.recordSessionEnd("P", editor);
|
|
|
|
}
|
2012-08-21 04:20:26 -07:00
|
|
|
editor.commit();
|
2013-09-19 14:41:04 -07:00
|
|
|
|
|
|
|
// In theory, the first browser session will not run long enough that we need to
|
|
|
|
// prune during it and we'd rather run it when the browser is inactive so we wait
|
|
|
|
// until here to register the prune service.
|
|
|
|
GeckoPreferences.broadcastHealthReportPrune(context);
|
2012-08-21 04:20:26 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-06-04 23:26:11 -07:00
|
|
|
if (mAppStateListeners != null) {
|
|
|
|
for(GeckoAppShell.AppStateListener listener: mAppStateListeners) {
|
|
|
|
listener.onPause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-21 04:20:26 -07:00
|
|
|
super.onPause();
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
|
|
|
public void onRestart()
|
|
|
|
{
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-08-21 04:20:26 -07:00
|
|
|
public void run() {
|
2013-06-04 17:16:57 -07:00
|
|
|
SharedPreferences prefs = GeckoApp.getAppSharedPreferences();
|
2012-08-21 04:20:26 -07:00
|
|
|
SharedPreferences.Editor editor = prefs.edit();
|
|
|
|
editor.putBoolean(GeckoApp.PREFS_WAS_STOPPED, false);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
super.onRestart();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy()
|
|
|
|
{
|
2012-08-04 00:33:07 -07:00
|
|
|
unregisterEventListener("log");
|
2013-06-10 09:25:35 -07:00
|
|
|
unregisterEventListener("Reader:ListCountRequest");
|
2013-10-14 06:58:16 -07:00
|
|
|
unregisterEventListener("Reader:ListStatusRequest");
|
2013-02-24 20:51:04 -08:00
|
|
|
unregisterEventListener("Reader:Added");
|
|
|
|
unregisterEventListener("Reader:Removed");
|
|
|
|
unregisterEventListener("Reader:Share");
|
2012-08-04 00:33:07 -07:00
|
|
|
unregisterEventListener("Reader:FaviconRequest");
|
|
|
|
unregisterEventListener("onCameraCapture");
|
|
|
|
unregisterEventListener("Gecko:Ready");
|
|
|
|
unregisterEventListener("Toast:Show");
|
|
|
|
unregisterEventListener("DOMFullScreen:Start");
|
|
|
|
unregisterEventListener("DOMFullScreen:Stop");
|
|
|
|
unregisterEventListener("ToggleChrome:Hide");
|
|
|
|
unregisterEventListener("ToggleChrome:Show");
|
|
|
|
unregisterEventListener("ToggleChrome:Focus");
|
|
|
|
unregisterEventListener("Permissions:Data");
|
|
|
|
unregisterEventListener("Session:StatePurged");
|
|
|
|
unregisterEventListener("Bookmark:Insert");
|
|
|
|
unregisterEventListener("Accessibility:Event");
|
|
|
|
unregisterEventListener("Accessibility:Ready");
|
|
|
|
unregisterEventListener("Shortcut:Remove");
|
|
|
|
unregisterEventListener("Share:Text");
|
|
|
|
unregisterEventListener("Share:Image");
|
2013-08-05 14:21:28 -07:00
|
|
|
unregisterEventListener("Image:SetAs");
|
2012-08-04 00:33:07 -07:00
|
|
|
unregisterEventListener("Sanitize:ClearHistory");
|
2012-08-31 06:31:29 -07:00
|
|
|
unregisterEventListener("Update:Check");
|
2013-03-13 08:47:38 -07:00
|
|
|
unregisterEventListener("Update:Download");
|
|
|
|
unregisterEventListener("Update:Install");
|
2012-10-09 11:26:33 -07:00
|
|
|
unregisterEventListener("PrivateBrowsing:Data");
|
2013-06-10 09:17:56 -07:00
|
|
|
unregisterEventListener("Contact:Add");
|
2013-08-06 22:13:21 -07:00
|
|
|
unregisterEventListener("Intent:Open");
|
|
|
|
unregisterEventListener("Intent:GetHandlers");
|
2014-01-13 17:58:36 -08:00
|
|
|
unregisterEventListener("Locale:Set");
|
2014-01-31 14:51:24 -08:00
|
|
|
unregisterEventListener("NativeApp:IsDebuggable");
|
2014-01-22 11:56:11 -08:00
|
|
|
unregisterEventListener("SystemUI:Visibility");
|
2014-01-24 21:57:13 -08:00
|
|
|
|
|
|
|
EventListener.unregisterEvents();
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2012-07-10 14:25:15 -07:00
|
|
|
deleteTempFiles();
|
|
|
|
|
2012-08-20 12:43:53 -07:00
|
|
|
if (mLayerView != null)
|
|
|
|
mLayerView.destroy();
|
2012-08-04 16:34:42 -07:00
|
|
|
if (mDoorHangerPopup != null)
|
|
|
|
mDoorHangerPopup.destroy();
|
2012-07-13 07:17:03 -07:00
|
|
|
if (mFormAssistPopup != null)
|
|
|
|
mFormAssistPopup.destroy();
|
2013-07-23 13:14:00 -07:00
|
|
|
if (mContactService != null)
|
|
|
|
mContactService.destroy();
|
2012-07-13 07:17:03 -07:00
|
|
|
if (mPromptService != null)
|
|
|
|
mPromptService.destroy();
|
2012-07-19 13:16:44 -07:00
|
|
|
if (mTextSelection != null)
|
|
|
|
mTextSelection.destroy();
|
2013-11-05 22:08:15 -08:00
|
|
|
NotificationHelper.destroy();
|
2012-07-13 07:17:03 -07: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
|
|
|
|
2014-02-04 19:41:29 -08:00
|
|
|
final HealthRecorder rec = mHealthRecorder;
|
2013-06-04 17:16:57 -07:00
|
|
|
mHealthRecorder = null;
|
2014-02-04 19:41:29 -08:00
|
|
|
if (rec != null && rec.isEnabled()) {
|
2013-06-04 17:16:57 -07:00
|
|
|
// Closing a BrowserHealthRecorder could incur a write.
|
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
rec.close();
|
|
|
|
}
|
|
|
|
});
|
2013-05-22 10:23:53 -07:00
|
|
|
}
|
2013-05-30 17:42:56 -07:00
|
|
|
|
2013-09-12 07:49:20 -07:00
|
|
|
Favicons.close();
|
|
|
|
|
2013-05-30 17:42:56 -07:00
|
|
|
super.onDestroy();
|
|
|
|
|
|
|
|
Tabs.unregisterOnTabsChangedListener(this);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2012-08-26 21:33:11 -07:00
|
|
|
protected void registerEventListener(String event) {
|
2012-08-04 00:33:07 -07:00
|
|
|
GeckoAppShell.getEventDispatcher().registerEventListener(event, this);
|
|
|
|
}
|
|
|
|
|
2012-08-26 21:33:11 -07:00
|
|
|
protected void unregisterEventListener(String event) {
|
2012-08-04 00:33:07 -07:00
|
|
|
GeckoAppShell.getEventDispatcher().unregisterEventListener(event, this);
|
|
|
|
}
|
|
|
|
|
2012-07-19 14:36:48 -07:00
|
|
|
// Get a temporary directory, may return null
|
2012-07-10 14:25:15 -07:00
|
|
|
public static File getTempDirectory() {
|
2013-05-24 09:21:01 -07:00
|
|
|
File dir = sAppContext.getExternalFilesDir("temp");
|
2012-07-10 14:25:15 -07:00
|
|
|
return dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete any files in our temporary directory
|
|
|
|
public static void deleteTempFiles() {
|
2012-07-19 14:36:48 -07:00
|
|
|
File dir = getTempDirectory();
|
|
|
|
if (dir == null)
|
|
|
|
return;
|
|
|
|
File[] files = dir.listFiles();
|
2012-07-10 14:25:15 -07:00
|
|
|
if (files == null)
|
|
|
|
return;
|
|
|
|
for (File file : files) {
|
|
|
|
file.delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
@Override
|
2012-10-23 09:45:40 -07:00
|
|
|
public void onConfigurationChanged(Configuration newConfig) {
|
2013-12-03 15:05:43 -08:00
|
|
|
Log.d(LOGTAG, "onConfigurationChanged: " + newConfig.locale);
|
|
|
|
LocaleManager.correctLocale(getResources(), newConfig);
|
2011-12-21 00:03:34 -08:00
|
|
|
|
2014-02-20 09:50:18 -08:00
|
|
|
// onConfigurationChanged is not called for 180 degree orientation changes,
|
|
|
|
// we will miss such rotations and the screen orientation will not be
|
|
|
|
// updated.
|
|
|
|
if (GeckoScreenOrientation.getInstance().update(newConfig.orientation)) {
|
2012-06-14 20:12:06 -07:00
|
|
|
if (mFormAssistPopup != null)
|
|
|
|
mFormAssistPopup.hide();
|
2012-06-11 15:18:40 -07:00
|
|
|
refreshChrome();
|
2011-12-21 00:03:34 -08:00
|
|
|
}
|
2014-02-20 09:50:18 -08:00
|
|
|
super.onConfigurationChanged(newConfig);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2012-05-16 15:28:28 -07:00
|
|
|
|
2013-04-09 17:10:47 -07:00
|
|
|
public String getContentProcessName() {
|
|
|
|
return AppConstants.MOZ_CHILD_PROCESS_NAME;
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
|
|
|
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() {
|
2013-07-18 11:43:34 -07:00
|
|
|
doRestart(RESTARTER_ACTION, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void doRestart(String args) {
|
|
|
|
doRestart(RESTARTER_ACTION, args);
|
2012-01-24 20:32:12 -08:00
|
|
|
}
|
|
|
|
|
2013-07-18 11:43:34 -07:00
|
|
|
public void doRestart(String action, String args) {
|
2012-10-23 09:45:40 -07:00
|
|
|
Log.d(LOGTAG, "doRestart(\"" + action + "\")");
|
2011-11-18 10:28:17 -08:00
|
|
|
try {
|
|
|
|
Intent intent = new Intent(action);
|
2013-04-09 17:10:47 -07:00
|
|
|
intent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, RESTARTER_CLASS);
|
2011-11-18 10:28:17 -08:00
|
|
|
/* TODO: addEnvToIntent(intent); */
|
2013-07-18 11:43:34 -07:00
|
|
|
if (args != null)
|
|
|
|
intent.putExtra("args", args);
|
2013-09-10 11:17:42 -07:00
|
|
|
intent.putExtra("didRestart", true);
|
2012-10-23 09:45:40 -07:00
|
|
|
Log.d(LOGTAG, "Restart intent: " + intent.toString());
|
2011-11-18 10:28:17 -08:00
|
|
|
GeckoAppShell.killAnyZombies();
|
|
|
|
startActivity(intent);
|
|
|
|
} catch (Exception e) {
|
2012-10-23 09:45:40 -07:00
|
|
|
Log.e(LOGTAG, "Error effecting restart.", e);
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
2013-09-10 11:17:42 -07:00
|
|
|
|
2011-11-18 10:28:17 -08:00
|
|
|
finish();
|
|
|
|
// Give the restart process time to start before we die
|
|
|
|
GeckoAppShell.waitForAnotherGeckoProc();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void handleNotification(String action, String alertName, String alertCookie) {
|
2013-03-11 11:59:23 -07:00
|
|
|
// If Gecko isn't running yet, we ignore the notification. Note that
|
|
|
|
// even if Gecko is running but it was restarted since the notification
|
|
|
|
// was created, the notification won't be handled (bug 849653).
|
|
|
|
if (GeckoThread.checkLaunchState(GeckoThread.LaunchState.GeckoRunning)) {
|
|
|
|
GeckoAppShell.handleNotification(action, alertName, alertCookie);
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2011-12-19 13:56:11 -08:00
|
|
|
private void checkMigrateProfile() {
|
2012-04-17 13:01:28 -07:00
|
|
|
final File profileDir = getProfile().getDir();
|
2012-02-10 14:01:44 -08:00
|
|
|
|
2011-12-19 13:56:11 -08:00
|
|
|
if (profileDir != null) {
|
2013-05-24 09:21:01 -07:00
|
|
|
final GeckoApp app = GeckoApp.sAppContext;
|
2012-04-04 12:29:31 -07:00
|
|
|
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-04-19 07:41:52 -07:00
|
|
|
public void run() {
|
2013-07-24 15:50:26 -07:00
|
|
|
Handler handler = new Handler();
|
|
|
|
handler.postDelayed(new DeferredCleanupTask(), CLEANUP_DEFERRAL_SECONDS * 1000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2012-04-04 12:29:31 -07:00
|
|
|
|
2013-07-24 15:50:26 -07:00
|
|
|
private class DeferredCleanupTask implements Runnable {
|
|
|
|
// The cleanup-version setting is recorded to avoid repeating the same
|
|
|
|
// tasks on subsequent startups; CURRENT_CLEANUP_VERSION may be updated
|
|
|
|
// if we need to do additional cleanup for future Gecko versions.
|
2013-06-25 14:30:58 -07:00
|
|
|
|
2013-07-24 15:50:26 -07:00
|
|
|
private static final String CLEANUP_VERSION = "cleanup-version";
|
|
|
|
private static final int CURRENT_CLEANUP_VERSION = 1;
|
2012-04-19 13:07:39 -07:00
|
|
|
|
2013-07-24 15:50:26 -07:00
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
long cleanupVersion = getAppSharedPreferences().getInt(CLEANUP_VERSION, 0);
|
|
|
|
|
|
|
|
if (cleanupVersion < 1) {
|
|
|
|
// Reduce device storage footprint by removing .ttf files from
|
|
|
|
// the res/fonts directory: we no longer need to copy our
|
|
|
|
// bundled fonts out of the APK in order to use them.
|
|
|
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=878674.
|
|
|
|
File dir = new File("res/fonts");
|
|
|
|
if (dir.exists() && dir.isDirectory()) {
|
|
|
|
for (File file : dir.listFiles()) {
|
|
|
|
if (file.isFile() && file.getName().endsWith(".ttf")) {
|
|
|
|
Log.i(LOGTAG, "deleting " + file.toString());
|
|
|
|
file.delete();
|
|
|
|
}
|
2012-04-17 13:01:28 -07:00
|
|
|
}
|
2013-07-24 15:50:26 -07:00
|
|
|
if (!dir.delete()) {
|
|
|
|
Log.w(LOGTAG, "unable to delete res/fonts directory (not empty?)");
|
|
|
|
} else {
|
|
|
|
Log.i(LOGTAG, "res/fonts directory deleted");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 13:01:28 -07:00
|
|
|
|
2013-07-24 15:50:26 -07:00
|
|
|
// Additional cleanup needed for future versions would go here
|
|
|
|
|
|
|
|
if (cleanupVersion != CURRENT_CLEANUP_VERSION) {
|
|
|
|
SharedPreferences.Editor editor = getAppSharedPreferences().edit();
|
|
|
|
editor.putInt(CLEANUP_VERSION, CURRENT_CLEANUP_VERSION);
|
|
|
|
editor.commit();
|
|
|
|
}
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2013-05-24 09:21:01 -07:00
|
|
|
public PromptService getPromptService() {
|
2012-07-13 11:07:43 -07:00
|
|
|
return mPromptService;
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBackPressed() {
|
2013-07-08 15:05:27 -07:00
|
|
|
if (getSupportFragmentManager().getBackStackEntryCount() > 0) {
|
|
|
|
super.onBackPressed();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-19 13:37:57 -07:00
|
|
|
if (autoHideTabs()) {
|
2012-06-10 16:44:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-08-09 13:53:00 -07:00
|
|
|
if (mDoorHangerPopup != null && mDoorHangerPopup.isShowing()) {
|
2011-11-18 10:28:17 -08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-01 17:36:04 -07:00
|
|
|
if (mLayerView != null && mLayerView.isFullScreen()) {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-07-13 11:07:43 -07:00
|
|
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
2014-02-14 12:02:05 -08:00
|
|
|
if (!ActivityHandlerHelper.handleActivityResult(requestCode, resultCode, data)) {
|
2012-04-04 22:50:06 -07:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
2012-07-13 11:07:43 -07:00
|
|
|
}
|
2012-04-04 22:50:06 -07:00
|
|
|
}
|
|
|
|
|
2012-04-27 13:04:47 -07:00
|
|
|
public AbsoluteLayout getPluginContainer() { return mPluginContainer; }
|
|
|
|
|
2012-10-23 09:45:40 -07:00
|
|
|
// Accelerometer.
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-10-23 09:45:40 -07:00
|
|
|
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
|
|
|
}
|
2011-11-18 10:28:17 -08:00
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-10-23 09:45:40 -07: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
|
|
|
}
|
|
|
|
|
2012-10-23 09:45:40 -07:00
|
|
|
// Geolocation.
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-10-23 09:45:40 -07:00
|
|
|
public void onLocationChanged(Location location) {
|
|
|
|
// No logging here: user-identifying information.
|
2012-03-08 22:16:25 -08:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createLocationEvent(location));
|
2013-05-31 14:32:12 -07:00
|
|
|
if (mShouldReportGeoData)
|
|
|
|
collectAndReportLocInfo(location);
|
2013-05-30 09:50:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setCurrentSignalStrenth(SignalStrength ss) {
|
|
|
|
if (ss.isGsm())
|
|
|
|
mSignalStrenth = ss.getGsmSignalStrength();
|
|
|
|
}
|
|
|
|
|
|
|
|
private int getCellInfo(JSONArray cellInfo) {
|
|
|
|
TelephonyManager tm = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
|
|
|
|
if (tm == null)
|
|
|
|
return TelephonyManager.PHONE_TYPE_NONE;
|
|
|
|
List<NeighboringCellInfo> cells = tm.getNeighboringCellInfo();
|
|
|
|
CellLocation cl = tm.getCellLocation();
|
|
|
|
String mcc = "", mnc = "";
|
|
|
|
if (cl instanceof GsmCellLocation) {
|
|
|
|
JSONObject obj = new JSONObject();
|
|
|
|
GsmCellLocation gcl = (GsmCellLocation)cl;
|
|
|
|
try {
|
|
|
|
obj.put("lac", gcl.getLac());
|
|
|
|
obj.put("cid", gcl.getCid());
|
2013-09-05 11:57:18 -07:00
|
|
|
|
|
|
|
int psc = (Build.VERSION.SDK_INT >= 9) ? gcl.getPsc() : -1;
|
|
|
|
obj.put("psc", psc);
|
|
|
|
|
2013-05-30 09:50:45 -07:00
|
|
|
switch(tm.getNetworkType()) {
|
|
|
|
case TelephonyManager.NETWORK_TYPE_GPRS:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EDGE:
|
|
|
|
obj.put("radio", "gsm");
|
|
|
|
break;
|
|
|
|
case TelephonyManager.NETWORK_TYPE_UMTS:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
|
|
|
obj.put("radio", "umts");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
String mcc_mnc = tm.getNetworkOperator();
|
2013-06-25 11:53:43 -07:00
|
|
|
if (mcc_mnc.length() > 3) {
|
|
|
|
mcc = mcc_mnc.substring(0, 3);
|
|
|
|
mnc = mcc_mnc.substring(3);
|
|
|
|
obj.put("mcc", mcc);
|
|
|
|
obj.put("mnc", mnc);
|
|
|
|
}
|
2013-05-30 09:50:45 -07:00
|
|
|
obj.put("asu", mSignalStrenth);
|
|
|
|
} catch(JSONException jsonex) {}
|
|
|
|
cellInfo.put(obj);
|
|
|
|
}
|
|
|
|
if (cells != null) {
|
|
|
|
for (NeighboringCellInfo nci : cells) {
|
|
|
|
try {
|
|
|
|
JSONObject obj = new JSONObject();
|
|
|
|
obj.put("lac", nci.getLac());
|
|
|
|
obj.put("cid", nci.getCid());
|
|
|
|
obj.put("psc", nci.getPsc());
|
|
|
|
obj.put("mcc", mcc);
|
|
|
|
obj.put("mnc", mnc);
|
|
|
|
|
|
|
|
int dbm;
|
|
|
|
switch(nci.getNetworkType()) {
|
|
|
|
case TelephonyManager.NETWORK_TYPE_GPRS:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_EDGE:
|
|
|
|
obj.put("radio", "gsm");
|
|
|
|
break;
|
|
|
|
case TelephonyManager.NETWORK_TYPE_UMTS:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSDPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSUPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPA:
|
|
|
|
case TelephonyManager.NETWORK_TYPE_HSPAP:
|
|
|
|
obj.put("radio", "umts");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
obj.put("asu", nci.getRssi());
|
|
|
|
cellInfo.put(obj);
|
|
|
|
} catch(JSONException jsonex) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tm.getPhoneType();
|
|
|
|
}
|
|
|
|
|
2013-06-04 08:09:54 -07:00
|
|
|
private static boolean shouldLog(final ScanResult sr) {
|
2014-02-06 20:25:35 -08:00
|
|
|
return sr.SSID == null || !sr.SSID.endsWith("_nomap");
|
2013-06-04 08:09:54 -07:00
|
|
|
}
|
|
|
|
|
2013-05-30 09:50:45 -07:00
|
|
|
private void collectAndReportLocInfo(Location location) {
|
|
|
|
final JSONObject locInfo = new JSONObject();
|
2013-06-04 08:09:54 -07:00
|
|
|
WifiManager wm = (WifiManager)getSystemService(Context.WIFI_SERVICE);
|
|
|
|
wm.startScan();
|
2013-05-30 09:50:45 -07:00
|
|
|
try {
|
|
|
|
JSONArray cellInfo = new JSONArray();
|
2013-08-01 16:14:42 -07:00
|
|
|
|
|
|
|
String radioType = getRadioTypeName(getCellInfo(cellInfo));
|
|
|
|
if (radioType != null) {
|
|
|
|
locInfo.put("radio", radioType);
|
|
|
|
}
|
|
|
|
|
2013-05-30 09:50:45 -07:00
|
|
|
locInfo.put("lon", location.getLongitude());
|
|
|
|
locInfo.put("lat", location.getLatitude());
|
2014-02-06 20:25:35 -08:00
|
|
|
|
|
|
|
// If we have an accuracy, round it up to the next meter.
|
|
|
|
if (location.hasAccuracy()) {
|
|
|
|
locInfo.put("accuracy", (int) Math.ceil(location.getAccuracy()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have an altitude, round it to the nearest meter.
|
|
|
|
if (location.hasAltitude()) {
|
|
|
|
locInfo.put("altitude", Math.round(location.getAltitude()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reduce timestamp precision so as to expose less PII.
|
|
|
|
DateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
|
2013-05-30 09:50:45 -07:00
|
|
|
locInfo.put("time", df.format(new Date(location.getTime())));
|
|
|
|
locInfo.put("cell", cellInfo);
|
|
|
|
|
2013-06-04 08:09:54 -07:00
|
|
|
JSONArray wifiInfo = new JSONArray();
|
|
|
|
List<ScanResult> aps = wm.getScanResults();
|
2013-06-28 09:42:28 -07:00
|
|
|
if (aps != null) {
|
|
|
|
for (ScanResult ap : aps) {
|
|
|
|
if (!shouldLog(ap))
|
|
|
|
continue;
|
2013-06-04 08:09:54 -07:00
|
|
|
|
2014-02-06 20:25:35 -08:00
|
|
|
JSONObject obj = new JSONObject();
|
|
|
|
obj.put("key", ap.BSSID);
|
|
|
|
obj.put("frequency", ap.frequency);
|
|
|
|
obj.put("signal", ap.level);
|
|
|
|
wifiInfo.put(obj);
|
2013-06-04 08:09:54 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
locInfo.put("wifi", wifiInfo);
|
|
|
|
} catch (JSONException jsonex) {
|
|
|
|
Log.w(LOGTAG, "json exception", jsonex);
|
2013-08-01 16:14:42 -07:00
|
|
|
return;
|
2013-06-04 08:09:54 -07:00
|
|
|
}
|
2013-08-01 16:14:42 -07:00
|
|
|
|
2013-05-30 09:50:45 -07:00
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
URL url = new URL(LOCATION_URL);
|
|
|
|
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
|
|
|
|
try {
|
|
|
|
urlConnection.setDoOutput(true);
|
2014-02-06 20:25:35 -08:00
|
|
|
|
|
|
|
// Workaround for a bug in Android HttpURLConnection. When the library
|
|
|
|
// reuses a stale connection, the connection may fail with an EOFException.
|
|
|
|
if (Build.VERSION.SDK_INT >= 14 && Build.VERSION.SDK_INT <= 18) {
|
|
|
|
urlConnection.setRequestProperty("Connection", "Close");
|
|
|
|
}
|
|
|
|
|
2013-05-30 09:50:45 -07:00
|
|
|
JSONArray batch = new JSONArray();
|
|
|
|
batch.put(locInfo);
|
|
|
|
JSONObject wrapper = new JSONObject();
|
|
|
|
wrapper.put("items", batch);
|
|
|
|
byte[] bytes = wrapper.toString().getBytes();
|
|
|
|
urlConnection.setFixedLengthStreamingMode(bytes.length);
|
|
|
|
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
|
|
|
|
out.write(bytes);
|
|
|
|
out.flush();
|
|
|
|
} catch (JSONException jsonex) {
|
2013-06-04 08:09:54 -07:00
|
|
|
Log.e(LOGTAG, "error wrapping data as a batch", jsonex);
|
2013-05-30 09:50:45 -07:00
|
|
|
} catch (IOException ioex) {
|
2013-06-04 08:09:54 -07:00
|
|
|
Log.e(LOGTAG, "error submitting data", ioex);
|
2013-05-30 09:50:45 -07:00
|
|
|
} finally {
|
|
|
|
urlConnection.disconnect();
|
|
|
|
}
|
|
|
|
} catch (IOException ioex) {
|
2013-06-04 08:09:54 -07:00
|
|
|
Log.e(LOGTAG, "error submitting data", ioex);
|
2013-05-30 09:50:45 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-11-18 10:28:17 -08:00
|
|
|
}
|
|
|
|
|
2013-08-01 16:14:42 -07:00
|
|
|
private static String getRadioTypeName(int phoneType) {
|
|
|
|
switch (phoneType) {
|
|
|
|
case TelephonyManager.PHONE_TYPE_CDMA:
|
|
|
|
return "cdma";
|
|
|
|
|
|
|
|
case TelephonyManager.PHONE_TYPE_GSM:
|
|
|
|
return "gsm";
|
|
|
|
|
|
|
|
case TelephonyManager.PHONE_TYPE_NONE:
|
|
|
|
case TelephonyManager.PHONE_TYPE_SIP:
|
|
|
|
// These devices have no radio.
|
|
|
|
return null;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Log.e(LOGTAG, "", new IllegalArgumentException("Unexpected PHONE_TYPE: " + phoneType));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onProviderDisabled(String provider)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
public void onProviderEnabled(String provider)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2011-11-18 10:28:17 -08:00
|
|
|
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
|
|
|
|
2013-03-13 08:47:38 -07:00
|
|
|
public void notifyCheckUpdateResult(String result) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Update:CheckResult", result));
|
2012-08-31 06:31:29 -07:00
|
|
|
}
|
|
|
|
|
2013-05-29 21:34:02 -07:00
|
|
|
protected void geckoConnected() {
|
|
|
|
mLayerView.geckoConnected();
|
2013-09-23 11:46:50 -07:00
|
|
|
mLayerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
|
2013-03-07 02:17:32 -08:00
|
|
|
}
|
2012-07-20 10:06:01 -07:00
|
|
|
|
2013-04-12 08:51:56 -07:00
|
|
|
public void setAccessibilityEnabled(boolean enabled) {
|
|
|
|
}
|
|
|
|
|
2013-03-07 02:17:32 -08:00
|
|
|
public static class MainLayout extends RelativeLayout {
|
2013-03-28 09:40:06 -07:00
|
|
|
private TouchEventInterceptor mTouchEventInterceptor;
|
2013-03-28 09:40:06 -07:00
|
|
|
private MotionEventInterceptor mMotionEventInterceptor;
|
2012-10-12 16:23:20 -07:00
|
|
|
|
|
|
|
public MainLayout(Context context, AttributeSet attrs) {
|
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
2013-03-28 09:40:06 -07:00
|
|
|
public void setTouchEventInterceptor(TouchEventInterceptor interceptor) {
|
|
|
|
mTouchEventInterceptor = interceptor;
|
2012-10-12 16:23:20 -07:00
|
|
|
}
|
2012-07-20 10:06:01 -07:00
|
|
|
|
2013-03-28 09:40:06 -07:00
|
|
|
public void setMotionEventInterceptor(MotionEventInterceptor interceptor) {
|
|
|
|
mMotionEventInterceptor = interceptor;
|
|
|
|
}
|
|
|
|
|
2012-07-20 10:06:01 -07:00
|
|
|
@Override
|
2012-10-12 16:23:20 -07:00
|
|
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
2013-03-28 09:40:06 -07:00
|
|
|
if (mTouchEventInterceptor != null && mTouchEventInterceptor.onInterceptTouchEvent(this, event)) {
|
2012-07-20 10:06:01 -07:00
|
|
|
return true;
|
2013-03-28 09:40:06 -07:00
|
|
|
}
|
2012-10-12 16:23:20 -07:00
|
|
|
return super.onInterceptTouchEvent(event);
|
2012-07-20 10:06:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-10-12 16:23:20 -07:00
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
2013-03-28 09:40:06 -07:00
|
|
|
if (mTouchEventInterceptor != null && mTouchEventInterceptor.onTouch(this, event)) {
|
2012-07-20 10:06:01 -07:00
|
|
|
return true;
|
2013-03-28 09:40:06 -07:00
|
|
|
}
|
2012-10-12 16:23:20 -07:00
|
|
|
return super.onTouchEvent(event);
|
2012-07-20 10:06:01 -07:00
|
|
|
}
|
2012-10-15 08:18:30 -07:00
|
|
|
|
2013-03-28 09:40:06 -07:00
|
|
|
@Override
|
|
|
|
public boolean onGenericMotionEvent(MotionEvent event) {
|
|
|
|
if (mMotionEventInterceptor != null && mMotionEventInterceptor.onInterceptMotionEvent(this, event)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.onGenericMotionEvent(event);
|
|
|
|
}
|
|
|
|
|
2012-10-15 08:18:30 -07:00
|
|
|
@Override
|
|
|
|
public void setDrawingCacheEnabled(boolean enabled) {
|
|
|
|
// Instead of setting drawing cache in the view itself, we simply
|
|
|
|
// enable drawing caching on its children. This is mainly used in
|
|
|
|
// animations (see PropertyAnimator)
|
|
|
|
super.setChildrenDrawnWithCacheEnabled(enabled);
|
|
|
|
}
|
2012-07-20 10:06:01 -07:00
|
|
|
}
|
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
private class FullScreenHolder extends FrameLayout {
|
|
|
|
|
2012-06-06 19:39:36 -07:00
|
|
|
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);
|
|
|
|
|
2013-03-15 03:52:53 -07:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
2013-02-26 21:48:00 -08:00
|
|
|
@Override
|
2012-06-06 19:39:36 -07:00
|
|
|
public void run() {
|
2013-11-21 11:18:40 -08:00
|
|
|
mLayerView.hideSurface();
|
2012-06-06 19:39:36 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2013-03-21 13:32:11 -07:00
|
|
|
protected NotificationClient makeNotificationClient() {
|
|
|
|
// Don't use a notification service; we may be killed in the background
|
|
|
|
// during downloads.
|
|
|
|
return new AppNotificationClient(getApplicationContext());
|
|
|
|
}
|
2013-07-03 15:24:57 -07:00
|
|
|
|
|
|
|
private int getVersionCode() {
|
|
|
|
int versionCode = 0;
|
|
|
|
try {
|
|
|
|
versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
|
|
|
|
} catch (NameNotFoundException e) {
|
|
|
|
Log.wtf(LOGTAG, getPackageName() + " not found", e);
|
|
|
|
}
|
|
|
|
return versionCode;
|
|
|
|
}
|
2013-12-03 15:05:43 -08:00
|
|
|
|
2014-01-31 14:51:24 -08:00
|
|
|
protected boolean getIsDebuggable() {
|
2014-02-11 23:41:05 -08:00
|
|
|
// Return false so Fennec doesn't appear to be debuggable. WebappImpl
|
2014-01-31 14:51:24 -08:00
|
|
|
// then overrides this and returns the value of android:debuggable for
|
|
|
|
// the webapp APK, so webapps get the behavior supported by this method
|
|
|
|
// (i.e. automatic configuration and enabling of the remote debugger).
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// If we ever want to expose this for Fennec, here's how we would do it:
|
|
|
|
// int flags = 0;
|
|
|
|
// try {
|
|
|
|
// flags = getPackageManager().getPackageInfo(getPackageName(), 0).applicationInfo.flags;
|
|
|
|
// } catch (NameNotFoundException e) {
|
|
|
|
// Log.wtf(LOGTAG, getPackageName() + " not found", e);
|
|
|
|
// }
|
|
|
|
// return (flags & android.content.pm.ApplicationInfo.FLAG_DEBUGGABLE) != 0;
|
|
|
|
}
|
|
|
|
|
2013-12-03 15:05:43 -08:00
|
|
|
// FHR reason code for a session end prior to a restart for a
|
|
|
|
// locale change.
|
|
|
|
private static final String SESSION_END_LOCALE_CHANGED = "L";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Use LocaleManager to change our persisted and current locales,
|
2014-02-04 19:41:29 -08:00
|
|
|
* and poke HealthRecorder to tell it of our changed state.
|
2013-12-03 15:05:43 -08:00
|
|
|
*/
|
|
|
|
private void setLocale(final String locale) {
|
|
|
|
if (locale == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final String resultant = LocaleManager.setSelectedLocale(locale);
|
|
|
|
if (resultant == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
final boolean startNewSession = true;
|
|
|
|
final boolean shouldRestart = false;
|
2014-02-04 19:41:30 -08:00
|
|
|
|
|
|
|
// If the HealthRecorder is not yet initialized (unlikely), the locale change won't
|
|
|
|
// trigger a session transition and subsequent events will be recorded in an environment
|
|
|
|
// with the wrong locale.
|
|
|
|
final HealthRecorder rec = mHealthRecorder;
|
|
|
|
if (rec != null) {
|
|
|
|
rec.onAppLocaleChanged(resultant);
|
|
|
|
rec.onEnvironmentChanged(startNewSession, SESSION_END_LOCALE_CHANGED);
|
|
|
|
}
|
2013-12-03 15:05:43 -08:00
|
|
|
|
|
|
|
if (!shouldRestart) {
|
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GeckoApp.this.onLocaleReady(resultant);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do this in the background so that the health recorder has its
|
|
|
|
// time to finish.
|
|
|
|
ThreadUtils.postToBackgroundThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
GeckoApp.this.doRestart();
|
|
|
|
GeckoApp.this.finish();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-01-22 11:56:11 -08:00
|
|
|
|
|
|
|
private void setSystemUiVisible(final boolean visible) {
|
2014-02-18 09:18:44 -08:00
|
|
|
if (Build.VERSION.SDK_INT < 14) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-22 11:56:11 -08:00
|
|
|
ThreadUtils.postToUiThread(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (visible) {
|
|
|
|
mMainLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
|
|
|
} else {
|
|
|
|
mMainLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2014-02-04 19:41:29 -08:00
|
|
|
|
|
|
|
protected HealthRecorder createHealthRecorder(final Context context,
|
|
|
|
final String profilePath,
|
|
|
|
final EventDispatcher dispatcher,
|
|
|
|
final String osLocale,
|
|
|
|
final String appLocale,
|
2014-02-04 19:41:29 -08:00
|
|
|
final SessionInformation previousSession) {
|
2014-02-04 19:41:29 -08:00
|
|
|
// GeckoApp does not need to record any health information - return a stub.
|
|
|
|
return new StubbedHealthRecorder();
|
|
|
|
}
|
2012-05-02 13:55:27 -07:00
|
|
|
}
|