2012-06-18 10:03:03 -07:00
|
|
|
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; 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/. */
|
|
|
|
|
|
|
|
#filter substitution
|
|
|
|
package @ANDROID_PACKAGE_NAME@;
|
|
|
|
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.util.Log;
|
2012-08-27 17:11:44 -07:00
|
|
|
import android.view.View;
|
2012-07-27 17:53:54 -07:00
|
|
|
import android.view.MenuItem;
|
2012-08-27 17:11:44 -07:00
|
|
|
import android.widget.LinearLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
import android.widget.RelativeLayout;
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import java.net.URL;
|
2012-07-27 17:53:54 -07:00
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
import org.mozilla.gecko.GeckoApp;
|
|
|
|
import org.mozilla.gecko.GeckoAppShell;
|
2012-08-31 04:05:50 -07:00
|
|
|
import org.mozilla.gecko.GeckoEvent;
|
2012-08-27 17:11:44 -07:00
|
|
|
import org.mozilla.gecko.WebAppAllocator;
|
|
|
|
import org.mozilla.gecko.Tab;
|
|
|
|
import org.mozilla.gecko.Tabs;
|
2012-06-18 10:03:03 -07:00
|
|
|
import org.mozilla.gecko.R;
|
|
|
|
|
|
|
|
public class WebApp extends GeckoApp {
|
2012-08-27 17:11:44 -07:00
|
|
|
private URL mOrigin;
|
|
|
|
private TextView mTitlebarText = null;
|
|
|
|
private View mTitlebar = null;
|
2012-06-18 10:03:03 -07:00
|
|
|
private static final String LOGTAG = "WebApp";
|
|
|
|
|
2012-08-27 17:11:44 -07:00
|
|
|
protected int getIndex() { return 0; }
|
|
|
|
|
2012-06-18 10:03:03 -07:00
|
|
|
@Override
|
|
|
|
public int getLayout() { return R.layout.web_app; }
|
2012-07-23 13:08:48 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasTabsSideBar() { return false; }
|
2012-06-18 10:03:03 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState)
|
|
|
|
{
|
|
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
2012-08-27 17:11:44 -07:00
|
|
|
String action = getIntent().getAction();
|
2012-06-18 10:03:03 -07:00
|
|
|
Bundle extras = getIntent().getExtras();
|
|
|
|
String title = extras != null ? extras.getString(Intent.EXTRA_SHORTCUT_NAME) : null;
|
|
|
|
setTitle(title != null ? title : "Web App");
|
2012-08-27 17:11:44 -07:00
|
|
|
|
|
|
|
mTitlebarText = (TextView)findViewById(R.id.webapp_title);
|
|
|
|
mTitlebar = findViewById(R.id.webapp_titlebar);
|
|
|
|
if (!action.startsWith(ACTION_WEBAPP_PREFIX)) {
|
|
|
|
Log.e(LOGTAG, "WebApp launch, but intent action is " + action + "!");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to use the origin stored in the WebAppAllocator first
|
|
|
|
String origin = WebAppAllocator.getInstance(this).getAppForIndex(getIndex());
|
|
|
|
try {
|
|
|
|
mOrigin = new URL(origin);
|
|
|
|
} catch (java.net.MalformedURLException ex) {
|
|
|
|
// If that failed fall back to the origin stored in the shortcut
|
|
|
|
Log.i(LOGTAG, "Webapp is not registered with allocator");
|
|
|
|
try {
|
|
|
|
mOrigin = new URL(getIntent().getData().toString());
|
|
|
|
} catch (java.net.MalformedURLException ex2) {
|
|
|
|
Log.e(LOGTAG, "Unable to parse intent url: ", ex);
|
|
|
|
}
|
|
|
|
}
|
2012-06-18 10:03:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getPackageName() {
|
|
|
|
return "@ANDROID_PACKAGE_NAME@";
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getContentProcessName() {
|
|
|
|
return "@MOZ_CHILD_PROCESS_NAME@";
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDefaultUAString() {
|
|
|
|
String deviceType = "Mobile";
|
|
|
|
if (GeckoAppShell.isTablet())
|
|
|
|
deviceType = "Tablet";
|
|
|
|
return "Mozilla/5.0 (Android; " + deviceType + "; rv:@MOZ_APP_VERSION@) Gecko/@MOZ_APP_VERSION@ Firefox/@MOZ_APP_VERSION@";
|
|
|
|
}
|
|
|
|
|
|
|
|
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 "Redirector/@MOZ_APP_VERSION@ (Android; rv:@MOZ_APP_VERSION@)";
|
|
|
|
return getDefaultUAString();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected String getDefaultProfileName() {
|
|
|
|
String action = getIntent().getAction();
|
|
|
|
if (!action.startsWith(ACTION_WEBAPP_PREFIX)) {
|
|
|
|
Log.e(LOGTAG, "WebApp launch, but intent action is " + action + "!");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "webapp" + action.substring(ACTION_WEBAPP_PREFIX.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onOptionsItemSelected(MenuItem item) {
|
|
|
|
#ifdef MOZ_PROFILING
|
|
|
|
if (item.getItemId() == R.id.toggle_profiling) {
|
|
|
|
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("ToggleProfiling", null));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return super.onOptionsItemSelected(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef MOZ_LINKER_EXTRACT
|
|
|
|
@Override
|
|
|
|
public boolean linkerExtract() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
#endif
|
2012-08-27 17:11:44 -07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTabChanged(Tab tab, Tabs.TabEvents msg, Object data) {
|
|
|
|
switch(msg) {
|
|
|
|
case LOCATION_CHANGE:
|
|
|
|
if (Tabs.getInstance().isSelectedTab(tab)) {
|
|
|
|
try {
|
|
|
|
String title = tab.getURL();
|
|
|
|
URL page = new URL(title);
|
|
|
|
mTitlebarText.setText(page.getProtocol() + "://" + page.getHost());
|
|
|
|
|
|
|
|
if (mOrigin != null && mOrigin.getHost().equals(page.getHost()))
|
|
|
|
mTitlebar.setVisibility(View.GONE);
|
|
|
|
else
|
|
|
|
mTitlebar.setVisibility(View.VISIBLE);
|
|
|
|
} catch (java.net.MalformedURLException ex) {
|
|
|
|
Log.e(LOGTAG, "Unable to parse url: ", ex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
super.onTabChanged(tab, msg, data);
|
|
|
|
}
|
2012-09-12 13:36:36 -07:00
|
|
|
|
|
|
|
protected void connectGeckoLayerClient() {
|
|
|
|
super.connectGeckoLayerClient();
|
|
|
|
getLayerView().setOverScrollMode(View.OVER_SCROLL_NEVER);
|
|
|
|
}
|
2012-06-18 10:03:03 -07:00
|
|
|
};
|
|
|
|
|