Bug 707665 - Save as PDF option should be disabled for about:home and any XUL documents. r=mfinkle a=android-only

This commit is contained in:
Margaret Leibovic 2011-12-13 16:23:35 -08:00
parent b6eb805dd7
commit 5633818cb8
3 changed files with 39 additions and 4 deletions

View File

@ -456,11 +456,13 @@ abstract public class GeckoApp
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);
if (tab == null) {
bookmark.setEnabled(false);
forward.setEnabled(false);
share.setEnabled(false);
saveAsPDF.setEnabled(false);
return true;
}
@ -481,7 +483,11 @@ abstract public class GeckoApp
// Don't share about:, chrome: and file: URIs
String scheme = Uri.parse(tab.getURL()).getScheme();
share.setEnabled(!scheme.equals("about") && !scheme.equals("chrome") && !scheme.equals("file"));
share.setEnabled(!(scheme.equals("about") || scheme.equals("chrome") || scheme.equals("file")));
// 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")));
return true;
}
@ -667,7 +673,8 @@ abstract public class GeckoApp
tab.setFaviconLoadId(id);
}
void handleLocationChange(final int tabId, final String uri) {
void handleLocationChange(final int tabId, final String uri,
final String documentURI, final String contentType) {
final Tab tab = Tabs.getInstance().getTab(tabId);
if (tab == null)
return;
@ -681,6 +688,8 @@ abstract public class GeckoApp
String oldBaseURI = tab.getURL();
tab.updateURL(uri);
tab.setDocumentURI(documentURI);
tab.setContentType(contentType);
String baseURI = uri;
if (baseURI.indexOf('#') != -1)
@ -848,8 +857,10 @@ abstract public class GeckoApp
} else if (event.equals("Content:LocationChange")) {
final int tabId = message.getInt("tabID");
final String uri = message.getString("uri");
final String documentURI = message.getString("documentURI");
final String contentType = message.getString("contentType");
Log.i(LOGTAG, "URI - " + uri);
handleLocationChange(tabId, uri);
handleLocationChange(tabId, uri, documentURI, contentType);
} else if (event.equals("Content:SecurityChange")) {
final int tabId = message.getInt("tabID");
final String mode = message.getString("mode");

View File

@ -75,6 +75,8 @@ public class Tab {
private HashMap<String, DoorHanger> mDoorHangers;
private long mFaviconLoadId;
private AgentMode mAgentMode = AgentMode.MOBILE;
private String mDocumentURI;
private String mContentType;
static class HistoryEntry {
public final String mUri; // must never be null
@ -103,6 +105,8 @@ public class Tab {
mBookmark = false;
mDoorHangers = new HashMap<String, DoorHanger>();
mFaviconLoadId = 0;
mDocumentURI = "";
mContentType = "";
}
public int getId() {
@ -182,6 +186,22 @@ public class Tab {
}
}
public void setDocumentURI(String documentURI) {
mDocumentURI = documentURI;
}
public String getDocumentURI() {
return mDocumentURI;
}
public void setContentType(String contentType) {
mContentType = contentType;
}
public String getContentType() {
return mContentType;
}
public void updateTitle(String title) {
mTitle = (title == null ? "" : title);

View File

@ -1393,12 +1393,16 @@ Tab.prototype = {
let browser = BrowserApp.getBrowserForWindow(contentWin);
let uri = browser.currentURI.spec;
let documentURI = browser.contentDocument.documentURIObject.spec;
let contentType = browser.contentDocument.contentType;
let message = {
gecko: {
type: "Content:LocationChange",
tabID: this.id,
uri: uri
uri: uri,
documentURI: documentURI,
contentType: contentType
}
};