Bug 384854 - Hide certain context menu options (view source, view selection source, etc) when viewing non-text content (images, plugins) p=Ehsan Akhgari <ehsan.akhgari@gmail.com> r=mano

This commit is contained in:
asqueella@gmail.com 2007-09-02 15:11:38 -07:00
parent 3464346525
commit e58ad36242
4 changed files with 39 additions and 14 deletions

View File

@ -20,6 +20,7 @@
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
@ -204,7 +205,8 @@
<menuseparator/>
<menuitem label="&viewFrameSourceCmd.label;"
accesskey="&viewFrameSourceCmd.accesskey;"
oncommand="gContextMenu.viewFrameSource();"/>
oncommand="gContextMenu.viewFrameSource();"
observes="isFrameImage"/>
<menuitem label="&viewFrameInfoCmd.label;"
accesskey="&viewFrameInfoCmd.accesskey;"
oncommand="gContextMenu.viewFrameInfo();"/>
@ -214,15 +216,18 @@
<menuitem id="context-viewpartialsource-selection"
label="&viewPartialSourceForSelectionCmd.label;"
accesskey="&viewPartialSourceCmd.accesskey;"
oncommand="gContextMenu.viewPartialSource('selection');"/>
oncommand="gContextMenu.viewPartialSource('selection');"
observes="isImage"/>
<menuitem id="context-viewpartialsource-mathml"
label="&viewPartialSourceForMathMLCmd.label;"
accesskey="&viewPartialSourceCmd.accesskey;"
oncommand="gContextMenu.viewPartialSource('mathml');"/>
oncommand="gContextMenu.viewPartialSource('mathml');"
observes="isImage"/>
<menuitem id="context-viewsource"
label="&viewPageSourceCmd.label;"
accesskey="&viewPageSourceCmd.accesskey;"
oncommand="BrowserViewSourceOfDocument(content.document);"/>
oncommand="BrowserViewSourceOfDocument(content.document);"
observes="isImage"/>
<menuitem id="context-viewinfo"
label="&viewPageInfoCmd.label;"
accesskey="&viewPageInfoCmd.accesskey;"

View File

@ -23,6 +23,7 @@
# Ben Goodger <ben@bengoodger.com> (v2.0)
# Blake Ross <blakeross@telocity.com>
# Shawn Wilsher <me@shawnwilsher.com>
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
@ -155,6 +156,7 @@
oncommand="gPopupBlockerObserver.dontShowMessage();"/>
<broadcaster id="blockedPopupsSeparator"/>
<broadcaster id="isImage"/>
<broadcaster id="isFrameImage"/>
</broadcasterset>
<keyset id="mainKeyset">

View File

@ -3183,6 +3183,20 @@ var FullScreen =
}
};
/**
* Returns true if |aMimeType| is text-based, false otherwise.
*
* @param aMimeType
* The MIME type to check.
*/
function mimeTypeIsTextBased(aMimeType)
{
return /^text\/|\+xml$/.test(aMimeType) ||
aMimeType == "application/x-javascript" ||
aMimeType == "application/xml" ||
aMimeType == "mozilla.application/cached-xul";
}
function nsBrowserStatusHandler()
{
this.init();
@ -3281,14 +3295,6 @@ nsBrowserStatusHandler.prototype =
}
},
mimeTypeIsTextBased : function(contentType)
{
return /^text\/|\+xml$/.test(contentType) ||
contentType == "application/x-javascript" ||
contentType == "application/xml" ||
contentType == "mozilla.application/cached-xul";
},
onLinkIconAvailable : function(aBrowser)
{
if (gProxyFavIcon &&
@ -3408,7 +3414,7 @@ nsBrowserStatusHandler.prototype =
this.setDefaultStatus(msg);
// Disable menu entries for images, enable otherwise
if (content.document && this.mimeTypeIsTextBased(content.document.contentType))
if (content.document && mimeTypeIsTextBased(content.document.contentType))
this.isImage.removeAttribute('disabled');
else
this.isImage.setAttribute('disabled', 'true');
@ -3487,7 +3493,7 @@ nsBrowserStatusHandler.prototype =
selectedBrowser.lastURI = aLocationURI;
// Disable menu entries for images, enable otherwise
if (content.document && this.mimeTypeIsTextBased(content.document.contentType))
if (content.document && mimeTypeIsTextBased(content.document.contentType))
this.isImage.removeAttribute('disabled');
else
this.isImage.setAttribute('disabled', 'true');

View File

@ -40,6 +40,7 @@
# Michael Ventnor <ventnors_dogs234@yahoo.com.au>
# Simon Bünzli <zeniko@gmail.com>
# Gijs Kruitbosch <gijskruitbosch@gmail.com>
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
@ -59,6 +60,7 @@ function nsContextMenu(aXulMenu, aBrowser) {
this.target = null;
this.browser = null;
this.menu = null;
this.isFrameImage = false;
this.onTextInput = false;
this.onKeywordField = false;
this.onImage = false;
@ -97,6 +99,8 @@ nsContextMenu.prototype = {
this.menu = aPopup;
this.browser = aBrowser;
this.isFrameImage = document.getElementById("isFrameImage");
// Get contextual info.
this.setTarget(document.popupNode, document.popupRangeParent,
document.popupRangeOffset);
@ -213,6 +217,14 @@ nsContextMenu.prototype = {
this.showItem("frame", this.inFrame);
this.showItem("frame-sep", this.inFrame);
// Hide menu entries for images, show otherwise
if (this.inFrame) {
if (mimeTypeIsTextBased(this.target.ownerDocument.contentType))
this.isFrameImage.removeAttribute('hidden');
else
this.isFrameImage.setAttribute('hidden', 'true');
}
// BiDi UI
this.showItem("context-sep-bidi", top.gBidiUI);
this.showItem("context-bidi-text-direction-toggle",