get rid of contentAreaContextOverlay.xul, make view source in context menu work.

This commit is contained in:
blakeross%telocity.com 2002-04-05 07:37:59 +00:00
parent 32d78a4f1d
commit 4f3dca1051
2 changed files with 218 additions and 12 deletions

View File

@ -1179,16 +1179,50 @@ function OpenAddressbook()
"chrome,extrachrome,menubar,resizable,status,toolbar");
}
function BrowserViewSource()
function BrowserViewSourceOfDocument(aDocument)
{
var focusedWindow = document.commandDispatcher.focusedWindow;
if (focusedWindow == window)
focusedWindow = _content;
var docCharset;
var pageCookie;
var webNav;
if (focusedWindow)
var docCharset = "charset=" + focusedWindow.document.characterSet;
// Get the document charset
docCharset = "charset=" + aDocument.characterSet;
BrowserViewSourceOfURL(getWebNavigation().currentURI.spec, docCharset);
// Get the nsIWebNavigation associated with the document
try {
var win;
var ifRequestor;
// Get the DOMWindow for the requested document. If the DOMWindow
// cannot be found, then just use the _content window...
//
// XXX: This is a bit of a hack...
win = aDocument.defaultView;
if (win == window) {
win = _content;
}
ifRequestor = win.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
webNav = ifRequestor.getInterface(Components.interfaces.nsIWebNavigation);
} catch(err) {
// If nsIWebNavigation cannot be found, just get the one for the whole
// window...
webNav = getWebNavigation();
}
//
// Get the 'PageDescriptor' for the current document. This allows the
// view-source to access the cached copy of the content rather than
// refetching it from the network...
//
try{
var PageLoader = webNav.QueryInterface(Components.interfaces.nsIWebPageDescriptor);
pageCookie = PageLoader.currentDescriptor;
} catch(err) {
// If no page descriptor is available, just use the view-source URL...
}
BrowserViewSourceOfURL(webNav.currentURI.spec, docCharset, pageCookie);
}
function BrowserViewSourceOfURL(url, charset)

View File

@ -25,8 +25,6 @@ Contributor(s): ______________________________________. -->
<?xul-overlay href="chrome://browser/content/navigatorOverlay.xul"?>
<?xul-overlay href="chrome://browser/content/bookmarks/bookmarksOverlay.xul"?>
<?xul-overlay href="chrome://communicator/content/contentAreaContextOverlay.xul"?>
<!DOCTYPE window [
<!ENTITY % brandDTD SYSTEM "chrome://global/locale/brand.dtd" >
@ -35,8 +33,10 @@ Contributor(s): ______________________________________. -->
%buildDTD;
<!ENTITY % navigatorDTD SYSTEM "chrome://browser/locale/navigator.dtd" >
%navigatorDTD;
<!ENTITY % policyDTD SYSTEM "chrome://browser/locale/policy/policy.dtd" >
%policyDTD;
<!--<!ENTITY % policyDTD SYSTEM "chrome://browser/locale/policy/policy.dtd" >
%policyDTD;-->
<!ENTITY % contextMenuDTD SYSTEM "chrome://communicator/locale/contentAreaCommands.dtd" >
%contextMenuDTD;
]>
<window id="main-window"
@ -76,6 +76,15 @@ Contributor(s): ______________________________________. -->
<script type="application/x-javascript" src="chrome://browser/content/policy/policy.js"/>
<script type="application/x-javascript" src="chrome://browser/content/utilityOverlay.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/builtinURLs.js"/>
<script type="application/x-javascript">
// Global variable that holds the nsContextMenu instance.
var gContextMenu = null;
// Global variable that caches the default search engine info
var gDefaultEngine = null;
</script>
<script type="application/x-javascript" src="chrome://communicator/content/nsContextMenu.js"/>
<script type="application/x-javascript" src="chrome://communicator/content/contentAreaUtils.js"/>
<!-- hook for stringbundle overlays -->
<stringbundleset id="stringbundleset">
@ -118,7 +127,170 @@ Contributor(s): ______________________________________. -->
<popupset id="bookmarksPopupset"/>
<!-- context menu -->
<popupset id="contentAreaContextSet"/>
<popupset id="contentAreaContextSet">
<!-- This is a generic context menu for a content area. It contains
each and every possible menu choice. The appropriate items are
hidden/shown upon display, based on what the user has clicked-on.
-->
<popup id="contentAreaContextMenu"
onpopupshowing="gContextMenu = new nsContextMenu( this ); return gContextMenu.shouldDisplay;"
onpopuphiding="gContextMenu = null;">
<menuitem id="context-openlinkintab"
label="&openLinkCmdInTab.label;"
accesskey="&openLinkCmdInTab.accesskey;"
oncommand="gContextMenu.openLinkInTab();"/>
<menuitem id="context-openlink"
label="&openLinkCmd.label;"
accesskey="&openLinkCmd.accesskey;"
oncommand="gContextMenu.openLink();"/>
<menuseparator id="context-sep-open"/>
<menuitem id="context-bookmarklink"
label="&bookmarkLinkCmd.label;"
accesskey="&bookmarkLinkCmd.accesskey;"
oncommand="BookmarksUtils.addBookmark(gContextMenu.linkURL(),
gContextMenu.linkText(),
undefined, false);"/>
<menuitem id="context-savelink"
label="&saveLinkCmd.label;"
accesskey="&saveLinkCmd.accesskey;"
oncommand="gContextMenu.saveLink();"/>
<menuitem id="context-copyemail"
label="&copyEmailCmd.label;"
accesskey="&copyEmailCmd.accesskey;"
oncommand="gContextMenu.copyEmail();"/>
<menuitem id="context-copylink"
label="&copyLinkCmd.label;"
accesskey="&copyLinkCmd.accesskey;"
command="cmd_copyLink"/>
<menuseparator id="context-sep-copylink"/>
<menuitem id="context-viewimage"
label="&viewImageCmd.label;"
accesskey="&viewImageCmd.accesskey;"
oncommand="gContextMenu.viewImage();"/>
<menuitem id="context-copyimage"
label="&copyImageCmd.label;"
accesskey="&copyImageCmd.accesskey;"
command="cmd_copyImageLocation"/>
<menuseparator id="context-sep-copyimage"/>
<menuitem id="context-saveimage"
label="&saveImageCmd.label;"
accesskey="&saveImageCmd.accesskey;"
oncommand="gContextMenu.saveImage();"/>
<menuitem id="context-setWallpaper"
label="&setWallpaperCmd.label;"
accesskey="&setWallpaperCmd.accesskey;"
oncommand="gContextMenu.setWallpaper();"/>
<menuseparator id="context-sep-setWallpaper"/>
<menuitem id="context-back"
label="&goBackCmd.label;"
accesskey="&goBackCmd.accesskey;"
oncommand="BrowserBack()"/>
<menuitem id="context-forward"
label="&goForwardCmd.label;"
accesskey="&goForwardCmd.accesskey;"
oncommand="BrowserForward()"/>
<menuitem id="context-reload"
label="&reloadCmd.label;"
accesskey="&reloadCmd.accesskey;"
oncommand="BrowserReload();"/>
<menuitem id="context-stop"
label="&stopCmd.label;"
accesskey="&stopCmd.accesskey;"
disabled="true"
oncommand="BrowserStop();"/>
<menuseparator id="context-sep-stop"/>
<menuitem id="context-bookmarkpage"
label="&bookmarkPageCmd.label;"
accesskey="&bookmarkPageCmd.accesskey;"
oncommand="gContextMenu.addBookmark();"/>
<menuitem id="context-savepage"
label="&savePageCmd.label;"
accesskey="&savePageCmd.accesskey;"
oncommand="saveDocument(window._content.document);"/>
<menuseparator id="context-sep-viewbgimage"/>
<menuitem id="context-viewbgimage"
label="&viewBGImageCmd.label;"
accesskey="&viewBGImageCmd.accesskey;"
oncommand="gContextMenu.viewBGImage();"/>
<menuitem id="context-undo"
label="&undoCmd.label;"
accesskey="&undoCmd.accesskey;"
command="cmd_undo"/>
<menuseparator id="context-sep-undo"/>
<menuitem id="context-cut"
label="&cutCmd.label;"
accesskey="&cutCmd.accesskey;"
command="cmd_cut"/>
<menuitem id="context-copy"
label="&copyCmd.label;"
accesskey="&copyCmd.accesskey;"
command="cmd_copy"/>
<menuitem id="context-paste"
label="&pasteCmd.label;"
accesskey="&pasteCmd.accesskey;"
command="cmd_paste"/>
<menuitem id="context-delete"
label="&deleteCmd.label;"
accesskey="&deleteCmd.accesskey;"
command="cmd_delete"/>
<menuseparator id="context-sep-paste"/>
<menuitem id="context-selectall"
label="&selectAllCmd.label;"
accesskey="&selectAllCmd.accesskey;"
command="cmd_selectAll"/>
<menuseparator id="context-sep-selectall"/>
<menuitem id="context-searchselect"
accesskey="&search.accesskey;"
oncommand="OpenSearch('internet', false, gContextMenu.searchSelected(), true);"/>
<menuseparator id="frame-sep"/>
<menu id="frame" label="&thisFrameMenu.label;" accesskey="&thisFrameMenu.accesskey;">
<menupopup id="frame_popup">
<menuitem label="&showOnlyThisFrameCmd.label;"
accesskey="&showOnlyThisFrameCmd.accesskey;"
oncommand="gContextMenu.showOnlyThisFrame();"/>
<menuitem label="&openFrameCmdInTab.label;"
accesskey="&openFrameCmdInTab.accesskey;"
oncommand="gContextMenu.openFrameInTab();"/>
<menuitem label="&openFrameCmd.label;"
accesskey="&openFrameCmd.accesskey;"
oncommand="gContextMenu.openFrame();"/>
<menuseparator/>
<menuitem id="context-reload-frame"
label="&reloadFrameCmd.label;"
accesskey="&reloadFrameCmd.accesskey;"
oncommand="gContextMenu.reloadFrame();"/>
<menuseparator/>
<menuitem label="&bookmarkFrameCmd.label;"
accesskey="&bookmarkFrameCmd.accesskey;"
oncommand="gContextMenu.addBookmarkForFrame();"/>
<menuitem id="saveframeas"
label="&saveFrameCmd.label;"
accesskey="&saveFrameCmd.accesskey;"
oncommand="saveDocument(gContextMenu.target.ownerDocument);"/>
<menuseparator/>
<menuitem label="&viewFrameSourceCmd.label;"
accesskey="&viewFrameSourceCmd.accesskey;"
oncommand="gContextMenu.viewFrameSource();"/>
<menuitem label="&viewFrameInfoCmd.label;"
accesskey="&viewFrameInfoCmd.accesskey;"
oncommand="gContextMenu.viewFrameInfo();"/>
</menupopup>
</menu>
<menuseparator id="context-sep-properties"/>
<menuitem id="context-viewsource"
label="&viewPageSourceCmd.label;"
accesskey="&viewPageSourceCmd.accesskey;"
oncommand="BrowserViewSourceOfDocument(_content.document);"/>
<menuitem id="context-viewinfo"
label="&viewPageInfoCmd.label;"
accesskey="&viewPageInfoCmd.accesskey;"
oncommand="gContextMenu.viewInfo();"/>
<menuitem id="context-metadata"
label="&metadataCmd.label;"
accesskey="&metadataCmd.accesskey;"
oncommand="gContextMenu.showMetadata();"/>
</popup>
</popupset>
<script type="application/x-javascript">
var gBookmarkPopup = null;