2012-06-11 15:18:40 -07:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
package org.mozilla.gecko;
|
|
|
|
|
2012-08-26 21:33:11 -07:00
|
|
|
import org.mozilla.gecko.db.BrowserContract.Combined;
|
|
|
|
import org.mozilla.gecko.db.BrowserDB;
|
2012-11-27 12:04:14 -08:00
|
|
|
import org.mozilla.gecko.gfx.BitmapUtils;
|
2012-08-26 21:33:11 -07:00
|
|
|
import org.mozilla.gecko.util.GeckoAsyncTask;
|
|
|
|
import org.mozilla.gecko.util.GeckoBackgroundThread;
|
|
|
|
|
2012-07-27 17:54:28 -07:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.app.Activity;
|
2012-08-27 17:50:32 -07:00
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.DialogInterface;
|
2012-08-26 21:33:11 -07:00
|
|
|
import android.content.SharedPreferences;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.content.Intent;
|
2012-08-26 21:33:11 -07:00
|
|
|
import android.database.Cursor;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import android.graphics.drawable.BitmapDrawable;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2012-10-12 16:23:20 -07:00
|
|
|
import android.graphics.Rect;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.net.Uri;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.Bundle;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.util.Log;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.LayoutInflater;
|
|
|
|
import android.view.Menu;
|
|
|
|
import android.view.MenuInflater;
|
|
|
|
import android.view.MenuItem;
|
2012-10-12 16:23:20 -07:00
|
|
|
import android.view.MotionEvent;
|
2012-10-26 13:39:25 -07:00
|
|
|
import android.view.SubMenu;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
2012-10-12 04:57:06 -07:00
|
|
|
import android.view.animation.Interpolator;
|
2012-07-27 17:54:28 -07:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.Toast;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2012-10-09 12:20:36 -07:00
|
|
|
import dalvik.system.DexClassLoader;
|
|
|
|
|
|
|
|
import java.io.File;
|
2012-07-27 17:53:54 -07:00
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.Vector;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2012-07-17 17:54:54 -07:00
|
|
|
abstract public class BrowserApp extends GeckoApp
|
2012-06-12 22:47:52 -07:00
|
|
|
implements TabsPanel.TabsLayoutChangeListener,
|
|
|
|
PropertyAnimator.PropertyAnimationListener {
|
2012-06-11 15:18:40 -07:00
|
|
|
private static final String LOGTAG = "GeckoBrowserApp";
|
|
|
|
|
|
|
|
public static BrowserToolbar mBrowserToolbar;
|
|
|
|
private AboutHomeContent mAboutHomeContent;
|
2012-09-28 09:34:45 -07:00
|
|
|
private Boolean mAboutHomeShowing = null;
|
2012-11-26 14:57:11 -08:00
|
|
|
protected Telemetry.Timer mAboutHomeStartupTimer = null;
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2012-09-26 12:02:48 -07:00
|
|
|
private static final int ADDON_MENU_OFFSET = 1000;
|
2012-09-27 11:22:08 -07:00
|
|
|
private class MenuItemInfo {
|
2012-10-26 13:39:25 -07:00
|
|
|
public int id;
|
|
|
|
public String label;
|
|
|
|
public String icon;
|
|
|
|
public boolean checkable;
|
|
|
|
public int parent;
|
2012-09-27 11:22:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private Vector<MenuItemInfo> mAddonMenuItemsCache;
|
2012-07-26 23:53:48 -07:00
|
|
|
|
2012-06-12 22:47:52 -07:00
|
|
|
private PropertyAnimator mMainLayoutAnimator;
|
|
|
|
|
2012-10-12 04:57:06 -07:00
|
|
|
private static final Interpolator sTabsInterpolator = new Interpolator() {
|
|
|
|
public float getInterpolation(float t) {
|
|
|
|
t -= 1.0f;
|
|
|
|
return t * t * t * t * t + 1.0f;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-07-26 23:52:41 -07:00
|
|
|
private FindInPageBar mFindInPageBar;
|
|
|
|
|
2012-08-26 21:33:11 -07:00
|
|
|
// We'll ask for feedback after the user launches the app this many times.
|
2012-10-18 12:13:12 -07:00
|
|
|
private static final int FEEDBACK_LAUNCH_COUNT = 15;
|
2012-08-26 21:33:11 -07:00
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
@Override
|
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
|
|
|
switch(msg) {
|
|
|
|
case LOCATION_CHANGE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
2012-10-22 12:37:50 -07:00
|
|
|
maybeCancelFaviconLoad(tab);
|
|
|
|
}
|
|
|
|
// fall through
|
|
|
|
case SELECTED:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
if ("about:home".equals(tab.getURL()))
|
2012-06-11 15:18:40 -07:00
|
|
|
showAboutHome();
|
2012-10-22 12:37:50 -07:00
|
|
|
else
|
2012-06-11 15:18:40 -07:00
|
|
|
hideAboutHome();
|
|
|
|
}
|
|
|
|
break;
|
2012-07-24 16:12:12 -07:00
|
|
|
case LOAD_ERROR:
|
2012-06-14 20:12:06 -07:00
|
|
|
case START:
|
|
|
|
case STOP:
|
2012-07-24 16:12:12 -07:00
|
|
|
case MENU_UPDATED:
|
2012-06-14 20:12:06 -07:00
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
}
|
|
|
|
break;
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
super.onTabChanged(tab, msg, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void handlePageShow(final int tabId) {
|
|
|
|
super.handlePageShow(tabId);
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
loadFavicon(tab);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void handleLinkAdded(final int tabId, String rel, final String href, int size) {
|
|
|
|
super.handleLinkAdded(tabId, rel, href, size);
|
|
|
|
if (rel.indexOf("[icon]") == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If tab is not loading and the favicon is updated, we
|
|
|
|
// want to load the image straight away. If tab is still
|
|
|
|
// loading, we only load the favicon once the page's content
|
|
|
|
// is fully loaded (see handleContentLoaded()).
|
|
|
|
if (tab.getState() != Tab.STATE_LOADING) {
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
loadFavicon(tab);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void handleClearHistory() {
|
|
|
|
super.handleClearHistory();
|
2012-11-07 07:45:35 -08:00
|
|
|
updateAboutHomeTopSites();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void handleSecurityChange(final int tabId, final JSONObject identityData) {
|
|
|
|
super.handleSecurityChange(tabId, identityData);
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab))
|
|
|
|
mBrowserToolbar.setSecurityMode(tab.getSecurityMode());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleReaderEnabled(final int tabId) {
|
|
|
|
super.handleReaderEnabled(tabId);
|
|
|
|
final Tab tab = Tabs.getInstance().getTab(tabId);
|
|
|
|
if (tab == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab))
|
2012-07-13 08:36:45 -07:00
|
|
|
mBrowserToolbar.setReaderMode(tab.getReaderEnabled());
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void onStatePurged() {
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (mAboutHomeContent != null)
|
|
|
|
mAboutHomeContent.setLastTabsVisibility(false);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
super.onStatePurged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2012-11-26 14:57:11 -08:00
|
|
|
mAboutHomeStartupTimer = new Telemetry.Timer("FENNEC_STARTUP_TIME_ABOUTHOME");
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2012-07-20 12:58:42 -07:00
|
|
|
LinearLayout actionBar = (LinearLayout) getActionBarLayout();
|
|
|
|
mMainLayout.addView(actionBar, 0);
|
2012-06-11 15:18:40 -07:00
|
|
|
|
2012-10-12 16:23:20 -07:00
|
|
|
((GeckoApp.MainLayout) mMainLayout).setOnInterceptTouchListener(new HideTabsTouchListener());
|
|
|
|
|
2012-07-27 23:15:39 -07:00
|
|
|
mBrowserToolbar = new BrowserToolbar(this);
|
2012-06-11 15:18:40 -07:00
|
|
|
mBrowserToolbar.from(actionBar);
|
|
|
|
|
2012-06-12 22:47:52 -07:00
|
|
|
if (mTabsPanel != null)
|
|
|
|
mTabsPanel.setTabsLayoutChangeListener(this);
|
|
|
|
|
2012-07-26 23:52:41 -07:00
|
|
|
mFindInPageBar = (FindInPageBar) findViewById(R.id.find_in_page);
|
|
|
|
|
2012-08-27 17:50:32 -07:00
|
|
|
registerEventListener("CharEncoding:Data");
|
|
|
|
registerEventListener("CharEncoding:State");
|
2012-08-26 21:33:11 -07:00
|
|
|
registerEventListener("Feedback:LastUrl");
|
|
|
|
registerEventListener("Feedback:OpenPlayStore");
|
|
|
|
registerEventListener("Feedback:MaybeLater");
|
2012-10-09 12:20:36 -07:00
|
|
|
registerEventListener("Dex:Load");
|
2012-11-02 17:44:20 -07:00
|
|
|
registerEventListener("Telemetry:Gather");
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroy() {
|
|
|
|
super.onDestroy();
|
|
|
|
if (mAboutHomeContent != null)
|
|
|
|
mAboutHomeContent.onDestroy();
|
2012-08-26 21:33:11 -07:00
|
|
|
|
2012-08-27 17:50:32 -07:00
|
|
|
unregisterEventListener("CharEncoding:Data");
|
|
|
|
unregisterEventListener("CharEncoding:State");
|
2012-08-26 21:33:11 -07:00
|
|
|
unregisterEventListener("Feedback:LastUrl");
|
|
|
|
unregisterEventListener("Feedback:OpenPlayStore");
|
|
|
|
unregisterEventListener("Feedback:MaybeLater");
|
2012-10-09 12:20:36 -07:00
|
|
|
unregisterEventListener("Dex:Load");
|
2012-11-02 17:44:20 -07:00
|
|
|
unregisterEventListener("Telemetry:Gather");
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onContentChanged() {
|
|
|
|
super.onContentChanged();
|
|
|
|
if (mAboutHomeContent != null)
|
2012-07-27 23:31:42 -07:00
|
|
|
mAboutHomeContent.onActivityContentChanged();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void finishProfileMigration() {
|
|
|
|
// Update about:home with the new information.
|
|
|
|
updateAboutHomeTopSites();
|
|
|
|
|
|
|
|
super.finishProfileMigration();
|
|
|
|
}
|
|
|
|
|
2012-10-15 10:40:16 -07:00
|
|
|
@Override
|
|
|
|
protected void initializeChrome(String uri, Boolean isExternalURL) {
|
|
|
|
super.initializeChrome(uri, isExternalURL);
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
mBrowserToolbar.updateBackButton(false);
|
|
|
|
mBrowserToolbar.updateForwardButton(false);
|
|
|
|
|
2012-10-15 10:40:16 -07:00
|
|
|
mDoorHangerPopup.setAnchor(mBrowserToolbar.mFavicon);
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
if (!isExternalURL) {
|
|
|
|
// show about:home if we aren't restoring previous session
|
2012-10-29 16:34:29 -07:00
|
|
|
if (mRestoreMode == RESTORE_NONE) {
|
2012-10-15 10:40:16 -07:00
|
|
|
Tab tab = Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB);
|
2012-10-29 16:34:29 -07:00
|
|
|
} else {
|
|
|
|
hideAboutHome();
|
2012-11-26 14:57:11 -08:00
|
|
|
mAboutHomeStartupTimer.cancel();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
} else {
|
2012-10-29 16:34:29 -07:00
|
|
|
int flags = Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_USER_ENTERED;
|
|
|
|
Tabs.getInstance().loadUrl(uri, flags);
|
2012-11-26 14:57:11 -08:00
|
|
|
mAboutHomeStartupTimer.cancel();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-27 12:18:01 -08:00
|
|
|
@Override
|
2012-06-11 15:18:40 -07:00
|
|
|
void toggleChrome(final boolean aShow) {
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (aShow) {
|
|
|
|
mBrowserToolbar.show();
|
|
|
|
} else {
|
|
|
|
mBrowserToolbar.hide();
|
2012-11-27 12:18:16 -08:00
|
|
|
if (hasTabsSideBar()) {
|
|
|
|
hideTabs();
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
super.toggleChrome(aShow);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
void focusChrome() {
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-11-26 11:56:46 -08:00
|
|
|
mBrowserToolbar.show();
|
2012-06-11 15:18:40 -07:00
|
|
|
mBrowserToolbar.requestFocusFromTouch();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void refreshChrome() {
|
2012-06-19 14:09:44 -07:00
|
|
|
// Only ICS phones use a smaller action-bar in landscape mode.
|
|
|
|
if (Build.VERSION.SDK_INT >= 14 && !isTablet()) {
|
|
|
|
int index = mMainLayout.indexOfChild(mBrowserToolbar.getLayout());
|
|
|
|
mMainLayout.removeViewAt(index);
|
|
|
|
|
2012-07-20 12:58:42 -07:00
|
|
|
LinearLayout actionBar = (LinearLayout) getActionBarLayout();
|
2012-06-19 14:09:44 -07:00
|
|
|
mMainLayout.addView(actionBar, index);
|
|
|
|
mBrowserToolbar.from(actionBar);
|
2012-06-11 15:18:40 -07:00
|
|
|
mBrowserToolbar.refresh();
|
2012-08-09 08:31:05 -07:00
|
|
|
|
|
|
|
// The favicon view is different now, so we need to update the DoorHangerPopup anchor view.
|
|
|
|
if (mDoorHangerPopup != null)
|
|
|
|
mDoorHangerPopup.setAnchor(mBrowserToolbar.mFavicon);
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
2012-06-19 14:09:44 -07:00
|
|
|
|
|
|
|
invalidateOptionsMenu();
|
|
|
|
mTabsPanel.refresh();
|
2012-08-06 17:27:04 -07:00
|
|
|
|
|
|
|
if (mAboutHomeContent != null)
|
|
|
|
mAboutHomeContent.refresh();
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2012-07-20 12:58:42 -07:00
|
|
|
public View getActionBarLayout() {
|
2012-07-12 15:03:09 -07:00
|
|
|
int actionBarRes;
|
|
|
|
|
2012-07-27 23:31:42 -07:00
|
|
|
if (!hasPermanentMenuKey() || isTablet())
|
2012-07-12 15:03:09 -07:00
|
|
|
actionBarRes = R.layout.browser_toolbar_menu;
|
|
|
|
else
|
|
|
|
actionBarRes = R.layout.browser_toolbar;
|
|
|
|
|
2012-07-27 23:31:42 -07:00
|
|
|
LinearLayout actionBar = (LinearLayout) LayoutInflater.from(this).inflate(actionBarRes, null);
|
2012-07-12 15:03:09 -07:00
|
|
|
actionBar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
|
2012-07-27 23:31:42 -07:00
|
|
|
(int) getResources().getDimension(R.dimen.browser_toolbar_height)));
|
2012-07-12 15:03:09 -07:00
|
|
|
return actionBar;
|
|
|
|
}
|
|
|
|
|
2012-07-23 13:08:48 -07:00
|
|
|
@Override
|
|
|
|
public boolean hasTabsSideBar() {
|
|
|
|
return (mTabsPanel != null && mTabsPanel.isSideBar());
|
|
|
|
}
|
|
|
|
|
2012-07-26 23:53:48 -07:00
|
|
|
@Override
|
|
|
|
public void handleMessage(String event, JSONObject message) {
|
|
|
|
try {
|
|
|
|
if (event.equals("Menu:Add")) {
|
2012-10-26 13:39:25 -07:00
|
|
|
MenuItemInfo info = new MenuItemInfo();
|
|
|
|
info.label = message.getString("name");
|
|
|
|
info.id = message.getInt("id") + ADDON_MENU_OFFSET;
|
2012-07-26 23:53:48 -07:00
|
|
|
String iconRes = null;
|
|
|
|
try { // icon is optional
|
|
|
|
iconRes = message.getString("icon");
|
|
|
|
} catch (Exception ex) { }
|
2012-10-26 13:39:25 -07:00
|
|
|
info.icon = iconRes;
|
|
|
|
info.checkable = false;
|
|
|
|
try {
|
|
|
|
info.checkable = message.getBoolean("checkable");
|
|
|
|
} catch (Exception ex) { }
|
|
|
|
try { // parent is optional
|
|
|
|
info.parent = message.getInt("parent") + ADDON_MENU_OFFSET;
|
|
|
|
} catch (Exception ex) { }
|
|
|
|
final MenuItemInfo menuItemInfo = info;
|
2012-07-26 23:53:48 -07:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
2012-10-26 13:39:25 -07:00
|
|
|
addAddonMenuItem(menuItemInfo);
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("Menu:Remove")) {
|
2012-09-26 12:02:48 -07:00
|
|
|
final int id = message.getInt("id") + ADDON_MENU_OFFSET;
|
2012-07-26 23:53:48 -07:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
removeAddonMenuItem(id);
|
|
|
|
}
|
|
|
|
});
|
2012-08-27 17:50:32 -07:00
|
|
|
} else if (event.equals("CharEncoding:Data")) {
|
|
|
|
final JSONArray charsets = message.getJSONArray("charsets");
|
|
|
|
int selected = message.getInt("selected");
|
|
|
|
|
|
|
|
final int len = charsets.length();
|
|
|
|
final String[] titleArray = new String[len];
|
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
JSONObject charset = charsets.getJSONObject(i);
|
|
|
|
titleArray[i] = charset.getString("title");
|
|
|
|
}
|
|
|
|
|
|
|
|
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
|
|
|
dialogBuilder.setSingleChoiceItems(titleArray, selected, new AlertDialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
try {
|
|
|
|
JSONObject charset = charsets.getJSONObject(which);
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Set", charset.getString("code")));
|
|
|
|
dialog.dismiss();
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error parsing json", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
|
|
|
dialog.dismiss();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
dialogBuilder.show();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if (event.equals("CharEncoding:State")) {
|
|
|
|
final boolean visible = message.getString("visible").equals("true");
|
|
|
|
GeckoPreferences.setCharEncodingState(visible);
|
|
|
|
final Menu menu = mMenu;
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (menu != null)
|
|
|
|
menu.findItem(R.id.char_encoding).setVisible(visible);
|
|
|
|
}
|
|
|
|
});
|
2012-08-26 21:33:11 -07:00
|
|
|
} else if (event.equals("Feedback:OpenPlayStore")) {
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
|
|
intent.setData(Uri.parse("market://details?id=" + getPackageName()));
|
|
|
|
startActivity(intent);
|
|
|
|
} else if (event.equals("Feedback:MaybeLater")) {
|
|
|
|
resetFeedbackLaunchCount();
|
|
|
|
} else if (event.equals("Feedback:LastUrl")) {
|
|
|
|
getLastUrl();
|
2012-08-30 11:15:19 -07:00
|
|
|
} else if (event.equals("Gecko:Ready")) {
|
|
|
|
// Handle this message in GeckoApp, but also enable the Settings
|
|
|
|
// menuitem, which is specific to BrowserApp.
|
|
|
|
super.handleMessage(event, message);
|
|
|
|
final Menu menu = mMenu;
|
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (menu != null)
|
|
|
|
menu.findItem(R.id.settings).setEnabled(true);
|
|
|
|
}
|
|
|
|
});
|
2012-11-02 17:44:20 -07:00
|
|
|
} else if (event.equals("Telemetry:Gather")) {
|
|
|
|
Telemetry.HistogramAdd("PLACES_PAGES_COUNT", BrowserDB.getCount(getContentResolver(), "history"));
|
|
|
|
Telemetry.HistogramAdd("PLACES_BOOKMARKS_COUNT", BrowserDB.getCount(getContentResolver(), "bookmarks"));
|
|
|
|
Telemetry.HistogramAdd("FENNEC_FAVICONS_COUNT", BrowserDB.getCount(getContentResolver(), "favicons"));
|
|
|
|
Telemetry.HistogramAdd("FENNEC_THUMBNAILS_COUNT", BrowserDB.getCount(getContentResolver(), "thumbnails"));
|
2012-10-09 12:20:36 -07:00
|
|
|
} else if (event.equals("Dex:Load")) {
|
|
|
|
String zipFile = message.getString("zipfile");
|
|
|
|
String implClass = message.getString("impl");
|
|
|
|
Log.d(LOGTAG, "Attempting to load classes.dex file from " + zipFile + " and instantiate " + implClass);
|
|
|
|
try {
|
|
|
|
File tmpDir = getDir("dex", 0);
|
|
|
|
DexClassLoader loader = new DexClassLoader(zipFile, tmpDir.getAbsolutePath(), null, ClassLoader.getSystemClassLoader());
|
|
|
|
Class<?> c = loader.loadClass(implClass);
|
|
|
|
c.newInstance();
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Unable to initialize addon", e);
|
|
|
|
}
|
2012-07-26 23:53:48 -07:00
|
|
|
} else {
|
|
|
|
super.handleMessage(event, message);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
void addTab() {
|
|
|
|
showAwesomebar(AwesomeBar.Target.NEW_TAB);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showLocalTabs() {
|
|
|
|
showTabs(TabsPanel.Panel.LOCAL_TABS);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showRemoteTabs() {
|
|
|
|
showTabs(TabsPanel.Panel.REMOTE_TABS);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showTabs(TabsPanel.Panel panel) {
|
2012-10-29 16:34:28 -07:00
|
|
|
if (Tabs.getInstance().getCount() == 0)
|
2012-06-11 15:18:40 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
mTabsPanel.show(panel);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void hideTabs() {
|
|
|
|
mTabsPanel.hide();
|
|
|
|
}
|
|
|
|
|
2012-06-19 13:37:57 -07:00
|
|
|
public boolean autoHideTabs() {
|
2012-07-23 13:08:48 -07:00
|
|
|
if (!hasTabsSideBar() && areTabsShown()) {
|
2012-06-19 13:37:57 -07:00
|
|
|
hideTabs();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
public boolean areTabsShown() {
|
|
|
|
return mTabsPanel.isShown();
|
|
|
|
}
|
|
|
|
|
2012-06-12 22:47:52 -07:00
|
|
|
@Override
|
|
|
|
public void onTabsLayoutChange(int width, int height) {
|
|
|
|
if (mMainLayoutAnimator != null)
|
|
|
|
mMainLayoutAnimator.stop();
|
|
|
|
|
2012-07-11 16:11:42 -07:00
|
|
|
if (mTabsPanel.isShown())
|
|
|
|
mTabsPanel.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
|
|
|
|
|
2012-10-12 04:57:06 -07:00
|
|
|
mMainLayoutAnimator = new PropertyAnimator(450, sTabsInterpolator);
|
2012-06-12 22:47:52 -07:00
|
|
|
mMainLayoutAnimator.setPropertyAnimationListener(this);
|
|
|
|
|
2012-10-12 04:57:07 -07:00
|
|
|
boolean usingTextureView = mLayerView.shouldUseTextureView();
|
|
|
|
mMainLayoutAnimator.setUseHardwareLayer(usingTextureView);
|
|
|
|
|
2012-07-23 13:08:48 -07:00
|
|
|
if (hasTabsSideBar()) {
|
2012-10-12 04:57:07 -07:00
|
|
|
mBrowserToolbar.prepareTabsAnimation(mMainLayoutAnimator, width);
|
2012-06-12 22:47:52 -07:00
|
|
|
|
|
|
|
// Set the gecko layout for sliding.
|
|
|
|
if (!mTabsPanel.isShown()) {
|
|
|
|
((LinearLayout.LayoutParams) mGeckoLayout.getLayoutParams()).setMargins(0, 0, 0, 0);
|
2012-10-12 04:57:07 -07:00
|
|
|
if (!usingTextureView)
|
|
|
|
mGeckoLayout.scrollTo(mTabsPanel.getWidth() * -1, 0);
|
2012-06-12 22:47:52 -07:00
|
|
|
mGeckoLayout.requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
mMainLayoutAnimator.attach(mGeckoLayout,
|
2012-10-12 04:57:07 -07:00
|
|
|
usingTextureView ? PropertyAnimator.Property.TRANSLATION_X :
|
|
|
|
PropertyAnimator.Property.SCROLL_X,
|
|
|
|
usingTextureView ? width : -width);
|
2012-06-12 22:47:52 -07:00
|
|
|
} else {
|
|
|
|
mMainLayoutAnimator.attach(mMainLayout,
|
2012-10-12 04:57:07 -07:00
|
|
|
usingTextureView ? PropertyAnimator.Property.TRANSLATION_Y :
|
|
|
|
PropertyAnimator.Property.SCROLL_Y,
|
|
|
|
usingTextureView ? height : -height);
|
2012-06-12 22:47:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mMainLayoutAnimator.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationStart() {
|
2012-10-12 04:57:07 -07:00
|
|
|
mBrowserToolbar.updateTabs(true);
|
|
|
|
|
|
|
|
// Although the tabs panel is not animating per se, it will be re-drawn several
|
|
|
|
// times while the main/gecko layout slides to left/top. Adding a hardware layer
|
|
|
|
// here considerably improves the frame rate of the animation.
|
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
mTabsPanel.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
2012-10-15 08:18:30 -07:00
|
|
|
else
|
|
|
|
mTabsPanel.setDrawingCacheEnabled(true);
|
2012-06-12 22:47:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPropertyAnimationEnd() {
|
2012-10-12 04:57:07 -07:00
|
|
|
// Destroy the hardware layer used during the animation
|
|
|
|
if (Build.VERSION.SDK_INT >= 11)
|
|
|
|
mTabsPanel.setLayerType(View.LAYER_TYPE_NONE, null);
|
2012-10-15 08:18:30 -07:00
|
|
|
else
|
|
|
|
mTabsPanel.setDrawingCacheEnabled(false);
|
2012-06-14 11:14:00 -07:00
|
|
|
|
2012-10-31 22:07:49 -07:00
|
|
|
if (mTabsPanel.isShown()) {
|
|
|
|
if (hasTabsSideBar()) {
|
|
|
|
boolean usingTextureView = mLayerView.shouldUseTextureView();
|
2012-10-12 04:57:07 -07:00
|
|
|
|
2012-10-31 22:07:49 -07:00
|
|
|
int leftMargin = (usingTextureView ? 0 : mTabsPanel.getWidth());
|
|
|
|
int rightMargin = (usingTextureView ? mTabsPanel.getWidth() : 0);
|
|
|
|
((LinearLayout.LayoutParams) mGeckoLayout.getLayoutParams()).setMargins(leftMargin, 0, rightMargin, 0);
|
2012-10-12 04:57:07 -07:00
|
|
|
|
2012-10-31 22:07:49 -07:00
|
|
|
if (!usingTextureView)
|
|
|
|
mGeckoLayout.scrollTo(0, 0);
|
|
|
|
}
|
2012-10-12 04:57:07 -07:00
|
|
|
|
|
|
|
mGeckoLayout.requestLayout();
|
2012-10-31 22:07:49 -07:00
|
|
|
} else {
|
2012-10-12 04:57:07 -07:00
|
|
|
mBrowserToolbar.updateTabs(false);
|
|
|
|
mBrowserToolbar.finishTabsAnimation();
|
|
|
|
mTabsPanel.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
|
|
|
}
|
2012-10-31 22:07:49 -07:00
|
|
|
|
2012-10-31 22:12:02 -07:00
|
|
|
mBrowserToolbar.refreshBackground();
|
|
|
|
|
2012-10-31 22:07:49 -07:00
|
|
|
if (hasTabsSideBar())
|
|
|
|
mBrowserToolbar.adjustTabsAnimation(true);
|
2012-06-12 22:47:52 -07:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
/* Favicon methods */
|
|
|
|
private void loadFavicon(final Tab tab) {
|
|
|
|
maybeCancelFaviconLoad(tab);
|
|
|
|
|
2012-10-09 11:26:33 -07:00
|
|
|
long id = getFavicons().loadFavicon(tab.getURL(), tab.getFaviconURL(), !tab.isPrivate(),
|
2012-06-11 15:18:40 -07:00
|
|
|
new Favicons.OnFaviconLoadedListener() {
|
|
|
|
|
2012-11-05 03:42:25 -08:00
|
|
|
public void onFaviconLoaded(String pageUrl, Bitmap favicon) {
|
2012-06-11 15:18:40 -07:00
|
|
|
// Leave favicon UI untouched if we failed to load the image
|
|
|
|
// for some reason.
|
|
|
|
if (favicon == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// The tab might be pointing to another URL by the time the
|
|
|
|
// favicon is finally loaded, in which case we simply ignore it.
|
|
|
|
if (!tab.getURL().equals(pageUrl))
|
|
|
|
return;
|
|
|
|
|
|
|
|
tab.updateFavicon(favicon);
|
|
|
|
tab.setFaviconLoadId(Favicons.NOT_LOADING);
|
|
|
|
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab))
|
|
|
|
mBrowserToolbar.setFavicon(tab.getFavicon());
|
|
|
|
|
|
|
|
Tabs.getInstance().notifyListeners(tab, Tabs.TabEvents.FAVICON);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
tab.setFaviconLoadId(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void maybeCancelFaviconLoad(Tab tab) {
|
|
|
|
long faviconLoadId = tab.getFaviconLoadId();
|
|
|
|
|
|
|
|
if (faviconLoadId == Favicons.NOT_LOADING)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Cancel pending favicon load task
|
2012-07-18 03:03:14 -07:00
|
|
|
getFavicons().cancelFaviconLoad(faviconLoadId);
|
2012-06-11 15:18:40 -07:00
|
|
|
|
|
|
|
// Reset favicon load state
|
|
|
|
tab.setFaviconLoadId(Favicons.NOT_LOADING);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* About:home UI */
|
|
|
|
void updateAboutHomeTopSites() {
|
|
|
|
if (mAboutHomeContent == null)
|
|
|
|
return;
|
|
|
|
|
2012-07-27 23:31:42 -07:00
|
|
|
mAboutHomeContent.update(EnumSet.of(AboutHomeContent.UpdateFlags.TOP_SITES));
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
|
2012-09-28 09:34:45 -07:00
|
|
|
private void showAboutHome() {
|
|
|
|
// Don't create an additional AboutHomeRunnable if about:home
|
|
|
|
// is already visible.
|
|
|
|
if (mAboutHomeShowing != null && mAboutHomeShowing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mAboutHomeShowing = true;
|
2012-06-11 15:18:40 -07:00
|
|
|
Runnable r = new AboutHomeRunnable(true);
|
|
|
|
mMainHandler.postAtFrontOfQueue(r);
|
|
|
|
}
|
|
|
|
|
2012-09-28 09:34:45 -07:00
|
|
|
private void hideAboutHome() {
|
|
|
|
// If hideAboutHome gets called before showAboutHome, we still need
|
|
|
|
// to create an AboutHomeRunnable to hide the about:home content.
|
|
|
|
if (mAboutHomeShowing != null && !mAboutHomeShowing)
|
|
|
|
return;
|
|
|
|
|
2012-10-29 16:34:29 -07:00
|
|
|
mBrowserToolbar.setShadowVisibility(true);
|
2012-09-28 09:34:45 -07:00
|
|
|
mAboutHomeShowing = false;
|
2012-06-11 15:18:40 -07:00
|
|
|
Runnable r = new AboutHomeRunnable(false);
|
|
|
|
mMainHandler.postAtFrontOfQueue(r);
|
|
|
|
}
|
|
|
|
|
2012-09-28 09:34:45 -07:00
|
|
|
private class AboutHomeRunnable implements Runnable {
|
2012-06-11 15:18:40 -07:00
|
|
|
boolean mShow;
|
|
|
|
AboutHomeRunnable(boolean show) {
|
|
|
|
mShow = show;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
if (mShow) {
|
|
|
|
if (mAboutHomeContent == null) {
|
|
|
|
mAboutHomeContent = (AboutHomeContent) findViewById(R.id.abouthome_content);
|
|
|
|
mAboutHomeContent.init();
|
2012-07-27 23:31:42 -07:00
|
|
|
mAboutHomeContent.update(AboutHomeContent.UpdateFlags.ALL);
|
2012-06-11 15:18:40 -07:00
|
|
|
mAboutHomeContent.setUriLoadCallback(new AboutHomeContent.UriLoadCallback() {
|
|
|
|
public void callback(String url) {
|
|
|
|
mBrowserToolbar.setProgressVisibility(true);
|
2012-10-05 14:51:18 -07:00
|
|
|
Tabs.getInstance().loadUrl(url);
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
|
|
|
});
|
2012-10-01 13:57:00 -07:00
|
|
|
mAboutHomeContent.setLoadCompleteCallback(new AboutHomeContent.VoidCallback() {
|
2012-11-26 14:57:11 -08:00
|
|
|
public void callback() {
|
|
|
|
mAboutHomeStartupTimer.stop();
|
|
|
|
}
|
2012-10-01 13:57:00 -07:00
|
|
|
});
|
2012-06-11 15:18:40 -07:00
|
|
|
} else {
|
2012-07-27 23:31:42 -07:00
|
|
|
mAboutHomeContent.update(EnumSet.of(AboutHomeContent.UpdateFlags.TOP_SITES,
|
2012-06-11 15:18:40 -07:00
|
|
|
AboutHomeContent.UpdateFlags.REMOTE_TABS));
|
|
|
|
}
|
|
|
|
mAboutHomeContent.setVisibility(View.VISIBLE);
|
|
|
|
} else {
|
|
|
|
findViewById(R.id.abouthome_content).setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-12 16:23:20 -07:00
|
|
|
private class HideTabsTouchListener implements OnInterceptTouchListener {
|
|
|
|
private boolean mIsHidingTabs = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onInterceptTouchEvent(View view, MotionEvent event) {
|
|
|
|
// We need to account for scroll state for the touched view otherwise
|
|
|
|
// tapping on an "empty" part of the view will still be considered a
|
|
|
|
// valid touch event.
|
|
|
|
if (view.getScrollX() != 0 || view.getScrollY() != 0) {
|
|
|
|
Rect rect = new Rect();
|
|
|
|
view.getHitRect(rect);
|
|
|
|
rect.offset(-view.getScrollX(), -view.getScrollY());
|
|
|
|
|
|
|
|
int[] viewCoords = new int[2];
|
|
|
|
view.getLocationOnScreen(viewCoords);
|
|
|
|
|
|
|
|
int x = (int) event.getRawX() - viewCoords[0];
|
|
|
|
int y = (int) event.getRawY() - viewCoords[1];
|
|
|
|
|
|
|
|
if (!rect.contains(x, y))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the tab tray is showing, hide the tab tray and don't send the event to content.
|
|
|
|
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && autoHideTabs()) {
|
|
|
|
mIsHidingTabs = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onTouch(View view, MotionEvent event) {
|
|
|
|
if (mIsHidingTabs) {
|
|
|
|
// Keep consuming events until the gesture finishes.
|
|
|
|
int action = event.getActionMasked();
|
|
|
|
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
|
|
|
|
mIsHidingTabs = false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-26 13:39:25 -07:00
|
|
|
private void addAddonMenuItem(final MenuItemInfo info) {
|
2012-09-27 11:22:08 -07:00
|
|
|
if (mMenu == null) {
|
|
|
|
if (mAddonMenuItemsCache == null)
|
|
|
|
mAddonMenuItemsCache = new Vector<MenuItemInfo>();
|
|
|
|
|
2012-10-26 13:39:25 -07:00
|
|
|
mAddonMenuItemsCache.add(info);
|
2012-07-26 23:53:48 -07:00
|
|
|
return;
|
2012-09-27 11:22:08 -07:00
|
|
|
}
|
2012-07-26 23:53:48 -07:00
|
|
|
|
2012-10-26 13:39:25 -07:00
|
|
|
Menu menu;
|
|
|
|
if (info.parent == 0) {
|
|
|
|
menu = mMenu;
|
|
|
|
} else {
|
|
|
|
MenuItem parent = mMenu.findItem(info.parent);
|
|
|
|
if (parent == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!parent.hasSubMenu()) {
|
|
|
|
mMenu.removeItem(parent.getItemId());
|
|
|
|
menu = mMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle());
|
|
|
|
if (parent.getIcon() != null)
|
|
|
|
((SubMenu) menu).getItem().setIcon(parent.getIcon());
|
|
|
|
} else {
|
|
|
|
menu = parent.getSubMenu();
|
|
|
|
}
|
|
|
|
}
|
2012-07-26 23:53:48 -07:00
|
|
|
|
2012-10-26 13:39:25 -07:00
|
|
|
final MenuItem item = menu.add(Menu.NONE, info.id, Menu.NONE, info.label);
|
2012-07-26 23:53:48 -07:00
|
|
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onMenuItemClick(MenuItem item) {
|
|
|
|
Log.i(LOGTAG, "menu item clicked");
|
2012-10-26 13:39:25 -07:00
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET)));
|
2012-07-26 23:53:48 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-10-26 13:39:25 -07:00
|
|
|
if (info.icon != null) {
|
|
|
|
if (info.icon.startsWith("data")) {
|
|
|
|
BitmapDrawable drawable = new BitmapDrawable(BitmapUtils.getBitmapFromDataURI(info.icon));
|
2012-07-26 23:53:48 -07:00
|
|
|
item.setIcon(drawable);
|
|
|
|
}
|
2012-10-26 13:39:25 -07:00
|
|
|
else if (info.icon.startsWith("jar:") || info.icon.startsWith("file://")) {
|
2012-07-26 23:53:48 -07:00
|
|
|
GeckoAppShell.getHandler().post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
try {
|
2012-10-26 13:39:25 -07:00
|
|
|
URL url = new URL(info.icon);
|
2012-07-26 23:53:48 -07:00
|
|
|
InputStream is = (InputStream) url.getContent();
|
2012-08-31 11:15:50 -07:00
|
|
|
try {
|
|
|
|
Drawable drawable = Drawable.createFromStream(is, "src");
|
|
|
|
item.setIcon(drawable);
|
|
|
|
} finally {
|
|
|
|
is.close();
|
|
|
|
}
|
2012-07-26 23:53:48 -07:00
|
|
|
} catch (Exception e) {
|
|
|
|
Log.w(LOGTAG, "Unable to set icon", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2012-10-26 13:39:25 -07:00
|
|
|
|
|
|
|
item.setCheckable(info.checkable);
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private void removeAddonMenuItem(int id) {
|
2012-09-27 11:22:08 -07:00
|
|
|
// Remove add-on menu item from cache, if available.
|
|
|
|
if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
|
|
|
|
for (MenuItemInfo item : mAddonMenuItemsCache) {
|
|
|
|
if (item.id == id) {
|
|
|
|
mAddonMenuItemsCache.remove(item);
|
|
|
|
break;
|
|
|
|
}
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
|
|
|
}
|
2012-09-27 11:22:08 -07:00
|
|
|
|
|
|
|
if (mMenu == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
MenuItem menuItem = mMenu.findItem(id);
|
|
|
|
if (menuItem != null)
|
|
|
|
mMenu.removeItem(id);
|
2012-07-26 23:53:48 -07:00
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
@Override
|
2012-07-26 23:52:41 -07:00
|
|
|
public boolean onCreateOptionsMenu(Menu menu) {
|
|
|
|
super.onCreateOptionsMenu(menu);
|
2012-06-11 15:18:40 -07:00
|
|
|
|
|
|
|
// Inform the menu about the action-items bar.
|
|
|
|
if (menu instanceof GeckoMenu && isTablet())
|
|
|
|
((GeckoMenu) menu).setActionItemBarPresenter(mBrowserToolbar);
|
|
|
|
|
|
|
|
MenuInflater inflater = getMenuInflater();
|
2012-07-26 23:52:41 -07:00
|
|
|
inflater.inflate(R.menu.browser_app_menu, mMenu);
|
2012-09-27 11:22:08 -07:00
|
|
|
|
|
|
|
// Add add-on menu items if any.
|
|
|
|
if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
|
|
|
|
for (MenuItemInfo item : mAddonMenuItemsCache) {
|
2012-10-26 13:39:25 -07:00
|
|
|
addAddonMenuItem(item);
|
2012-09-27 11:22:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
mAddonMenuItemsCache.clear();
|
|
|
|
}
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openOptionsMenu() {
|
2012-07-24 21:30:46 -07:00
|
|
|
if (!hasTabsSideBar() && areTabsShown())
|
|
|
|
return;
|
|
|
|
|
2012-06-11 15:18:40 -07:00
|
|
|
// Scroll custom menu to the top
|
|
|
|
if (mMenuPanel != null)
|
|
|
|
mMenuPanel.scrollTo(0, 0);
|
|
|
|
|
|
|
|
if (!mBrowserToolbar.openOptionsMenu())
|
|
|
|
super.openOptionsMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeOptionsMenu() {
|
2012-09-19 10:37:35 -07:00
|
|
|
if (!mBrowserToolbar.closeOptionsMenu())
|
2012-06-11 15:18:40 -07:00
|
|
|
super.closeOptionsMenu();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setFullScreen(final boolean fullscreen) {
|
|
|
|
super.setFullScreen(fullscreen);
|
2012-07-18 14:02:04 -07:00
|
|
|
mMainHandler.post(new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
if (fullscreen)
|
|
|
|
mBrowserToolbar.hide();
|
|
|
|
else
|
|
|
|
mBrowserToolbar.show();
|
|
|
|
}
|
|
|
|
});
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
@Override
|
2012-07-26 23:52:41 -07:00
|
|
|
public boolean onPrepareOptionsMenu(Menu aMenu) {
|
2012-06-18 10:03:03 -07:00
|
|
|
if (aMenu == null)
|
|
|
|
return false;
|
|
|
|
|
2012-10-27 12:18:26 -07:00
|
|
|
if (!checkLaunchState(LaunchState.GeckoRunning))
|
2012-06-18 10:03:03 -07:00
|
|
|
aMenu.findItem(R.id.settings).setEnabled(false);
|
|
|
|
|
|
|
|
Tab tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
MenuItem bookmark = aMenu.findItem(R.id.bookmark);
|
|
|
|
MenuItem forward = aMenu.findItem(R.id.forward);
|
|
|
|
MenuItem share = aMenu.findItem(R.id.share);
|
|
|
|
MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf);
|
|
|
|
MenuItem charEncoding = aMenu.findItem(R.id.char_encoding);
|
|
|
|
MenuItem findInPage = aMenu.findItem(R.id.find_in_page);
|
2012-06-22 12:53:40 -07:00
|
|
|
MenuItem desktopMode = aMenu.findItem(R.id.desktop_mode);
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
if (tab == null || tab.getURL() == null) {
|
|
|
|
bookmark.setEnabled(false);
|
|
|
|
forward.setEnabled(false);
|
|
|
|
share.setEnabled(false);
|
|
|
|
saveAsPDF.setEnabled(false);
|
|
|
|
findInPage.setEnabled(false);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-06-29 08:55:54 -07:00
|
|
|
bookmark.setEnabled(!tab.getURL().startsWith("about:reader"));
|
2012-06-18 10:03:03 -07:00
|
|
|
bookmark.setCheckable(true);
|
2012-09-27 11:04:02 -07:00
|
|
|
bookmark.setChecked(tab.isBookmark());
|
|
|
|
bookmark.setIcon(tab.isBookmark() ? R.drawable.ic_menu_bookmark_remove : R.drawable.ic_menu_bookmark_add);
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
forward.setEnabled(tab.canDoForward());
|
2012-06-22 12:53:40 -07:00
|
|
|
desktopMode.setChecked(tab.getDesktopMode());
|
2012-09-27 11:04:02 -07:00
|
|
|
desktopMode.setIcon(tab.getDesktopMode() ? R.drawable.ic_menu_desktop_mode_on : R.drawable.ic_menu_desktop_mode_off);
|
2012-06-18 10:03:03 -07:00
|
|
|
|
2012-09-11 10:51:44 -07:00
|
|
|
String url = tab.getURL();
|
2012-11-12 07:58:41 -08:00
|
|
|
if (ReaderModeUtils.isAboutReader(url)) {
|
|
|
|
String urlFromReader = ReaderModeUtils.getUrlFromAboutReader(url);
|
|
|
|
if (urlFromReader != null)
|
|
|
|
url = urlFromReader;
|
|
|
|
}
|
2012-09-11 10:51:44 -07:00
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
// Disable share menuitem for about:, chrome:, file:, and resource: URIs
|
2012-09-11 10:51:44 -07:00
|
|
|
String scheme = Uri.parse(url).getScheme();
|
2012-06-18 10:03:03 -07:00
|
|
|
share.setEnabled(!(scheme.equals("about") || scheme.equals("chrome") ||
|
|
|
|
scheme.equals("file") || scheme.equals("resource")));
|
|
|
|
|
|
|
|
// Disable save as PDF for about:home and xul pages
|
|
|
|
saveAsPDF.setEnabled(!(tab.getURL().equals("about:home") ||
|
|
|
|
tab.getContentType().equals("application/vnd.mozilla.xul+xml")));
|
|
|
|
|
|
|
|
// Disable find in page for about:home, since it won't work on Java content
|
2012-06-26 10:32:55 -07:00
|
|
|
findInPage.setEnabled(!tab.getURL().equals("about:home"));
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
charEncoding.setVisible(GeckoPreferences.getCharEncodingState());
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-07-26 23:52:41 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
Tab tab = null;
|
|
|
|
Intent intent = null;
|
|
|
|
switch (item.getItemId()) {
|
|
|
|
case R.id.bookmark:
|
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null) {
|
|
|
|
if (item.isChecked()) {
|
|
|
|
tab.removeBookmark();
|
|
|
|
Toast.makeText(this, R.string.bookmark_removed, Toast.LENGTH_SHORT).show();
|
|
|
|
item.setIcon(R.drawable.ic_menu_bookmark_add);
|
|
|
|
} else {
|
|
|
|
tab.addBookmark();
|
|
|
|
Toast.makeText(this, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
|
|
|
|
item.setIcon(R.drawable.ic_menu_bookmark_remove);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case R.id.share:
|
|
|
|
shareCurrentUrl();
|
|
|
|
return true;
|
|
|
|
case R.id.reload:
|
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.doReload();
|
|
|
|
return true;
|
|
|
|
case R.id.forward:
|
|
|
|
tab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (tab != null)
|
|
|
|
tab.doForward();
|
|
|
|
return true;
|
|
|
|
case R.id.save_as_pdf:
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("SaveAs:PDF", null));
|
|
|
|
return true;
|
|
|
|
case R.id.settings:
|
|
|
|
intent = new Intent(this, GeckoPreferences.class);
|
|
|
|
startActivity(intent);
|
|
|
|
return true;
|
|
|
|
case R.id.addons:
|
2012-10-05 14:51:18 -07:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:addons");
|
2012-07-26 23:52:41 -07:00
|
|
|
return true;
|
|
|
|
case R.id.downloads:
|
2012-10-05 14:51:18 -07:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:downloads");
|
2012-07-26 23:52:41 -07:00
|
|
|
return true;
|
|
|
|
case R.id.apps:
|
2012-10-05 14:51:18 -07:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:apps");
|
2012-07-26 23:52:41 -07:00
|
|
|
return true;
|
|
|
|
case R.id.char_encoding:
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("CharEncoding:Get", null));
|
|
|
|
return true;
|
|
|
|
case R.id.find_in_page:
|
|
|
|
mFindInPageBar.show();
|
|
|
|
return true;
|
|
|
|
case R.id.desktop_mode:
|
|
|
|
Tab selectedTab = Tabs.getInstance().getSelectedTab();
|
|
|
|
if (selectedTab == null)
|
|
|
|
return true;
|
|
|
|
JSONObject args = new JSONObject();
|
|
|
|
try {
|
|
|
|
args.put("desktopMode", !item.isChecked());
|
|
|
|
args.put("tabId", selectedTab.getId());
|
|
|
|
} catch (JSONException e) {
|
|
|
|
Log.e(LOGTAG, "error building json arguments");
|
|
|
|
}
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("DesktopMode:Change", args.toString()));
|
|
|
|
return true;
|
2012-11-28 18:55:05 -08:00
|
|
|
case R.id.private_browsing:
|
2012-10-09 11:26:33 -07:00
|
|
|
Tabs.getInstance().loadUrl("about:home", Tabs.LOADURL_NEW_TAB | Tabs.LOADURL_PRIVATE);
|
|
|
|
return true;
|
2012-07-26 23:52:41 -07:00
|
|
|
default:
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
}
|
2012-08-26 21:33:11 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the app has been launched a certain number of times, and we haven't asked for feedback before,
|
|
|
|
* open a new tab with about:feedback when launching the app from the icon shortcut.
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
protected void onNewIntent(Intent intent) {
|
|
|
|
super.onNewIntent(intent);
|
|
|
|
|
2012-10-11 20:16:35 -07:00
|
|
|
if (!Intent.ACTION_MAIN.equals(intent.getAction()) || !mInitialized)
|
2012-08-26 21:33:11 -07:00
|
|
|
return;
|
|
|
|
|
2012-10-08 01:54:23 -07:00
|
|
|
(new GeckoAsyncTask<Void, Void, Boolean>(mAppContext, GeckoAppShell.getHandler()) {
|
2012-08-26 21:33:11 -07:00
|
|
|
@Override
|
|
|
|
public synchronized Boolean doInBackground(Void... params) {
|
|
|
|
// Check to see how many times the app has been launched.
|
|
|
|
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
String keyName = getPackageName() + ".feedback_launch_count";
|
|
|
|
int launchCount = settings.getInt(keyName, 0);
|
|
|
|
if (launchCount >= FEEDBACK_LAUNCH_COUNT)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// Increment the launch count and store the new value.
|
|
|
|
launchCount++;
|
|
|
|
settings.edit().putInt(keyName, launchCount).commit();
|
|
|
|
|
|
|
|
// If we've reached our magic number, show the feedback page.
|
|
|
|
return launchCount == FEEDBACK_LAUNCH_COUNT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(Boolean shouldShowFeedbackPage) {
|
|
|
|
if (shouldShowFeedbackPage)
|
2012-10-05 14:51:18 -07:00
|
|
|
Tabs.getInstance().loadUrlInTab("about:feedback");
|
2012-08-26 21:33:11 -07:00
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void resetFeedbackLaunchCount() {
|
|
|
|
GeckoBackgroundThread.post(new Runnable() {
|
|
|
|
@Override
|
|
|
|
public synchronized void run() {
|
|
|
|
SharedPreferences settings = getPreferences(Activity.MODE_PRIVATE);
|
|
|
|
settings.edit().putInt(getPackageName() + ".feedback_launch_count", 0).commit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private void getLastUrl() {
|
2012-10-08 01:54:23 -07:00
|
|
|
(new GeckoAsyncTask<Void, Void, String>(mAppContext, GeckoAppShell.getHandler()) {
|
2012-08-26 21:33:11 -07:00
|
|
|
@Override
|
|
|
|
public synchronized String doInBackground(Void... params) {
|
|
|
|
// Get the most recent URL stored in browser history.
|
|
|
|
String url = "";
|
|
|
|
Cursor c = BrowserDB.getRecentHistory(getContentResolver(), 1);
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
url = c.getString(c.getColumnIndexOrThrow(Combined.URL));
|
|
|
|
}
|
|
|
|
c.close();
|
|
|
|
return url;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onPostExecute(String url) {
|
|
|
|
// Don't bother sending a message if there is no URL.
|
|
|
|
if (url.length() > 0)
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Feedback:LastUrl", url));
|
|
|
|
}
|
|
|
|
}).execute();
|
|
|
|
}
|
2012-06-11 15:18:40 -07:00
|
|
|
}
|