Bug 709888 - Remove UA switcher. r=mfinkle

This commit is contained in:
Brian Nicholson 2012-01-12 12:26:26 -08:00
Родитель 158b1d0c69
Коммит 1e663bbff4
6 изменённых файлов: 1 добавлений и 114 удалений

Просмотреть файл

@ -438,7 +438,6 @@ abstract public class GeckoApp
MenuItem bookmark = aMenu.findItem(R.id.bookmark);
MenuItem forward = aMenu.findItem(R.id.forward);
MenuItem share = aMenu.findItem(R.id.share);
MenuItem agentMode = aMenu.findItem(R.id.agent_mode);
MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf);
MenuItem downloads = aMenu.findItem(R.id.downloads);
@ -447,7 +446,6 @@ abstract public class GeckoApp
forward.setEnabled(false);
share.setEnabled(false);
saveAsPDF.setEnabled(false);
agentMode.setEnabled(false);
return true;
}
@ -464,12 +462,11 @@ abstract public class GeckoApp
forward.setEnabled(tab.canDoForward());
// Disable share and agentMode menuitems for about:, chrome: and file: URIs
// Disable share menuitem for about:, chrome: and file: URIs
String scheme = Uri.parse(tab.getURL()).getScheme();
boolean enabled = !(scheme.equals("about") || scheme.equals("chrome") ||
scheme.equals("file"));
share.setEnabled(enabled);
agentMode.setEnabled(enabled);
// Disable save as PDF for about:home and xul pages
saveAsPDF.setEnabled(!(tab.getURL().equals("about:home") ||
@ -541,19 +538,6 @@ abstract public class GeckoApp
intent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS);
startActivity(intent);
return true;
case R.id.agent_mode:
Tab selectedTab = Tabs.getInstance().getSelectedTab();
if (selectedTab == null)
return true;
JSONObject args = new JSONObject();
try {
args.put("agent", selectedTab.getAgentMode() == Tab.AgentMode.MOBILE ? "desktop" : "mobile");
args.put("tabId", selectedTab.getId());
} catch (JSONException e) {
Log.e(LOGTAG, "error building json arguments");
}
GeckoAppShell.sendEventToGecko(new GeckoEvent("AgentMode:Change", args.toString()));
return true;
default:
return super.onOptionsItemSelected(item);
}
@ -964,16 +948,6 @@ abstract public class GeckoApp
}
});
}
} else if (event.equals("AgentMode:Changed")) {
Tab.AgentMode agentMode = message.getString("agentMode").equals("mobile") ? Tab.AgentMode.MOBILE : Tab.AgentMode.DESKTOP;
int tabId = message.getInt("tabId");
Tab tab = Tabs.getInstance().getTab(tabId);
if (tab == null)
return;
tab.setAgentMode(agentMode);
if (tab == Tabs.getInstance().getSelectedTab())
updateAgentModeMenuItem(tab, agentMode);
} else if (event.equals("Permissions:Data")) {
String host = message.getString("host");
JSONArray permissions = message.getJSONArray("permissions");
@ -1028,20 +1002,6 @@ abstract public class GeckoApp
}
}
void updateAgentModeMenuItem(final Tab tab, final Tab.AgentMode agentMode) {
if (sMenu == null)
return;
mMainHandler.post(new Runnable() {
public void run() {
if (Tabs.getInstance().isSelectedTab(tab)) {
int strId = agentMode == Tab.AgentMode.MOBILE ? R.string.agent_request_desktop : R.string.agent_request_mobile;
sMenu.findItem(R.id.agent_mode).setTitle(getString(strId));
}
}
});
}
/**
* @param aPermissions
* Array of JSON objects to represent site permissions.
@ -1181,8 +1141,6 @@ abstract public class GeckoApp
else
hideAboutHome();
updateAgentModeMenuItem(tab, tab.getAgentMode());
mMainHandler.post(new Runnable() {
public void run() {
mAutoCompletePopup.hide();
@ -1584,7 +1542,6 @@ abstract public class GeckoApp
GeckoAppShell.registerGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
GeckoAppShell.registerGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
GeckoAppShell.registerGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
GeckoAppShell.registerGeckoEventListener("AgentMode:Changed", GeckoApp.mAppContext);
GeckoAppShell.registerGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext);
GeckoAppShell.registerGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
GeckoAppShell.registerGeckoEventListener("Downloads:Done", GeckoApp.mAppContext);
@ -1820,7 +1777,6 @@ abstract public class GeckoApp
GeckoAppShell.unregisterGeckoEventListener("Toast:Show", GeckoApp.mAppContext);
GeckoAppShell.unregisterGeckoEventListener("ToggleChrome:Hide", GeckoApp.mAppContext);
GeckoAppShell.unregisterGeckoEventListener("ToggleChrome:Show", GeckoApp.mAppContext);
GeckoAppShell.unregisterGeckoEventListener("AgentMode:Changed", GeckoApp.mAppContext);
GeckoAppShell.unregisterGeckoEventListener("FormAssist:AutoComplete", GeckoApp.mAppContext);
GeckoAppShell.unregisterGeckoEventListener("Permissions:Data", GeckoApp.mAppContext);
GeckoAppShell.unregisterGeckoEventListener("Downloads:Done", GeckoApp.mAppContext);

Просмотреть файл

@ -56,7 +56,6 @@ import java.util.List;
import org.mozilla.gecko.db.BrowserDB;
public class Tab {
public static enum AgentMode { MOBILE, DESKTOP };
private static final String LOGTAG = "GeckoTab";
private static final int kThumbnailWidth = 120;
private static final int kThumbnailHeight = 80;
@ -78,7 +77,6 @@ public class Tab {
private boolean mBookmark;
private HashMap<String, DoorHanger> mDoorHangers;
private long mFaviconLoadId;
private AgentMode mAgentMode = AgentMode.MOBILE;
private String mDocumentURI;
private String mContentType;
@ -445,12 +443,4 @@ public class Tab {
setBookmark(false);
}
}
public void setAgentMode(AgentMode agentMode) {
mAgentMode = agentMode;
}
public AgentMode getAgentMode() {
return mAgentMode;
}
}

Просмотреть файл

@ -74,8 +74,6 @@
<!ENTITY share "Share">
<!ENTITY save_as_pdf "Save as PDF">
<!ENTITY agent_request_desktop "Request Desktop Site">
<!ENTITY agent_request_mobile "Request Mobile Site">
<!ENTITY contextmenu_open_new_tab "Open in New Tab">
<!ENTITY contextmenu_add_to_launcher "Add to Home Screen">

Просмотреть файл

@ -21,9 +21,6 @@
android:icon="@drawable/ic_menu_save_as_pdf"
android:title="@string/save_as_pdf" />
<item android:id="@+id/agent_mode"
android:title="@string/agent_request_desktop" />
<item android:id="@+id/settings"
android:title="@string/settings" />

Просмотреть файл

@ -46,8 +46,6 @@
<string name="share">&share;</string>
<string name="save_as_pdf">&save_as_pdf;</string>
<string name="agent_request_desktop">&agent_request_desktop;</string>
<string name="agent_request_mobile">&agent_request_mobile;</string>
<string name="settings">&settings;</string>
<string name="settings_title">&settings_title;</string>

Просмотреть файл

@ -105,9 +105,6 @@ const kElementsReceivingInput = {
video: true
};
const UA_MODE_MOBILE = "mobile";
const UA_MODE_DESKTOP = "desktop";
function dump(a) {
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage(a);
}
@ -224,7 +221,6 @@ var BrowserApp = {
Services.obs.addObserver(this, "PanZoom:PanZoom", false);
Services.obs.addObserver(this, "FullScreen:Exit", false);
Services.obs.addObserver(this, "Viewport:Change", false);
Services.obs.addObserver(this, "AgentMode:Change", false);
Services.obs.addObserver(this, "SearchEngines:Get", false);
function showFullScreenWarning() {
@ -835,11 +831,6 @@ var BrowserApp = {
this.getPreferences(aData);
} else if (aTopic == "Preferences:Set") {
this.setPreferences(aData);
} else if (aTopic == "AgentMode:Change") {
let args = JSON.parse(aData);
let tab = this.getTabForId(args.tabId);
tab.setAgentMode(args.agent);
tab.browser.reload();
} else if (aTopic == "ScrollTo:FocusedInput") {
this.scrollToFocusedInput(browser);
} else if (aTopic == "Sanitize:ClearAll") {
@ -1294,8 +1285,6 @@ function Tab(aURL, aParams) {
this.browser = null;
this.vbox = null;
this.id = 0;
this.agentMode = UA_MODE_MOBILE;
this.lastHost = null;
this.create(aURL, aParams);
this._viewport = { x: 0, y: 0, width: gScreenWidth, height: gScreenHeight, offsetX: 0, offsetY: 0,
pageWidth: gScreenWidth, pageHeight: gScreenHeight, zoom: 1.0 };
@ -1359,7 +1348,6 @@ Tab.prototype = {
this.browser.addEventListener("pagehide", this, true);
this.browser.addEventListener("pageshow", this, true);
Services.obs.addObserver(this, "http-on-modify-request", false);
Services.obs.addObserver(this, "document-shown", false);
if (!aParams.delayLoad) {
@ -1385,29 +1373,6 @@ Tab.prototype = {
}
},
setAgentMode: function(aMode) {
if (this.agentMode != aMode) {
this.agentMode = aMode;
sendMessageToJava({
gecko: {
type: "AgentMode:Changed",
agentMode: aMode,
tabId: this.id
}
});
}
},
setHostFromURL: function(aURL) {
let uri = Services.io.newURI(aURL, null, null);
let host = uri.asciiHost;
if (this.lastHost != host) {
this.lastHost = host;
// TODO: remember mobile/desktop selection for each host (bug 705840)
this.setAgentMode(UA_MODE_MOBILE);
}
},
destroy: function() {
if (!this.browser)
return;
@ -1428,7 +1393,6 @@ Tab.prototype = {
BrowserApp.deck.removeChild(this.vbox);
BrowserApp.deck.selectedPanel = selectedPanel;
Services.obs.removeObserver(this, "http-on-modify-request", false);
this.browser = null;
this.vbox = null;
this.documentIdForCurrentViewport = null;
@ -1982,22 +1946,6 @@ Tab.prototype = {
observe: function(aSubject, aTopic, aData) {
switch (aTopic) {
case "http-on-modify-request":
if (!(aSubject instanceof Ci.nsIHttpChannel))
return;
let channel = aSubject.QueryInterface(Ci.nsIHttpChannel);
if (!(channel.loadFlags & Ci.nsIChannel.LOAD_DOCUMENT_URI))
return;
let channelWindow = this.getWindowForRequest(channel);
if (channelWindow == this.browser.contentWindow) {
this.setHostFromURL(channel.URI.spec);
if (this.agentMode == UA_MODE_DESKTOP)
channel.setRequestHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1", false);
}
break;
case "document-shown":
// Is it on the top level?
let contentDocument = aSubject;